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 GL2Encoder::s_glUseProgram(void *self, GLuint program) { GL2Encoder *ctx = (GL2Encoder*)self; GLClientState* state = ctx->m_state; GLSharedGroupPtr shared = ctx->m_shared; ctx->m_glUseProgram_enc(self, program); ctx->m_state->setCurrentProgram(program); GLenum origActiveTexture = state->getActiveTextureUnit(); GLenum hostActiveTexture = origActiveTexture; GLint samplerIdx = -1; GLint samplerVal; GLenum samplerTarget; while ((samplerIdx = shared->getNextSamplerUniform(program, samplerIdx, &samplerVal, &samplerTarget)) != -1) { if (samplerVal < 0 || samplerVal >= GLClientState::MAX_TEXTURE_UNITS) continue; if (ctx->updateHostTexture2DBinding(GL_TEXTURE0 + samplerVal, samplerTarget)) { hostActiveTexture = GL_TEXTURE0 + samplerVal; } } state->setActiveTextureUnit(origActiveTexture); if (hostActiveTexture != origActiveTexture) { ctx->m_glActiveTexture_enc(self, origActiveTexture); } }
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 GLEncoder::s_glGetBooleanv(void *self, GLenum param, GLboolean *ptr) { GLEncoder *ctx = (GLEncoder *)self; assert(ctx->m_state != NULL); GLClientState* state = ctx->m_state; switch (param) { case GL_COMPRESSED_TEXTURE_FORMATS: { GLint* compressedTextureFormats = ctx->getCompressedTextureFormats(); if (ctx->m_num_compressedTextureFormats > 0 && compressedTextureFormats != NULL) { for (int i = 0; i < ctx->m_num_compressedTextureFormats; i++) { ptr[i] = compressedTextureFormats[i] != 0 ? GL_TRUE : GL_FALSE; } } break; } case GL_TEXTURE_BINDING_2D: *ptr = state->getBoundTexture(GL_TEXTURE_2D) != 0 ? GL_TRUE : GL_FALSE; break; case GL_TEXTURE_BINDING_EXTERNAL_OES: *ptr = state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES) != 0 ? GL_TRUE : GL_FALSE; break; default: if (!state->getClientStateParameter<GLboolean>(param,ptr)) { ctx->m_glGetBooleanv_enc(self, param, ptr); } break; } }
void GL2Encoder::s_glDeleteTextures(void* self, GLsizei n, const GLuint* textures) { GL2Encoder* ctx = (GL2Encoder*)self; GLClientState* state = ctx->m_state; state->deleteTextures(n, textures); ctx->m_glDeleteTextures_enc(ctx, n, textures); }
void GL2Encoder::s_glActiveTexture(void* self, GLenum texture) { GL2Encoder* ctx = (GL2Encoder*)self; GLClientState* state = ctx->m_state; GLenum err; SET_ERROR_IF((err = state->setActiveTextureUnit(texture)) != GL_NO_ERROR, err); ctx->m_glActiveTexture_enc(ctx, texture); }
void GLEncoder::s_glActiveTexture(void* self, GLenum texture) { GLEncoder* ctx = (GLEncoder*)self; GLClientState* state = ctx->m_state; GLenum err; if ((err = state->setActiveTextureUnit(texture)) != GL_NO_ERROR) { LOGE("%s:%s:%d GL error %#x\n", __FILE__, __FUNCTION__, __LINE__, err); ctx->setError(err); return; } ctx->m_glActiveTexture_enc(ctx, texture); }
void GL2Encoder::s_glGetFloatv(void *self, GLenum param, GLfloat *ptr) { GL2Encoder *ctx = (GL2Encoder *)self; assert(ctx->m_state != NULL); GLClientState* state = ctx->m_state; switch (param) { case GL_NUM_SHADER_BINARY_FORMATS: *ptr = 0; break; case GL_SHADER_BINARY_FORMATS: // do nothing break; case GL_COMPRESSED_TEXTURE_FORMATS: { GLint *compressedTextureFormats = ctx->getCompressedTextureFormats(); if (ctx->m_num_compressedTextureFormats > 0 && compressedTextureFormats != NULL) { for (int i = 0; i < ctx->m_num_compressedTextureFormats; i++) { ptr[i] = (GLfloat) compressedTextureFormats[i]; } } break; } case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: case GL_MAX_TEXTURE_IMAGE_UNITS: ctx->m_glGetFloatv_enc(self, param, ptr); *ptr = MIN(*ptr, (GLfloat)GLClientState::MAX_TEXTURE_UNITS); break; case GL_TEXTURE_BINDING_2D: *ptr = (GLfloat)state->getBoundTexture(GL_TEXTURE_2D); break; case GL_TEXTURE_BINDING_EXTERNAL_OES: *ptr = (GLfloat)state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES); break; default: if (!ctx->m_state->getClientStateParameter<GLfloat>(param, ptr)) { ctx->m_glGetFloatv_enc(self, param, ptr); } break; } }
void GL2Encoder::s_glUniform1i(void *self , GLint location, GLint x) { GL2Encoder *ctx = (GL2Encoder*)self; GLClientState* state = ctx->m_state; GLSharedGroupPtr shared = ctx->m_shared; GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); ctx->m_glUniform1i_enc(self, hostLoc, x); GLenum target; if (shared->setSamplerUniform(state->currentProgram(), location, x, &target)) { GLenum origActiveTexture = state->getActiveTextureUnit(); if (ctx->updateHostTexture2DBinding(GL_TEXTURE0 + x, target)) { ctx->m_glActiveTexture_enc(self, origActiveTexture); } state->setActiveTextureUnit(origActiveTexture); } }
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); } }
void GLEncoder::s_glGetFixedv(void *self, GLenum param, GLfixed *ptr) { GLEncoder *ctx = (GLEncoder *)self; assert(ctx->m_state != NULL); GLClientState* state = ctx->m_state; switch (param) { case GL_COMPRESSED_TEXTURE_FORMATS: { GLint * compressedTextureFormats = ctx->getCompressedTextureFormats(); if (ctx->m_num_compressedTextureFormats > 0 && compressedTextureFormats != NULL) { for (int i = 0; i < ctx->m_num_compressedTextureFormats; i++) { ptr[i] = compressedTextureFormats[i] << 16; } } break; } case GL_MAX_TEXTURE_UNITS: ctx->m_glGetFixedv_enc(self, param, ptr); *ptr = MIN(*ptr, GLClientState::MAX_TEXTURE_UNITS << 16); break; case GL_TEXTURE_BINDING_2D: *ptr = state->getBoundTexture(GL_TEXTURE_2D) << 16; break; case GL_TEXTURE_BINDING_EXTERNAL_OES: *ptr = state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES) << 16; break; default: if (!state->getClientStateParameter<GLfixed>(param,ptr)) { ctx->m_glGetFixedv_enc(self, param, ptr); } break; } }
void GLEncoder::s_glGetIntegerv(void *self, GLenum param, GLint *ptr) { GLEncoder *ctx = (GLEncoder *)self; assert(ctx->m_state != NULL); GLClientState* state = ctx->m_state; switch (param) { case GL_COMPRESSED_TEXTURE_FORMATS: { GLint * compressedTextureFormats = ctx->getCompressedTextureFormats(); if (ctx->m_num_compressedTextureFormats > 0 && compressedTextureFormats != NULL) { memcpy(ptr, compressedTextureFormats, ctx->m_num_compressedTextureFormats * sizeof(GLint)); } break; } case GL_MAX_TEXTURE_UNITS: ctx->m_glGetIntegerv_enc(self, param, ptr); *ptr = MIN(*ptr, GLClientState::MAX_TEXTURE_UNITS); break; case GL_TEXTURE_BINDING_2D: *ptr = state->getBoundTexture(GL_TEXTURE_2D); break; case GL_TEXTURE_BINDING_EXTERNAL_OES: *ptr = state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES); break; default: if (!state->getClientStateParameter<GLint>(param,ptr)) { ctx->m_glGetIntegerv_enc(self, param, ptr); } break; } }
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); } }