summaryrefslogtreecommitdiffstats
path: root/driver
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2011-08-05 15:27:25 -0700
committerAlex Sakhartchouk <alexst@google.com>2011-08-05 15:27:25 -0700
commitba157304ce99d212403898b055998e6da7a20e9b (patch)
treedd283d219d4ee4c366944d8fa2064b9d08bd8b3a /driver
parentc40ad9ae72f335e035d0881a2ee7ebf0352cfc40 (diff)
downloadandroid_frameworks_rs-ba157304ce99d212403898b055998e6da7a20e9b.tar.gz
android_frameworks_rs-ba157304ce99d212403898b055998e6da7a20e9b.tar.bz2
android_frameworks_rs-ba157304ce99d212403898b055998e6da7a20e9b.zip
Fixing rs crash when no texture is bound.
Change-Id: I2c15106f50de995c63691f27e2c4d89dbffc758e
Diffstat (limited to 'driver')
-rw-r--r--driver/rsdProgram.cpp3
-rw-r--r--driver/rsdShader.cpp18
-rw-r--r--driver/rsdShader.h1
3 files changed, 18 insertions, 4 deletions
diff --git a/driver/rsdProgram.cpp b/driver/rsdProgram.cpp
index 39b3805f..27a66639 100644
--- a/driver/rsdProgram.cpp
+++ b/driver/rsdProgram.cpp
@@ -44,6 +44,9 @@ bool rsdProgramVertexInit(const Context *rsc, const ProgramVertex *pv,
static void SyncProgramConstants(const Context *rsc, const Program *p) {
for (uint32_t ct=0; ct < p->mHal.state.texturesCount; ct++) {
const Allocation *a = p->mHal.state.textures[ct].get();
+ if (!a) {
+ continue;
+ }
DrvAllocation *drvAlloc = (DrvAllocation *)a->mHal.drv;
if (drvAlloc->uploadDeferred) {
rsdAllocationSyncAll(rsc, a, RS_ALLOCATION_USAGE_SCRIPT);
diff --git a/driver/rsdShader.cpp b/driver/rsdShader.cpp
index 15cc4179..90fe4b23 100644
--- a/driver/rsdShader.cpp
+++ b/driver/rsdShader.cpp
@@ -48,6 +48,7 @@ RsdShader::~RsdShader() {
delete[] mAttribNames;
delete[] mUniformNames;
delete[] mUniformArraySizes;
+ delete[] mTextureTargets;
}
void RsdShader::initMemberVars() {
@@ -59,6 +60,7 @@ void RsdShader::initMemberVars() {
mAttribNames = NULL;
mUniformNames = NULL;
mUniformArraySizes = NULL;
+ mTextureTargets = NULL;
mIsValid = false;
}
@@ -81,6 +83,7 @@ void RsdShader::init() {
mUniformArraySizes[uniformCount] = 1;
uniformCount++;
}
+
}
String8 RsdShader::getGLSLInputString() const {
@@ -141,8 +144,10 @@ void RsdShader::appendTextures() {
for (uint32_t ct=0; ct < mRSProgram->mHal.state.texturesCount; ct++) {
if (mRSProgram->mHal.state.textureTargets[ct] == RS_TEXTURE_2D) {
snprintf(buf, sizeof(buf), "uniform sampler2D UNI_Tex%i;\n", ct);
+ mTextureTargets[ct] = GL_TEXTURE_2D;
} else {
snprintf(buf, sizeof(buf), "uniform samplerCube UNI_Tex%i;\n", ct);
+ mTextureTargets[ct] = GL_TEXTURE_CUBE_MAP;
}
mShader.append(buf);
}
@@ -400,9 +405,11 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) {
for (uint32_t ct=0; ct < numTexturesToBind; ct++) {
glActiveTexture(GL_TEXTURE0 + ct);
+ glUniform1i(sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct);
+
if (!mRSProgram->mHal.state.textures[ct].get()) {
- LOGE("No texture bound for shader id %u, texture unit %u", (uint)this, ct);
- rsc->setError(RS_ERROR_BAD_SHADER, "No texture bound");
+ // if nothing is bound, reset to default GL texture
+ glBindTexture(mTextureTargets[ct], 0);
continue;
}
@@ -422,8 +429,6 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) {
glTexParameteri(drvTex->glTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
rsdGLCheckError(rsc, "ProgramFragment::setup tex env");
}
-
- glUniform1i(sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct);
rsdGLCheckError(rsc, "ProgramFragment::setup uniforms");
}
@@ -516,6 +521,11 @@ void RsdShader::initAttribAndUniformArray() {
mUniformNames = new String8[mUniformCount];
mUniformArraySizes = new uint32_t[mUniformCount];
}
+
+ mTextureCount = mRSProgram->mHal.state.texturesCount;
+ if (mTextureCount) {
+ mTextureTargets = new uint32_t[mTextureCount];
+ }
}
void RsdShader::initAddUserElement(const Element *e, String8 *names, uint32_t *arrayLengths, uint32_t *count, const char *prefix) {
diff --git a/driver/rsdShader.h b/driver/rsdShader.h
index 63c42316..3f0d6eae 100644
--- a/driver/rsdShader.h
+++ b/driver/rsdShader.h
@@ -84,6 +84,7 @@ protected:
uint32_t mType;
uint32_t mTextureCount;
+ uint32_t *mTextureTargets;
uint32_t mAttribCount;
uint32_t mUniformCount;
android::String8 *mAttribNames;