void GLEncoder::s_glDisable(void* self, GLenum cap) { GLEncoder* ctx = (GLEncoder*)self; GLClientState* state = ctx->m_state; if (cap == GL_TEXTURE_2D || cap == GL_TEXTURE_EXTERNAL_OES) { GLenum prevTarget = state->getPriorityEnabledTarget(GL_INVALID_ENUM); state->disableTextureTarget(cap); GLenum currTarget = state->getPriorityEnabledTarget(GL_INVALID_ENUM); if (prevTarget != currTarget) { if (currTarget == GL_INVALID_ENUM) { ctx->m_glDisable_enc(ctx, GL_TEXTURE_2D); currTarget = GL_TEXTURE_2D; } // maintain the invariant that when TEXTURE_EXTERNAL_OES is // disabled, the TEXTURE_2D binding is active, even if // TEXTURE_2D is also disabled. ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, state->getBoundTexture(currTarget)); } } else { ctx->m_glDisable_enc(ctx, cap); } }
void GL2Encoder::s_glBindTexture(void* self, GLenum target, GLuint texture) { GL2Encoder* ctx = (GL2Encoder*)self; GLClientState* state = ctx->m_state; GLenum err; GLboolean firstUse; SET_ERROR_IF((err = state->bindTexture(target, texture, &firstUse)) != GL_NO_ERROR, err); if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES) { ctx->m_glBindTexture_enc(ctx, target, texture); return; } GLenum priorityTarget = state->getPriorityEnabledTarget(GL_TEXTURE_2D); if (target == GL_TEXTURE_EXTERNAL_OES && firstUse) { ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, texture); ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (target != priorityTarget) { ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, state->getBoundTexture(GL_TEXTURE_2D)); } } if (target == priorityTarget) { ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, texture); } }
void GLEncoder::s_glEnable(void* self, GLenum cap) { GLEncoder* ctx = (GLEncoder*)self; GLClientState* state = ctx->m_state; if (cap == GL_TEXTURE_2D || cap == GL_TEXTURE_EXTERNAL_OES) { GLenum prevTarget = state->getPriorityEnabledTarget(GL_INVALID_ENUM); state->enableTextureTarget(cap); GLenum currTarget = state->getPriorityEnabledTarget(GL_INVALID_ENUM); if (prevTarget != currTarget) { if (prevTarget == GL_INVALID_ENUM) { ctx->m_glEnable_enc(ctx, GL_TEXTURE_2D); } if (currTarget == GL_TEXTURE_EXTERNAL_OES) { ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, state->getBoundTexture(currTarget)); } } } else { ctx->m_glEnable_enc(ctx, cap); } }
void GLEncoder::s_glBindTexture(void* self, GLenum target, GLuint texture) { GLEncoder* ctx = (GLEncoder*)self; GLClientState* state = ctx->m_state; GLenum err; GLboolean firstUse; if ((err = state->bindTexture(target, texture, &firstUse)) != GL_NO_ERROR) { LOGE("%s:%s:%d GL error %#x\n", __FILE__, __FUNCTION__, __LINE__, err); ctx->setError(err); return; } if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES) { ctx->m_glBindTexture_enc(ctx, target, texture); return; } GLenum priorityTarget = state->getPriorityEnabledTarget(GL_TEXTURE_2D); if (target == GL_TEXTURE_EXTERNAL_OES && firstUse) { // set TEXTURE_EXTERNAL_OES default states which differ from TEXTURE_2D ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, texture); ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (target != priorityTarget) { ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, state->getBoundTexture(GL_TEXTURE_2D)); } } if (target == priorityTarget) { ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, texture); } }