/** * Draws the emulated screens to the emulator window. */ void RendererOpenGL::DrawScreens() { auto viewport_extent = GetViewportExtent(); glViewport(viewport_extent.left, viewport_extent.top, viewport_extent.GetWidth(), viewport_extent.GetHeight()); // TODO: Or bottom? glClear(GL_COLOR_BUFFER_BIT); glUseProgram(program_id); // Set projection matrix std::array<GLfloat, 3*2> ortho_matrix = MakeOrthographicMatrix((float)resolution_width, (float)resolution_height); glUniformMatrix3x2fv(uniform_modelview_matrix, 1, GL_FALSE, ortho_matrix.data()); // Bind texture in Texture Unit 0 glActiveTexture(GL_TEXTURE0); glUniform1i(uniform_color_texture, 0); const float max_width = std::max((float)VideoCore::kScreenTopWidth, (float)VideoCore::kScreenBottomWidth); const float top_x = 0.5f * (max_width - VideoCore::kScreenTopWidth); const float bottom_x = 0.5f * (max_width - VideoCore::kScreenBottomWidth); DrawSingleScreenRotated(textures[0], top_x, 0, (float)VideoCore::kScreenTopWidth, (float)VideoCore::kScreenTopHeight); DrawSingleScreenRotated(textures[1], bottom_x, (float)VideoCore::kScreenTopHeight, (float)VideoCore::kScreenBottomWidth, (float)VideoCore::kScreenBottomHeight); m_current_frame++; }
/** * Draws the emulated screens to the emulator window. */ void RendererOpenGL::DrawScreens() { auto layout = render_window->GetFramebufferLayout(); glViewport(0, 0, layout.width, layout.height); glClear(GL_COLOR_BUFFER_BIT); state.draw.shader_program = program_id; state.Apply(); // Set projection matrix std::array<GLfloat, 3 * 2> ortho_matrix = MakeOrthographicMatrix((float)layout.width, (float)layout.height); glUniformMatrix3x2fv(uniform_modelview_matrix, 1, GL_FALSE, ortho_matrix.data()); // Bind texture in Texture Unit 0 glActiveTexture(GL_TEXTURE0); glUniform1i(uniform_color_texture, 0); DrawSingleScreenRotated(textures[0], (float)layout.top_screen.left, (float)layout.top_screen.top, (float)layout.top_screen.GetWidth(), (float)layout.top_screen.GetHeight()); DrawSingleScreenRotated(textures[1], (float)layout.bottom_screen.left,(float)layout.bottom_screen.top, (float)layout.bottom_screen.GetWidth(), (float)layout.bottom_screen.GetHeight()); m_current_frame++; }
void Shader::setUniform<glm::mat3x2>(const std::string& name, const glm::mat3x2& data) { int prev_bound_program; glGetIntegerv(GL_CURRENT_PROGRAM, &prev_bound_program); if(name_to_location.count(name) == 0) { throw Exceptions::InvalidUniformNameException(name); } if(prev_bound_program != program_object) useProgram(); glUniformMatrix3x2fv(name_to_location[name], 1, false, glm::value_ptr(data)); if(prev_bound_program != program_object) glUseProgram(prev_bound_program); }
void program::set_uniform_matrix3x2fv( char const* varname, GLsizei count, GLboolean transpose, GLfloat* value ) const { GLint location = get_uniform_location(varname); if (location >= 0) { #if GPUCAST_GL_DIRECT_STATE_ACCESS glProgramUniformMatrix3x2fv(id_, location, count, transpose, value); #else glUniformMatrix3x2fv(location, count, transpose, value); #endif } }
void GLSLProgram::setUniformMatrix3x2fv( const std::string & name, const GLfloat * value, const GLboolean transpose, const GLsizei count ) { #ifdef __OPENGLES2__ #pragma message("GLSLProgram::setUniformMatrix3x2fv(): not implemented in ES2") assert( false ); #else const GLint loc = getUniformLocation( name ); assert( value != 0 ); assert( count != 0 ); if ( loc != -1 ) glUniformMatrix3x2fv( loc, count, transpose, value ); #endif // #ifdef __OPENGLES2__ }
uintptr_t processFn(struct fnargs* args, char* parg) { uintptr_t ret = 0; switch (args->fn) { case glfnUNDEFINED: abort(); // bad glfn break; case glfnActiveTexture: glActiveTexture((GLenum)args->a0); break; case glfnAttachShader: glAttachShader((GLint)args->a0, (GLint)args->a1); break; case glfnBindAttribLocation: glBindAttribLocation((GLint)args->a0, (GLint)args->a1, (GLchar*)args->a2); break; case glfnBindBuffer: glBindBuffer((GLenum)args->a0, (GLuint)args->a1); break; case glfnBindFramebuffer: glBindFramebuffer((GLenum)args->a0, (GLint)args->a1); break; case glfnBindRenderbuffer: glBindRenderbuffer((GLenum)args->a0, (GLint)args->a1); break; case glfnBindTexture: glBindTexture((GLenum)args->a0, (GLint)args->a1); break; case glfnBlendColor: glBlendColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnBlendEquation: glBlendEquation((GLenum)args->a0); break; case glfnBlendEquationSeparate: glBlendEquationSeparate((GLenum)args->a0, (GLenum)args->a1); break; case glfnBlendFunc: glBlendFunc((GLenum)args->a0, (GLenum)args->a1); break; case glfnBlendFuncSeparate: glBlendFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3); break; case glfnBlitFramebuffer: glBlitFramebuffer((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7, (GLbitfield)args->a8, (GLenum)args->a9); break; case glfnBufferData: glBufferData((GLenum)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg, (GLenum)args->a2); break; case glfnBufferSubData: glBufferSubData((GLenum)args->a0, (GLint)args->a1, (GLsizeiptr)args->a2, (GLvoid*)parg); break; case glfnCheckFramebufferStatus: ret = glCheckFramebufferStatus((GLenum)args->a0); break; case glfnClear: glClear((GLenum)args->a0); break; case glfnClearColor: glClearColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnClearDepthf: glClearDepthf(*(GLfloat*)&args->a0); break; case glfnClearStencil: glClearStencil((GLint)args->a0); break; case glfnColorMask: glColorMask((GLboolean)args->a0, (GLboolean)args->a1, (GLboolean)args->a2, (GLboolean)args->a3); break; case glfnCompileShader: glCompileShader((GLint)args->a0); break; case glfnCompressedTexImage2D: glCompressedTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLsizeiptr)args->a6, (GLvoid*)parg); break; case glfnCompressedTexSubImage2D: glCompressedTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLenum)args->a6, (GLsizeiptr)args->a7, (GLvoid*)parg); break; case glfnCopyTexImage2D: glCopyTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7); break; case glfnCopyTexSubImage2D: glCopyTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7); break; case glfnCreateProgram: ret = glCreateProgram(); break; case glfnCreateShader: ret = glCreateShader((GLenum)args->a0); break; case glfnCullFace: glCullFace((GLenum)args->a0); break; case glfnDeleteBuffer: glDeleteBuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteFramebuffer: glDeleteFramebuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteProgram: glDeleteProgram((GLint)args->a0); break; case glfnDeleteRenderbuffer: glDeleteRenderbuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteShader: glDeleteShader((GLint)args->a0); break; case glfnDeleteTexture: glDeleteTextures(1, (const GLuint*)(&args->a0)); break; case glfnDepthFunc: glDepthFunc((GLenum)args->a0); break; case glfnDepthMask: glDepthMask((GLboolean)args->a0); break; case glfnDepthRangef: glDepthRangef(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1); break; case glfnDetachShader: glDetachShader((GLint)args->a0, (GLint)args->a1); break; case glfnDisable: glDisable((GLenum)args->a0); break; case glfnDisableVertexAttribArray: glDisableVertexAttribArray((GLint)args->a0); break; case glfnDrawArrays: glDrawArrays((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2); break; case glfnDrawElements: glDrawElements((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (void*)args->a3); break; case glfnEnable: glEnable((GLenum)args->a0); break; case glfnEnableVertexAttribArray: glEnableVertexAttribArray((GLint)args->a0); break; case glfnFinish: glFinish(); break; case glfnFlush: glFlush(); break; case glfnFramebufferRenderbuffer: glFramebufferRenderbuffer((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3); break; case glfnFramebufferTexture2D: glFramebufferTexture2D((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4); break; case glfnFrontFace: glFrontFace((GLenum)args->a0); break; case glfnGenBuffer: glGenBuffers(1, (GLuint*)&ret); break; case glfnGenFramebuffer: glGenFramebuffers(1, (GLuint*)&ret); break; case glfnGenRenderbuffer: glGenRenderbuffers(1, (GLuint*)&ret); break; case glfnGenTexture: glGenTextures(1, (GLuint*)&ret); break; case glfnGenerateMipmap: glGenerateMipmap((GLenum)args->a0); break; case glfnGetActiveAttrib: glGetActiveAttrib( (GLuint)args->a0, (GLuint)args->a1, (GLsizei)args->a2, NULL, (GLint*)&ret, (GLenum*)args->a3, (GLchar*)parg); break; case glfnGetActiveUniform: glGetActiveUniform( (GLuint)args->a0, (GLuint)args->a1, (GLsizei)args->a2, NULL, (GLint*)&ret, (GLenum*)args->a3, (GLchar*)parg); break; case glfnGetAttachedShaders: glGetAttachedShaders((GLuint)args->a0, (GLsizei)args->a1, (GLsizei*)&ret, (GLuint*)parg); break; case glfnGetAttribLocation: ret = glGetAttribLocation((GLint)args->a0, (GLchar*)args->a1); break; case glfnGetBooleanv: glGetBooleanv((GLenum)args->a0, (GLboolean*)parg); break; case glfnGetBufferParameteri: glGetBufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetFloatv: glGetFloatv((GLenum)args->a0, (GLfloat*)parg); break; case glfnGetIntegerv: glGetIntegerv((GLenum)args->a0, (GLint*)parg); break; case glfnGetError: ret = glGetError(); break; case glfnGetFramebufferAttachmentParameteriv: glGetFramebufferAttachmentParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint*)&ret); break; case glfnGetProgramiv: glGetProgramiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetProgramInfoLog: glGetProgramInfoLog((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetRenderbufferParameteriv: glGetRenderbufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetShaderiv: glGetShaderiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetShaderInfoLog: glGetShaderInfoLog((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetShaderPrecisionFormat: glGetShaderPrecisionFormat((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg, &((GLint*)parg)[2]); break; case glfnGetShaderSource: glGetShaderSource((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetString: ret = (uintptr_t)glGetString((GLenum)args->a0); break; case glfnGetTexParameterfv: glGetTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnGetTexParameteriv: glGetTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnGetUniformfv: glGetUniformfv((GLuint)args->a0, (GLint)args->a1, (GLfloat*)parg); break; case glfnGetUniformiv: glGetUniformiv((GLuint)args->a0, (GLint)args->a1, (GLint*)parg); break; case glfnGetUniformLocation: ret = glGetUniformLocation((GLint)args->a0, (GLchar*)args->a1); break; case glfnGetVertexAttribfv: glGetVertexAttribfv((GLuint)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnGetVertexAttribiv: glGetVertexAttribiv((GLuint)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnHint: glHint((GLenum)args->a0, (GLenum)args->a1); break; case glfnIsBuffer: ret = glIsBuffer((GLint)args->a0); break; case glfnIsEnabled: ret = glIsEnabled((GLenum)args->a0); break; case glfnIsFramebuffer: ret = glIsFramebuffer((GLint)args->a0); break; case glfnIsProgram: ret = glIsProgram((GLint)args->a0); break; case glfnIsRenderbuffer: ret = glIsRenderbuffer((GLint)args->a0); break; case glfnIsShader: ret = glIsShader((GLint)args->a0); break; case glfnIsTexture: ret = glIsTexture((GLint)args->a0); break; case glfnLineWidth: glLineWidth(*(GLfloat*)&args->a0); break; case glfnLinkProgram: glLinkProgram((GLint)args->a0); break; case glfnPixelStorei: glPixelStorei((GLenum)args->a0, (GLint)args->a1); break; case glfnPolygonOffset: glPolygonOffset(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1); break; case glfnReadPixels: glReadPixels((GLint)args->a0, (GLint)args->a1, (GLsizei)args->a2, (GLsizei)args->a3, (GLenum)args->a4, (GLenum)args->a5, (void*)parg); break; case glfnReleaseShaderCompiler: glReleaseShaderCompiler(); break; case glfnRenderbufferStorage: glRenderbufferStorage((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnSampleCoverage: glSampleCoverage(*(GLfloat*)&args->a0, (GLboolean)args->a1); break; case glfnScissor: glScissor((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnShaderSource: #if defined(os_ios) || defined(os_osx) glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar *const *)args->a2, NULL); #else glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar **)args->a2, NULL); #endif break; case glfnStencilFunc: glStencilFunc((GLenum)args->a0, (GLint)args->a1, (GLuint)args->a2); break; case glfnStencilFuncSeparate: glStencilFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLuint)args->a3); break; case glfnStencilMask: glStencilMask((GLuint)args->a0); break; case glfnStencilMaskSeparate: glStencilMaskSeparate((GLenum)args->a0, (GLuint)args->a1); break; case glfnStencilOp: glStencilOp((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2); break; case glfnStencilOpSeparate: glStencilOpSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3); break; case glfnTexImage2D: glTexImage2D( (GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLsizei)args->a3, (GLsizei)args->a4, 0, // border (GLenum)args->a5, (GLenum)args->a6, (const GLvoid*)parg); break; case glfnTexSubImage2D: glTexSubImage2D( (GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLsizei)args->a4, (GLsizei)args->a5, (GLenum)args->a6, (GLenum)args->a7, (const GLvoid*)parg); break; case glfnTexParameterf: glTexParameterf((GLenum)args->a0, (GLenum)args->a1, *(GLfloat*)&args->a2); break; case glfnTexParameterfv: glTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnTexParameteri: glTexParameteri((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2); break; case glfnTexParameteriv: glTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnUniform1f: glUniform1f((GLint)args->a0, *(GLfloat*)&args->a1); break; case glfnUniform1fv: glUniform1fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform1i: glUniform1i((GLint)args->a0, (GLint)args->a1); break; case glfnUniform1ui: glUniform1ui((GLint)args->a0, (GLuint)args->a1); break; case glfnUniform1iv: glUniform1iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform2f: glUniform2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2); break; case glfnUniform2fv: glUniform2fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform2i: glUniform2i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2); break; case glfnUniform2ui: glUniform2ui((GLint)args->a0, (GLuint)args->a1, (GLuint)args->a2); break; case glfnUniform2iv: glUniform2iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform3f: glUniform3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnUniform3fv: glUniform3fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform3i: glUniform3i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnUniform3ui: glUniform3ui((GLint)args->a0, (GLuint)args->a1, (GLuint)args->a2, (GLuint)args->a3); break; case glfnUniform3iv: glUniform3iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform4f: glUniform4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4); break; case glfnUniform4fv: glUniform4fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform4i: glUniform4i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4); break; case glfnUniform4ui: glUniform4ui((GLint)args->a0, (GLuint)args->a1, (GLuint)args->a2, (GLuint)args->a3, (GLuint)args->a4); break; case glfnUniform4iv: glUniform4iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniformMatrix2fv: glUniformMatrix2fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix3fv: glUniformMatrix3fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix4fv: glUniformMatrix4fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix2x3fv: glUniformMatrix2x3fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix3x2fv: glUniformMatrix3x2fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix2x4fv: glUniformMatrix2x4fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix4x2fv: glUniformMatrix4x2fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix3x4fv: glUniformMatrix3x4fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix4x3fv: glUniformMatrix4x3fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUseProgram: glUseProgram((GLint)args->a0); break; case glfnValidateProgram: glValidateProgram((GLint)args->a0); break; case glfnVertexAttrib1f: glVertexAttrib1f((GLint)args->a0, *(GLfloat*)&args->a1); break; case glfnVertexAttrib1fv: glVertexAttrib1fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib2f: glVertexAttrib2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2); break; case glfnVertexAttrib2fv: glVertexAttrib2fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib3f: glVertexAttrib3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnVertexAttrib3fv: glVertexAttrib3fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib4f: glVertexAttrib4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4); break; case glfnVertexAttrib4fv: glVertexAttrib4fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttribPointer: glVertexAttribPointer((GLuint)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLboolean)args->a3, (GLsizei)args->a4, (const GLvoid*)args->a5); break; case glfnViewport: glViewport((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; } return ret; }
bool Shader::setShaderUniform(const std::string &name, GLsizei row, GLsizei column, GLsizei count, GLboolean transpose, const GLfloat *value) { GLint loc; if(!this->getUniformLoc(name, loc)) return false; if(count > (row * column)) return false; // TODO: check veracity of this decision tree switch(column) { case 1: { switch(row) { case 1: glUniform1f(loc, value[0]); break; case 2: glUniform2f(loc, value[0], value[1]); break; case 3: glUniform3f(loc, value[0], value[1], value[2]); break; case 4: glUniform4f(loc, value[0], value[1], value[2], value[3]); break; default: return false; } break; } case 2: { switch(column) { case 2: glUniformMatrix2fv(loc, count, transpose, value); break; case 3: glUniformMatrix2x3fv(loc, count, transpose, value); break; case 4: glUniformMatrix2x4fv(loc, count, transpose, value); break; default: return false; } break; } case 3: { switch(column) { case 2: glUniformMatrix3x2fv(loc, count, transpose, value); break; case 3: glUniformMatrix3fv(loc, count, transpose, value); break; case 4: glUniformMatrix3x4fv(loc, count, transpose, value); break; default: return false; } break; } case 4: { switch(column) { case 2: glUniformMatrix4x2fv(loc, count, transpose, value); case 3: glUniformMatrix4x3fv(loc, count, transpose, value); break; case 4: glUniformMatrix4fv(loc, count, transpose, value); break; default: return false; } break; } default: return false; } return true; }
/* * Sets the given uniform variable to the given value. */ void sstSetUniformData( sstProgram *program, char *name, GLvoid *data ) { uniform *un; int i; /* Find our data */ for( i = 0; i < program->un_count; i++ ) { un = &program->uniforms[i]; if( strcmp(un->name, name) == 0 ) { break; } } /* Lookup failure */ if( i >= program->un_count ) { printf("WARN: Uniform variable [%s] does not exist!\n", name); return; } switch( un->first ) { case 1: switch( un->type ) { case GL_FLOAT: glUniform1fv(un->location, un->count, (const GLfloat*)data); return; case GL_INT: glUniform1iv(un->location, un->count, (const GLint*)data); return; case GL_UNSIGNED_INT: glUniform1uiv(un->location, un->count, (const GLuint*)data); return; default: printf("WARN: Invalid type for uniform value [%s]!\n", name); return; } case 2: switch( un->second ) { case 0: case 1: switch( un->type ) { case GL_FLOAT: glUniform2fv(un->location, un->count, (const GLfloat*)data); return; case GL_INT: glUniform2iv(un->location, un->count, (const GLint*)data); return; case GL_UNSIGNED_INT: glUniform2uiv(un->location, un->count, (const GLuint*)data); return; default: printf("WARN: Invalid type for uniform value [%s]!\n", name); return; } case 2: glUniformMatrix2fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; case 3: glUniformMatrix2x3fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; case 4: glUniformMatrix2x4fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; default: printf("WARN: Invalid second matrix component: %d!\n", un->second); return; } case 3: switch( un->second ) { case 0: case 1: switch( un->type ) { case GL_FLOAT: glUniform3fv(un->location, un->count, (const GLfloat*)data); return; case GL_INT: glUniform3iv(un->location, un->count, (const GLint*)data); return; case GL_UNSIGNED_INT: glUniform3uiv(un->location, un->count, (const GLuint*)data); return; default: printf("WARN: Invalid type for uniform value [%s]!\n", name); return; } case 2: glUniformMatrix3x2fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; case 3: glUniformMatrix3fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; case 4: glUniformMatrix3x4fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; default: printf("WARN: Invalid second matrix component: %d!\n", un->second); return; } case 4: switch( un->second ) { case 0: case 1: switch( un->type ) { case GL_FLOAT: glUniform4fv(un->location, un->count, (const GLfloat*)data); return; case GL_INT: glUniform4iv(un->location, un->count, (const GLint*)data); return; case GL_UNSIGNED_INT: glUniform4uiv(un->location, un->count, (const GLuint*)data); return; default: printf("WARN: Invalid type for uniform value [%s]!\n", name); return; } case 2: glUniformMatrix4x2fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; case 3: glUniformMatrix4x3fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; case 4: glUniformMatrix4fv(un->location, un->count, un->transpose, (const GLfloat*)data); return; default: printf("WARN: Invalid second matrix component: %d!\n", un->second); return; } default: printf("WARN: Invalid first matrix component: %d!\n", un->first); return; } }
void GLSLShader::SetMatrix3x2(GLint variable,GLsizei count,GLboolean transpose, const GLfloat *value) { if (variable!=-1) glUniformMatrix3x2fv(variable, count, transpose, value); }
GLvoid Program::setUniformMatrix(GLint location, glm::mat3x2 matrix) { glUniformMatrix3x2fv(location, 1, GL_FALSE, glm::value_ptr(matrix)); }
void RendererBase::BindUniformBuffer(UniformBuffer * resource, ShaderProgram * program) { BindShaderProgram(program); UniformBufferPimpl * resource_pimpl = (UniformBufferPimpl *) resource->PRIVATE; if (resource->index == 0) { ShaderProgramPimpl * shader_pimpl = (ShaderProgramPimpl *) program->PRIVATE; //ShaderDomain & shader_domain = program->domains[resource->domain]; //ShaderDomainPimpl * domain_pimpl = (ShaderDomainPimpl *) shader_domain.PRIVATE; if (shader_pimpl->bound_uniform_buffers[0] != resource) { shader_pimpl->bound_uniform_buffers[0] = resource; for (unsigned int i = 0; i < program->uniforms.GetSize(); ++i) { if (program->GetUniformBufferIndex(i)) continue; unsigned char rows = program->GetUniformRows(i); unsigned char columns = program->GetUniformColumns(i); GLuint location = shader_pimpl->uniform_locations[i]; unsigned int count = program->GetUniformArrayLength(i); float * data = (float *) (resource_pimpl->cpu_data + program->GetUniformBufferOffset(i)); switch(rows) { case 1: switch (columns) { case 1: glUniform1fv(location, count, data); break; case 2: glUniform2fv(location, count, data); break; case 3: glUniform3fv(location, count, data); break; case 4: glUniform4fv(location, count, data); break; } break; case 2: switch (columns) { case 2: glUniformMatrix2fv(location, count, false, data); break; case 3: glUniformMatrix2x3fv(location, count, false, data); break; case 4: glUniformMatrix2x4fv(location, count, false, data); break; } break; case 3: switch (columns) { case 2: glUniformMatrix3x2fv(location, count, false, data); break; case 3: glUniformMatrix3fv(location, count, false, data); break; case 4: glUniformMatrix3x4fv(location, count, false, data); break; } break; case 4: switch (columns) { case 2: glUniformMatrix4x2fv(location, count, false, data); break; case 3: glUniformMatrix4x3fv(location, count, false, data); break; case 4: glUniformMatrix4fv(location, count, false, data); break; } break; } } //resource_pimpl->dirty_data = false; } } else if (GLEW_ARB_uniform_buffer_object) { ShaderProgramPimpl * shader_pimpl = (ShaderProgramPimpl *) program->PRIVATE; glBindBufferRange(GL_UNIFORM_BUFFER, shader_pimpl->block_bind_points[resource->index], resource_pimpl->buffer, 0, resource->byte_count); //glBindBufferBase(GL_UNIFORM_BUFFER, domain_pimpl->block_bind_points[resource->index], resource_pimpl->buffer); } }
void Uniform::setMatrix3x2(const glm::mat3x2& m32) { glUniformMatrix3x2fv(uniformLocation, 1, GL_FALSE, glm::value_ptr(m32)); }
void UniformImplementation_Legacy::set(const Program * program, const GLint location, const glm::mat3x2 & value) const { program->use(); glUniformMatrix3x2fv(location, 1, GL_FALSE, glm::value_ptr(value)); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL21_nglUniformMatrix3x2fv(JNIEnv *env, jclass clazz, jint location, jint count, jboolean transpose, jobject matrices, jint matrices_position, jlong function_pointer) { GLfloat *matrices_address = ((GLfloat *)(*env)->GetDirectBufferAddress(env, matrices)) + matrices_position; glUniformMatrix3x2fvPROC glUniformMatrix3x2fv = (glUniformMatrix3x2fvPROC)((intptr_t)function_pointer); glUniformMatrix3x2fv(location, count, transpose, matrices_address); }
/* uniformMatrix(location, matrixTable, rows, cols, transpose) */ int gl_UniformMatrix(State& state){ size_t count = 0; size_t size = 0; GLfloat * data = nullptr; vector<float> _data; int rows = state.stack->to<int>(3), cols = state.stack->to<int>(4); //supported sizes are: 2x2, 3x3, 4x4, 2x3, 3x2, 2x4, 4x2, 3x4, 4x3 if ((rows >= 2) && (cols >= 2) && (rows <= 4) && (cols <= 4) && state.stack->is<LUA_TTABLE>(2)){ count = state.stack->objLen(2); if (count > 0){ //is this a table of matrices? state.stack->push<int>(1); state.stack->getTable(2); bool isTable = state.stack->is<LUA_TTABLE>(); state.stack->pop(1); if (!isTable){ count = 1; size = getArray<float>(state, 2, _data); data = new GLfloat[rows * cols]; memcpy(data, _data.data(), size * sizeof(float)); }else{ data = new GLfloat[rows * cols * count]; for (size_t i=0; i < count; i++){ state.stack->push<int>(i+1); state.stack->getTable(2); size = getArray<float>(state, 2, _data); memcpy( data + (rows * cols * sizeof(GLfloat) * i), _data.data(), size * sizeof(float) ); state.stack->pop(1); } } GLboolean transpose = false; if (state.stack->is<LUA_TBOOLEAN>(5)){ transpose = state.stack->to<bool>(5); } if (rows == 2){ if (cols == 2){ glUniformMatrix2fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); }else if (cols == 3){ glUniformMatrix2x3fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); }else{ glUniformMatrix2x4fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); } }else if (rows == 3){ if (cols == 2){ glUniformMatrix3x2fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); }else if (cols == 3){ glUniformMatrix3fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); }else{ glUniformMatrix3x4fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); } }else{ if (cols == 2){ glUniformMatrix4x2fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); }else if (cols == 3){ glUniformMatrix4x3fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); }else{ glUniformMatrix4fv((GLint) state.stack->to<int>(1), (GLsizei) count, (GLboolean) transpose, (GLfloat *) data); } } delete[] data; } } return 0; }
//----------------------------------------------------------------------- void GLSLLinkProgram::updateUniforms(GpuProgramParametersSharedPtr params, uint16 mask, GpuProgramType fromProgType) { // Iterate through uniform reference list and update uniform values GLUniformReferenceIterator currentUniform = mGLUniformReferences.begin(); GLUniformReferenceIterator endUniform = mGLUniformReferences.end(); // determine if we need to transpose matrices when binding int transpose = GL_TRUE; if ((fromProgType == GPT_FRAGMENT_PROGRAM && mVertexProgram && (!mVertexProgram->getGLSLProgram()->getColumnMajorMatrices())) || (fromProgType == GPT_VERTEX_PROGRAM && mFragmentProgram && (!mFragmentProgram->getGLSLProgram()->getColumnMajorMatrices())) || (fromProgType == GPT_GEOMETRY_PROGRAM && mGeometryProgram && (!mGeometryProgram->getGLSLProgram()->getColumnMajorMatrices())) || (fromProgType == GPT_HULL_PROGRAM && mHullProgram && (!mHullProgram->getGLSLProgram()->getColumnMajorMatrices())) || (fromProgType == GPT_DOMAIN_PROGRAM && mDomainProgram && (!mDomainProgram->getGLSLProgram()->getColumnMajorMatrices())) || (fromProgType == GPT_COMPUTE_PROGRAM && mComputeProgram && (!mComputeProgram->getGLSLProgram()->getColumnMajorMatrices()))) { transpose = GL_FALSE; } for (;currentUniform != endUniform; ++currentUniform) { // Only pull values from buffer it's supposed to be in (vertex or fragment) // This method will be called twice, once for vertex program params, // and once for fragment program params. if (fromProgType == currentUniform->mSourceProgType) { const GpuConstantDefinition* def = currentUniform->mConstantDef; if (def->variability & mask) { GLsizei glArraySize = (GLsizei)def->arraySize; // Get the index in the parameter real list switch (def->constType) { case GCT_FLOAT1: OGRE_CHECK_GL_ERROR(glUniform1fv(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex))); break; case GCT_FLOAT2: OGRE_CHECK_GL_ERROR(glUniform2fv(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex))); break; case GCT_FLOAT3: OGRE_CHECK_GL_ERROR(glUniform3fv(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex))); break; case GCT_FLOAT4: OGRE_CHECK_GL_ERROR(glUniform4fv(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex))); break; case GCT_DOUBLE1: OGRE_CHECK_GL_ERROR(glUniform1dv(currentUniform->mLocation, glArraySize, params->getDoublePointer(def->physicalIndex))); break; case GCT_DOUBLE2: OGRE_CHECK_GL_ERROR(glUniform2dv(currentUniform->mLocation, glArraySize, params->getDoublePointer(def->physicalIndex))); break; case GCT_DOUBLE3: OGRE_CHECK_GL_ERROR(glUniform3dv(currentUniform->mLocation, glArraySize, params->getDoublePointer(def->physicalIndex))); break; case GCT_DOUBLE4: OGRE_CHECK_GL_ERROR(glUniform4dv(currentUniform->mLocation, glArraySize, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_2X2: OGRE_CHECK_GL_ERROR(glUniformMatrix2dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_2X3: OGRE_CHECK_GL_ERROR(glUniformMatrix2x3dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_2X4: OGRE_CHECK_GL_ERROR(glUniformMatrix2x4dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_3X2: OGRE_CHECK_GL_ERROR(glUniformMatrix3x2dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_3X3: OGRE_CHECK_GL_ERROR(glUniformMatrix3dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_3X4: OGRE_CHECK_GL_ERROR(glUniformMatrix3x4dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_4X2: OGRE_CHECK_GL_ERROR(glUniformMatrix4x2dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_4X3: OGRE_CHECK_GL_ERROR(glUniformMatrix4x3dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_DOUBLE_4X4: OGRE_CHECK_GL_ERROR(glUniformMatrix4dv(currentUniform->mLocation, glArraySize, transpose, params->getDoublePointer(def->physicalIndex))); break; case GCT_MATRIX_2X2: OGRE_CHECK_GL_ERROR(glUniformMatrix2fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_MATRIX_2X3: OGRE_CHECK_GL_ERROR(glUniformMatrix2x3fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_MATRIX_2X4: OGRE_CHECK_GL_ERROR(glUniformMatrix2x4fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_MATRIX_3X2: OGRE_CHECK_GL_ERROR(glUniformMatrix3x2fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_MATRIX_3X3: OGRE_CHECK_GL_ERROR(glUniformMatrix3fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_MATRIX_3X4: OGRE_CHECK_GL_ERROR(glUniformMatrix3x4fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_MATRIX_4X2: OGRE_CHECK_GL_ERROR(glUniformMatrix4x2fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_MATRIX_4X3: OGRE_CHECK_GL_ERROR(glUniformMatrix4x3fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_MATRIX_4X4: OGRE_CHECK_GL_ERROR(glUniformMatrix4fv(currentUniform->mLocation, glArraySize, transpose, params->getFloatPointer(def->physicalIndex))); break; case GCT_INT1: OGRE_CHECK_GL_ERROR(glUniform1iv(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex))); break; case GCT_INT2: OGRE_CHECK_GL_ERROR(glUniform2iv(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex))); break; case GCT_INT3: OGRE_CHECK_GL_ERROR(glUniform3iv(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex))); break; case GCT_INT4: OGRE_CHECK_GL_ERROR(glUniform4iv(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex))); break; case GCT_SAMPLER1D: case GCT_SAMPLER1DSHADOW: case GCT_SAMPLER2D: case GCT_SAMPLER2DSHADOW: case GCT_SAMPLER2DARRAY: case GCT_SAMPLER3D: case GCT_SAMPLERCUBE: case GCT_SAMPLERRECT: // Samplers handled like 1-element ints OGRE_CHECK_GL_ERROR(glUniform1iv(currentUniform->mLocation, 1, (GLint*)params->getIntPointer(def->physicalIndex))); break; case GCT_SUBROUTINE: case GCT_UNKNOWN: break; } // End switch } // Variability & mask } // fromProgType == currentUniform->mSourceProgType } // End for }
void ShaderFamily::setUniformMatrix3x2fv(const char* _var, size_t _count, bool _transpose, const float* _m) { glUniformMatrix3x2fv(getUniformLocation(_var),_count,_transpose,_m); }
void UniformImplementation_Legacy::set(const Program * program, const GLint location, const std::vector<glm::mat3x2> & value) const { program->use(); glUniformMatrix3x2fv(location, static_cast<GLint>(value.size()), GL_FALSE, reinterpret_cast<const float*>(value.data())); }
void ShaderProgram::sendUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *v) { bind(); glUniformMatrix3x2fv(location, count, transpose, v); unbind(); }
void CShaderInterface::sendUniformMatrix3x2fv(const QString& p_name, GLsizei count, GLboolean transpose, const GLfloat * value){ QByteArray ba = p_name.toLocal8Bit(); glUniformMatrix3x2fv( glGetUniformLocation( m_singleton.m_current, (const char*) ba.data() ), count, transpose, value ); }
//----------------------------------------------------------------------- void GLSLLinkProgram::updateUniforms(GpuProgramParametersSharedPtr params, uint16 mask, GpuProgramType fromProgType) { // iterate through uniform reference list and update uniform values GLUniformReferenceIterator currentUniform = mGLUniformReferences.begin(); GLUniformReferenceIterator endUniform = mGLUniformReferences.end(); for (; currentUniform != endUniform; ++currentUniform) { // Only pull values from buffer it's supposed to be in (vertex or fragment) // This method will be called twice, once for vertex program params, // and once for fragment program params. if (fromProgType == currentUniform->mSourceProgType) { const GpuConstantDefinition* def = currentUniform->mConstantDef; if (def->variability & mask) { GLsizei glArraySize = (GLsizei)def->arraySize; // get the index in the parameter real list switch (def->constType) { case GCT_FLOAT1: glUniform1fvARB(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex)); break; case GCT_FLOAT2: glUniform2fvARB(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex)); break; case GCT_FLOAT3: glUniform3fvARB(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex)); break; case GCT_FLOAT4: glUniform4fvARB(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex)); break; case GCT_MATRIX_2X2: glUniformMatrix2fvARB(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); break; case GCT_MATRIX_2X3: if (GLEW_VERSION_2_1) { glUniformMatrix2x3fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_2X4: if (GLEW_VERSION_2_1) { glUniformMatrix2x4fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_3X2: if (GLEW_VERSION_2_1) { glUniformMatrix3x2fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_3X3: glUniformMatrix3fvARB(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); break; case GCT_MATRIX_3X4: if (GLEW_VERSION_2_1) { glUniformMatrix3x4fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_4X2: if (GLEW_VERSION_2_1) { glUniformMatrix4x2fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_4X3: if (GLEW_VERSION_2_1) { glUniformMatrix4x3fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_4X4: glUniformMatrix4fvARB(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); break; case GCT_INT1: glUniform1ivARB(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_INT2: glUniform2ivARB(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_INT3: glUniform3ivARB(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_INT4: glUniform4ivARB(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_SAMPLER1D: case GCT_SAMPLER1DSHADOW: case GCT_SAMPLER2D: case GCT_SAMPLER2DSHADOW: case GCT_SAMPLER3D: case GCT_SAMPLERCUBE: // samplers handled like 1-element ints glUniform1ivARB(currentUniform->mLocation, 1, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_UNKNOWN: break; } // end switch #if OGRE_DEBUG_MODE checkForGLSLError( "GLSLLinkProgram::updateUniforms", "Error updating uniform", 0 ); #endif } // variability & mask } // fromProgType == currentUniform->mSourceProgType } // end for }
void RendererBase::Unmap(UniformBuffer * resource) { if (resource->index > 0 && GLEW_ARB_uniform_buffer_object) { UniformBufferPimpl * resource_pimpl = (UniformBufferPimpl *) resource->PRIVATE; glBindBuffer(GL_UNIFORM_BUFFER, resource_pimpl->buffer); glUnmapBuffer(GL_UNIFORM_BUFFER); } else if (resource->index == 0) { UniformBufferPimpl * resource_pimpl = (UniformBufferPimpl *) resource->PRIVATE; if (pimpl->bound_shader_program) //Update uniforms if a shader program is bound. { ShaderProgram * program = pimpl->bound_shader_program; ShaderProgramPimpl * shader_pimpl = (ShaderProgramPimpl *) program->PRIVATE; for (unsigned int i = 0; i < program->uniforms.GetSize(); ++i) { if (program->GetUniformBufferIndex(i)) continue; unsigned char rows = program->GetUniformRows(i); unsigned char columns = program->GetUniformColumns(i); GLuint location = shader_pimpl->uniform_locations[i]; unsigned int count = program->GetUniformArrayLength(i); float * data = (float *) (resource_pimpl->cpu_data + program->GetUniformBufferOffset(i)); switch(rows) { case 1: switch (columns) { case 1: glUniform1fv(location, count, data); break; case 2: glUniform2fv(location, count, data); break; case 3: glUniform3fv(location, count, data); break; case 4: glUniform4fv(location, count, data); break; } break; case 2: switch (columns) { case 2: glUniformMatrix2fv(location, count, false, data); break; case 3: glUniformMatrix2x3fv(location, count, false, data); break; case 4: glUniformMatrix2x4fv(location, count, false, data); break; } break; case 3: switch (columns) { case 2: glUniformMatrix3x2fv(location, count, false, data); break; case 3: glUniformMatrix3fv(location, count, false, data); break; case 4: glUniformMatrix3x4fv(location, count, false, data); break; } break; case 4: switch (columns) { case 2: glUniformMatrix4x2fv(location, count, false, data); break; case 3: glUniformMatrix4x3fv(location, count, false, data); break; case 4: glUniformMatrix4fv(location, count, false, data); break; } break; } } } } }
void operator()(GLint location, GLboolean transpose, const glm::mat3x2 &value) { glUniformMatrix3x2fv(location, 1, transpose, glm::value_ptr(value)); }
void kore::BindUniform::doExecute(void) const { if(!_componentUniform) { Log::getInstance()->write("[ERROR] Uniform binding undefined"); return; } GLerror::gl_ErrorCheckStart(); _renderManager-> useShaderProgram(_shaderUniform->shader->getProgramLocation()); switch (_componentUniform->type) { case GL_FLOAT: glUniform1fv(_shaderUniform->location, _componentUniform->size, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_VEC2: glUniform2fv(_shaderUniform->location, _componentUniform->size, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_VEC3: glUniform3fv(_shaderUniform->location, _componentUniform->size, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_VEC4: glUniform4fv(_shaderUniform->location, _componentUniform->size, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_DOUBLE: glUniform1d(_shaderUniform->location, *static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_VEC2: glUniform2dv(_shaderUniform->location, _componentUniform->size, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_VEC3: glUniform3dv(_shaderUniform->location, _componentUniform->size, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_VEC4: glUniform4dv(_shaderUniform->location, _componentUniform->size, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_BOOL: case GL_INT: glUniform1i(_shaderUniform->location, *static_cast<GLint*>(_componentUniform->data)); break; case GL_BOOL_VEC2: case GL_INT_VEC2: glUniform2iv(_shaderUniform->location, _componentUniform->size, static_cast<GLint*>(_componentUniform->data)); break; case GL_BOOL_VEC3: case GL_INT_VEC3: glUniform3iv(_shaderUniform->location, _componentUniform->size, static_cast<GLint*>(_componentUniform->data)); break; case GL_BOOL_VEC4: case GL_INT_VEC4: glUniform4iv(_shaderUniform->location, _componentUniform->size, static_cast<GLint*>(_componentUniform->data)); break; case GL_UNSIGNED_INT: glUniform1ui(_shaderUniform->location, *static_cast<GLuint*>(_componentUniform->data)); break; case GL_UNSIGNED_INT_VEC2: glUniform2uiv(_shaderUniform->location, _componentUniform->size, static_cast<GLuint*>(_componentUniform->data)); break; case GL_UNSIGNED_INT_VEC3: glUniform3uiv(_shaderUniform->location, _componentUniform->size, static_cast<GLuint*>(_componentUniform->data)); break; case GL_UNSIGNED_INT_VEC4: glUniform4uiv(_shaderUniform->location, _componentUniform->size, static_cast<GLuint*>(_componentUniform->data)); break; case GL_FLOAT_MAT2: glUniformMatrix2fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT2x3: glUniformMatrix2x3fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT2x4: glUniformMatrix2x4fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT3x2: glUniformMatrix3x2fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT3x4: glUniformMatrix3x4fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT4x2: glUniformMatrix4x2fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT4x3: glUniformMatrix3x4fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_DOUBLE_MAT2: glUniformMatrix2dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT3: glUniformMatrix3dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT4: glUniformMatrix4dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT2x3: glUniformMatrix2x3dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT2x4: glUniformMatrix2x4dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT3x2: glUniformMatrix3x2dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT3x4: glUniformMatrix3x4dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT4x2: glUniformMatrix4x2dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT4x3: glUniformMatrix4x3dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; // Note(dlazarek): Currently, we handle texture-bindings outside of // Uniform-bindigs for sorting and performance-reasons. case GL_SAMPLER_1D: case GL_SAMPLER_2D: case GL_SAMPLER_3D: case GL_SAMPLER_CUBE: case GL_SAMPLER_1D_SHADOW: case GL_SAMPLER_2D_SHADOW: case GL_SAMPLER_CUBE_SHADOW: case GL_SAMPLER_1D_ARRAY: case GL_SAMPLER_2D_ARRAY: case GL_SAMPLER_1D_ARRAY_SHADOW: case GL_SAMPLER_2D_ARRAY_SHADOW: case GL_SAMPLER_2D_MULTISAMPLE: case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_SAMPLER_BUFFER: case GL_SAMPLER_2D_RECT: case GL_SAMPLER_2D_RECT_SHADOW: case GL_INT_SAMPLER_1D: case GL_INT_SAMPLER_2D: case GL_INT_SAMPLER_3D: case GL_INT_SAMPLER_CUBE: case GL_INT_SAMPLER_1D_ARRAY: case GL_INT_SAMPLER_2D_ARRAY: case GL_INT_SAMPLER_2D_MULTISAMPLE: case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_INT_SAMPLER_BUFFER: case GL_INT_SAMPLER_2D_RECT: case GL_UNSIGNED_INT_SAMPLER_1D: case GL_UNSIGNED_INT_SAMPLER_2D: case GL_UNSIGNED_INT_SAMPLER_3D: case GL_UNSIGNED_INT_SAMPLER_CUBE: case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_UNSIGNED_INT_SAMPLER_BUFFER: case GL_UNSIGNED_INT_SAMPLER_2D_RECT: //glActiveTexture(GL_TEXTURE0 + _componentUniform->texUnit); //glProgramUniform1i(_shaderID, _shaderUniform->location, _componentUniform->texUnit); kore::Log::getInstance()->write("[ERROR] sampler type was adressed" "as uniform"); break; /* break; case GL_IMAGE_1D: break; case GL_IMAGE_2D: break; case GL_IMAGE_3D: break; case GL_IMAGE_2D_RECT: break; case GL_IMAGE_CUBE: break; case GL_IMAGE_BUFFER: break; case GL_IMAGE_1D_ARRAY: break; case GL_IMAGE_2D_ARRAY: break; case GL_IMAGE_2D_MULTISAMPLE: break; case GL_IMAGE_2D_MULTISAMPLE_ARRAY: break; case GL_INT_IMAGE_1D: break; case GL_INT_IMAGE_2D: break; case GL_INT_IMAGE_3D: break; case GL_INT_IMAGE_2D_RECT: break; case GL_INT_IMAGE_CUBE: break; case GL_INT_IMAGE_BUFFER: break; case GL_INT_IMAGE_1D_ARRAY: break; case GL_INT_IMAGE_2D_ARRAY: break; case GL_INT_IMAGE_2D_MULTISAMPLE: break; case GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY: break; case GL_UNSIGNED_INT_IMAGE_1D: break; case GL_UNSIGNED_INT_IMAGE_2D: break; case GL_UNSIGNED_INT_IMAGE_3D: break; case GL_UNSIGNED_INT_IMAGE_2D_RECT: break; case GL_UNSIGNED_INT_IMAGE_CUBE: break; case GL_UNSIGNED_INT_IMAGE_BUFFER: break; case GL_UNSIGNED_INT_IMAGE_1D_ARRAY: break; case GL_UNSIGNED_INT_IMAGE_2D_ARRAY: break; case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE: break; case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: break; */ default: kore::Log::getInstance()->write("[ERROR] Unknown uniform binding\n"); break; } GLerror::gl_ErrorCheckFinish("BindUniformOperation: " + _shaderUniform->name); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL21_nglUniformMatrix3x2fv__IIZJ(JNIEnv *__env, jclass clazz, jint location, jint count, jboolean transpose, jlong valueAddress) { glUniformMatrix3x2fvPROC glUniformMatrix3x2fv = (glUniformMatrix3x2fvPROC)tlsGetFunction(546); intptr_t value = (intptr_t)valueAddress; UNUSED_PARAM(clazz) glUniformMatrix3x2fv(location, count, transpose, value); }