/*!**************************************************************************** @Function DrawQuad @Input x1 left coordinate of the rectangle to draw on the screen (between -1 and 1) @Input y1 top coordinate of the rectangle to draw on the screen (between -1 and 1) @Input x2 right coordinate of the rectangle to draw on the screen (between -1 and 1) @Input y2 bottom coordinate of the rectangle to draw on the screen (between -1 and 1) @Input uiTexture OpenGL ES texture handle to use @Description Draws a given texture on a quad on the screen. ******************************************************************************/ void OGLES3AlphaBlend::DrawQuad(float x1, float y1, float x2, float y2, GLuint uiTexture) { // Set the uniforms for rectangle position and width if (m_bRotateScreen) { glUniform2f(m_ShaderProgram.uiLowerLeftLoc, -y1, x1); float afMatrix[4] = { 0, x2 - x1, y1 - y2, 0 }; glUniformMatrix2fv(m_ShaderProgram.uiScaleMatrixLoc, 1, GL_FALSE, afMatrix); } else { glUniform2f(m_ShaderProgram.uiLowerLeftLoc, x1, y1); float afMatrix[4] = { x2 - x1, 0, 0, y2 - y1 }; glUniformMatrix2fv(m_ShaderProgram.uiScaleMatrixLoc, 1, GL_FALSE, afMatrix); } // Use the given texture glBindTexture(GL_TEXTURE_2D, uiTexture); // Bind the vertex buffer object glBindBuffer(GL_ARRAY_BUFFER, m_uiVbo); glEnableVertexAttribArray(VERTEX_ARRAY); glVertexAttribPointer(VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, 0); // Draws a short triangle strip glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableVertexAttribArray(VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); }
void Shader::setUniform(int location, int type, const GLfloat* val) const { switch(type) { case GL_FLOAT: glUniform1f(location,val[0]); break; case GL_FLOAT_VEC2: glUniform2f(location,val[0],val[1]); break; case GL_FLOAT_VEC3: glUniform3f(location,val[0],val[1],val[2]); break; case GL_FLOAT_VEC4: glUniform4f(location,val[0],val[1],val[2],val[3]); break; case GL_FLOAT_MAT2: glUniformMatrix2fv(location,1,GL_FALSE,val); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(location,1,GL_FALSE,val); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(location,1,GL_FALSE,val); break; } }
inline void Program::Uniform(GLint location, GLsizei count, GLboolean transpose, const glm::mat2 *value) { GL_ASSERT(m_id > 0); GL_ASSERT(location >= 0); glUniformMatrix2fv(location, count, transpose, glm::value_ptr(*value)); }
bool COGLES2SLMaterialRenderer::setUniform( int index, const void* data, int count ) { SUniformInfo& ui = UniformInfo[index]; if ( ui.location == -1 ) return false; switch ( ui.type ) { case GL_FLOAT: glUniform1fv( ui.location, count, static_cast<const GLfloat*>( data ) ); break; case GL_FLOAT_VEC2: glUniform2fv( ui.location, count, static_cast<const GLfloat*>( data ) ); break; case GL_FLOAT_VEC3: glUniform3fv( ui.location, count, static_cast<const GLfloat*>( data ) ); break; case GL_FLOAT_VEC4: glUniform4fv( ui.location, count, static_cast<const GLfloat*>( data ) ); break; case GL_FLOAT_MAT2: glUniformMatrix2fv( ui.location, count, false, static_cast<const GLfloat*>( data ) ); break; case GL_FLOAT_MAT3: glUniformMatrix3fv( ui.location, count, false, static_cast<const GLfloat*>( data ) ); break; case GL_FLOAT_MAT4: glUniformMatrix4fv( ui.location, count, false, static_cast<const GLfloat*>( data ) ); break; default: glUniform1iv( ui.location, count, static_cast<const GLint*>( data ) ); break; } return !Driver->testGLError(); }
/** * Sets an uniform matrix. * Matrices are always of type float. * \warning uses glGetError(); * \param name - name of the parameter * \param m - a float array containing up to 16 floats for the matrix. * \param bTranspose - if true, the matrix will be transposed before uploading. * \return void * \author <a href="mailto:[email protected]">Jens Schneider</a> * \date Mar.2005 */ void GLSLProgram::SetUniformMatrix(const char *name,const float *m,bool bTranspose) const { assert(m_bEnabled); CheckGLError(); GLenum iType; GLint iLocation; try { iLocation = get_uniform_vector(name, m_hProgram, &iType); } catch(tuvok::GLError gl) { T_ERROR("Error (%d) obtaining uniform %s in '%s' or '%s'.", gl.errno(), name, m_sVS.c_str(), m_sFS.c_str()); return; } switch (iType) { case GL_FLOAT_MAT2: glUniformMatrix2fv(iLocation,1,bTranspose,m); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(iLocation,1,bTranspose,m); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(iLocation,1,bTranspose,m); break; default: T_ERROR("Unknown type (%d) for %s.", iType, name); break; } #ifdef GLSL_DEBUG CheckGLError("SetUniformMatrix(%s,float*,bool)",name); #endif }
void video_ok::checker(float x,float y,float w,float h) { float x2 = 2*x/set.get_x(); float y2 = 2*y/set.get_y(); float scale_w = set.get_x()/w; float scale_h = set.get_y()/h; float sample_matrix[] = {\ 1,0, 0,1 }; float vertex_array[] = {\ -1/scale_w, 1/scale_h, 0.0f, // Position 0 -1/scale_w, -1/scale_h, 0.0f, // Position 1 1/scale_w, -1/scale_h, 0.0f, // Position 2 1/scale_w, 1/scale_h, 0.0f // Position 3 }; // glClear(GL_COLOR_BUFFER_BIT); glVertexAttribPointer(position,3,GL_FLOAT,false,\ 0,vertex_array); glVertexAttribPointer(texture_coord,2,GL_FLOAT,false,\ 0,texture_array); glEnableVertexAttribArray(position); glEnableVertexAttribArray(texture_coord); glUniform1f(offset_x,x2+1/scale_w-1); glUniform1f(offset_y,-y2-1/scale_h+1); glUniformMatrix2fv(matrix_scale,1,false,sample_matrix); glEnable(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,id2); glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_SHORT,indices); }
void GFXGLShader::setConstantsFromBuffer(GFXGLShaderConstBuffer* buffer) { for(Vector<GFXGLShaderConstHandle*>::iterator i = mValidHandles.begin(); i != mValidHandles.end(); ++i) { GFXGLShaderConstHandle* handle = *i; AssertFatal(handle, "GFXGLShader::setConstantsFromBuffer - Null handle"); if(handle->mInstancingConstant) continue; // Don't set if the value has not be changed. if(dMemcmp(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize()) == 0) continue; // Copy new value into our const buffer and set in GL. dMemcpy(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize()); switch(handle->mDesc.constType) { case GFXSCT_Float: glUniform1fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Float2: glUniform2fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Float3: glUniform3fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Float4: glUniform4fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Int: case GFXSCT_Sampler: case GFXSCT_SamplerCube: glUniform1iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Int2: glUniform2iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Int3: glUniform3iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Int4: glUniform4iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Float2x2: glUniformMatrix2fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Float3x3: glUniformMatrix3fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset)); break; case GFXSCT_Float4x4: glUniformMatrix4fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset)); break; default: AssertFatal(0,""); break; } } }
void GLSLProgram::setUniformMatrix2fv( const std::string & name, const GLfloat * value, const GLboolean transpose, const GLsizei count ) { const GLint loc = getUniformLocation( name ); assert( value != 0 ); assert( count != 0 ); if ( loc != -1 ) glUniformMatrix2fv( loc, count, transpose, value ); }
void UniformMatrix2fv( const GLint Location, const GLsizei Count, const EBool::Value Transpose, const GLfloat* const Value) { glUniformMatrix2fv(Location, Count, Transpose, Value); }
void GLProgram::setUniformLocationWithMatrix2fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices) { bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*4*numberOfMatrices); if (updated) { glUniformMatrix2fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray); } }
void ROC::ShaderUniform::Update() { if(!m_updated) { switch(m_type) { case SUT_Float: glUniform1f(m_uniform, m_float[0]); break; case SUT_Float2: glUniform2f(m_uniform, m_float[0], m_float[1]); break; case SUT_Float3: glUniform3f(m_uniform, m_float[0], m_float[1], m_float[2]); break; case SUT_Float4: glUniform4f(m_uniform, m_float[0], m_float[1], m_float[2], m_float[3]); break; case SUT_Int: case SUT_Sampler: case SUT_ShadowSampler: case SUT_CubeSampler: glUniform1i(m_uniform, m_int[0]); break; case SUT_Int2: glUniform2i(m_uniform, m_int[0], m_int[1]); break; case SUT_Int3: glUniform3i(m_uniform, m_int[0], m_int[1], m_int[2]); break; case SUT_Int4: glUniform4i(m_uniform, m_int[0], m_int[1], m_int[2], m_int[3]); break; case SUT_Bool: glUniform1ui(m_uniform, m_bool[0]); break; case SUT_Bool2: glUniform2ui(m_uniform, m_bool[0], m_bool[1]); break; case SUT_Bool3: glUniform3ui(m_uniform, m_bool[0], m_bool[1], m_bool[2]); break; case SUT_Bool4: glUniform4ui(m_uniform, m_bool[0], m_bool[1], m_bool[2], m_bool[3]); break; case SUT_Mat2: glUniformMatrix2fv(m_uniform, 1, GL_FALSE, m_float); break; case SUT_Mat3: glUniformMatrix3fv(m_uniform, 1, GL_FALSE, m_float); break; case SUT_Mat4: glUniformMatrix4fv(m_uniform, 1, GL_FALSE, m_float); break; } m_updated = true; } }
/*!*************************************************************************** @Function SetDefaultSemanticValue @Input pszName name of uniform @Input psDefaultValue pointer to default value @Description Sets the default value for the uniform semantic. *****************************************************************************/ void CPVRTPFXEffect::SetDefaultUniformValue(const char *const pszName, const SPVRTSemanticDefaultData *psDefaultValue) { GLint nLocation = glGetUniformLocation(m_uiProgram, pszName); switch(psDefaultValue->eType) { case eDataTypeMat2: glUniformMatrix2fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData); break; case eDataTypeMat3: glUniformMatrix3fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData); break; case eDataTypeMat4: glUniformMatrix4fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData); break; case eDataTypeVec2: glUniform2fv(nLocation, 1, psDefaultValue->pfData); break; case eDataTypeVec3: glUniform3fv(nLocation, 1, psDefaultValue->pfData); break; case eDataTypeVec4: glUniform4fv(nLocation, 1, psDefaultValue->pfData); break; case eDataTypeIvec2: glUniform2iv(nLocation, 1, psDefaultValue->pnData); break; case eDataTypeIvec3: glUniform3iv(nLocation, 1, psDefaultValue->pnData); break; case eDataTypeIvec4: glUniform4iv(nLocation, 1, psDefaultValue->pnData); break; case eDataTypeBvec2: glUniform2i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0); break; case eDataTypeBvec3: glUniform3i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0, psDefaultValue->pbData[2] ? 1 : 0); break; case eDataTypeBvec4: glUniform4i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0, psDefaultValue->pbData[2] ? 1 : 0, psDefaultValue->pbData[3] ? 1 : 0); break; case eDataTypeFloat: glUniform1f(nLocation, psDefaultValue->pfData[0]); break; case eDataTypeInt: glUniform1i(nLocation, psDefaultValue->pnData[0]); break; case eDataTypeBool: glUniform1i(nLocation, psDefaultValue->pbData[0] ? 1 : 0); break; case eNumDefaultDataTypes: case eDataTypeNone: default: break; } }
void ShaderAPITest::test_uniform_neg_location(void) { GLuint program; GLfloat data[4]; program = make_program("#version 110\nvoid main() { gl_Position = vec4(1.0, 1.0, 1.0, 1.0); }\n", NULL); (void) program; assert_no_error(); glUniform1i(-1, 1); assert_no_error(); glUniform1i(-200, 1); assert_error(GL_INVALID_OPERATION); glUniformMatrix2fv(-1, 1, GL_FALSE, data); assert_no_error(); glUniformMatrix2fv(-200, 1, GL_FALSE, data); assert_error(GL_INVALID_OPERATION); }
bool ShaderManager :: SetUniformMatrix ( const char * name, const Matrix2D& value ) { int location = glGetUniformLocation ( Program, name ); if ( location < 0 ) return false; glUniformMatrix2fv ( location, 1, GL_FALSE, value [0] ); return true; }
void GL3ProgramObjectProvider::set_uniform_matrix(int location, int size, int count, bool transpose, const float *data) { throw_if_disposed(); if (location >= 0) { ProgramObjectStateTracker state_tracker(handle); if( size == 2 ) glUniformMatrix2fv(location, count, transpose, data); else if( size == 3 ) glUniformMatrix3fv(location, count, transpose, data); else if( size == 4 ) glUniformMatrix4fv(location, count, transpose, data); } }
void SpriteShader::SetParameter(const std::string ¶meterName, const Matrix2 &value) { if(pimpl->uniforms.find(parameterName) == pimpl->uniforms.end()) throw std::runtime_error("Couldn't find the named SpriteEffect parameter: " + parameterName); auto &uniformData = pimpl->uniforms[parameterName]; if(uniformData.type != GL_FLOAT_MAT2) throw std::runtime_error("Type mismatch for named SpriteEffect paramater: " + parameterName); glUniformMatrix2fv(uniformData.location, 1, GL_FALSE, value.Transpose()); }
void Shader::setUniform<glm::mat2>(const std::string& name, const glm::mat2& 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(); glUniformMatrix2fv(name_to_location[name], 1, false, glm::value_ptr(data)); if(prev_bound_program != program_object) glUseProgram(prev_bound_program); }
bool COpenGLGPUProgram::setUniformfv( E_UNIFORM_TYPE uniform, const f32* floats, u32 size_bytes) { GLint loc = m_Uniforms[uniform].Location; if (loc == -1) { LOGGER.logErr("Can't set uniform '%s', due to unknown location", getUniformName(uniform)); return false; } GLenum type = m_Uniforms[uniform].Type; s32 count = m_Uniforms[uniform].Size; u32 actual_size = m_Uniforms[uniform].Bytes; if (size_bytes != actual_size) { LOGGER.logErr("Incorrect uniform '%s' size bytes (actual=%d, expected=%d)", getUniformName(uniform), actual_size, size_bytes); return false; } switch (type) { case GL_FLOAT: glUniform1fv(loc, count, floats); break; case GL_FLOAT_VEC2: glUniform2fv(loc, count, floats); break; case GL_FLOAT_VEC3: glUniform3fv(loc, count, floats); break; case GL_FLOAT_VEC4: glUniform4fv(loc, count, floats); break; case GL_FLOAT_MAT2: glUniformMatrix2fv(loc, count, false, floats); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(loc, count, false, floats); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(loc, count, false, floats); break; default: LOGGER.logErr("Unknown OpenGL uniform float type %X", type); return false; } return true; }
void CL_OpenGLProgramObjectProvider::set_uniform_matrix(const CL_StringRef &name, int size, int count, bool transpose, float *data) { throw_if_disposed(); CL_ProgramObjectStateTracker state_tracker(handle); int loc = get_uniform_location(name); if (loc == -1) return; if( size == 2 ) glUniformMatrix2fv(loc, count, transpose, data); else if( size == 3 ) glUniformMatrix3fv(loc, count, transpose, data); else if( size == 4 ) glUniformMatrix4fv(loc, count, transpose, data); else throw CL_Exception(cl_format("Unsupported size given to uniform '%1'.", name)); }
void program::set_uniform_matrix2fv(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 glProgramUniformMatrix2fv(id_, location, count, transpose, value); #else glUniformMatrix2fv(location, count, transpose, value); #endif } }
bool COGLES2MaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count) { if(index < 0 || UniformInfo[index].location < 0) return false; bool status = true; switch (UniformInfo[index].type) { case GL_FLOAT: glUniform1fv(UniformInfo[index].location, count, floats); break; case GL_FLOAT_VEC2: glUniform2fv(UniformInfo[index].location, count/2, floats); break; case GL_FLOAT_VEC3: glUniform3fv(UniformInfo[index].location, count/3, floats); break; case GL_FLOAT_VEC4: glUniform4fv(UniformInfo[index].location, count/4, floats); break; case GL_FLOAT_MAT2: glUniformMatrix2fv(UniformInfo[index].location, count/4, false, floats); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(UniformInfo[index].location, count/9, false, floats); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(UniformInfo[index].location, count/16, false, floats); break; case GL_SAMPLER_2D: case GL_SAMPLER_CUBE: { if(floats) { const GLint id = (GLint)(*floats); glUniform1iv(UniformInfo[index].location, 1, &id); } else status = false; } break; default: status = false; break; } return status; }
void RendererES2::draw(unsigned int numInstances) { glUseProgram(mProgram); glBindBuffer(GL_ARRAY_BUFFER, mVB); glVertexAttribPointer(mPosAttrib, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)offsetof(Vertex, pos)); glVertexAttribPointer(mColorAttrib, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (const GLvoid*)offsetof(Vertex, rgba)); glEnableVertexAttribArray(mPosAttrib); glEnableVertexAttribArray(mColorAttrib); for (unsigned int i = 0; i < numInstances; i++) { glUniformMatrix2fv(mScaleRotUniform, 1, GL_FALSE, mScaleRot + 4*i); glUniform2fv(mOffsetUniform, 1, mOffsets + 2*i); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } }
void aa::uniform_variable::set(aa::matrix<float> &m) { if(m.num_cols() == 2 && m.num_rows() == 2) { glUniformMatrix2fv(id, 1, GL_FALSE, m.get_raw_ptr()); } else if(m.num_cols() == 3 && m.num_rows() == 3) { glUniformMatrix3fv(id, 1, GL_FALSE, m.get_raw_ptr()); } else if(m.num_cols() == 4 && m.num_rows() == 4) { glUniformMatrix4fv(id, 1, GL_FALSE, m.get_raw_ptr()); } //error }
void TUniform::Load() const { switch (type.value) { case Id::UniformTypeBool: case Id::UniformTypeInt: glUniform1i(location, value.i[0]); break; case Id::UniformTypeIvec2: glUniform2iv(location, 1, (int*) value.i); break; case Id::UniformTypeIvec3: glUniform3iv(location, 1, (int*) value.i); break; case Id::UniformTypeIvec4: glUniform4iv(location, 1, (int*) value.i); break; case Id::UniformTypeFloat: glUniform1f(location, value.f[0]); break; case Id::UniformTypeVec2: glUniform2fv(location, 1, (float*) value.f); break; case Id::UniformTypeVec3: glUniform3fv(location, 1, (float*) value.f); break; case Id::UniformTypeVec4: glUniform4fv(location, 1, (float*) value.f); break; case Id::UniformTypeMat2: glUniformMatrix2fv(location, 1, GL_FALSE, (float*) value.f); break; case Id::UniformTypeMat3: glUniformMatrix3fv(location, 1, GL_FALSE, (float*) value.f); break; case Id::UniformTypeMat4: glUniformMatrix4fv(location, 1, GL_FALSE, (float*) value.f); break; } }
/** bind array of uniform matrices */ void FragmentProgram::BindMatrix(string parameterName, int n, int m, vector<vector<float> > floatmatrices, const bool transpose) { if (floatmatrices.size() == 0) return; int matrixsize = floatmatrices.at(0).size(); // num entries in each matrix logger.info << "n: " << n << " m: " << m << logger.end; if (matrixsize != n*m) throw PPEResourceException("supplied vector-size doesn't match supplied dimensions!"); if (n<2 || n>4 || m<2 || m>4) throw PPEResourceException("unsupported dimensions!"); if (n != m) throw PPEResourceException("dimensions not equal!"); // create a C array of all the floatmatrix-entries (to be supplied to OpenGL) float* floatarray = new float[matrixsize * floatmatrices.size()]; for (unsigned int i=0; i<floatmatrices.size(); i++) { vector<float> floatmatrix = floatmatrices.at(i); if (floatmatrix.size() != matrixsize) throw PPEResourceException("all matrices in an array must have the same size!"); for (unsigned int j=0; j<matrixsize; j++) floatarray[i*matrixsize + j] = floatmatrix.at(j); } GuardedBind(); // get input parameter handle by name GLint paramID = glGetUniformLocation(programID, parameterName.c_str()); if (paramID == -1) logger.error << "uniform \"" << parameterName << "\" does not exist" << logger.end; // set value of variable if (n==2 && m==2) glUniformMatrix2fv (paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); /* CPVC, gl 2.1 if (n==2 && m==3) glUniformMatrix2x3fv(paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); if (n==2 && m==4) glUniformMatrix2x4fv(paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); if (n==3 && m==2) glUniformMatrix3x2fv(paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); */ if (n==3 && m==3) glUniformMatrix3fv (paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); /* CPVC, gl 2.1 if (n==3 && m==4) glUniformMatrix3x4fv(paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); if (n==4 && m==2) glUniformMatrix4x2fv(paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); if (n==4 && m==3) glUniformMatrix4x3fv(paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); */ if (n==4 && m==4) glUniformMatrix4fv (paramID, floatmatrices.size(), (GLboolean)transpose, floatarray); GuardedUnbind(); delete floatarray; }
void Cc3dProgram::passUnifoValueMatrixNfv(string unifoName,const GLfloat *array,int arrayLen){ assert(arrayLen==4||arrayLen==9||arrayLen==16); switch (arrayLen) { case 4: glUniformMatrix2fv(m_unifoMap[unifoName],1,GL_FALSE,array); break; case 9: glUniformMatrix3fv(m_unifoMap[unifoName],1,GL_FALSE,array); break; case 16: glUniformMatrix4fv(m_unifoMap[unifoName],1,GL_FALSE,array); break; default: assert(false); break; } }
void SkeletalMeshGraphicComponent::unitDraw(RenderParameter ¶m)//Actor *actor,Engine::Scene* scene) { glDebug(); TransformComponent* trans = 0; if(m_pOwner)trans = m_pOwner->getComponent<TransformComponent>(ComponentId::Transform); //glPushMatrix(); glColor3f(0, 1, 0); Shader* currentShader = 0; if(param.flag & RenderFlag::Default)currentShader = shader; else if(param.flag & RenderFlag::Shadow)currentShader = shader_shadow; if(currentShader) { currentShader->Use(); glDebug(); GLuint p = currentShader->getProgramId(); int loc; glDebug(); if(trans) { loc=currentShader->getUniformLocation("MVM"); if(loc>=0)glUniformMatrix4fv(loc, 1, 0, &trans->getMatrix()[0][0]); } glDebug(param.flag); loc=currentShader->getUniformLocation("textureMatrix"); if(param.flag & RenderFlag::Default)if(loc>-1)glUniformMatrix2fv(loc, 1, 0, &textureMatrix[0][0]); glDebug(param.flag); mesh->updateUniform(currentShader->getProgramId()); mesh->draw(materials, currentShader,param.flag); glDebug(); } //glPopMatrix(); }
bool queso::ShaderProgram::setUniform(const std::string& name, MatrixType matType, GLboolean transpose, const GLfloat* value) { GLint loc = getLocation(name); if (loc != -1) { switch(matType) { case TWO_BY_TWO: glUniformMatrix2fv(loc, 1, transpose, value); return true; case THREE_BY_THREE: glUniformMatrix3fv(loc, 1, transpose, value); return true; case FOUR_BY_FOUR: glUniformMatrix4fv(loc, 1, transpose, value); return true; default: LOG(WARNING) << "Unknown matrix type."; break; } } return false; }
void nuiUniformDesc::Apply() const { total++; // if (!(total % 10000)) // NGL_OUT("Uniform stats: %d on %d applied (%d skipped) %f cache hit\n", applied, total, skipped, (float)skipped/(float)total); if (!mChanged) { skipped++; return; } applied++; mChanged = false; switch (mType) { case GL_FLOAT: glUniform1fv(mLocation, mCount, mValues.mpFloats); break; case GL_FLOAT_VEC2: glUniform2fv(mLocation, mCount, mValues.mpFloats); break; case GL_FLOAT_VEC3: glUniform3fv(mLocation, mCount, mValues.mpFloats); break; case GL_FLOAT_VEC4: glUniform4fv(mLocation, mCount, mValues.mpFloats); break; case GL_INT: glUniform1iv(mLocation, mCount, mValues.mpInts); break; case GL_INT_VEC2: glUniform2iv(mLocation, mCount, mValues.mpInts); break; case GL_INT_VEC3: glUniform3iv(mLocation, mCount, mValues.mpInts); break; case GL_INT_VEC4: glUniform4iv(mLocation, mCount, mValues.mpInts); break; case GL_UNSIGNED_INT: glUniform1iv(mLocation, mCount, mValues.mpInts); break; case GL_FLOAT_MAT2: glUniformMatrix2fv(mLocation, mCount, GL_FALSE, mValues.mpFloats); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(mLocation, mCount, GL_FALSE, mValues.mpFloats); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(mLocation, mCount, GL_FALSE, mValues.mpFloats); break; case GL_SAMPLER_2D: glUniform1iv(mLocation, mCount, mValues.mpInts); break; case GL_SAMPLER_CUBE: glUniform1iv(mLocation, mCount, mValues.mpInts); break; default: NGL_ASSERT(0); } }
void GLShader::draw(const DrawCall& drawCall) { if (drawCall.predraw) drawCall.predraw(); /// update uniform for (auto& p : mUniform.t_float) glUniform1f(uniform_loc(p.first), p.second); for (auto& p : mUniform.t_int ) glUniform1i(uniform_loc(p.first), p.second); for (auto& p : mUniform.t_vec2 ) glUniform2fv(uniform_loc(p.first), 1, p.second.data()); for (auto& p : mUniform.t_vec3 ) glUniform3fv(uniform_loc(p.first), 1, p.second.data()); for (auto& p : mUniform.t_vec4 ) glUniform4fv(uniform_loc(p.first), 1, p.second.data()); for (auto& p : mUniform.t_mat2 ) glUniformMatrix2fv(uniform_loc(p.first), 1, GL_FALSE, p.second.data()); for (auto& p : mUniform.t_mat3 ) glUniformMatrix3fv(uniform_loc(p.first), 1, GL_FALSE, p.second.data()); for (auto& p : mUniform.t_mat4 ) glUniformMatrix4fv(uniform_loc(p.first), 1, GL_FALSE, p.second.data()); /// bind buffers for (auto& p : drawCall.buffer) { auto& buffer = *p.second; glBindBuffer(GL_ARRAY_BUFFER, buffer.id); glVertexAttribPointer(attrib_loc(p.first), buffer.dim, buffer.glType, buffer.integral, 0, 0); } glDrawArrays(drawCall.mode, 0, drawCall.count); if (drawCall.postdraw) drawCall.postdraw(); }