static void schro_opengl_upsampled_frame_render_quad (SchroOpenGLShader *shader, int x, int y, int quad_width, int quad_height, int total_width, int total_height) { int x_inverse, y_inverse; int four_x = 0, four_y = 0, three_x = 0, three_y = 0, two_x = 0, two_y = 0, one_x = 0, one_y = 0; x_inverse = total_width - x - quad_width; y_inverse = total_height - y - quad_height; if (quad_width == total_width && quad_height < total_height) { four_y = 4; three_y = 3; two_y = 2; one_y = 1; } else if (quad_width < total_width && quad_height == total_height) { four_x = 4; three_x = 3; two_x = 2; one_x = 1; } else { SCHRO_ERROR ("invalid quad to total relation"); SCHRO_ASSERT (0); } SCHRO_ASSERT (x_inverse >= 0); SCHRO_ASSERT (y_inverse >= 0); #define UNIFORM(_number, _operation, __x, __y) \ do { \ if (shader->_number##_##_operation != -1) { \ glUniform2fARB (shader->_number##_##_operation, \ __x < _number##_x ? __x : _number##_x, \ __y < _number##_y ? __y : _number##_y); \ } \ } while (0) UNIFORM (four, decrease, x, y); UNIFORM (three, decrease, x, y); UNIFORM (two, decrease, x, y); UNIFORM (one, decrease, x, y); UNIFORM (one, increase, x_inverse, y_inverse); UNIFORM (two, increase, x_inverse, y_inverse); UNIFORM (three, increase, x_inverse, y_inverse); UNIFORM (four, increase, x_inverse, y_inverse); #undef UNIFORM schro_opengl_render_quad (x, y, quad_width, quad_height); }
void R_Shader_Init(void) { //RenderState_ShaderPermutation *s; char *vertstring, *fragstring; //unsigned int vertstrings_count, fragstrings_count; //const char *vertstrings_list[R_SHADERPERMUTATION_LIMIT]; //const char *fragstrings_list[R_SHADERPERMUTATION_LIMIT]; // set up the lighting shaders memset(&r_refdef.lightShader, 0, sizeof(r_refdef.lightShader)); // if (!R.ext.ARB_fragment_shader) if (!gl_support_GLSL_shaders) return; // vertstring = File_LoadFile("shaders/light.vert", NULL); // fragstring = File_LoadFile("shaders/light.frag", NULL); #define VERTEX_SHADER_FILENAME "shaders/standard.vert" #define FRAGMENT_SHADER_FILENAME "shaders/standard.frag" vertstring = COM_LoadMallocFile( VERTEX_SHADER_FILENAME ); fragstring = COM_LoadMallocFile( FRAGMENT_SHADER_FILENAME ); if (!vertstring || !fragstring) r_refdef.lightShader.programObject = R_CompileGLSLProgram (1, &builtinvertshader, 1, &builtinfragshader); else r_refdef.lightShader.programObject = R_CompileGLSLProgram( 1, &vertstring, 1, &fragstring ); if( r_refdef.lightShader.programObject == 0 ) { Con_Printf( "Couldn't load light shaders '" VERTEX_SHADER_FILENAME "' and '" FRAGMENT_SHADER_FILENAME "'!\n" ); } // free the source strings if (fragstring) Z_Free( fragstring ); if (vertstring) Z_Free( vertstring ); // determine the uniform locations #define UNIFORM( name ) r_refdef.lightShader.##name = qglGetUniformLocationARB( r_refdef.lightShader.programObject, #name ); UNIFORM( lightPosition ); //UNIFORM( eyePosition ); UNIFORM( viewToLightMatrix ); UNIFORM( diffuseSampler ); //UNIFORM( normalSampler ); //UNIFORM( specularSampler ); UNIFORM( lightColor ); UNIFORM( lightMaxDistance ); /* Black: According to the specs, these two caps don't exist so comment them out for a beginning. */ /* // ? glEnable(GL_FRAGMENT_SHADER_ARB); glEnable(GL_VERTEX_SHADER_ARB); */ /* for (i = 0, s = r_refdef.shader_standard;i < R_LIGHTSHADERPERMUTATION_LIMIT;i++, s++) { // build the source list for this shader permutation vertstrings_count = 0; fragstrings_count = 0; if (i & R_LIGHTSHADERPERMUTATION_SPECULAR) { vertstrings_list[vertstrings_count++] = "#define USESPECULAR\n"; fragstrings_list[fragstrings_count++] = "#define USESPECULAR\n"; } if (i & R_LIGHTSHADERPERMUTATION_FOG) { vertstrings_list[vertstrings_count++] = "#define USEFOG\n"; fragstrings_list[fragstrings_count++] = "#define USEFOG\n"; } if (i & R_LIGHTSHADERPERMUTATION_CUBEFILTER) { vertstrings_list[vertstrings_count++] = "#define USECUBEFILTER\n"; fragstrings_list[fragstrings_count++] = "#define USECUBEFILTER\n"; } if (i & R_LIGHTSHADERPERMUTATION_OFFSETMAPPING) { vertstrings_list[vertstrings_count++] = "#define USEOFFSETMAPPING\n"; fragstrings_list[fragstrings_count++] = "#define USEOFFSETMAPPING\n"; } vertstrings_list[vertstrings_count++] = vertstring; fragstrings_list[fragstrings_count++] = fragstring; // vertstrings_list[vertstrings_count++] = vertstring ? vertstring : builtinshader_standard_vert; // fragstrings_list[fragstrings_count++] = fragstring ? fragstring : builtinshader_standard_frag; // compile this shader permutation s->programmObject = R_CompileGLSL(vertstrings_count, vertstrings_list, fragstrings_count, fragstrings_list); if (!s->programmObject) { // Console_Printf("permutation %s %s %s %s failed for lighting shader (glsl/light.frag and .vert), some features may not work properly!\n", i & 1 ? "specular" : "", i & 1 ? "fog" : "", i & 1 ? "cubefilter" : "", i & 1 ? "offsetmapping" : ""); Con_Printf("permutation %s %s %s %s failed for lighting shader (shaders/standard.frag and .vert), some features may not work properly!\n", i & 1 ? "specular" : "", i & 1 ? "fog" : "", i & 1 ? "cubefilter" : "", i & 1 ? "offsetmapping" : ""); continue; } // R_CheckError(); // switch to the new program object qglUseProgramObjectARB(s->programmObject); // fetch all the uniform locations s->loc_LightPosition = qglGetUniformLocationARB(s->programmObject, "LightPosition"); s->loc_EyePosition = qglGetUniformLocationARB(s->programmObject, "EyePosition"); s->loc_LightColor = qglGetUniformLocationARB(s->programmObject, "LightColor"); s->loc_OffsetMapping_Scale = qglGetUniformLocationARB(s->programmObject, "OffsetMapping_Scale"); s->loc_OffsetMapping_Bias = qglGetUniformLocationARB(s->programmObject, "OffsetMapping_Bias"); s->loc_SpecularPower = qglGetUniformLocationARB(s->programmObject, "SpecularPower"); s->loc_FogRangeRecip = qglGetUniformLocationARB(s->programmObject, "FogRangeRecip"); s->loc_AmbientScale = qglGetUniformLocationARB(s->programmObject, "AmbientScale"); s->loc_DiffuseScale = qglGetUniformLocationARB(s->programmObject, "DiffuseScale"); s->loc_SpecularScale = qglGetUniformLocationARB(s->programmObject, "SpecularScale"); s->loc_Texture_Normal = qglGetUniformLocationARB(s->programmObject, "Texture_Normal"); s->loc_Texture_Color = qglGetUniformLocationARB(s->programmObject, "Texture_Color"); s->loc_Texture_Gloss = qglGetUniformLocationARB(s->programmObject, "Texture_Gloss"); s->loc_Texture_Cube = qglGetUniformLocationARB(s->programmObject, "Texture_Cube"); s->loc_Texture_FogMask = qglGetUniformLocationARB(s->programmObject, "Texture_FogMask"); // set static uniforms if (s->loc_Texture_Normal) qglUniform1iARB(s->loc_Texture_Normal, 0); if (s->loc_Texture_Color) qglUniform1iARB(s->loc_Texture_Color, 1); if (s->loc_Texture_Gloss) qglUniform1iARB(s->loc_Texture_Gloss, 2); if (s->loc_Texture_Cube) qglUniform1iARB(s->loc_Texture_Cube, 3); if (s->loc_Texture_FogMask) qglUniform1iARB(s->loc_Texture_FogMask, 4); // R_CheckError(); } // free the source strings if (fragstring) // Mem_Free(&fragstring); free(&fragstring); if (vertstring) // Mem_Free(&vertstring); free(&vertstring); // switch back to fixed function program qglUseProgramObjectARB( 0 ); */ }