//------------------------------------------------------------------------------ void bindProgram(GLuint program) { glUseProgram(program); // shader uniform setting GLint position = glGetUniformLocation(program, "lightSource[0].position"); GLint ambient = glGetUniformLocation(program, "lightSource[0].ambient"); GLint diffuse = glGetUniformLocation(program, "lightSource[0].diffuse"); GLint specular = glGetUniformLocation(program, "lightSource[0].specular"); GLint position1 = glGetUniformLocation(program, "lightSource[1].position"); GLint ambient1 = glGetUniformLocation(program, "lightSource[1].ambient"); GLint diffuse1 = glGetUniformLocation(program, "lightSource[1].diffuse"); GLint specular1 = glGetUniformLocation(program, "lightSource[1].specular"); glProgramUniform4f(program, position, 0.5, 0.2f, 1.0f, 0.0f); glProgramUniform4f(program, ambient, 0.1f, 0.1f, 0.1f, 1.0f); glProgramUniform4f(program, diffuse, 0.7f, 0.7f, 0.7f, 1.0f); glProgramUniform4f(program, specular, 0.8f, 0.8f, 0.8f, 1.0f); glProgramUniform4f(program, position1, -0.8f, 0.4f, -1.0f, 0.0f); glProgramUniform4f(program, ambient1, 0.0f, 0.0f, 0.0f, 1.0f); glProgramUniform4f(program, diffuse1, 0.5f, 0.5f, 0.5f, 1.0f); glProgramUniform4f(program, specular1, 0.8f, 0.8f, 0.8f, 1.0f); GLint otcMatrix = glGetUniformLocation(program, "objectToClipMatrix"); GLint oteMatrix = glGetUniformLocation(program, "objectToEyeMatrix"); GLfloat modelView[16], proj[16], mvp[16]; glGetFloatv(GL_MODELVIEW_MATRIX, modelView); glGetFloatv(GL_PROJECTION_MATRIX, proj); multMatrix(mvp, modelView, proj); glProgramUniformMatrix4fv(program, otcMatrix, 1, false, mvp); glProgramUniformMatrix4fv(program, oteMatrix, 1, false, modelView); }
void Material::Bind() { glUseProgram(program); for (std::unordered_map<std::string, Texture2D*>::iterator it = textures.begin(); it != textures.end(); ++it) { it->second->Bind(); } for (std::unordered_map<std::string, ShaderVariable>::iterator it = uniforms.begin(); it != uniforms.end(); ++it) { ShaderVariable v = it->second; switch (v.size) { case 1: glProgramUniform1f(program, v.index, data[v.offset]); break; case 2: glProgramUniform2f(program, v.index, data[v.offset], data[v.offset + 1]); break; case 3: glProgramUniform3f(program, v.index, data[v.offset], data[v.offset + 1], data[v.offset + 2]); break; case 4: glProgramUniform4f(program, v.index, data[v.offset], data[v.offset + 1], data[v.offset + 2], data[v.offset + 3]); break; case 16: glProgramUniformMatrix4fv(program, v.index, 1, GL_TRUE, &data[v.offset]); break; } } }
void ssquadResize(RenderPacket* ssquad, float* proj, float x, float y, float w, float h) { uint32 proj_loc = glGetUniformLocation(ssquad->vsh, "proj"); uint32 offset_loc = glGetUniformLocation(ssquad->vsh, "offset"); glProgramUniformMatrix4fv(ssquad->vsh, proj_loc, 1, false, proj); glProgramUniform4f(ssquad->vsh, offset_loc, x, y, w, h); }
void RenderCB(GlRunner *runner) { glClearColor(0.2, 0.1, 0.2, 0.0); glClearDepthf(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); clock_t current_time = clock(); float delta = 0.00001*(current_time-start_time); glProgramUniform1f(VS, glGetUniformLocation(VS, "uTime"), delta); glProgramUniform4f(FS, glGetUniformLocation(FS, "uColor"), 1.0, 0.0, 0.0, 0.0); glDrawArrays(GL_POINTS, 0, xmesh*ymesh); glProgramUniform4f(FS, glGetUniformLocation(FS, "uColor"), 1.0, 1.0, 0.0, 0.0); glDrawElements(GL_TRIANGLE_STRIP, xmesh*(ymesh-1)*2, GL_UNSIGNED_INT, (void*)0); }
void Material::SetColor(std::string name, Color& color) { int location = glGetUniformLocation(program, name.c_str()); if (location == -1) { //std::cout << "Attempt made to set invalid uniform variable: " << name << std::endl; } glProgramUniform4f(program, location, color.r, color.g, color.b, color.a); }
void Material::SetFloat4(std::string name, Vector4& value) { int location = glGetUniformLocation(program, name.c_str()); if (location == -1) { //std::cout << "Attempt made to set invalid uniform variable: " << name << std::endl; } glProgramUniform4f(program, location, value.x, value.y, value.z, value.w); }
void updateUniform(GLuint ProgramName, std::size_t DrawIndex, testDrawArrays::uniformUpdate const & UniformUpdate) { switch(UniformUpdate) { case testDrawArrays::PER_DRAW_UNIFORM_DSA: case testDrawArrays::PER_DRAW_UNIFORM2_DSA: { if(DrawIndex % 2) { glProgramUniform4f(ProgramName, UniformDiffuse0, 1.0f, 0.5f, 0.0f, 1.0f); if(UniformDiffuse1 != -1) glProgramUniform4f(ProgramName, UniformDiffuse1, 0.9f, 0.7f, 0.5f, 1.0f); } else { glProgramUniform4f(ProgramName, UniformDiffuse0, 0.0f, 0.5f, 1.0f, 1.0f); if(UniformDiffuse1 != -1) glProgramUniform4f(ProgramName, UniformDiffuse1, 0.9f, 0.7f, 0.5f, 1.0f); } } break; case testDrawArrays::REDUNDANT_UNIFORM_DSA: case testDrawArrays::REDUNDANT_UNIFORM2_DSA: { glProgramUniform4f(ProgramName, UniformDiffuse0, 1.0f, 0.5f, 0.0f, 1.0f); if(UniformDiffuse1 != -1) glProgramUniform4f(ProgramName, UniformDiffuse1, 0.9f, 0.7f, 0.5f, 1.0f); } break; case testDrawArrays::PER_DRAW_UNIFORM_B2E: case testDrawArrays::PER_DRAW_UNIFORM2_B2E: { if(DrawIndex % 2) { glUniform4f(UniformDiffuse0, 1.0f, 0.5f, 0.0f, 1.0f); if(UniformDiffuse1 != -1) glUniform4f(UniformDiffuse1, 0.9f, 0.7f, 0.5f, 1.0f); } else { glUniform4f(UniformDiffuse0, 0.0f, 0.5f, 1.0f, 1.0f); if(UniformDiffuse1 != -1) glUniform4f(UniformDiffuse1, 0.9f, 0.7f, 0.5f, 1.0f); } } break; case testDrawArrays::REDUNDANT_UNIFORM_B2E: case testDrawArrays::REDUNDANT_UNIFORM2_B2E: { glUniform4f(UniformDiffuse0, 1.0f, 0.5f, 0.0f, 1.0f); if(UniformDiffuse1 != -1) glUniform4f(UniformDiffuse1, 0.9f, 0.7f, 0.5f, 1.0f); } break; default: break; } }
void program::set_uniform4f(char const* varname, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) const { GLint location = get_uniform_location(varname); if (location >= 0) { #if GPUCAST_GL_DIRECT_STATE_ACCESS glProgramUniform4f(id_, location, v0, v1, v2, v3); #else glUniform4f(location, v0, v1, v2, v3); #endif } //assert((location >= 0) && "set_uniform4f() : uniform not in use"); }
void MyEffect::BindDrawConfig(MyDrawConfig *config, OpenSubdiv::OsdDrawContext::PatchDescriptor desc) { // bind uniforms // currently, these are used only in conjunction with tessellation shaders #if defined(GL_EXT_direct_state_access) || defined(GL_VERSION_4_1) GLint program = config->program; GLint diffuseColor = config->diffuseColorUniform; if (displayPatchColor) { float const * color = getAdaptivePatchColor( desc ); glProgramUniform4f(program, diffuseColor, color[0], color[1], color[2], color[3]); } #endif }
bool SimpleUniformGL::InitScene() { glClearColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a); std::vector<GLuint> shaders; shaders.push_back(GLUtil::CreateShader(GL_VERTEX_SHADER, "SimpleUniformVert.glsl")); shaders.push_back(GLUtil::CreateShader(GL_FRAGMENT_SHADER, "SimpleUniformFrag.glsl")); shaderProgram = GLUtil::CreateProgram(shaders); for_each(shaders.begin(), shaders.end(), glDeleteShader); glUseProgram(shaderProgram); GLint overrideColor = glGetUniformLocation(shaderProgram, "overrideColor"); glProgramUniform4f(shaderProgram, overrideColor, 1.0f, 0.0f, 0.0f, 1.0f); GLuint bindingPoint = 1; float colorsBlock[8] = { 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0, 1.0f }; GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(colorsBlock), colorsBlock, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, buffer); GLuint blockIndex = glGetUniformBlockIndex(shaderProgram, "ColorBlock"); glUniformBlockBinding(shaderProgram, blockIndex, bindingPoint); glCreateVertexArrays(1, &vao); glBindVertexArray(vao); glCreateBuffers(1, &vbo); glNamedBufferData(vbo, sizeof(Data::vertices), Data::vertices, GL_STATIC_DRAW); glVertexArrayAttribBinding(vao, 0, 0); glVertexArrayAttribBinding(vao, 1, 0); glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(Vertex2)); glEnableVertexArrayAttrib(vao, 0); glEnableVertexArrayAttrib(vao, 1); glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, GL_FALSE, 0); glVertexArrayAttribFormat(vao, 1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2().position)); return true; }
GLUniform::GLUniform(const char* name, GLuint program, int size, const char* type) : GLNode(name) { this->location = glGetUniformLocation(program, name); if(size == 1 && std::string(type) == std::string("i") ) glProgramUniform1i(program, this->location, 0); else if(size == 1 && std::string(type) == std::string("f") ) glProgramUniform1f(program, this->location, 0); else if(size == 2 && std::string(type) == std::string("f") ) glProgramUniform2f(program, this->location, 0, 0); else if(size == 3 && std::string(type) == std::string("f") ) glProgramUniform3f(program, this->location, 0, 0, 0); else if(size == 3 && std::string(type) == std::string("f") ) glProgramUniform3f(program, this->location, 0, 0, 0); else if(size == 4 && std::string(type) == std::string("f") ) glProgramUniform4f(program, this->location, 0, 0, 0, 0); this->id = UINT_MAX; }
void ShaderProgram::setUniform(const std::string& name, float first, float second, float third, float fourth) { if(!ext::separateShaderObjects()) //If we can't do uniforms without binding { //Get the currently-bound program and bind this program auto previous = getBound(); bind(); //Set the uniform glCheck(glUniform4f(uniformLocation(name), first, second, third, fourth)); //Set the previous program back glCheck(glUseProgram(previous)); } else //If we can do uniforms without binding { //Set the uniform with this program glCheck(glProgramUniform4f(program_, uniformLocation(name), first, second, third, fourth)); } }
void Material::SetFloat4(std::string name, Vector4& value) { uint location = glGetUniformLocation(program, name.c_str()); glProgramUniform4f(program, location, value.x, value.y, value.z, value.w); }
void Material::SetColor(std::string name, Color& color) { uint location = glGetUniformLocation(program, name.c_str()); glProgramUniform4f(program, location, color.r, color.g, color.b, color.a); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL41_nglProgramUniform4f(JNIEnv *env, jclass clazz, jint program, jint location, jfloat v0, jfloat v1, jfloat v2, jfloat v3, jlong function_pointer) { glProgramUniform4fPROC glProgramUniform4f = (glProgramUniform4fPROC)((intptr_t)function_pointer); glProgramUniform4f(program, location, v0, v1, v2, v3); }
bool testDrawArrays::initProgram() { bool Validated(true); std::size_t ShaderIndex(0); switch(this->UniformUpdate) { case CONSTANT_UNIFORM: case PER_DRAW_UNIFORM_DSA: case REDUNDANT_UNIFORM_DSA: case PER_DRAW_UNIFORM_B2E: case REDUNDANT_UNIFORM_B2E: ShaderIndex = 1; break; case PER_DRAW_UNIFORM2_DSA: case REDUNDANT_UNIFORM2_DSA: case PER_DRAW_UNIFORM2_B2E: case REDUNDANT_UNIFORM2_B2E: ShaderIndex = 2; break; case NO_UNIFORM: default: ShaderIndex = 0; break; } glGenProgramPipelines(1, &this->PipelineName); compiler Compiler; GLuint VertShaderName = Compiler.create(GL_VERTEX_SHADER, getDataDirectory() + VERT_SHADER_SOURCE[ShaderIndex], "--version 420 --profile core"); GLuint FragShaderName = Compiler.create(GL_FRAGMENT_SHADER, getDataDirectory() + FRAG_SHADER_SOURCE[ShaderIndex], "--version 420 --profile core"); Validated = Validated && Compiler.check(); this->ProgramName = glCreateProgram(); glProgramParameteri(this->ProgramName, GL_PROGRAM_SEPARABLE, GL_TRUE); glAttachShader(this->ProgramName, VertShaderName); glAttachShader(this->ProgramName, FragShaderName); glLinkProgram(this->ProgramName); Validated = Validated && Compiler.checkProgram(this->ProgramName); UniformDiffuse0 = glGetUniformLocation(ProgramName, "Diffuse0"); UniformDiffuse1 = glGetUniformLocation(ProgramName, "Diffuse1"); if(Validated) glUseProgramStages(this->PipelineName, GL_VERTEX_SHADER_BIT | GL_FRAGMENT_SHADER_BIT, ProgramName); if( this->UniformUpdate == testDrawArrays::CONSTANT_UNIFORM || this->UniformUpdate == testDrawArrays::PER_DRAW_UNIFORM_B2E || this->UniformUpdate == testDrawArrays::REDUNDANT_UNIFORM_B2E || this->UniformUpdate == testDrawArrays::PER_DRAW_UNIFORM2_B2E || this->UniformUpdate == testDrawArrays::REDUNDANT_UNIFORM2_B2E) glActiveShaderProgram(this->PipelineName, this->ProgramName); if(this->UniformUpdate == testDrawArrays::CONSTANT_UNIFORM) { glProgramUniform4f(this->ProgramName, UniformDiffuse0, 1.0f, 0.5f, 0.0f, 1.0f); if(UniformDiffuse1 != -1) glProgramUniform4f(this->ProgramName, UniformDiffuse1, 0.0f, 0.5f, 1.0f, 1.0f); } return Validated; }
//------------------------------------------------------------------------------ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, g_width, g_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_LIGHTING); glColor3f(1, 1, 1); glBegin(GL_QUADS); glColor3f(1, 1, 1); glVertex3f(-1, -1, 1); glVertex3f( 1, -1, 1); glVertex3f( 1, 1, 1); glVertex3f(-1, 1, 1); glEnd(); double aspect = g_width/(double)g_height; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, aspect, 0.01, 500.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(-g_pan[0], -g_pan[1], -g_dolly); glRotatef(g_rotate[1], 1, 0, 0); glRotatef(g_rotate[0], 0, 1, 0); glTranslatef(-g_center[0], -g_center[1], -g_center[2]); glRotatef(-90, 1, 0, 0); // z-up model GLuint bVertex = g_vertexBuffer->GetGpuBuffer(); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, bVertex); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof (GLfloat) * 6, 0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof (GLfloat) * 6, (float*)12); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_elementArrayBuffer->GetGlBuffer()); GLenum primType = GL_LINES_ADJACENCY; if (g_scheme == kLoop) { primType = GL_TRIANGLES; bindProgram(g_triFillProgram); } else { bindProgram(g_quadFillProgram); } if (g_wire > 0) { glDrawElements(primType, g_elementArrayBuffer->GetNumIndices(), GL_UNSIGNED_INT, NULL); } if (g_wire == 0 || g_wire == 2) { GLuint lineProgram = g_scheme == kLoop ? g_triLineProgram : g_quadLineProgram; bindProgram(lineProgram); GLuint fragColor = glGetUniformLocation(lineProgram, "fragColor"); if (g_wire == 2) { glProgramUniform4f(lineProgram, fragColor, 0, 0, 0.5, 1); } else { glProgramUniform4f(lineProgram, fragColor, 1, 1, 1, 1); } glDrawElements(primType, g_elementArrayBuffer->GetNumIndices(), GL_UNSIGNED_INT, NULL); } glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glUseProgram(0); if (g_drawNormals) drawNormals(); if (g_drawCoarseMesh) drawCoarseMesh(g_drawCoarseMesh); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDisableClientState(GL_VERTEX_ARRAY); if (g_drawHUD) { glColor3f(1, 1, 1); drawString(10, 10, "LEVEL = %d", g_level); drawString(10, 30, "# of Vertices = %d", g_osdmesh->GetFarMesh()->GetNumVertices()); drawString(10, 50, "KERNEL = %s", getKernelName(g_kernel)); drawString(10, 70, "CPU TIME = %.3f ms", g_cpuTime); drawString(10, 90, "GPU TIME = %.3f ms", g_gpuTime); drawString(10, 110, "SUBDIVISION = %s", g_scheme==kBilinear ? "BILINEAR" : (g_scheme == kLoop ? "LOOP" : "CATMARK")); drawString(10, g_height-30, "w: toggle wireframe"); drawString(10, g_height-50, "e: display normal vector"); drawString(10, g_height-70, "m: toggle vertex deforming"); drawString(10, g_height-90, "h: display control cage"); drawString(10, g_height-110, "n/p: change model"); drawString(10, g_height-130, "1-7: subdivision level"); drawString(10, g_height-150, "space: freeze/unfreeze time"); } glFinish(); glutSwapBuffers(); }
//------------------------------------------------------------------------------ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, g_width, g_height); double aspect = g_width/(double)g_height; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, aspect, g_size*0.001f, g_size+g_dolly); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(-g_pan[0], -g_pan[1], -g_dolly); glRotatef(g_rotate[1], 1, 0, 0); glRotatef(g_rotate[0], 0, 1, 0); glTranslatef(-g_center[0], -g_center[1], -g_center[2]); glUseProgram(g_program); { // shader uniform setting GLint position = glGetUniformLocation(g_program, "lightSource[0].position"); GLint ambient = glGetUniformLocation(g_program, "lightSource[0].ambient"); GLint diffuse = glGetUniformLocation(g_program, "lightSource[0].diffuse"); GLint specular = glGetUniformLocation(g_program, "lightSource[0].specular"); glProgramUniform4f(g_program, position, 0, 0.2f, 1, 0); glProgramUniform4f(g_program, ambient, 0.4f, 0.4f, 0.4f, 1.0f); glProgramUniform4f(g_program, diffuse, 0.3f, 0.3f, 0.3f, 1.0f); glProgramUniform4f(g_program, specular, 0.2f, 0.2f, 0.2f, 1.0f); GLint otcMatrix = glGetUniformLocation(g_program, "objectToClipMatrix"); GLint oteMatrix = glGetUniformLocation(g_program, "objectToEyeMatrix"); GLfloat modelView[16], proj[16], mvp[16]; glGetFloatv(GL_MODELVIEW_MATRIX, modelView); glGetFloatv(GL_PROJECTION_MATRIX, proj); multMatrix(mvp, modelView, proj); glProgramUniformMatrix4fv(g_program, otcMatrix, 1, false, mvp); glProgramUniformMatrix4fv(g_program, oteMatrix, 1, false, modelView); } GLuint bVertex = g_vertexBuffer->GetGpuBuffer(); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, bVertex); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof (GLfloat) * 6, 0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof (GLfloat) * 6, (float*)12); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_elementArrayBuffer->GetGlBuffer()); glPolygonMode(GL_FRONT_AND_BACK, g_wire==0 ? GL_LINE : GL_FILL); // glPatchParameteri(GL_PATCH_VERTICES, 4); // glDrawElements(GL_PATCHES, g_numIndices, GL_UNSIGNED_INT, 0); glDrawElements(GL_LINES_ADJACENCY, g_elementArrayBuffer->GetNumIndices(), GL_UNSIGNED_INT, 0); glUseProgram(0); if (g_drawNormals) drawNormals(); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); if (g_ptexDebug) drawPtexLayout(g_ptexDebug-1); glColor3f(1, 1, 1); drawFmtString(10, 10, "LEVEL = %d", g_level); drawFmtString(10, 30, "# of Vertices = %d", g_osdmesh->GetFarMesh()->GetNumVertices()); drawFmtString(10, 50, "KERNEL = %s", getKernelName(g_kernel)); drawFmtString(10, 70, "CPU TIME = %.3f ms", g_cpuTime); drawFmtString(10, 90, "GPU TIME = %.3f ms", g_gpuTime); g_fpsTimer.Stop(); drawFmtString(10, 110, "FPS = %3.1f", 1.0/g_fpsTimer.GetElapsed()); g_fpsTimer.Start(); drawFmtString(10, 130, "SUBDIVISION = %s", g_scheme==0 ? "CATMARK" : "BILINEAR"); drawString(10, g_height-10, "a: ambient occlusion on/off"); drawString(10, g_height-30, "c: color on/off"); drawString(10, g_height-50, "d: displacement on/off"); drawString(10, g_height-70, "e: show normal vector"); drawString(10, g_height-90, "f: fit frame"); drawString(10, g_height-110, "w: toggle wireframe"); drawString(10, g_height-130, "m: toggle vertex moving"); drawString(10, g_height-150, "s: bilinear / catmark"); drawString(10, g_height-170, "1-7: subdivision level"); glFinish(); glutSwapBuffers(); }
static bool test_float(const char *version_string) { GLint loc; bool pass = true; float values[4]; float got[ARRAY_SIZE(values)]; GLuint prog; static const char subtest_name[] = "float scalar and vectors"; const char *const shader_strings[] = { version_string, float_code, common_body }; BUILD_SHADER(true); /* Try float */ loc = glGetUniformLocation(prog, "v1"); random_floats(values, ARRAY_SIZE(values)); glProgramUniform1f(prog, loc, values[0]); pass = piglit_check_gl_error(0) && pass; glGetUniformfv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_float_values(values, got, 1) && pass; random_floats(values, ARRAY_SIZE(values)); glProgramUniform1fv(prog, loc, 1, values); pass = piglit_check_gl_error(0) && pass; glGetUniformfv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_float_values(values, got, 1) && pass; /* Try vec2 */ loc = glGetUniformLocation(prog, "v2"); random_floats(values, ARRAY_SIZE(values)); glProgramUniform2f(prog, loc, values[0], values[1]); pass = piglit_check_gl_error(0) && pass; glGetUniformfv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_float_values(values, got, 2) && pass; random_floats(values, ARRAY_SIZE(values)); glProgramUniform2fv(prog, loc, 1, values); pass = piglit_check_gl_error(0) && pass; glGetUniformfv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_float_values(values, got, 2) && pass; /* Try vec3 */ loc = glGetUniformLocation(prog, "v3"); random_floats(values, ARRAY_SIZE(values)); glProgramUniform3f(prog, loc, values[0], values[1], values[2]); pass = piglit_check_gl_error(0) && pass; glGetUniformfv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_float_values(values, got, 3) && pass; random_floats(values, ARRAY_SIZE(values)); glProgramUniform3fv(prog, loc, 1, values); pass = piglit_check_gl_error(0) && pass; glGetUniformfv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_float_values(values, got, 3) && pass; /* Try vec4 */ loc = glGetUniformLocation(prog, "v4"); random_floats(values, ARRAY_SIZE(values)); glProgramUniform4f(prog, loc, values[0], values[1], values[2], values[3]); pass = piglit_check_gl_error(0) && pass; glGetUniformfv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_float_values(values, got, 4) && pass; random_floats(values, ARRAY_SIZE(values)); glProgramUniform4fv(prog, loc, 1, values); pass = piglit_check_gl_error(0) && pass; glGetUniformfv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_float_values(values, got, 4) && pass; piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, subtest_name); glDeleteProgram(prog); return pass; }