From 0011bcf57ff711a221a3a4c73f2a79125111647d Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Tue, 15 Dec 2009 12:58:36 -0800 Subject: Continue development of es2.0 user shader support for renderscript. This change cleans up ProgramVertex creation and adds support for passing input, output, and constant type info. --- libs/rs/rsProgram.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) (limited to 'libs/rs/rsProgram.cpp') diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index db40f1619185..ba27fd4196a7 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -24,7 +24,7 @@ using namespace android; using namespace android::renderscript; -Program::Program(Context *rsc, Element *in, Element *out) : ObjectBase(rsc) +Program::Program(Context *rsc) : ObjectBase(rsc) { mAllocFile = __FILE__; mAllocLine = __LINE__; @@ -33,13 +33,72 @@ Program::Program(Context *rsc, Element *in, Element *out) : ObjectBase(rsc) mAttribCount = 0; mUniformCount = 0; - mElementIn.set(in); - mElementOut.set(out); + mInputElements = NULL; + mOutputElements = NULL; + mConstantTypes = NULL; + mInputCount = 0; + mOutputCount = 0; + mConstantCount = 0; +} + +Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, + const uint32_t * params, uint32_t paramLength) : + ObjectBase(rsc) +{ + mAllocFile = __FILE__; + mAllocLine = __LINE__; + mDirty = true; + mShaderID = 0; + mAttribCount = 0; + mUniformCount = 0; + + mInputCount = 0; + mOutputCount = 0; + mConstantCount = 0; + + for (uint32_t ct=0; ct < paramLength; ct+=2) { + if (params[ct] == RS_PROGRAM_PARAM_INPUT) { + mInputCount++; + } + if (params[ct] == RS_PROGRAM_PARAM_OUTPUT) { + mOutputCount++; + } + if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) { + mConstantCount++; + } + } + + mInputElements = new ObjectBaseRef[mInputCount]; + mOutputElements = new ObjectBaseRef[mOutputCount]; + mConstantTypes = new ObjectBaseRef[mConstantCount]; + + uint32_t input = 0; + uint32_t output = 0; + uint32_t constant = 0; + for (uint32_t ct=0; ct < paramLength; ct+=2) { + if (params[ct] == RS_PROGRAM_PARAM_INPUT) { + mInputElements[input++].set(reinterpret_cast(params[ct+1])); + } + if (params[ct] == RS_PROGRAM_PARAM_OUTPUT) { + mOutputElements[output++].set(reinterpret_cast(params[ct+1])); + } + if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) { + mConstantTypes[constant++].set(reinterpret_cast(params[ct+1])); + } + } + mUserShader.setTo(shaderText, shaderLength); } Program::~Program() { bindAllocation(NULL); + + delete[] mInputElements; + delete[] mOutputElements; + delete[] mConstantTypes; + mInputCount = 0; + mOutputCount = 0; + mConstantCount = 0; } @@ -102,3 +161,19 @@ void Program::setShader(const char *txt, uint32_t len) mUserShader.setTo(txt, len); } + + +namespace android { +namespace renderscript { + + +void rsi_ProgramBindConstants(Context *rsc, RsProgram vp, uint32_t slot, RsAllocation constants) +{ + Program *p = static_cast(vp); + p->bindAllocation(static_cast(constants)); +} + + +} +} + -- cgit v1.2.3-59-g8ed1b