diff options
Diffstat (limited to 'libs/rs/rsProgram.cpp')
-rw-r--r-- | libs/rs/rsProgram.cpp | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index 5f2a609..db40f16 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -17,6 +17,9 @@ #include "rsContext.h" #include "rsProgram.h" +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + using namespace android; using namespace android::renderscript; @@ -25,6 +28,10 @@ Program::Program(Context *rsc, Element *in, Element *out) : ObjectBase(rsc) { mAllocFile = __FILE__; mAllocLine = __LINE__; + mDirty = true; + mShaderID = 0; + mAttribCount = 0; + mUniformCount = 0; mElementIn.set(in); mElementOut.set(out); @@ -32,19 +39,66 @@ Program::Program(Context *rsc, Element *in, Element *out) : ObjectBase(rsc) Program::~Program() { + bindAllocation(NULL); } void Program::bindAllocation(Allocation *alloc) { + if (mConstants.get() == alloc) { + return; + } + if (mConstants.get()) { + mConstants.get()->removeProgramToDirty(this); + } mConstants.set(alloc); + if (alloc) { + alloc->addProgramToDirty(this); + } mDirty = true; } -void Program::checkUpdatedAllocation(const Allocation *alloc) +void Program::createShader() { - if (mConstants.get() == alloc) { - mDirty = true; +} + +bool Program::loadShader(uint32_t type) +{ + mShaderID = glCreateShader(type); + rsAssert(mShaderID); + + LOGV("Loading shader type %x, ID %i", type, mShaderID); + LOGE(mShader.string()); + + if (mShaderID) { + const char * ss = mShader.string(); + glShaderSource(mShaderID, 1, &ss, NULL); + glCompileShader(mShaderID); + + GLint compiled = 0; + glGetShaderiv(mShaderID, GL_COMPILE_STATUS, &compiled); + if (!compiled) { + GLint infoLen = 0; + glGetShaderiv(mShaderID, GL_INFO_LOG_LENGTH, &infoLen); + if (infoLen) { + char* buf = (char*) malloc(infoLen); + if (buf) { + glGetShaderInfoLog(mShaderID, infoLen, NULL, buf); + LOGE("Could not compile shader \n%s\n", buf); + free(buf); + } + glDeleteShader(mShaderID); + mShaderID = 0; + return false; + } + } } + LOGV("--Shader load result %x ", glGetError()); + return true; +} + +void Program::setShader(const char *txt, uint32_t len) +{ + mUserShader.setTo(txt, len); } |