Example #1
1
nuiUniformDesc::nuiUniformDesc(const nglString& rName, GLenum Type, int count, GLuint Location, nuiShaderProgram* pProgram)
: mName(rName), mType(Type), mCount(count), mLocation(Location), mChanged(false)
{
  switch (mType)
  {
    case GL_FLOAT:              mValues.mpFloats  = new float[1 * count];  break;
    case GL_FLOAT_VEC2:         mValues.mpFloats  = new float[2 * count];  break;
    case GL_FLOAT_VEC3:         mValues.mpFloats  = new float[3 * count];  break;
    case GL_FLOAT_VEC4:         mValues.mpFloats  = new float[4 * count];  break;

    case GL_INT:                mValues.mpInts    = new int32[1 * count];  break;
    case GL_INT_VEC2:           mValues.mpInts    = new int32[2 * count];  break;
    case GL_INT_VEC3:           mValues.mpInts    = new int32[3 * count];  break;
    case GL_INT_VEC4:           mValues.mpInts    = new int32[4 * count];  break;
    case GL_UNSIGNED_INT:       mValues.mpInts    = new int32[1 * count];  break;

    case GL_FLOAT_MAT2:         mValues.mpFloats  = new float[2 * 2 * count];  break;
    case GL_FLOAT_MAT3:         mValues.mpFloats  = new float[3 * 3 * count];  break;
    case GL_FLOAT_MAT4:         mValues.mpFloats  = new float[4 * 4 * count];  break;

    case GL_SAMPLER_2D:         mValues.mpInts    = new int32[1 * count];  break;
    case GL_SAMPLER_CUBE:       mValues.mpInts    = new int32[1 * count];  break;

    default:
      NGL_ASSERT(0);
  }

  if (pProgram)
  {
    switch (mType)
    {
      case GL_FLOAT:
      case GL_FLOAT_VEC2:
      case GL_FLOAT_VEC3:
      case GL_FLOAT_VEC4:
      case GL_FLOAT_MAT2:
      case GL_FLOAT_MAT3:
      case GL_FLOAT_MAT4:
        glGetUniformfv(pProgram->GetProgram(), mLocation, mValues.mpFloats);
        break;

      case GL_INT:
      case GL_INT_VEC2:
      case GL_INT_VEC3:
      case GL_INT_VEC4:
      case GL_UNSIGNED_INT:
      case GL_SAMPLER_2D:
      case GL_SAMPLER_CUBE:
        glGetUniformiv(pProgram->GetProgram(), mLocation, mValues.mpInts);
        break;

      default:
        NGL_ASSERT(0);
    }
  }
}
// 2 components
void ProgramUniformGLSL::Get(int &nX, int &nY)
{
	int nElements[2];
	glGetUniformiv(m_nOpenGLESProgram, m_nOpenGLESUniformLocation, nElements);
	nX = nElements[0];
	nY = nElements[1];
}
TYPED_TEST(UniformTest, GetUniformNoCurrentProgram)
{
    glUseProgram(mProgram);
    glUniform1f(mUniformFLocation, 1.0f);
    glUniform1i(mUniformILocation, 1);
    glUseProgram(0);

    GLfloat f;
    glGetnUniformfvEXT(mProgram, mUniformFLocation, 4, &f);
    ASSERT_GL_NO_ERROR();
    EXPECT_EQ(1.0f, f);

    glGetUniformfv(mProgram, mUniformFLocation, &f);
    ASSERT_GL_NO_ERROR();
    EXPECT_EQ(1.0f, f);

    GLint i;
    glGetnUniformivEXT(mProgram, mUniformILocation, 4, &i);
    ASSERT_GL_NO_ERROR();
    EXPECT_EQ(1, i);

    glGetUniformiv(mProgram, mUniformILocation, &i);
    ASSERT_GL_NO_ERROR();
    EXPECT_EQ(1, i);
}
Example #4
0
File: g.cpp Project: soulik/luagl
	int gl_GetUniformi(State & state){
		GLint value[4] = {0, 0, 0, 0};
		glGetUniformiv((GLuint) state.stack->to<int>(1), (GLint) state.stack->to<int>(2), value);
		for (int i=0; i<4; i++){
			state.stack->push<int>(value[i]);
		}
		return 4;
	}
Example #5
0
QVariantMap ShaderLibrary::uniformUserVariableList(QString const& shaderName)
{
   if (shaderName == NoShader) return s_currentMaterial;
   QVariantMap map;

   if (s_shaders.contains(shaderName)) {
      unsigned program(s_shaders.value(shaderName));

      int total(0);
      glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &total); 

      int length, number;
      char buf[100];
      GLenum type;
      GLfloat values[4];
      GLint boolean;
      GLuint location;
      QColor color;

      for (int i = 0; i < total; ++i)  {
          glGetActiveUniform(program, GLuint(i), sizeof(buf)-1, &length, &number, &type, buf);
          buf[length] = 0;
          QString name(buf);

          if (name.startsWith("user_")) {
             location = glGetUniformLocation(program, buf);

             switch (type) {
                case GL_FLOAT:
                   glGetUniformfv(program, location, values);
                   map.insert(name, values[0]);
                   break;

                case GL_BOOL:
                   glGetUniformiv(program, location, &boolean);
                   map.insert(name, (boolean == 1));
                   break;
                   
                case GL_FLOAT_VEC4:
                   glGetUniformfv(program, location, values);
                   color.setRgbF(values[0], values[1], values[2], values[3]);
                   map.insert(name, color);
                   break;

                default:
                   // Assume anything else is installed by the Viewer
                   QLOG_DEBUG() << "Unknown GL_Type" << type;
                   break;
             }
         }
      }
   }

   return map;
}
Example #6
0
float* Shader::GetUniform(const char* uniformVariable){
	GLint uniformLocation = GetUniformLocation(uniformVariable);
	float fRet[4] = {0.0, 0.0, 0.0, 0.0};

	glGetUniformfv(_id, uniformLocation, fRet);
	return fRet;

	int iRet[4] = {0, 0, 0, 0};
	glGetUniformiv(_id, uniformLocation, iRet);
	return (float*)iRet;
}
Example #7
0
 int* Shader::getUniformiv(std::string name, int size)
 {
     if(name.empty() || size <= 0) {
         std::cerr << "ERROR: getUniform -> Invalid parameter(s)" << std::endl;
         return NULL;
     }
     int* params = new int[size];
     GLint loc = getUniformLocation(name);
     glGetUniformiv(getProgramId(), loc, params);
     return params;
 }
Example #8
0
GLint OpenGL::getShaderInteger( ShaderProgramType shaderProgramType, std::string varName )
{
    LOCK

    GLint varLocation = -1;
    GLint varValue = 0;

    varLocation = getShaderVariableLocation( varName,
                               shaderProgramsIDs_.at( shaderProgramType ) );

    glGetUniformiv( shaderProgramsIDs_.at( shaderProgramType ), varLocation, &varValue );

    return varValue;
}
Example #9
0
static bool
check_uniform_int(GLuint prog, int loc, int expect)
{
        int v = 0xdeadcafe;

        glGetUniformiv(prog, loc, &v);
        if (v != expect) {
                fprintf(stderr, "Invalid value for uniform %d\n"
                        "   Expected: %d\n"
                        "   Observed: %d\n",
                        loc, expect, v);
                return false;
        }

        return piglit_check_gl_error(GL_NO_ERROR);
}
Example #10
0
int Rekd2D::Core::Shader::GetInt(const std::string &location)
{
    std::map<std::string, unsigned int>::iterator it = m_Locations.find(location);
    int uniform;
    if (it == m_Locations.end())
    {
        uniform = glGetUniformLocation(m_Program, location.c_str());
        m_Locations.insert(std::pair<std::string, unsigned int>(location, uniform));
    }
    else
    {
        uniform = m_Locations[location];
    }
    int out;
    glGetUniformiv(m_Program, uniform, &out);
    return out;
}
Example #11
0
void
ShaderAPITest::test_uniform_bool_conversion(void)
{
	GLuint program;
	GLint location;
	GLint value[16];  /* in case glGetUniformiv goes nuts on the stack */

	assert_no_error();
	program = make_program("uniform bool b;\nvoid main() { gl_Position.x = b ? 1.5 : 0.5; }\n", NULL);
	location = glGetUniformLocation(program, "b");
	assert(location != -1);
	assert_no_error();
	glUniform1i(location, 5);
	assert_no_error();
	glGetUniformiv(program, location, &value[0]);
	assert_no_error();
	assert(value[0] == 1);
}
Example #12
0
// RENDERS AN OBJECT USING A SKYBOX AS THE TEXTURE SOURCE
void displayBoxFun(GLuint shaderProg) {
  Matrix4f viewMat, projMat, modelMat, m;
  // set up the mode to wireframe

  // setting up the transformaiton of the object from model coord. system to world coord.
  modelMat = Matrix4f::identity();
  //modelMat = Matrix4f::translation(0,0,0);

  modelMat = Matrix4f::scale(50,50,50);

  // ROATE THE OBJECT AROUND THE CAMERA VECTOR
  // CAN ADD ROTATIONS AROUND THE PRIMARY AXIS
  modelMat = modelMat * Matrix4f::rotateVector(cam.getLookAtVector(),angle,1);

  // setting up the viewpoint transformation
  viewMat = cam.getViewMatrix(NULL);

  // setting up the projection transformation
  projMat= cam.getProjectionMatrix(NULL);

  // putting it all together
  m = projMat * viewMat * modelMat;

  // tell openfl which shader program to use
  glUseProgram(shaderProg);

  // transfer the modelViewProjection  matrix to the shader
  GLuint locMat= 0;
  locMat=glGetUniformLocation(shaderProg,  "modelViewProjMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // transfer the modelView matrix to the shader
  m = viewMat * modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelViewMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // transfer the model matrix to the shader
  m = modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // load the camera position to the shader
  locMat=glGetUniformLocation(shaderProg,  "camPos");
  Vector3f camPos = cam.getPosition();
  glUniform3fv(locMat,1, (float *) &camPos);

  // load the refract flag to the shader
  locMat=glGetUniformLocation(shaderProg,  "refractFlag");
  glUniform1i(locMat, refractFlag);

  glActiveTexture(GL_TEXTURE3);
  GLuint texCube = skybox.getTexHandle();
  glBindTexture(GL_TEXTURE_CUBE_MAP, texCube);
  GLuint samLoc = glGetUniformLocation(shaderProg, "texCube");
  glUniform1i(samLoc, 3);

  GLint ttt = 0;
  glGetUniformiv(shaderProg, samLoc, &ttt);

  // bind the buffers to the shaders
  GLuint positionLoc = glGetAttribLocation(shaderProg, "vertex_position");
  GLuint normalLoc = glGetAttribLocation(shaderProg, "vertex_normal");

  glEnableVertexAttribArray(positionLoc);
  glEnableVertexAttribArray(normalLoc);

  glBindBuffer(GL_ARRAY_BUFFER, vertex_handle);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangle_handle);

  // Tells OpenGL how to walk through the two VBOs
  struct sphereVertex v;
  int relAddress = (char *) v.pos - (char *) &v;
  glVertexAttribPointer(positionLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);
  relAddress = (char *) v.normal - (char *) &v;
  glVertexAttribPointer(normalLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);

  // draw the triangles
  glDrawElements(GL_TRIANGLES, numTriangles*3, GL_UNSIGNED_INT, (char*) NULL+0);

  // glUseProgram(0);
  // glUseProgram(shaderProg);

  // draw the second sphere

  modelMat = Matrix4f::identity();
  //modelMat = Matrix4f::translation(0,0,0);

  modelMat = Matrix4f::scale(50,50,50) * Matrix4f::translation(2, 0, 0);

  // ROATE THE OBJECT AROUND THE CAMERA VECTOR
  // CAN ADD ROTATIONS AROUND THE PRIMARY AXIS
  modelMat = modelMat * Matrix4f::rotateVector(cam.getLookAtVector(),angle,1);

  // setting up the viewpoint transformation
  viewMat = cam.getViewMatrix(NULL);

  // setting up the projection transformation
  projMat= cam.getProjectionMatrix(NULL);

  // putting it all together
  m = projMat * viewMat * modelMat;

  locMat= 0;
  locMat=glGetUniformLocation(shaderProg,  "modelViewProjMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // transfer the modelView matrix to the shader
  m = viewMat * modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelViewMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // transfer the model matrix to the shader
  m = modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  glActiveTexture(GL_TEXTURE3);
  GLuint texCube2 = skybox2.getTexHandle();
  glBindTexture(GL_TEXTURE_CUBE_MAP, texCube2);
  GLuint samLoc2 = glGetUniformLocation(shaderProg, "texCube");
  glUniform1i(samLoc2, 3);

  GLint ttt2 = 0;
  glGetUniformiv(shaderProg, samLoc, &ttt2);

  glBindBuffer(GL_ARRAY_BUFFER, vertex_handle2);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangle_handle2);

  // Tells OpenGL how to walk through the two VBOs
  // struct sphereVertex v;
  relAddress = (char *) v.pos - (char *) &v;
  glVertexAttribPointer(positionLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);
  relAddress = (char *) v.normal - (char *) &v;
  glVertexAttribPointer(normalLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);

  // draw the triangles
  glDrawElements(GL_TRIANGLES, numTriangles*3, GL_UNSIGNED_INT, (char*) NULL+0);

  return;
}
// any getUniform(WebGLProgram? program, WebGLUniformLocation? location);
bool JSB_glGetUniformfv(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2( argc == 2, cx, false, "JSB_glGetUniformfv: Invalid number of arguments" );
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    bool ok = true;
    uint32_t arg0, arg1;

    ok &= jsval_to_uint( cx, args.get(0), &arg0 );
    ok &= jsval_to_uint( cx, args.get(1), &arg1 );

    JSB_PRECONDITION2(ok, cx, false, "JSB_glGetUniformfv: Error processing arguments");

    GLint activeUniforms;
    glGetProgramiv(arg0, GL_ACTIVE_UNIFORMS, &activeUniforms);
    
    GLsizei length;
    glGetProgramiv(arg0, GL_ACTIVE_UNIFORM_MAX_LENGTH, &length);
    GLchar* namebuffer = new (std::nothrow) GLchar[length+1];
    GLint size = -1;
    GLenum type = -1;

    bool isLocationFound = false;
    for(int i = 0; i  <  activeUniforms; ++i)
    {
        glGetActiveUniform(arg0, i, length, NULL, &size, &type, namebuffer);
        if(arg1 == glGetUniformLocation(arg0, namebuffer))
        {
            isLocationFound = true;
            break;
        }
    }
    if(!isLocationFound)
    {
        size = -1;
        type = -1;
    }
    CC_SAFE_DELETE_ARRAY(namebuffer);

    int usize = 0;
    int utype = 0;
    switch(type) {

        // float
        case GL_FLOAT:
            usize = 1;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_MAT2:
            usize = 2 * 2;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_MAT3:
            usize = 3 * 3;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_MAT4:
            usize = 4 * 4;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_VEC2:
            usize = 2;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_VEC3:
            usize = 3;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_VEC4:
            usize = 4;
            utype = GL_FLOAT;           
            break;

        // int
        case GL_INT:
            usize = 1;
            utype = GL_INT;
            break;
        case GL_INT_VEC2:
            usize = 1;
            utype = GL_INT;
            break;
        case GL_INT_VEC3:
            usize = 1;
            utype = GL_INT;
            break;
        case GL_INT_VEC4:
            usize = 1;
            utype = GL_INT;
            break;

        default:
            JSB_PRECONDITION2(false, cx, false, "JSB_glGetUniformfv: Uniform Type not supported");
    }

    JSObject *typedArray = NULL;
    if( utype == GL_FLOAT) {
        // FIXME: glew on windows will cause array overflow after invoking glGetUniformfv.
        // It seems that glGetUniformfv re-assign the memeroy with a wrong size which is 4x than we pass in.
        // For temporary solution, we allocate 4x array. 
        GLfloat* param = new (std::nothrow) GLfloat[usize*4];
        glGetUniformfv(arg0, arg1, param);

        typedArray = JS_NewFloat32Array(cx, usize);
        float *buffer = (float*)JS_GetArrayBufferViewData(typedArray);
        memcpy( buffer, param, sizeof(float) * usize);
        CC_SAFE_DELETE_ARRAY(param);
    } else if( utype == GL_INT ) {
        // FIXME: glew on windows will cause array overflow after invoking glGetUniformfv.
        // It seems that glGetUniformfv re-assign the memeroy with a wrong size which is 4x than we pass in.
        // For temporary solution, we allocate 4x array. 
        GLint* param = new (std::nothrow) GLint[usize*4];
        glGetUniformiv(arg0, arg1, param);

        typedArray = JS_NewInt32Array(cx, usize);
        GLint *buffer = (GLint*)JS_GetArrayBufferViewData(typedArray);
        memcpy( buffer, param, sizeof(GLint) * usize);
        CC_SAFE_DELETE_ARRAY(param);
    }

    args.rval().set(OBJECT_TO_JSVAL(typedArray));
    return true;
}
Example #14
0
int OGL::OGLShader::GetInt(std::string const& valueName) const
{
	int value;
	glGetUniformiv(_pImpl->ProgramID, _pImpl->GetUniformLocation(valueName), &value);
	return value;
}
Example #15
0
// any getUniform(WebGLProgram? program, WebGLUniformLocation? location);
JSBool JSB_glGetUniformfv(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2( argc == 2, cx, JS_FALSE, "JSB_glGetUniformfv: Invalid number of arguments" );
    jsval *argvp = JS_ARGV(cx,vp);
    JSBool ok = JS_TRUE;
    uint32_t arg0, arg1;

    ok &= jsval_to_uint( cx, *argvp++, &arg0 );
    ok &= jsval_to_uint( cx, *argvp++, &arg1 );

    JSB_PRECONDITION2(ok, cx, JS_FALSE, "JSB_glGetUniformfv: Error processing arguments");

    GLsizei length;
    glGetProgramiv(arg0, GL_ACTIVE_UNIFORM_MAX_LENGTH, &length);
    GLchar* namebuffer = new GLchar[length+1];
    GLint size = -1;
    GLenum type = -1;

    glGetActiveUniform(arg0, arg1, length, NULL, &size, &type, namebuffer);
    CC_SAFE_DELETE_ARRAY(namebuffer);

    int usize = 0;
    int utype = 0;
    switch(type) {

        // float
        case GL_FLOAT:
            usize = 1;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_MAT2:
            usize = 2 * 2;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_MAT3:
            usize = 3 * 3;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_MAT4:
            usize = 4 * 4;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_VEC2:
            usize = 2;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_VEC3:
            usize = 3;
            utype = GL_FLOAT;
            break;
        case GL_FLOAT_VEC4:
            usize = 4;
            utype = GL_FLOAT;           
            break;

        // int
        case GL_INT:
            usize = 1;
            utype = GL_INT;
            break;
        case GL_INT_VEC2:
            usize = 1;
            utype = GL_INT;
            break;
        case GL_INT_VEC3:
            usize = 1;
            utype = GL_INT;
            break;
        case GL_INT_VEC4:
            usize = 1;
            utype = GL_INT;
            break;

        default:
            JSB_PRECONDITION2(false, cx, JS_FALSE, "JSB_glGetUniformfv: Uniform Type not supported");
    }

    JSObject *typedArray = NULL;
    if( utype == GL_FLOAT) {
        // FIXME: glew on windows will cause array overflow after invoking glGetUniformfv.
        // It seems that glGetUniformfv re-assign the memeroy with a wrong size which is 4x than we pass in.
        // For temporary solution, we allocate 4x array. 
        GLfloat* param = new GLfloat[usize*4];
        glGetUniformfv(arg0, arg1, param);

        typedArray = JS_NewFloat32Array(cx, usize);
        float *buffer = (float*)JS_GetArrayBufferViewData(typedArray);
        memcpy( buffer, param, sizeof(float) * usize);
        CC_SAFE_DELETE_ARRAY(param);
    } else if( utype == GL_INT ) {
        // FIXME: glew on windows will cause array overflow after invoking glGetUniformfv.
        // It seems that glGetUniformfv re-assign the memeroy with a wrong size which is 4x than we pass in.
        // For temporary solution, we allocate 4x array. 
        GLint* param = new GLint[usize*4];
        glGetUniformiv(arg0, arg1, param);

        typedArray = JS_NewInt32Array(cx, usize);
        GLint *buffer = (GLint*)JS_GetArrayBufferViewData(typedArray);
        memcpy( buffer, param, sizeof(GLint) * usize);
        CC_SAFE_DELETE_ARRAY(param);
    }

    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(typedArray));
    return JS_TRUE;
}
Example #16
0
static PyObject* py_glGetUniform(PyObject *, PyObject *args) {
  CHECK_ARG_COUNT(args, 2);
  PyObject *rv = 0;
  Uint prg(PyTuple_GetItem(args, 0));
  Int loc(PyTuple_GetItem(args, 1));
  GLint size;
  GLenum type;
  GLchar dummy;
  glGetActiveUniform(prg, loc, 0, 0, &size, &type, &dummy);
  bool integer = false;
  int dim = 0;
  switch (type) {
    case GL_FLOAT:
      dim = 1;
      break;
    case GL_FLOAT_VEC2:
      dim = 2;
      break;
    case GL_FLOAT_VEC3:
      dim = 3;
      break;
    case GL_FLOAT_VEC4:
    case GL_FLOAT_MAT2:
      dim = 4;
      break;
    case GL_FLOAT_MAT3:
      dim = 9;
      break;
    case GL_FLOAT_MAT4:
      dim = 16;
      break;
    // Those are in fact OpenGL 2.1 additions
    case GL_FLOAT_MAT2x3:
    case GL_FLOAT_MAT3x2:
      dim = 6;
      break;
    case GL_FLOAT_MAT2x4:
    case GL_FLOAT_MAT4x2:
      dim = 8;
      break;
    case GL_FLOAT_MAT3x4:
    case GL_FLOAT_MAT4x3:
      dim = 12;
      break;
    case GL_INT:
    case GL_BOOL:
    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:
      integer = true;
      dim = 1;
      break;
    case GL_INT_VEC2:
    case GL_BOOL_VEC2:
      integer = true;
      dim = 2;
      break;
    case GL_INT_VEC3:
    case GL_BOOL_VEC3:
      integer = true;
      dim = 3;
      break;
    case GL_INT_VEC4:
    case GL_BOOL_VEC4:
      integer = true;
      dim = 4;
    default:
      break;
  }
  if (dim == 0) {
    PyErr_SetString(PyExc_RuntimeError, "gl.GetUniform: invalid type");
    return NULL;
  }
  if (integer) {
    GLint values[4];
    glGetUniformiv(prg, loc, values);
    if (dim == 1) {
      rv = PyInt_FromLong(values[0]);
    } else {
      rv = Array1D<Int>(values, dim).toPy();
    }
  } else {
    GLfloat values[16];
    glGetUniformfv(prg, loc, values);
    if (dim == 1) {
      rv = PyFloat_FromDouble(values[0]);
    } else {
      rv = Array1D<Float>(values, dim).toPy();
    }
  }
  return rv;
}
Example #17
0
void
USDVMP::draw(FnKat::ViewerModifierInput& input) 
{
    TF_DEBUG(KATANA_DEBUG_VMP_USD).Msg("%s @ %p : %s\n",
            TF_FUNC_NAME().c_str(), this, _prim.GetPath().GetString().c_str());

    // Render
    if (_stage) {
        // Get draw options needed for styling.
        bool isSelected = input.getDrawOption("selected");
        bool drawPoints = input.getDrawOption("fillPoints");
        bool drawWireframe = input.getDrawOption("fillWireframe");
        bool drawSmooth = input.getDrawOption("shadingSmooth");
        bool isPicking = input.getDrawOption("isPicking");

        // Clear out override color
        _params.overrideColor[3] = 0.0f;

        // Determine the approrpiate draw mode based on the styling options.
        if ( drawSmooth ) {
            if (_GetProxyOverlayMode() == _tokens->wireframe) {
                _params.drawMode = UsdImagingGL::DRAW_WIREFRAME_ON_SURFACE;
            } else {
                _params.drawMode = UsdImagingGL::DRAW_SHADED_SMOOTH;
            }
        }
        if ( drawWireframe ) {
            _params.drawMode = UsdImagingGL::DRAW_WIREFRAME;
        }
        if ( drawPoints ) { 
            // TODO: support draw points
            _params.drawMode = UsdImagingGL::DRAW_POINTS;
        }

        // If this gprim is selected setup drawmode and selection color.
        if ( isSelected ) {
            _params.drawMode = UsdImagingGL::DRAW_GEOM_SMOOTH;
            _params.overrideColor = GfVec4f(0.0f, 1.0f, 1.0f, 1.0f);
            glColor4fv(_params.overrideColor.GetArray());
        }
        if (isPicking) {
            if(input.getDrawOption("hasPickColor") == 1) {
                GfVec4f pickColor(0, 0, 0, 1);
                pickColor[0] = input.getDrawOptionFloat("pickColorR");
                pickColor[1] = input.getDrawOptionFloat("pickColorG");
                pickColor[2] = input.getDrawOptionFloat("pickColorB");
                _params.overrideColor = pickColor;
            }
            else {
                // Most horrible hack in the world :(
                // Katana does it's picking by setting a shader
                // that takes a pick id and renders geometry with
                // the color representation of that id.
                // Unfortunately if we are using Hydra, we need to
                // use our own shaders. To get around this, we are
                // using specific knowledge of the katana pick shader
                // to extract the pick id and set our own override color
                // based on this id. This is basically emulating what the
                // katana shader is doing.
                GLint program = -1;
                glGetIntegerv(GL_CURRENT_PROGRAM, &program);
                TF_VERIFY(program != -1);
                GLint kat_PickIdLoc = glGetUniformLocation(program, "kat_PickId");
                if (TF_VERIFY(kat_PickIdLoc != -1)) {
                    GLint kat_PickId;
                    glGetUniformiv(program, kat_PickIdLoc, &kat_PickId);
                    // Simulate pick id with color
                    _params.overrideColor = GfVec4f(
                        ((float)((kat_PickId >> 0  ) & 0xff)) / 255.0f,
                        ((float)((kat_PickId >> 8  ) & 0xff)) / 255.0f,
                        ((float)((kat_PickId >> 16 ) & 0xff)) / 255.0f,
                        1.0f);
                }
            }
            // Using DRAW_GEOM_ONLY will disable lighting and make
            // sure we are rendering a solid color
            _params.drawMode = UsdImagingGL::DRAW_GEOM_ONLY;
        }

        // Save and restore shader settings around render call
        // because hydra does not restore shader state.
        GLint oldProgram = -1;
        glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgram);

        if (TF_VERIFY(_renderer)) {
            _renderer->SetCameraStateFromOpenGL();

            glPushAttrib(GL_LIGHTING_BIT | GL_ENABLE_BIT);

            if (_GetProxyOverlayMode() == _tokens->ghosted) {
                glEnable(GL_LIGHT0);
                float f = 0.1;
                float params[4] = { f, 0.0, f, 1.0 };
                glLightfv(GL_LIGHT0, GL_AMBIENT, params);
            }

            _renderer->SetLightingStateFromOpenGL();

            glPopAttrib();

            // The multi-threaded Usd Op may be loading or unloading models on
            // the stage we need, so we grab the global lock in reader mode
            // before rendering.
            boost::shared_lock<boost::upgrade_mutex> 
                                            readerLock(UsdKatanaGetStageLock());
            
            _renderer->Render(_prim, _params);
        }

        // Restore old shader
        glUseProgram(oldProgram);
    }
Example #18
0
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 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 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 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 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 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 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;
}
Example #19
0
static bool
test_int(const char *version_string)
{
	GLint loc;
	bool pass = true;
	int values[4];
	int got[ARRAY_SIZE(values)];
	GLuint prog;
	static const char subtest_name[] = "integer scalar and vectors";
	const char *const shader_strings[] = {
		version_string,
		int_code,
		common_body
	};

	BUILD_SHADER(version_string == NULL);

	/* Try int
	 */
	random_ints(values, ARRAY_SIZE(values));
	loc = glGetUniformLocation(prog, "v1");
	glProgramUniform1i(prog, loc,
			   values[0]);
	pass = piglit_check_gl_error(0) && pass;

	glGetUniformiv(prog, loc, got);
	pass = piglit_check_gl_error(0) && pass;

	pass = check_int_values(values, got, 1) && pass;

	random_ints(values, ARRAY_SIZE(values));
	glProgramUniform1iv(prog, loc, 1, values);
	pass = piglit_check_gl_error(0) && pass;

	glGetUniformiv(prog, loc, got);
	pass = piglit_check_gl_error(0) && pass;

	pass = check_int_values(values, got, 1) && pass;

	/* Try ivec2
	 */
	random_ints(values, ARRAY_SIZE(values));
	loc = glGetUniformLocation(prog, "v2");
	glProgramUniform2i(prog, loc,
			   values[0], values[1]);
	pass = piglit_check_gl_error(0) && pass;

	glGetUniformiv(prog, loc, got);
	pass = piglit_check_gl_error(0) && pass;

	pass = check_int_values(values, got, 2) && pass;

	random_ints(values, ARRAY_SIZE(values));
	glProgramUniform2iv(prog, loc, 1, values);
	pass = piglit_check_gl_error(0) && pass;

	glGetUniformiv(prog, loc, got);
	pass = piglit_check_gl_error(0) && pass;

	pass = check_int_values(values, got, 2) && pass;

	/* Try ivec3
	 */
	random_ints(values, ARRAY_SIZE(values));
	loc = glGetUniformLocation(prog, "v3");
	glProgramUniform3i(prog, loc,
			   values[0], values[1], values[2]);
	pass = piglit_check_gl_error(0) && pass;

	glGetUniformiv(prog, loc, got);
	pass = piglit_check_gl_error(0) && pass;

	pass = check_int_values(values, got, 3) && pass;

	random_ints(values, ARRAY_SIZE(values));
	glProgramUniform3iv(prog, loc, 1, values);
	pass = piglit_check_gl_error(0) && pass;

	glGetUniformiv(prog, loc, got);
	pass = piglit_check_gl_error(0) && pass;

	pass = check_int_values(values, got, 3) && pass;

	/* Try ivec4
	 */
	random_ints(values, ARRAY_SIZE(values));
	loc = glGetUniformLocation(prog, "v4");
	glProgramUniform4i(prog, loc,
			   values[0], values[1], values[2], values[3]);
	pass = piglit_check_gl_error(0) && pass;

	glGetUniformiv(prog, loc, got);
	pass = piglit_check_gl_error(0) && pass;

	pass = check_int_values(values, got, 4) && pass;

	random_ints(values, ARRAY_SIZE(values));
	glProgramUniform4iv(prog, loc, 1, values);
	pass = piglit_check_gl_error(0) && pass;

	glGetUniformiv(prog, loc, got);
	pass = piglit_check_gl_error(0) && pass;

	pass = check_int_values(values, got, 4) && pass;

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     subtest_name);

	glDeleteProgram(prog);
	return pass;
}
Example #20
0
//----------------------------------------------------------------------------------------------------------------------
void ShaderProgram::getUniformiv(const char* _varname,int *o_values ) const
{
  glGetUniformiv(m_programID,getUniformLocation(_varname),o_values);
}
Example #21
0
void GlShaderProgram::getUniformIntVariableValue(const std::string &variableName, int *value) {
  GLint loc = getUniformVariableLocation(variableName);
  glGetUniformiv(programObjectId, loc, (GLint *)value);
}
Example #22
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL20_nglGetUniformiv(JNIEnv *env, jclass clazz, jint program, jint location, jlong params, jlong function_pointer) {
	GLint *params_address = (GLint *)(intptr_t)params;
	glGetUniformivPROC glGetUniformiv = (glGetUniformivPROC)((intptr_t)function_pointer);
	glGetUniformiv(program, location, params_address);
}
void ProgramUniformGLSL::Get4(int *pnComponents)
{
	glGetUniformiv(m_nOpenGLESProgram, m_nOpenGLESUniformLocation, pnComponents);
}
void ProgramUniformGLSL::Get(Vector3i &vVector)
{
	glGetUniformiv(m_nOpenGLESProgram, m_nOpenGLESUniformLocation, vVector.nV);
}
Example #25
0
void GraphicsContext3D::getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value)
{
    makeContextCurrent();
    glGetUniformiv(program, location, value);
}
Example #26
0
 GLint Program::GetUniformi(const GLchar *name) const
 {
     GLint ret;
     glGetUniformiv(mID, mUniformLocations.find(name)->second, &ret);
     return ret;
 }
Example #27
0
 void get_uniformiv(gl::uint_t program, gl::int_t location, gl::int_t * params) {
   glGetUniformiv(program, location, params);
 }
Example #28
0
void SkyBox::displaySkybox(camera cam) {

  int t = 1;  // remove
  glDisable(GL_DEPTH_TEST);    // need depth test to correctly draw 3D objects

  Matrix4f viewMat, projMat, modelMat, m;

  // set local camera for the skybox
  camera c1 = cam;
  //c1.changeAbsPoition(0,0,0);
  //c1.changeLookAtVector(1, 1, 1);

  //glFrontFace(GL_CW);
  //glCullFace(FRONT);

  // set up the mode to wireframe
  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  //set up the mode to fill
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  // get the transformation matrix
  modelMat = Matrix4f::translation(cam.getPosition());

  // setting up the viewpoint transformation
  viewMat = c1.getViewMatrix(NULL);

  // setting up the projection transformation  make sure that it is the same
  // projection as the display function!!!
  //projMat =   Matrix4f::symmetricPerspectiveProjectionMatrix(30, 1, 0.1, 500);
  projMat = cam.getProjectionMatrix(NULL);

  // frustum matrix
  //projMat = Matrix4f::frustumProjectionMatrix(-1,-1,1,1, 10,100);

  // putting it all together
  m = projMat * viewMat * modelMat;

  // load the program to the shader
  glUseProgram(shaderProg);

  viewMat.m = (float *) viewMat.vm;
  projMat.m = (float *) projMat.vm;

  // transfer the matrix to the shader
  GLuint locMat= 0;
  locMat=glGetUniformLocation(shaderProg,  "modelViewProjMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  m = viewMat*modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelViewMat");
  glUniformMatrix4fv(locMat,1,1,(float *) m.vm);

  // set the time
  GLuint tLoc = glGetUniformLocation(shaderProg, "t");
  glUniform1i(tLoc, t);

  // set the time
  GLuint cameraPositiontLoc = glGetUniformLocation(shaderProg, "cameraPosition");
  glEnableVertexAttribArray(cameraPositiontLoc);

  Vector3f camPos = c1.getPosition();
  glUniform3f(cameraPositiontLoc, camPos.x, camPos.y, camPos.z);

  //glActiveTexture (GL_TEXTURE1);
  glActiveTexture(GL_TEXTURE3);
  glBindTexture(GL_TEXTURE_CUBE_MAP, texHandle);
  GLuint texLoc = glGetUniformLocation(shaderProg, "texCube");
    glUniform1i(texLoc, 3);
  GLint ttt = 0;
  glGetUniformiv(shaderProg, texLoc, &ttt);

  //glUniform1i(glGetUniformLocation(skyboxProg, "texCube"), texCube);
  //glDisable(GL_CULL_FACE);

  // bind the buffers to the shaders
  GLuint positionLoc = glGetAttribLocation(shaderProg, "vertex_position");
  //GLuint normalLoc = glGetAttribLocation(shaderProg, "vertex_normal");
  //GLuint texLoc = glGetAttribLocation(shaderProg, "texCoord");

  glEnableVertexAttribArray(positionLoc);
  //glEnableVertexAttribArray(normalLoc);
  //glEnableVertexAttribArray(texLoc);
  glBindBuffer(GL_ARRAY_BUFFER, vboCube);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboCube);


  // Tells OpenGL how to walk through the two VBOs
  glVertexAttribPointer(positionLoc,4,GL_FLOAT, GL_FALSE, 0,0);
  // draw the triangles
  glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, (char*) NULL+0);

  //glutSwapBuffers();
  glEnable(GL_DEPTH_TEST);    // need depth test to correctly draw 3D objects
  return;
}
static void
dumpUniform(StateWriter &writer,
            GLint program,
            const AttribDesc & desc,
            const GLchar *name)
{
    if (desc.elemType == GL_NONE) {
        return;
    }

    union {
        GLfloat fvalues[4*4];
        GLdouble dvalues[4*4];
        GLint ivalues[4*4];
        GLuint uivalues[4*4];
        GLint64 i64values[4*4];
        GLuint64 ui64values[4*4];
        GLbyte data[4*4*4];
    } u;

    GLint i;

    std::string qualifiedName = resolveUniformName(name, desc.size);

    writer.beginMember(qualifiedName);
    if (desc.size > 1) {
        writer.beginArray();
    }

    for (i = 0; i < desc.size; ++i) {
        std::stringstream ss;
        ss << qualifiedName;
        if (desc.size > 1) {
            ss << '[' << i << ']';
        }
        std::string elemName = ss.str();

        GLint location = glGetUniformLocation(program, elemName.c_str());
        assert(location != -1);
        if (location == -1) {
            continue;
        }

        switch (desc.elemType) {
        case GL_FLOAT:
            glGetUniformfv(program, location, u.fvalues);
            break;
        case GL_DOUBLE:
            glGetUniformdv(program, location, u.dvalues);
            break;
        case GL_INT:
            glGetUniformiv(program, location, u.ivalues);
            break;
        case GL_UNSIGNED_INT:
            glGetUniformuiv(program, location, u.uivalues);
            break;
        case GL_INT64_ARB:
            glGetUniformi64vARB(program, location, u.i64values);
            break;
        case GL_UNSIGNED_INT64_ARB:
            glGetUniformui64vARB(program, location, u.ui64values);
            break;
        case GL_BOOL:
            glGetUniformiv(program, location, u.ivalues);
            break;
        default:
            assert(0);
            break;
        }

        dumpAttrib(writer, desc, u.data);
    }

    if (desc.size > 1) {
        writer.endArray();
    }

    writer.endMember();
}
//[-------------------------------------------------------]
//[ Public virtual PLRenderer::ProgramUniform functions   ]
//[-------------------------------------------------------]
// 1 component
void ProgramUniformGLSL::Get(int &nX)
{
	glGetUniformiv(m_nOpenGLESProgram, m_nOpenGLESUniformLocation, &nX);
}