diff options
author | Alex Sakhartchouk <alexst@google.com> | 2012-02-01 14:30:36 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-02-01 14:30:36 -0800 |
commit | a8313025ecc6b1ff7ee624f82def6ea7793c16a8 (patch) | |
tree | b35ea57af055666d1acba14ebdeaf826245231e1 /tests/RenderScriptTests | |
parent | 2ff0188a9975b0e87f590618ec33ba51eebfdd05 (diff) | |
parent | 0c9523357f48a26c8214ccff0b0d95c6927ac0d3 (diff) | |
download | frameworks_base-a8313025ecc6b1ff7ee624f82def6ea7793c16a8.zip frameworks_base-a8313025ecc6b1ff7ee624f82def6ea7793c16a8.tar.gz frameworks_base-a8313025ecc6b1ff7ee624f82def6ea7793c16a8.tar.bz2 |
Merge "Making sure that parameter updates are properly propagated to RS. Cleanup of param creation code." into graphics-dev
Diffstat (limited to 'tests/RenderScriptTests')
11 files changed, 150 insertions, 158 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java index c417544..4098129 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java @@ -37,68 +37,65 @@ import android.util.Log; public class Float4Param extends ShaderParam { private static String TAG = "Float4Param"; - Float4 mValue; - Camera mCamera; LightBase mLight; - int mVecSize; public Float4Param(String name) { super(name); - mValue = new Float4(); } - public Float4Param(String name, float value) { + public Float4Param(String name, float x) { super(name); - mValue = new Float4(); - mValue.x = value; - mVecSize = 1; + set(x, 0, 0, 0, 1); } public Float4Param(String name, float x, float y) { super(name); - mValue = new Float4(); - mValue.x = x; - mValue.y = y; - mVecSize = 2; + set(x, y, 0, 0, 2); } public Float4Param(String name, float x, float y, float z) { super(name); - mValue = new Float4(); - mValue.x = x; - mValue.y = y; - mValue.z = z; - mVecSize = 3; + set(x, y, z, 0, 3); } public Float4Param(String name, float x, float y, float z, float w) { super(name); - mValue = new Float4(); - mValue.x = x; - mValue.y = y; - mValue.z = z; - mValue.w = w; - mVecSize = 4; + set(x, y, z, w, 4); + } + + void set(float x, float y, float z, float w, int vecSize) { + mData.float_value.x = x; + mData.float_value.y = y; + mData.float_value.z = z; + mData.float_value.w = w; + mData.float_vecSize = vecSize; + if (mField != null) { + mField.set_float_value(0, mData.float_value, false); + mField.set_float_vecSize(0, mData.float_vecSize, true); + } } public void setValue(Float4 v) { - mValue = v; + set(v.x, v.y, v.z, v.w, mData.float_vecSize); } public Float4 getValue() { - return mValue; + return mData.float_value; } public void setVecSize(int vecSize) { - mVecSize = vecSize; - } - - public void setCamera(Camera c) { - mCamera = c; + mData.float_vecSize = vecSize; + if (mField != null) { + mField.set_float_vecSize(0, mData.float_vecSize, true); + } } public void setLight(LightBase l) { mLight = l; + if (mField != null) { + mData.light = mLight.getRSData().getAllocation(); + mField.set_light(0, mData.light, true); + } } boolean findLight(String property) { @@ -139,16 +136,13 @@ public class Float4Param extends ShaderParam { return paramType; } - void initLocalData(RenderScriptGL rs) { - mRsFieldItem.type = getTypeFromName(); - mRsFieldItem.bufferOffset = mOffset; - mRsFieldItem.float_value = mValue; - mRsFieldItem.float_vecSize = mVecSize; + void initLocalData() { + mData.type = getTypeFromName(); if (mCamera != null) { - mRsFieldItem.camera = mCamera.getRSData().getAllocation(); + mData.camera = mCamera.getRSData().getAllocation(); } if (mLight != null) { - mRsFieldItem.light = mLight.getRSData().getAllocation(); + mData.light = mLight.getRSData().getAllocation(); } } } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java index ca03263..ff6bbba 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java @@ -129,7 +129,7 @@ public class FragmentShader extends Shader { linkConstants(rs); if (mPerShaderConstants != null) { item.shaderConst = mConstantBuffer; - item.shaderConstParams = mConstantBufferParams; + item.shaderConstParams = mConstantBufferParams.getAllocation(); mProgram.bindConstants(item.shaderConst, 0); } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java index eaf36fe..2b6c1b9 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java @@ -49,9 +49,6 @@ public class Renderable extends RenderableBase { HashMap<String, ShaderParam> mSourceParams; - ArrayList<ShaderParam> mVertexParamList; - ArrayList<ShaderParam> mFragmentParamList; - Mesh mMesh; int mMeshIndex; @@ -74,8 +71,6 @@ public class Renderable extends RenderableBase { public Renderable() { mSourceParams = new HashMap<String, ShaderParam>(); - mVertexParamList = new ArrayList<ShaderParam>(); - mFragmentParamList = new ArrayList<ShaderParam>(); } public void setCullType(int cull) { @@ -160,20 +155,6 @@ public class Renderable extends RenderableBase { mRsField.set(mRsFieldItem, 0, true); } - void linkConstants() { - // Assign all the fragment params - if (mFragmentConstants != null) { - Element fragmentConst = mFragmentConstants.getType().getElement(); - ShaderParam.fillInParams(fragmentConst, mSourceParams, mTransform, mFragmentParamList); - } - - // Assign all the vertex params - if (mVertexConstants != null) { - Element vertexConst = mVertexConstants.getType().getElement(); - ShaderParam.fillInParams(vertexConst, mSourceParams, mTransform, mVertexParamList); - } - } - ScriptField_Renderable_s getRsField(RenderScriptGL rs, Resources res) { if (mRsField != null) { return mRsField; @@ -202,25 +183,18 @@ public class Renderable extends RenderableBase { // Very important step that links available inputs and the constants vertex and // fragment shader request - linkConstants(); - - ScriptField_ShaderParam_s pvParams = null, pfParams = null; - int paramCount = mVertexParamList.size(); - if (paramCount != 0) { - pvParams = new ScriptField_ShaderParam_s(rs, paramCount); - for (int i = 0; i < paramCount; i++) { - pvParams.set(mVertexParamList.get(i).getRSData(rs), i, false); - } - pvParams.copyAll(); + ScriptField_ShaderParam_s pvParams = null; + // Assign all the vertex params + if (mVertexConstants != null) { + Element vertexConst = mVertexConstants.getType().getElement(); + pvParams = ShaderParam.fillInParams(vertexConst, mSourceParams, mTransform); } - paramCount = mFragmentParamList.size(); - if (paramCount != 0) { - pfParams = new ScriptField_ShaderParam_s(rs, paramCount); - for (int i = 0; i < paramCount; i++) { - pfParams.set(mFragmentParamList.get(i).getRSData(rs), i, false); - } - pfParams.copyAll(); + ScriptField_ShaderParam_s pfParams = null; + // Assign all the fragment params + if (mFragmentConstants != null) { + Element fragmentConst = mFragmentConstants.getType().getElement(); + pfParams = ShaderParam.fillInParams(fragmentConst, mSourceParams, mTransform); } mRsFieldItem = new ScriptField_Renderable_s.Item(); diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java index 41bd651..4975114 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java @@ -20,6 +20,9 @@ import java.lang.Math; import java.util.ArrayList; import java.util.HashMap; +import com.android.scenegraph.SceneGraphBase; +import com.android.scenegraph.ShaderParam; + import android.renderscript.*; import android.renderscript.ProgramFragment.Builder; import android.util.Log; @@ -32,18 +35,16 @@ public abstract class Shader extends SceneGraphBase { protected Type mPerShaderConstants; protected HashMap<String, ShaderParam> mSourceParams; - protected ArrayList<ShaderParam> mParamList; protected ArrayList<String> mShaderTextureNames; protected ArrayList<Program.TextureType > mShaderTextureTypes; protected ArrayList<String> mTextureNames; protected ArrayList<Program.TextureType > mTextureTypes; protected Allocation mConstantBuffer; - protected Allocation mConstantBufferParams; + protected ScriptField_ShaderParam_s mConstantBufferParams; public Shader() { mSourceParams = new HashMap<String, ShaderParam>(); - mParamList = new ArrayList<ShaderParam>(); mShaderTextureNames = new ArrayList<String>(); mShaderTextureTypes = new ArrayList<Program.TextureType>(); mTextureNames = new ArrayList<String>(); @@ -68,19 +69,8 @@ public abstract class Shader extends SceneGraphBase { } Element constElem = mPerShaderConstants.getElement(); - ShaderParam.fillInParams(constElem, mSourceParams, null, mParamList); + mConstantBufferParams = ShaderParam.fillInParams(constElem, mSourceParams, null); mConstantBuffer = Allocation.createTyped(rs, mPerShaderConstants); - - ScriptField_ShaderParam_s rsParams = null; - int paramCount = mParamList.size(); - if (paramCount != 0) { - rsParams = new ScriptField_ShaderParam_s(rs, paramCount); - for (int i = 0; i < paramCount; i++) { - rsParams.set(mParamList.get(i).getRSData(rs), i, false); - } - rsParams.copyAll(); - mConstantBufferParams = rsParams.getAllocation(); - } } } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java index 05e36a7..b1071d3 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java @@ -20,6 +20,7 @@ import java.lang.Math; import java.util.ArrayList; import java.util.HashMap; +import com.android.scenegraph.SceneManager; import com.android.scenegraph.Transform; import android.renderscript.Element; @@ -49,15 +50,19 @@ public abstract class ShaderParam extends SceneGraphBase { static final String modelView = "modelView"; static final String modelViewProj = "modelViewProj"; - ScriptField_ShaderParam_s.Item mRsFieldItem; + ScriptField_ShaderParamData_s.Item mData; + ScriptField_ShaderParamData_s mField; String mParamName; - int mOffset; + Camera mCamera; + + static ScriptField_ShaderParam_s fillInParams(Element constantElem, + HashMap<String, ShaderParam> sourceParams, + Transform transform) { + RenderScriptGL rs = SceneManager.getRS(); + ArrayList<ScriptField_ShaderParam_s.Item> paramList; + paramList = new ArrayList<ScriptField_ShaderParam_s.Item>(); - static void fillInParams(Element constantElem, - HashMap<String, ShaderParam> sourceParams, - Transform transform, - ArrayList<ShaderParam> paramList) { int subElemCount = constantElem.getSubElementCount(); for (int i = 0; i < subElemCount; i ++) { String inputName = constantElem.getSubElementName(i); @@ -75,45 +80,68 @@ public abstract class ShaderParam extends SceneGraphBase { matchingParam = trParam; } } - matchingParam.setOffset(offset); if (subElem.getDataType() == Element.DataType.FLOAT_32) { Float4Param fParam = (Float4Param)matchingParam; fParam.setVecSize(subElem.getVectorSize()); } - paramList.add(matchingParam); + ScriptField_ShaderParam_s.Item paramRS = new ScriptField_ShaderParam_s.Item(); + paramRS.bufferOffset = offset; + paramRS.transformTimestamp = 0; + paramRS.data = matchingParam.getRSData().getAllocation(); + + paramList.add(paramRS); + } + + ScriptField_ShaderParam_s rsParams = null; + int paramCount = paramList.size(); + if (paramCount != 0) { + rsParams = new ScriptField_ShaderParam_s(rs, paramCount); + for (int i = 0; i < paramCount; i++) { + rsParams.set(paramList.get(i), i, false); + } + rsParams.copyAll(); } + return rsParams; } public ShaderParam(String name) { mParamName = name; + mData = new ScriptField_ShaderParamData_s.Item(); } public String getParamName() { return mParamName; } - void setOffset(int offset) { - mOffset = offset; + public void setCamera(Camera c) { + mCamera = c; + if (mField != null) { + mData.camera = mCamera.getRSData().getAllocation(); + mField.set_camera(0, mData.camera, true); + } } - abstract void initLocalData(RenderScriptGL rs); + abstract void initLocalData(); - public ScriptField_ShaderParam_s.Item getRSData(RenderScriptGL rs) { - if (mRsFieldItem != null) { - return mRsFieldItem; + public ScriptField_ShaderParamData_s getRSData() { + if (mField != null) { + return mField; } - mRsFieldItem = new ScriptField_ShaderParam_s.Item(); - mRsFieldItem.transformTimestamp = 0; + RenderScriptGL rs = SceneManager.getRS(); + mField = new ScriptField_ShaderParamData_s(rs, 1); + if (mParamName != null) { - mRsFieldItem.paramName = SceneManager.getCachedAlloc(mParamName); - if (mRsFieldItem.paramName == null) { - mRsFieldItem.paramName = SceneManager.getStringAsAllocation(rs, mParamName); - SceneManager.cacheAlloc(mParamName, mRsFieldItem.paramName); + mData.paramName = SceneManager.getCachedAlloc(mParamName); + if (mData.paramName == null) { + mData.paramName = SceneManager.getStringAsAllocation(rs, mParamName); + SceneManager.cacheAlloc(mParamName, mData.paramName); } } - initLocalData(rs); - return mRsFieldItem; + initLocalData(); + + mField.set(mData, 0, true); + return mField; } } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java index d7d196b..dd6b8f2 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java @@ -53,7 +53,7 @@ public class TextureParam extends ShaderParam { return mTexture; } - void initLocalData(RenderScriptGL rs) { + void initLocalData() { } } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java index 87c124b..0950983 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java @@ -33,7 +33,6 @@ import android.util.Log; public class TransformParam extends ShaderParam { Transform mTransform; - Camera mCamera; LightBase mLight; public TransformParam(String name) { @@ -44,10 +43,6 @@ public class TransformParam extends ShaderParam { mTransform = t; } - public void setCamera(Camera c) { - mCamera = c; - } - int getTypeFromName() { int paramType = SceneManager.getConst().get_shaderParam_TRANSFORM_DATA(); if (mParamName.equalsIgnoreCase(view)) { @@ -66,17 +61,16 @@ public class TransformParam extends ShaderParam { return paramType; } - void initLocalData(RenderScriptGL rs) { - mRsFieldItem.type = getTypeFromName(); - mRsFieldItem.bufferOffset = mOffset; + void initLocalData() { + mData.type = getTypeFromName(); if (mTransform != null) { - mRsFieldItem.transform = mTransform.getRSData().getAllocation(); + mData.transform = mTransform.getRSData().getAllocation(); } if (mCamera != null) { - mRsFieldItem.camera = mCamera.getRSData().getAllocation(); + mData.camera = mCamera.getRSData().getAllocation(); } if (mLight != null) { - mRsFieldItem.light = mLight.getRSData().getAllocation(); + mData.light = mLight.getRSData().getAllocation(); } } } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java index e3c5193..f7d0e6d 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java @@ -92,7 +92,7 @@ public class VertexShader extends Shader { linkConstants(rs); if (mPerShaderConstants != null) { item.shaderConst = mConstantBuffer; - item.shaderConstParams = mConstantBufferParams; + item.shaderConstParams = mConstantBufferParams.getAllocation(); mProgram.bindConstants(item.shaderConst, 0); } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs index b066eb7..6201496 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs @@ -51,5 +51,6 @@ SgRenderPass *pExport; SgCamera *exportPtrCam; SgLight *exportPtrLight; SgShaderParam *spExport; +SgShaderParamData *spDataExport; SgVertexShader *pvExport; SgFragmentShader *pfExport; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh index d1ef120..2169de3 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh @@ -20,25 +20,26 @@ //#define DEBUG_PARAMS -static void debugParam(SgShaderParam *p, uint8_t *constantBuffer, const SgCamera *currentCam) { +static void debugParam(SgShaderParam *p, SgShaderParamData *pData, + uint8_t *constantBuffer, const SgCamera *currentCam) { rsDebug("____________ Param bufferOffset", p->bufferOffset); - rsDebug("Param Type ", p->type); - if (rsIsObject(p->paramName)) { - printName(p->paramName); + rsDebug("Param Type ", pData->type); + if (rsIsObject(pData->paramName)) { + printName(pData->paramName); } uint8_t *dataPtr = constantBuffer + p->bufferOffset; const SgTransform *pTransform = NULL; - if (rsIsObject(p->transform)) { - pTransform = (const SgTransform *)rsGetElementAt(p->transform, 0); + if (rsIsObject(pData->transform)) { + pTransform = (const SgTransform *)rsGetElementAt(pData->transform, 0); rsDebug("Param transform", pTransform); printName(pTransform->name); } const SgLight *pLight = NULL; - if (rsIsObject(p->light)) { - pLight = (const SgLight *)rsGetElementAt(p->light, 0); + if (rsIsObject(pData->light)) { + pLight = (const SgLight *)rsGetElementAt(pData->light, 0); printLightInfo(pLight); } } @@ -66,12 +67,13 @@ static void writeFloatData(float *ptr, const float4 *input, uint32_t vecSize) { } } -static bool processParam(SgShaderParam *p, uint8_t *constantBuffer, const SgCamera *currentCam) { +static bool processParam(SgShaderParam *p, SgShaderParamData *pData, + uint8_t *constantBuffer, const SgCamera *currentCam) { const SgTransform *pTransform = NULL; - if (rsIsObject(p->transform)) { - pTransform = (const SgTransform *)rsGetElementAt(p->transform, 0); + if (rsIsObject(pData->transform)) { + pTransform = (const SgTransform *)rsGetElementAt(pData->transform, 0); // If we are a transform param and our transform is unchanged, nothing to do - bool isTransformOnly = (p->type > SHADER_PARAM_DATA_ONLY); + bool isTransformOnly = (pData->type > SHADER_PARAM_DATA_ONLY); if (p->transformTimestamp == pTransform->timestamp && isTransformOnly) { return false; } @@ -79,25 +81,25 @@ static bool processParam(SgShaderParam *p, uint8_t *constantBuffer, const SgCame } const SgLight *pLight = NULL; - if (rsIsObject(p->light)) { - pLight = (const SgLight *)rsGetElementAt(p->light, 0); + if (rsIsObject(pData->light)) { + pLight = (const SgLight *)rsGetElementAt(pData->light, 0); } uint8_t *dataPtr = constantBuffer + p->bufferOffset; - switch(p->type) { + switch(pData->type) { case SHADER_PARAM_FLOAT4_DATA: - writeFloatData((float*)dataPtr, &p->float_value, p->float_vecSize); + writeFloatData((float*)dataPtr, &pData->float_value, pData->float_vecSize); break; case SHADER_PARAM_FLOAT4_CAMERA_POS: - writeFloatData((float*)dataPtr, ¤tCam->position, p->float_vecSize); + writeFloatData((float*)dataPtr, ¤tCam->position, pData->float_vecSize); break; case SHADER_PARAM_FLOAT4_CAMERA_DIR: break; case SHADER_PARAM_FLOAT4_LIGHT_COLOR: - writeFloatData((float*)dataPtr, &pLight->color, p->float_vecSize); + writeFloatData((float*)dataPtr, &pLight->color, pData->float_vecSize); break; case SHADER_PARAM_FLOAT4_LIGHT_POS: - writeFloatData((float*)dataPtr, &pLight->position, p->float_vecSize); + writeFloatData((float*)dataPtr, &pLight->position, pData->float_vecSize); break; case SHADER_PARAM_FLOAT4_LIGHT_DIR: break; @@ -145,10 +147,11 @@ static void processAllParams(rs_allocation shaderConst, bool updated = false; for (int i = 0; i < numParams; i ++) { SgShaderParam *current = (SgShaderParam*)rsGetElementAt(allParams, i); + SgShaderParamData *currentData = (SgShaderParamData*)rsGetElementAt(current->data, 0); #ifdef DEBUG_PARAMS - debugParam(current, constantBuffer, camera); + debugParam(current, currentData, constantBuffer, camera); #endif // DEBUG_PARAMS - updated = processParam(current, constantBuffer, camera) || updated; + updated = processParam(current, currentData, constantBuffer, camera) || updated; } } } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh index 393ae36..af39ecf 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh @@ -21,15 +21,15 @@ #include "rs_graphics.rsh" -#define TRANSFORM_NONE 0 +#define TRANSFORM_NONE 0 #define TRANSFORM_TRANSLATE 1 -#define TRANSFORM_ROTATE 2 -#define TRANSFORM_SCALE 3 +#define TRANSFORM_ROTATE 2 +#define TRANSFORM_SCALE 3 #define CULL_FRUSTUM 0 -#define CULL_ALWAYS 2 +#define CULL_ALWAYS 2 -#define LIGHT_POINT 0 +#define LIGHT_POINT 0 #define LIGHT_DIRECTIONAL 1 // Shader params that involve only data @@ -142,7 +142,7 @@ typedef struct RenderPass_s { bool should_clear_depth; } SgRenderPass; -typedef struct __attribute__((packed, aligned(4))) Camera_s { +typedef struct Camera_s { rs_matrix4x4 proj; rs_matrix4x4 view; rs_matrix4x4 viewProj; @@ -162,7 +162,7 @@ typedef struct __attribute__((packed, aligned(4))) Camera_s { uint32_t transformTimestamp; } SgCamera; -typedef struct __attribute__((packed, aligned(4))) Light_s { +typedef struct Light_s { float4 position; float4 color; float intensity; @@ -171,21 +171,29 @@ typedef struct __attribute__((packed, aligned(4))) Light_s { rs_allocation transformMatrix; } SgLight; -// This represents a shader parameter that knows for to update itself -typedef struct ShaderParam_s { - uint32_t type; - uint32_t bufferOffset; +// This represents the shader parameter data needed to set a float or transform data +typedef struct ShaderParamData_s { + int type; float4 float_value; // Use one param type to handle all vector types for now - uint32_t float_vecSize; + int float_vecSize; rs_allocation paramName; rs_allocation camera; rs_allocation light; rs_allocation transform; + rs_allocation texture; +} SgShaderParamData; + +// This represents a shader parameter that knows how to update itself for a given +// renderable or shader and contains a timestamp for the last time this buffer was updated +typedef struct ShaderParam_s { // Used to check whether transform params need to be updated uint32_t transformTimestamp; - rs_allocation texture; + // Specifies where in the constant buffer data gets written to + int bufferOffset; + // An instance of SgShaderParamData that could be shared by multiple objects + rs_allocation data; } SgShaderParam; // This represents a texture object |