コード例 #1
0
/*
 * sendUniformMatrix2fv
 *
 * parameter name - char*
 * parameter count - GLsizei
 * parameter transpose - GLboolean
 * parameter values - GLfloat*
 * return - bool
 */
bool ShaderObject::sendUniformMatrix2fv(const char * name, GLsizei count, GLboolean transpose, GLfloat* values) {
    GLint location = getUniLoc(name);
    if (location == -1)
        return false;
    glUniformMatrix2fvARB(location, count, transpose, values);
    return true;
} // end sendUniformMatrix2fv()
コード例 #2
0
ファイル: Shader.cpp プロジェクト: GuoXinxiao/meshlab
void GPU::Shader::SetUniform( const std::string& name,
                              const void *value )
{
    UniformMap::iterator uu = m_Uniforms.find( name );
    if( uu != m_Uniforms.end() )
    {
	    GLuint activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB );
	    glUseProgramObjectARB( m_Id );

        Uniform &u = uu->second;
	    switch( u.type )
	    {
		    case GL_FLOAT:          glUniform1fvARB( u.location, u.size, (GLfloat*) value ); break;
		    case GL_FLOAT_VEC2_ARB: glUniform2fvARB( u.location, u.size, (GLfloat*) value ); break;
		    case GL_FLOAT_VEC3_ARB: glUniform3fvARB( u.location, u.size, (GLfloat*) value ); break;
		    case GL_FLOAT_VEC4_ARB: glUniform4fvARB( u.location, u.size, (GLfloat*) value ); break;
		    case GL_INT:            glUniform1ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_INT_VEC2_ARB:   glUniform2ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_INT_VEC3_ARB:   glUniform3ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_INT_VEC4_ARB:   glUniform4ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_BOOL_ARB:       glUniform1ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_BOOL_VEC2_ARB:  glUniform2ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_BOOL_VEC3_ARB:  glUniform3ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_BOOL_VEC4_ARB:  glUniform4ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_FLOAT_MAT2_ARB: glUniformMatrix2fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
		    case GL_FLOAT_MAT3_ARB: glUniformMatrix3fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
		    case GL_FLOAT_MAT4_ARB: glUniformMatrix4fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
	    }

	    glUseProgramObjectARB( activeProgBackup );
    }
}
コード例 #3
0
bool Shader::sendUniformMatrix2fv(char* varname, GLsizei count, GLboolean transpose, GLfloat *value)
{
    GLint loc = GetUniformLocation(varname);
    if (loc == -1) return false;
    
    glUniformMatrix2fvARB(loc, count, transpose, value);

    return true;
}
コード例 #4
0
ファイル: Shaders.cpp プロジェクト: jitrc/p3d
 bool ShaderProgram::SetMatrixVariable(const char* name, int dim, const float* values, int count, bool transpose)
 {
     if (!_linked) return false;
     if (_id)
     {
         GLint location = glGetUniformLocationARB(_id, name);
         if (location == -1) return false;
         GLboolean trans = transpose ? GL_TRUE : GL_FALSE;
         switch (dim)
         {
             case 2: glUniformMatrix2fvARB(location, count, trans, values); break;
             case 3: glUniformMatrix3fvARB(location, count, trans, values); break;
             case 4: glUniformMatrix4fvARB(location, count, trans, values); break;
             default:
                 return false;
         }
         return true;
     } else
         return false;
 }
コード例 #5
0
ファイル: brush.c プロジェクト: johnh530/electro
static void use_uniform(struct brush *b, struct uniform *u)
{
    int L;

    /* Apply the uniform values to the OpenGL state. */

    if (GL_has_shader_objects && u && b->shad_prog)
    {
        glUseProgramObjectARB(b->shad_prog);

        if ((L = glGetUniformLocationARB(b->shad_prog, u->name)) != -1)
        {
            const float *k = u->vals;

            int r = u->rows;
            int c = u->cols;

            if      (r == 0 && c == 0)
                glUniform1iARB(L, u->indx);

            else if (r == 1 && c == 1)
                glUniform1fARB(L, k[0]);
            else if (r == 1 && c == 2)
                glUniform2fARB(L, k[0], k[1]);
            else if (r == 1 && c == 3)
                glUniform3fARB(L, k[0], k[1], k[2]);
            else if (r == 1 && c == 4)
                glUniform4fARB(L, k[0], k[1], k[2], k[3]);

            else if (r == 2 && c == 2) glUniformMatrix2fvARB(L, 1, 0, k);
            else if (r == 3 && c == 3) glUniformMatrix3fvARB(L, 1, 0, k);
            else if (r == 4 && c == 4) glUniformMatrix4fvARB(L, 1, 0, k);
        }

        glUseProgramObjectARB(0);
    }
}
コード例 #6
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBShaderObjects_nglUniformMatrix2fvARB(JNIEnv *env, jclass clazz, jint location, jint count, jboolean transpose, jobject matrices, jint matrices_position, jlong function_pointer) {
	const GLfloat *matrices_address = ((const GLfloat *)(*env)->GetDirectBufferAddress(env, matrices)) + matrices_position;
	glUniformMatrix2fvARBPROC glUniformMatrix2fvARB = (glUniformMatrix2fvARBPROC)((intptr_t)function_pointer);
	glUniformMatrix2fvARB(location, count, transpose, matrices_address);
}
コード例 #7
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();

    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
}
コード例 #8
0
ファイル: shader.hpp プロジェクト: dbc/pyPolyCSG
 ShaderProgram &umt2(const char *var, GLfloat *m) { glUniformMatrix2fvARB(uniform(var), 1, GL_TRUE, m); return *this; }
コード例 #9
0
ファイル: glsl_program.cpp プロジェクト: ch-nry/Gem
void glsl_program :: renderARB()
{
  if (m_linked) {
    glUseProgramObjectARB( m_programARB );
    for(int i=0; i<m_uniformCount; i++)
      {
        if(m_flag[i])
	  {
	    switch (m_type[i])
              {
		/* float vectors */
              case GL_FLOAT:
                glUniform1fARB( m_loc[i], static_cast<GLfloat>(m_param[i][0]) );
		break;
              case GL_FLOAT_VEC2_ARB:
                glUniform2fARB( m_loc[i], static_cast<GLfloat>(m_param[i][0]), static_cast<GLfloat>(m_param[i][1]) );
		break;
              case GL_FLOAT_VEC3_ARB:
                glUniform3fARB( m_loc[i], static_cast<GLfloat>(m_param[i][0]), static_cast<GLfloat>(m_param[i][1]),
                                static_cast<GLfloat>(m_param[i][2]) );
		break;
              case GL_FLOAT_VEC4_ARB:
                glUniform4fARB( m_loc[i], static_cast<GLfloat>(m_param[i][0]), static_cast<GLfloat>(m_param[i][1]),
                                static_cast<GLfloat>(m_param[i][2]), static_cast<GLfloat>(m_param[i][3]) );
		break;

		/* int vectors */
              case GL_INT:
                glUniform1iARB( m_loc[i], static_cast<GLint>(m_param[i][0]) );
		break;
              case GL_INT_VEC2_ARB:
                glUniform2iARB( m_loc[i], static_cast<GLint>(m_param[i][0]), static_cast<GLint>(m_param[i][1]) );
		break;
              case GL_INT_VEC3_ARB:
                glUniform3iARB( m_loc[i], static_cast<GLint>(m_param[i][0]), static_cast<GLint>(m_param[i][1]),
                                static_cast<GLint>(m_param[i][2]) );
		break;
              case GL_INT_VEC4_ARB:
                glUniform4iARB( m_loc[i], static_cast<GLint>(m_param[i][0]), static_cast<GLint>(m_param[i][1]),
                                static_cast<GLint>(m_param[i][2]), static_cast<GLint>(m_param[i][3]) );
		break;

		/* bool vectors */
	      case GL_BOOL_ARB:
                glUniform1fARB( m_loc[i], static_cast<GLfloat>(m_param[i][0]) );
		break;
              case GL_BOOL_VEC2_ARB:
                glUniform2fARB( m_loc[i], static_cast<GLfloat>(m_param[i][0]), static_cast<GLfloat>(m_param[i][1]) );
		break;
              case GL_BOOL_VEC3_ARB:
                glUniform3fARB( m_loc[i], static_cast<GLfloat>(m_param[i][0]), static_cast<GLfloat>(m_param[i][1]),
                                static_cast<GLfloat>(m_param[i][2]) );
		break;
              case GL_BOOL_VEC4_ARB:
                glUniform4fARB( m_loc[i], static_cast<GLfloat>(m_param[i][0]), static_cast<GLfloat>(m_param[i][1]),
                                static_cast<GLfloat>(m_param[i][2]), static_cast<GLfloat>(m_param[i][3]) );
		break;

		/* float matrices */
              case GL_FLOAT_MAT2_ARB:
                // GL_TRUE = row major order, GL_FALSE = column major
                glUniformMatrix2fvARB( m_loc[i], 1, GL_FALSE, m_param[i] );
		break;
              case GL_FLOAT_MAT3_ARB:
                glUniformMatrix3fvARB( m_loc[i], 1, GL_FALSE, m_param[i] );
		break;
              case GL_FLOAT_MAT4_ARB:
                glUniformMatrix4fvARB( m_loc[i], 1, GL_FALSE, m_param[i] );
		break;

		/* textures */
	      case GL_SAMPLER_1D_ARB: break;
	      case GL_SAMPLER_2D_ARB:
		glUniform1iARB(m_loc[i], m_param[i][0]);
		break;
	      case GL_SAMPLER_3D_ARB: break;
	      case GL_SAMPLER_CUBE_ARB: break;
	      case GL_SAMPLER_1D_SHADOW_ARB: break;
	      case GL_SAMPLER_2D_SHADOW_ARB: break;
	      case GL_SAMPLER_2D_RECT_ARB:
		glUniform1iARB(m_loc[i], m_param[i][0]);
		break;
              default:
		;
              }
            // remove flag because the value is in GL's state now...
            m_flag[i]=0;
	  }
      }
    //  glUniform1iARB(glGetUniformLocationARB(program_object, "MyTex1"), 1);
  } else {
    /* JMZ: this is really annoying... */
    //error("no program linked");
  }
}