diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp b/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp index dcfe9feed..f8820d23f 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp @@ -50,6 +50,7 @@ GLClientState::GLClientState(int nLocations) m_states[MATRIXINDEX_LOCATION].glConst = GL_MATRIX_INDEX_ARRAY_OES; m_states[WEIGHT_LOCATION].glConst = GL_WEIGHT_ARRAY_OES; m_activeTexture = 0; + m_currentProgram = 0; m_pixelStore.unpack_alignment = 4; m_pixelStore.pack_alignment = 4; diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.h b/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.h index bc895d750..6b12f6871 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.h +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.h @@ -120,6 +120,9 @@ public: } size_t pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) const; + void setCurrentProgram(GLint program) { m_currentProgram = program; } + GLint currentProgram() const { return m_currentProgram; } + private: PixelStoreState m_pixelStore; VertexAttribState *m_states; @@ -127,7 +130,7 @@ private: GLuint m_currentArrayVbo; GLuint m_currentIndexVbo; int m_activeTexture; - + GLint m_currentProgram; bool validLocation(int location) { return (location >= 0 && location < m_nLocations); } public: diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp b/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp index 768e3c9ab..ac360840f 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp @@ -11,7 +11,9 @@ BufferData::BufferData(GLsizeiptr size, void * data) : m_size(size) } /**** ProgramData ****/ -ProgramData::ProgramData() : m_numIndexes(0), m_initialized(false) +ProgramData::ProgramData() : m_numIndexes(0), + m_initialized(false), + m_locShiftWAR(false) { m_Indexes = NULL; } @@ -22,6 +24,7 @@ void ProgramData::initProgramData(GLuint numIndexes) m_numIndexes = numIndexes; delete[] m_Indexes; m_Indexes = new IndexInfo[numIndexes]; + m_locShiftWAR = false; } bool ProgramData::isInitialized() @@ -66,6 +69,30 @@ GLenum ProgramData::getTypeForLocation(GLint location) return 0; } +void ProgramData::setupLocationShiftWAR() +{ + m_locShiftWAR = false; + for (int i=0; i>16; + else return hostLoc; +} + +GLint ProgramData::locationWARAppToHost(GLint appLoc) +{ + if (m_locShiftWAR) return appLoc<<16; + else return appLoc; +} + + /***** GLSharedGroup ****/ GLSharedGroup::GLSharedGroup() : @@ -188,6 +215,29 @@ bool GLSharedGroup::isProgram(GLuint program) return (pData!=NULL); } +void GLSharedGroup::setupLocationShiftWAR(GLuint program) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) pData->setupLocationShiftWAR(); +} + +GLint GLSharedGroup::locationWARHostToApp(GLuint program, GLint hostLoc) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) return pData->locationWARHostToApp(hostLoc); + else return hostLoc; +} + +GLint GLSharedGroup::locationWARAppToHost(GLuint program, GLint appLoc) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) return pData->locationWARAppToHost(appLoc); + else return appLoc; +} + void GLSharedGroup::addShaderData(GLuint shader) { diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h b/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h index 46e91f893..2443562bc 100644 --- a/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h +++ b/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h @@ -54,6 +54,7 @@ private: GLuint m_numIndexes; IndexInfo* m_Indexes; bool m_initialized; + bool m_locShiftWAR; public: ProgramData(); void initProgramData(GLuint numIndexes); @@ -62,6 +63,11 @@ public: void setIndexInfo(GLuint index, GLint base, GLint size, GLenum type); GLuint getIndexForLocation(GLint location); GLenum getTypeForLocation(GLint location); + + void setupLocationShiftWAR(); + GLint locationWARHostToApp(GLint hostLoc); + GLint locationWARAppToHost(GLint appLoc); + }; class GLSharedGroup { @@ -86,6 +92,9 @@ public: void deleteProgramData(GLuint program); void setProgramIndexInfo(GLuint program, GLuint index, GLint base, GLint size, GLenum type); GLenum getProgramUniformType(GLuint program, GLint location); + void setupLocationShiftWAR(GLuint program); + GLint locationWARHostToApp(GLuint program, GLint hostLoc); + GLint locationWARAppToHost(GLuint program, GLint appLoc); void addShaderData(GLuint shader); bool isShader(GLuint shader); diff --git a/tools/emulator/opengl/system/GLESv2_enc/GL2Encoder.cpp b/tools/emulator/opengl/system/GLESv2_enc/GL2Encoder.cpp index 225d4ff68..5781dd4fe 100644 --- a/tools/emulator/opengl/system/GLESv2_enc/GL2Encoder.cpp +++ b/tools/emulator/opengl/system/GLESv2_enc/GL2Encoder.cpp @@ -54,6 +54,28 @@ GL2Encoder::GL2Encoder(IOStream *stream) : gl2_encoder_context_t(stream) m_glCreateProgram_enc = set_glCreateProgram(s_glCreateProgram); m_glCreateShader_enc = set_glCreateShader(s_glCreateShader); m_glDeleteShader_enc = set_glDeleteShader(s_glDeleteShader); + m_glGetUniformLocation_enc = set_glGetUniformLocation(s_glGetUniformLocation); + m_glUseProgram_enc = set_glUseProgram(s_glUseProgram); + + m_glUniform1f_enc = set_glUniform1f(s_glUniform1f); + m_glUniform1fv_enc = set_glUniform1fv(s_glUniform1fv); + m_glUniform1i_enc = set_glUniform1i(s_glUniform1i); + m_glUniform1iv_enc = set_glUniform1iv(s_glUniform1iv); + m_glUniform2f_enc = set_glUniform2f(s_glUniform2f); + m_glUniform2fv_enc = set_glUniform2fv(s_glUniform2fv); + m_glUniform2i_enc = set_glUniform2i(s_glUniform2i); + m_glUniform2iv_enc = set_glUniform2iv(s_glUniform2iv); + m_glUniform3f_enc = set_glUniform3f(s_glUniform3f); + m_glUniform3fv_enc = set_glUniform3fv(s_glUniform3fv); + m_glUniform3i_enc = set_glUniform3i(s_glUniform3i); + m_glUniform3iv_enc = set_glUniform3iv(s_glUniform3iv); + m_glUniform4f_enc = set_glUniform4f(s_glUniform4f); + m_glUniform4fv_enc = set_glUniform4fv(s_glUniform4fv); + m_glUniform4i_enc = set_glUniform4i(s_glUniform4i); + m_glUniform4iv_enc = set_glUniform4iv(s_glUniform4iv); + m_glUniformMatrix2fv_enc = set_glUniformMatrix2fv(s_glUniformMatrix2fv); + m_glUniformMatrix3fv_enc = set_glUniformMatrix3fv(s_glUniformMatrix3fv); + m_glUniformMatrix4fv_enc = set_glUniformMatrix4fv(s_glUniformMatrix4fv); } GL2Encoder::~GL2Encoder() @@ -450,9 +472,10 @@ void GL2Encoder::s_glLinkProgram(void * self, GLuint program) for (GLint i=0 ; iglGetActiveUniform(self, program, i, maxLength, NULL, &size, &type, name); - location = ctx->glGetUniformLocation(self, program, name); + location = ctx->m_glGetUniformLocation_enc(self, program, name); ctx->m_shared->setProgramIndexInfo(program, i, location, size, type); } + ctx->m_shared->setupLocationShiftWAR(program); delete[] name; } @@ -470,16 +493,18 @@ void GL2Encoder::s_glGetUniformiv(void *self, GLuint program, GLint location, GL GL2Encoder *ctx = (GL2Encoder*)self; SET_ERROR_IF(!(ctx->m_shared->isProgram(program) || ctx->m_shared->isShader(program)), GL_INVALID_VALUE); SET_ERROR_IF(!ctx->m_shared->isProgramInitialized(program), GL_INVALID_OPERATION); - SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,location)==0, GL_INVALID_OPERATION); - ctx->m_glGetUniformiv_enc(self, program, location, params); + GLint hostLoc = ctx->m_shared->locationWARAppToHost(program, location); + SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,hostLoc)==0, GL_INVALID_OPERATION); + ctx->m_glGetUniformiv_enc(self, program, hostLoc, params); } void GL2Encoder::s_glGetUniformfv(void *self, GLuint program, GLint location, GLfloat* params) { GL2Encoder *ctx = (GL2Encoder*)self; SET_ERROR_IF(!(ctx->m_shared->isProgram(program) || ctx->m_shared->isShader(program)), GL_INVALID_VALUE); SET_ERROR_IF(!ctx->m_shared->isProgramInitialized(program), GL_INVALID_OPERATION); - SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,location)==0, GL_INVALID_OPERATION); - ctx->m_glGetUniformfv_enc(self, program, location, params); + GLint hostLoc = ctx->m_shared->locationWARAppToHost(program,location); + SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,hostLoc)==0, GL_INVALID_OPERATION); + ctx->m_glGetUniformfv_enc(self, program, hostLoc, params); } GLuint GL2Encoder::s_glCreateProgram(void * self) @@ -506,3 +531,151 @@ void GL2Encoder::s_glDeleteShader(void *self, GLenum shader) ctx->m_glDeleteShader_enc(self,shader); ctx->m_shared->deleteShaderData(shader); } + +int GL2Encoder::s_glGetUniformLocation(void *self, GLuint program, const GLchar *name) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + int hostLoc = ctx->m_glGetUniformLocation_enc(self, program, name); + return ctx->m_shared->locationWARHostToApp(program, hostLoc); +} + +void GL2Encoder::s_glUseProgram(void *self, GLuint program) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + ctx->m_glUseProgram_enc(self, program); + ctx->m_state->setCurrentProgram(program); +} + +void GL2Encoder::s_glUniform1f(void *self , GLint location, GLfloat x) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform1f_enc(self, hostLoc, x); +} + +void GL2Encoder::s_glUniform1fv(void *self , GLint location, GLsizei count, const GLfloat* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform1fv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform1i(void *self , GLint location, GLint x) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform1i_enc(self, hostLoc, x); +} + +void GL2Encoder::s_glUniform1iv(void *self , GLint location, GLsizei count, const GLint* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform1iv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform2f(void *self , GLint location, GLfloat x, GLfloat y) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform2f_enc(self, hostLoc, x, y); +} + +void GL2Encoder::s_glUniform2fv(void *self , GLint location, GLsizei count, const GLfloat* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform2fv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform2i(void *self , GLint location, GLint x, GLint y) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform2i_enc(self, hostLoc, x, y); +} + +void GL2Encoder::s_glUniform2iv(void *self , GLint location, GLsizei count, const GLint* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform2iv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform3f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform3f_enc(self, hostLoc, x, y, z); +} + +void GL2Encoder::s_glUniform3fv(void *self , GLint location, GLsizei count, const GLfloat* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform3fv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform3i(void *self , GLint location, GLint x, GLint y, GLint z) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform3i_enc(self, hostLoc, x, y, z); +} + +void GL2Encoder::s_glUniform3iv(void *self , GLint location, GLsizei count, const GLint* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform3iv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform4f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform4f_enc(self, hostLoc, x, y, z, w); +} + +void GL2Encoder::s_glUniform4fv(void *self , GLint location, GLsizei count, const GLfloat* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform4fv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform4i(void *self , GLint location, GLint x, GLint y, GLint z, GLint w) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform4i_enc(self, hostLoc, x, y, z, w); +} + +void GL2Encoder::s_glUniform4iv(void *self , GLint location, GLsizei count, const GLint* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform4iv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniformMatrix2fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniformMatrix2fv_enc(self, hostLoc, count, transpose, value); +} + +void GL2Encoder::s_glUniformMatrix3fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniformMatrix3fv_enc(self, hostLoc, count, transpose, value); +} + +void GL2Encoder::s_glUniformMatrix4fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniformMatrix4fv_enc(self, hostLoc, count, transpose, value); +} + diff --git a/tools/emulator/opengl/system/GLESv2_enc/GL2Encoder.h b/tools/emulator/opengl/system/GLESv2_enc/GL2Encoder.h index 3e2dccf4b..2914fa905 100644 --- a/tools/emulator/opengl/system/GLESv2_enc/GL2Encoder.h +++ b/tools/emulator/opengl/system/GLESv2_enc/GL2Encoder.h @@ -141,5 +141,49 @@ private: glDeleteShader_client_proc_t m_glDeleteShader_enc; static void s_glDeleteShader(void *self, GLuint shader); + glGetUniformLocation_client_proc_t m_glGetUniformLocation_enc; + static int s_glGetUniformLocation(void *self, GLuint program, const GLchar *name); + glUseProgram_client_proc_t m_glUseProgram_enc; + + glUniform1f_client_proc_t m_glUniform1f_enc; + glUniform1fv_client_proc_t m_glUniform1fv_enc; + glUniform1i_client_proc_t m_glUniform1i_enc; + glUniform1iv_client_proc_t m_glUniform1iv_enc; + glUniform2f_client_proc_t m_glUniform2f_enc; + glUniform2fv_client_proc_t m_glUniform2fv_enc; + glUniform2i_client_proc_t m_glUniform2i_enc; + glUniform2iv_client_proc_t m_glUniform2iv_enc; + glUniform3f_client_proc_t m_glUniform3f_enc; + glUniform3fv_client_proc_t m_glUniform3fv_enc; + glUniform3i_client_proc_t m_glUniform3i_enc; + glUniform3iv_client_proc_t m_glUniform3iv_enc; + glUniform4f_client_proc_t m_glUniform4f_enc; + glUniform4fv_client_proc_t m_glUniform4fv_enc; + glUniform4i_client_proc_t m_glUniform4i_enc; + glUniform4iv_client_proc_t m_glUniform4iv_enc; + glUniformMatrix2fv_client_proc_t m_glUniformMatrix2fv_enc; + glUniformMatrix3fv_client_proc_t m_glUniformMatrix3fv_enc; + glUniformMatrix4fv_client_proc_t m_glUniformMatrix4fv_enc; + + static void s_glUseProgram(void *self, GLuint program); + static void s_glUniform1f(void *self , GLint location, GLfloat x); + static void s_glUniform1fv(void *self , GLint location, GLsizei count, const GLfloat* v); + static void s_glUniform1i(void *self , GLint location, GLint x); + static void s_glUniform1iv(void *self , GLint location, GLsizei count, const GLint* v); + static void s_glUniform2f(void *self , GLint location, GLfloat x, GLfloat y); + static void s_glUniform2fv(void *self , GLint location, GLsizei count, const GLfloat* v); + static void s_glUniform2i(void *self , GLint location, GLint x, GLint y); + static void s_glUniform2iv(void *self , GLint location, GLsizei count, const GLint* v); + static void s_glUniform3f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z); + static void s_glUniform3fv(void *self , GLint location, GLsizei count, const GLfloat* v); + static void s_glUniform3i(void *self , GLint location, GLint x, GLint y, GLint z); + static void s_glUniform3iv(void *self , GLint location, GLsizei count, const GLint* v); + static void s_glUniform4f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + static void s_glUniform4fv(void *self , GLint location, GLsizei count, const GLfloat* v); + static void s_glUniform4i(void *self , GLint location, GLint x, GLint y, GLint z, GLint w); + static void s_glUniform4iv(void *self , GLint location, GLsizei count, const GLint* v); + static void s_glUniformMatrix2fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + static void s_glUniformMatrix3fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + static void s_glUniformMatrix4fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); }; #endif