diff options
author | Jason Sams <rjsams@android.com> | 2009-12-15 13:27:04 -0800 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2009-12-15 13:27:04 -0800 |
commit | 7e5ab3b177b10fee304d011b3a4b9ee03e2b18b5 (patch) | |
tree | 87e037e70a81ed8d250eff1c20ae8f799c62c7c6 /libs/rs | |
parent | b686ec70445226d3f865b6e838b3f2cdf034ca31 (diff) | |
download | frameworks_base-7e5ab3b177b10fee304d011b3a4b9ee03e2b18b5.zip frameworks_base-7e5ab3b177b10fee304d011b3a4b9ee03e2b18b5.tar.gz frameworks_base-7e5ab3b177b10fee304d011b3a4b9ee03e2b18b5.tar.bz2 |
Continue es2 shader dev
Conflicts:
graphics/java/android/renderscript/Program.java
graphics/java/android/renderscript/ProgramVertex.java
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/RenderScript.h | 1 | ||||
-rw-r--r-- | libs/rs/rs.spec | 10 | ||||
-rw-r--r-- | libs/rs/rsProgram.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rsProgram.h | 1 | ||||
-rw-r--r-- | libs/rs/rsProgramFragment.cpp | 113 | ||||
-rw-r--r-- | libs/rs/rsProgramFragment.h | 3 |
6 files changed, 90 insertions, 42 deletions
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h index 12ae6e1..44ff901 100644 --- a/libs/rs/RenderScript.h +++ b/libs/rs/RenderScript.h @@ -167,6 +167,7 @@ enum RsProgramParam { RS_PROGRAM_PARAM_INPUT, RS_PROGRAM_PARAM_OUTPUT, RS_PROGRAM_PARAM_CONSTANT, + RS_PROGRAM_PARAM_TEXTURE_COUNT, }; enum RsPrimitive { diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 6ce6b35..5de76b2 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -406,6 +406,14 @@ ProgramFragmentCreate { ret RsProgramFragment } +ProgramFragmentCreate2 { + param const char * shaderText + param uint32_t shaderLength + param const uint32_t * params + param uint32_t paramLength + ret RsProgramFragment + } + ProgramVertexCreate { param bool texMat ret RsProgramVertex @@ -416,7 +424,7 @@ ProgramVertexCreate2 { param uint32_t shaderLength param const uint32_t * params param uint32_t paramLength - ret RsProgramFragment + ret RsProgramVertex } LightBegin { diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index ba27fd4..bcda5fb 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -51,6 +51,7 @@ Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, mShaderID = 0; mAttribCount = 0; mUniformCount = 0; + mTextureCount = 0; mInputCount = 0; mOutputCount = 0; @@ -66,6 +67,9 @@ Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) { mConstantCount++; } + if (params[ct] == RS_PROGRAM_PARAM_TEXTURE_COUNT) { + mTextureCount = params[ct+1]; + } } mInputElements = new ObjectBaseRef<Element>[mInputCount]; diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h index 01b4c88..e9837b7 100644 --- a/libs/rs/rsProgram.h +++ b/libs/rs/rsProgram.h @@ -66,6 +66,7 @@ protected: String8 mUserShader; uint32_t mShaderID; + uint32_t mTextureCount; uint32_t mAttribCount; uint32_t mUniformCount; String8 mAttribNames[MAX_ATTRIBS]; diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp index 3ddaa37..2d18c42 100644 --- a/libs/rs/rsProgramFragment.cpp +++ b/libs/rs/rsProgramFragment.cpp @@ -40,6 +40,19 @@ ProgramFragment::ProgramFragment(Context *rsc, Element *in, Element *out, bool p mEnvModes[1] = RS_TEX_ENV_MODE_DECAL; } +ProgramFragment::ProgramFragment(Context *rsc, const char * shaderText, + uint32_t shaderLength, const uint32_t * params, + uint32_t paramLength) : + Program(rsc, shaderText, shaderLength, params, paramLength) +{ + mAllocFile = __FILE__; + mAllocLine = __LINE__; + + init(rsc); + mTextureEnableMask = (1 << mTextureCount) -1; +} + + ProgramFragment::~ProgramFragment() { } @@ -158,58 +171,68 @@ void ProgramFragment::createShader() mShader.append("varying vec4 varColor;\n"); mShader.append("varying vec4 varTex0;\n"); - uint32_t mask = mTextureEnableMask; - uint32_t texNum = 0; - while (mask) { - if (mask & 1) { - char buf[64]; - mShader.append("uniform sampler2D uni_Tex"); - sprintf(buf, "%i", texNum); + if (mUserShader.length() > 1) { + for (uint32_t ct=0; ct < mTextureCount; ct++) { + char buf[256]; + sprintf(buf, "uniform sampler2D uni_Tex%i;\n", ct); mShader.append(buf); - mShader.append(";\n"); } - mask >>= 1; - texNum++; - } + mShader.append(mUserShader); + } else { + uint32_t mask = mTextureEnableMask; + uint32_t texNum = 0; + while (mask) { + if (mask & 1) { + char buf[64]; + mShader.append("uniform sampler2D uni_Tex"); + sprintf(buf, "%i", texNum); + mShader.append(buf); + mShader.append(";\n"); + } + mask >>= 1; + texNum++; + } - mShader.append("void main() {\n"); - mShader.append(" vec4 col = varColor;\n"); - if (mTextureEnableMask) { - if (mPointSpriteEnable) { - mShader.append(" vec2 tex0 = gl_PointCoord;\n"); - } else { - mShader.append(" vec2 tex0 = varTex0.xy;\n"); - } - } + mShader.append("void main() {\n"); + mShader.append(" vec4 col = varColor;\n"); - mask = mTextureEnableMask; - texNum = 0; - while (mask) { - if (mask & 1) { - switch(mEnvModes[texNum]) { - case RS_TEX_ENV_MODE_REPLACE: - mShader.append(" col = texture2D(uni_Tex0, tex0);\n"); - break; - case RS_TEX_ENV_MODE_MODULATE: - mShader.append(" col *= texture2D(uni_Tex0, tex0);\n"); - break; - case RS_TEX_ENV_MODE_DECAL: - mShader.append(" col = texture2D(uni_Tex0, tex0);\n"); - break; + if (mTextureEnableMask) { + if (mPointSpriteEnable) { + mShader.append(" vec2 tex0 = gl_PointCoord;\n"); + } else { + mShader.append(" vec2 tex0 = varTex0.xy;\n"); } + } + + mask = mTextureEnableMask; + texNum = 0; + while (mask) { + if (mask & 1) { + switch(mEnvModes[texNum]) { + case RS_TEX_ENV_MODE_REPLACE: + mShader.append(" col = texture2D(uni_Tex0, tex0);\n"); + break; + case RS_TEX_ENV_MODE_MODULATE: + mShader.append(" col *= texture2D(uni_Tex0, tex0);\n"); + break; + case RS_TEX_ENV_MODE_DECAL: + mShader.append(" col = texture2D(uni_Tex0, tex0);\n"); + break; + } + } + mask >>= 1; + texNum++; } - mask >>= 1; - texNum++; - } - //mShader.append(" col.a = 1.0;\n"); - //mShader.append(" col.r = 0.5;\n"); + //mShader.append(" col.a = 1.0;\n"); + //mShader.append(" col.r = 0.5;\n"); - mShader.append(" gl_FragColor = col;\n"); - mShader.append("}\n"); + mShader.append(" gl_FragColor = col;\n"); + mShader.append("}\n"); + } } void ProgramFragment::bindTexture(uint32_t slot, Allocation *a) @@ -361,6 +384,14 @@ RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc) return pf; } +RsProgramFragment rsi_ProgramFragmentCreate2(Context *rsc, const char * shaderText, + uint32_t shaderLength, const uint32_t * params, + uint32_t paramLength) +{ + ProgramFragment *pf = new ProgramFragment(rsc, shaderText, shaderLength, params, paramLength); + pf->incUserRef(); + return pf; +} } } diff --git a/libs/rs/rsProgramFragment.h b/libs/rs/rsProgramFragment.h index 6fc852e..1f548ad 100644 --- a/libs/rs/rsProgramFragment.h +++ b/libs/rs/rsProgramFragment.h @@ -33,6 +33,9 @@ public: ProgramFragment(Context *, Element *in, Element *out, bool pointSpriteEnable); + ProgramFragment(Context *rsc, const char * shaderText, + uint32_t shaderLength, const uint32_t * params, + uint32_t paramLength); virtual ~ProgramFragment(); virtual void setupGL(const Context *, ProgramFragmentState *); |