void TransitionTriangulation::configurePrograms() { glProgramUniform3f (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_SCENE_SIZE], Parameters::getInstance()->g_geometry.scale[0], Parameters::getInstance()->g_geometry.scale[1], Parameters::getInstance()->g_geometry.scale[2]); glProgramUniform2f (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_VIEWPORT], Parameters::getInstance()->g_window.width, Parameters::getInstance()->g_window.height); glProgramUniform1f (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_TAN_FOVY], tanf (Parameters::getInstance()->g_camera.fovy / 360.f * 3.14159f)); glProgramUniform1f(Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_SCALE], Parameters::getInstance()->g_scale); glProgramUniform1i (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_DENSITY], TEXTURE_DENSITY); glProgramUniform1i (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_CODE_CLASS_TR], TEXTURE_CODE_CLASS_TR); glProgramUniform1i (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_CODE_VERTICES_TR], TEXTURE_CODE_VERTICES_TR); glProgramUniform1i (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_CLASS_TRIANGLES_TR], TEXTURE_CLASS_TRIANGLES_TR); glProgramUniform1i (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_TESSEL], (int)Parameters::getInstance()->g_tessel); glProgramUniform1f(Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_ISOSURFACE], 0);//Parameters::getInstance()->g_isosurface); glProgramUniform1i (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_FROMTEXTURE], 1);//Parameters::getInstance()->g_fromtexture); glProgramUniform1i (Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_METRIC], 0);//Parameters::getInstance()->g_radial_length); glProgramUniform1f(Parameters::getInstance()->g_programs[PROGRAM_TRANSITION_DRAW], Parameters::getInstance()->g_uniform_locations[LOCATION_TRANSITION_TIME], Parameters::getInstance()->g_time_elapsed); }
void ShaderProgram::setUniform(const std::string& name, float first, float second, float third) { 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(glUniform3f(uniformLocation(name), first, second, third)); //Set the previous program back glCheck(glUseProgram(previous)); } else //If we can do uniforms without binding { //Set the uniform with this program glCheck(glProgramUniform3f(program_, uniformLocation(name), first, second, third)); } }
GLuint OpenSubdivPtexShader::bindProgram(const MHWRender::MDrawContext & mDrawContext, OpenSubdiv::OsdGLDrawContext *osdDrawContext, const OpenSubdiv::OsdPatchArray & patch) { CHECK_GL_ERROR("bindProgram begin\n"); // Build shader Effect effect; effect.color = _enableColor; effect.occlusion = _enableOcclusion; effect.displacement = _enableDisplacement; effect.normal = _enableNormal; EffectDesc effectDesc( patch.desc, effect ); EffectDrawRegistry::ConfigType * config = effectRegistry.GetDrawConfig(effectDesc); // Install shader GLuint program = config->program; glUseProgram(program); // Update and bind transform state struct Transform { float ModelViewMatrix[16]; float ProjectionMatrix[16]; float ModelViewProjectionMatrix[16]; } transformData; setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewMtx), transformData.ModelViewMatrix); setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kProjectionMtx), transformData.ProjectionMatrix); setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewProjMtx), transformData.ModelViewProjectionMatrix); if (!g_transformUB) { glGenBuffers(1, &g_transformUB); glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(transformData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(transformData), &transformData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_transformBinding, g_transformUB); // Update and bind tessellation state struct Tessellation { float TessLevel; int GregoryQuadOffsetBase; int PrimitiveIdBase; } tessellationData; tessellationData.TessLevel = static_cast<float>(1 << _tessFactor); tessellationData.GregoryQuadOffsetBase = patch.GetQuadOffsetBase; tessellationData.PrimitiveIdBase = patch.GetPatchIndex();; if (!g_tessellationUB) { glGenBuffers(1, &g_tessellationUB); glBindBuffer(GL_UNIFORM_BUFFER, g_tessellationUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(tessellationData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_tessellationUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(tessellationData), &tessellationData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_tessellationBinding, g_tessellationUB); #ifdef USE_NON_IMAGE_BASED_LIGHTING // Update and bind lighting state int numLights = mDrawContext.numberOfActiveLights(); struct Lighting { struct Light { float position[4]; float diffuse[4]; float ambient[4]; float specular[4]; } lightSource[2]; } lightingData; memset(&lightingData, 0, sizeof(lightingData)); for (int i = 0; i < numLights && i < 1; ++i) { MFloatPointArray positions; MFloatVector direction; float intensity; MColor color; bool hasDirection, hasPosition; mDrawContext.getLightInformation(i, positions, direction, intensity, color, hasDirection, hasPosition); Lighting::Light &light = lightingData.lightSource[i]; if (hasDirection) { light.position[0] = -direction[0]; light.position[1] = -direction[1]; light.position[2] = -direction[2]; for (int j = 0; j < 4; ++j) { light.diffuse[j] = color[j] * intensity; light.ambient[j] = color[j] * intensity; light.specular[j] = color[j] * intensity; } } } if (!g_lightingUB) { glGenBuffers(1, &g_lightingUB); glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(lightingData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(lightingData), &lightingData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_lightingBinding, g_lightingUB); #endif GLint eye = glGetUniformLocation(program, "eyePositionInWorld"); MPoint e = MPoint(0, 0, 0) * mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewInverseMtx); glProgramUniform3f(program, eye, static_cast<float>(e.x), static_cast<float>(e.y), static_cast<float>(e.z)); // update other uniforms float color[4] = { 0, 0, 0, 1 }; _diffuse.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "diffuseColor"), 1, color); _ambient.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "ambientColor"), 1, color); _specular.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "specularColor"), 1, color); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelBias"), _fresnelBias); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelScale"), _fresnelScale); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelPower"), _fresnelPower); // Ptex bindings // color ptex if (effectRegistry.getPtexColorValid()) { GLint texData = glGetUniformLocation(program, "textureImage_Data"); glProgramUniform1i(program, texData, CLR_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureImage_Packing"); glProgramUniform1i(program, texPacking, CLR_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureImage_Pages"); glProgramUniform1i(program, texPages, CLR_TEXTURE_UNIT + 2); } // displacement ptex if (effectRegistry.getPtexDisplacementValid()) { GLint texData = glGetUniformLocation(program, "textureDisplace_Data"); glProgramUniform1i(program, texData, DISP_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureDisplace_Packing"); glProgramUniform1i(program, texPacking, DISP_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureDisplace_Pages"); glProgramUniform1i(program, texPages, DISP_TEXTURE_UNIT + 2); } // occlusion ptex if (effectRegistry.getPtexOcclusionValid()) { GLint texData = glGetUniformLocation(program, "textureOcclusion_Data"); glProgramUniform1i(program, texData, OCC_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureOcclusion_Packing"); glProgramUniform1i(program, texPacking, OCC_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureOcclusion_Pages"); glProgramUniform1i(program, texPages, OCC_TEXTURE_UNIT + 2); } // diffuse environment map if (effectRegistry.getDiffuseEnvironmentId() != 0) { GLint difmap = glGetUniformLocation(program, "diffuseEnvironmentMap"); glProgramUniform1i(program, difmap, DIFF_TEXTURE_UNIT); } // specular environment map if (effectRegistry.getSpecularEnvironmentId() != 0) { GLint envmap = glGetUniformLocation(program, "specularEnvironmentMap"); glProgramUniform1i(program, envmap, ENV_TEXTURE_UNIT); } glActiveTexture(GL_TEXTURE0); CHECK_GL_ERROR("bindProgram leave\n"); return program; }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL41_nglProgramUniform3f(JNIEnv *env, jclass clazz, jint program, jint location, jfloat v0, jfloat v1, jfloat v2, jlong function_pointer) { glProgramUniform3fPROC glProgramUniform3f = (glProgramUniform3fPROC)((intptr_t)function_pointer); glProgramUniform3f(program, location, v0, v1, v2); }
//-------------------------------------------------------------------------- void GBuffer::Draw( const glm::mat4& _projection, const glm::mat4& _view, const SceneManager& _scene) { glBindFramebuffer(GL_FRAMEBUFFER,framebuffer); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glm::mat4 transform = _projection * _view; int nMeshes = int(_scene.regularMeshes.size()); if(nMeshes>0) { // Render at the same resolution than the original window // Draw all objects glUseProgram(regularRenderer.program.id); glProgramUniformMatrix4fv(regularRenderer.program.id, regularRenderer.transformVar, 1, GL_FALSE, &transform[0][0]); for(int i=0;i<nMeshes;++i) { const RegularMesh& mesh = _scene.regularMeshes[i]; glProgramUniformMatrix4fv(regularRenderer.program.id, regularRenderer.modelVar, 1, GL_FALSE, &_scene.transformations[i][0][0]); glProgramUniform1f(regularRenderer.program.id, regularRenderer.roughnessVar, mesh.roughness); glProgramUniform1f(regularRenderer.program.id, regularRenderer.specularityVar, mesh.specularity); mesh.diffuseTex->Bind(regularRenderer.diffuseTexUnit); mesh.normalTex->Bind(regularRenderer.normalTexUnit); mesh.Draw(); } glf::CheckError("GBuffer::Draw::Regulars"); } int nTerrains = int(_scene.terrainMeshes.size()); if(nTerrains>0) { // Render at the same resolution than the original window // Draw all objects glUseProgram(terrainRenderer.program.id); glProgramUniformMatrix4fv(terrainRenderer.program.id, terrainRenderer.transformVar, 1, GL_FALSE, &transform[0][0]); for(int i=0;i<nTerrains;++i) { const TerrainMesh& mesh = _scene.terrainMeshes[i]; glProgramUniform3f(terrainRenderer.program.id, terrainRenderer.tileOffsetVar, mesh.tileOffset.x, mesh.tileOffset.y, mesh.tileOffset.z); glProgramUniform2i(terrainRenderer.program.id, terrainRenderer.tileCountVar, mesh.tileCount.x, mesh.tileCount.y); glProgramUniform2f(terrainRenderer.program.id, terrainRenderer.tileSizeVar, mesh.tileSize.x, mesh.tileSize.y); glProgramUniform1f(terrainRenderer.program.id, terrainRenderer.tessFactorVar, mesh.tessFactor); glProgramUniform1f(terrainRenderer.program.id, terrainRenderer.heightFactorVar, mesh.heightFactor); glProgramUniform1f(terrainRenderer.program.id, terrainRenderer.projFactorVar, mesh.projFactor); glProgramUniform1f(terrainRenderer.program.id, terrainRenderer.roughnessVar, mesh.roughness); glProgramUniform1f(terrainRenderer.program.id, terrainRenderer.specularityVar, mesh.specularity); glProgramUniform1f(terrainRenderer.program.id, terrainRenderer.tileFactorVar, mesh.tileFactor); mesh.diffuseTex->Bind(terrainRenderer.diffuseTexUnit); mesh.normalTex->Bind(terrainRenderer.normalTexUnit); mesh.heightTex->Bind(terrainRenderer.heightTexUnit); mesh.Draw(); } glf::CheckError("GBuffer::Draw::Terrains"); } glBindFramebuffer(GL_FRAMEBUFFER,0); glf::CheckError("GBuffer::Draw"); }
void Material::SetFloat3(std::string name, Vector3& value) { uint location = glGetUniformLocation(program, name.c_str()); glProgramUniform3f(program, location, value.x, value.y, value.z); }
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; }
void configure_curv(GLuint program, GLuint first_loc) { glProgramUniform3f (program, Parameters::getInstance()->g_uniform_locations[first_loc], Parameters::getInstance()->g_geometry.scale[0], Parameters::getInstance()->g_geometry.scale[1], Parameters::getInstance()->g_geometry.scale[2]); glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+1], TEXTURE_DENSITY); glProgramUniform2f (program, Parameters::getInstance()->g_uniform_locations[first_loc+2], Parameters::getInstance()->g_window.width, Parameters::getInstance()->g_window.height); glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+3], Parameters::getInstance()->g_solid_wireframe); glProgramUniform1f (program, Parameters::getInstance()->g_uniform_locations[first_loc+4], Parameters::getInstance()->g_curvradius); glProgramUniform1f (program, Parameters::getInstance()->g_uniform_locations[first_loc+5], Parameters::getInstance()->g_curvmin); glProgramUniform1f (program, Parameters::getInstance()->g_uniform_locations[first_loc+6], Parameters::getInstance()->g_curvmax); glProgramUniform1f(program, Parameters::getInstance()->g_uniform_locations[first_loc+7], Parameters::getInstance()->g_sizetex); glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+8], (int)Parameters::getInstance()->g_curv_dir); glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+9], (int)Parameters::getInstance()->g_curv_val); glProgramUniform1f (program, Parameters::getInstance()->g_uniform_locations[first_loc+10], Parameters::getInstance()->g_lvl); glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+11], (int)Parameters::getInstance()->g_triangle_normals); glProgramUniform1f (program, Parameters::getInstance()->g_uniform_locations[first_loc+12], Parameters::getInstance()->g_time_elapsed); glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+13], TEXTURE_SUBDIV_SPHERE); /*glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+7], (int)Parameters::getInstance()->g_ground_truth);*/ /*glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+15], 1);//Parameters::getInstance()->g_fromtexture );*/ /* glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+12], TEXTURE_X2Y2Z2); glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+13], TEXTURE_XY_YZ_XZ); glProgramUniform1i (program, Parameters::getInstance()->g_uniform_locations[first_loc+14], TEXTURE_XYZ); */ /*glProgramUniform1f (program, Parameters::getInstance()->g_uniform_locations[first_loc+3], tanf (Parameters::getInstance()->g_camera.fovy / 360.f * 3.14159f)); glProgramUniform1f(program, Parameters::getInstance()->g_uniform_locations[first_loc+4], Parameters::getInstance()->g_scale); */ /* glProgramUniform3f (program, Parameters::getInstance()->g_uniform_locations[first_loc+6], Parameters::getInstance()->g_camera.pos[0], Parameters::getInstance()->g_camera.pos[1], Parameters::getInstance()->g_camera.pos[2] ); */ }