void UniformImplementation_Legacy::set(const Program * program, const GLint location, const glm::mat3x4 & value) const { program->use(); glUniformMatrix3x4fv(location, 1, GL_FALSE, glm::value_ptr(value)); }
/* * 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; } }
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; }
void operator()(GLint location, GLboolean transpose, const glm::mat3x4 &value) { glUniformMatrix3x4fv(location, 1, transpose, glm::value_ptr(value)); }
void GLSLShader::SetMatrix3x4(GLint variable,GLsizei count,GLboolean transpose, const GLfloat *value) { if (variable!=-1) glUniformMatrix3x4fv(variable, count, transpose, value); }
GLvoid Program::setUniformMatrix(GLint location, glm::mat3x4 matrix) { glUniformMatrix3x4fv(location, 1, GL_FALSE, glm::value_ptr(matrix)); }
//----------------------------------------------------------------------- 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 }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL21_nglUniformMatrix3x4fv(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; glUniformMatrix3x4fvPROC glUniformMatrix3x4fv = (glUniformMatrix3x4fvPROC)((intptr_t)function_pointer); glUniformMatrix3x4fv(location, count, transpose, matrices_address); }
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; }
void load_Program_uniforms( Shader_Arg* argv ) { // Load uniforms for( Shader_Arg *arg=argv; NULL!=arg; arg=next_Shader_Arg(arg) ) { pointer value = value_Shader_Arg( arg ); GLint location = arg->loc; GLsizei count = arg->type.count; switch( arg->type.glType ) { case GL_BOOL: case GL_INT: 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: glUniform1iv( location, count, value ); check_GL_error; break; case GL_BOOL_VEC2: case GL_INT_VEC2: glUniform2iv( location, count, value ); check_GL_error; break; case GL_BOOL_VEC3: case GL_INT_VEC3: glUniform3iv( location, count, value ); check_GL_error; break; case GL_BOOL_VEC4: case GL_INT_VEC4: glUniform4iv( location, count, value ); check_GL_error; break; case GL_FLOAT: glUniform1fv( location, count, value ); check_GL_error; break; case GL_FLOAT_VEC2: glUniform2fv( location, count, value ); check_GL_error; break; case GL_FLOAT_VEC3: glUniform3fv( location, count, value ); check_GL_error; break; case GL_FLOAT_VEC4: glUniform4fv( location, count, value ); check_GL_error; break; case GL_FLOAT_MAT2: glUniformMatrix2fv( location, count, 0, value ); check_GL_error; break; case GL_FLOAT_MAT3: glUniformMatrix3fv( location, count, 0, value ); check_GL_error; break; case GL_FLOAT_MAT4: glUniformMatrix4fv( location, count, 0, value ); check_GL_error; break; case GL_FLOAT_MAT2x3: glUniformMatrix2x3fv( location, count, 0, value ); check_GL_error; break; case GL_FLOAT_MAT2x4: glUniformMatrix2x4fv( location, count, 0, value ); check_GL_error; break; case GL_FLOAT_MAT3x2: glUniformMatrix2x3fv( location, count, 0, value ); check_GL_error; break; case GL_FLOAT_MAT3x4: glUniformMatrix3x4fv( location, count, 0, value ); check_GL_error; break; case GL_FLOAT_MAT4x2: glUniformMatrix4x2fv( location, count, 0, value ); check_GL_error; break; case GL_FLOAT_MAT4x3: glUniformMatrix4x3fv( location, count, 0, value ); check_GL_error; break; default: fatal( "Unknown uniform type: %d", arg->type.glType ); break; } } }
//----------------------------------------------------------------------- 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::setUniformMatrix3x4fv(const char* _var, size_t _count, bool _transpose, const float* _m) { glUniformMatrix3x4fv(getUniformLocation(_var),_count,_transpose,_m); }
/* 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 Uniform::setMatrix3x4(const glm::mat3x4& m34) { glUniformMatrix3x4fv(uniformLocation, 1, GL_FALSE, glm::value_ptr(m34)); }
void UniformImplementation_Legacy::set(const Program * program, const GLint location, const std::vector<glm::mat3x4> & value) const { program->use(); glUniformMatrix3x4fv(location, static_cast<GLint>(value.size()), GL_FALSE, reinterpret_cast<const float*>(value.data())); }
void ShaderProgram::sendUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *v) { bind(); glUniformMatrix3x4fv(location, count, transpose, v); unbind(); }
void CShaderInterface::sendUniformMatrix3x4fv(const QString& p_name, GLsizei count, GLboolean transpose, const GLfloat * value){ QByteArray ba = p_name.toLocal8Bit(); glUniformMatrix3x4fv( glGetUniformLocation( m_singleton.m_current, (const char*) ba.data() ), count, transpose, value ); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL21_nglUniformMatrix3x4fv__IIZJ(JNIEnv *__env, jclass clazz, jint location, jint count, jboolean transpose, jlong valueAddress) { glUniformMatrix3x4fvPROC glUniformMatrix3x4fv = (glUniformMatrix3x4fvPROC)tlsGetFunction(549); intptr_t value = (intptr_t)valueAddress; UNUSED_PARAM(clazz) glUniformMatrix3x4fv(location, count, transpose, value); }