summaryrefslogtreecommitdiff
path: root/rsProgram.cpp
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-12-15 12:58:36 -0800
committerJason Sams <rjsams@android.com>2009-12-15 12:58:36 -0800
commit4815c0d121310cfcd6a8aba4eab77a9910af53ac (patch)
tree6e6154879389c6b5bd745f3c0922d83ed232de8f /rsProgram.cpp
parentcf4c7c9b2f513be77a5b9853319ca82ac2b128ed (diff)
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.
Diffstat (limited to 'rsProgram.cpp')
-rw-r--r--rsProgram.cpp81
1 files changed, 78 insertions, 3 deletions
diff --git a/rsProgram.cpp b/rsProgram.cpp
index db40f161..ba27fd41 100644
--- a/rsProgram.cpp
+++ b/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<Element>[mInputCount];
+ mOutputElements = new ObjectBaseRef<Element>[mOutputCount];
+ mConstantTypes = new ObjectBaseRef<Type>[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<Element *>(params[ct+1]));
+ }
+ if (params[ct] == RS_PROGRAM_PARAM_OUTPUT) {
+ mOutputElements[output++].set(reinterpret_cast<Element *>(params[ct+1]));
+ }
+ if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) {
+ mConstantTypes[constant++].set(reinterpret_cast<Type *>(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<Program *>(vp);
+ p->bindAllocation(static_cast<Allocation *>(constants));
+}
+
+
+}
+}
+