From 9b39879a325569c8e1a0a9e687d00b6c2f291a97 Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 14 Feb 2016 19:59:33 +1100 Subject: [PATCH] [Glide64] Change display_warning to WriteTrace --- Source/Glide64/Main.cpp | 1 - Source/Glitch64/Glitch64.vcxproj | 12 + Source/Glitch64/Glitch64.vcxproj.filters | 12 + Source/Glitch64/OGLEScombiner.cpp | 4513 +++++++++++----------- Source/Glitch64/OGLESgeometry.cpp | 14 +- Source/Glitch64/OGLESglitchmain.cpp | 3771 +++++++++--------- Source/Glitch64/OGLEStextures.cpp | 28 +- Source/Glitch64/OGLcombiner.cpp | 146 +- Source/Glitch64/OGLgeometry.cpp | 14 +- Source/Glitch64/OGLglitchmain.cpp | 176 +- Source/Glitch64/OGLtextures.cpp | 28 +- Source/Glitch64/glitchmain.h | 93 +- 12 files changed, 4399 insertions(+), 4409 deletions(-) diff --git a/Source/Glide64/Main.cpp b/Source/Glide64/Main.cpp index 6e352e21e..bee14c455 100644 --- a/Source/Glide64/Main.cpp +++ b/Source/Glide64/Main.cpp @@ -1407,7 +1407,6 @@ output: none *******************************************************************/ void CALL GetDllInfo(PLUGIN_INFO * PluginInfo) { - WriteTrace(TraceGlide64, TraceDebug, "-"); PluginInfo->Version = 0x0104; // Set to 0x0104 PluginInfo->Type = PLUGIN_TYPE_GFX; // Set to PLUGIN_TYPE_GFX #ifdef _DEBUG diff --git a/Source/Glitch64/Glitch64.vcxproj b/Source/Glitch64/Glitch64.vcxproj index b009b23c3..70d08ae5e 100644 --- a/Source/Glitch64/Glitch64.vcxproj +++ b/Source/Glitch64/Glitch64.vcxproj @@ -42,6 +42,18 @@ + + true + + + true + + + true + + + true + diff --git a/Source/Glitch64/Glitch64.vcxproj.filters b/Source/Glitch64/Glitch64.vcxproj.filters index ce5a98aad..39577f21e 100644 --- a/Source/Glitch64/Glitch64.vcxproj.filters +++ b/Source/Glitch64/Glitch64.vcxproj.filters @@ -23,6 +23,18 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + diff --git a/Source/Glitch64/OGLEScombiner.cpp b/Source/Glitch64/OGLEScombiner.cpp index 0408ea394..748ea6388 100644 --- a/Source/Glitch64/OGLEScombiner.cpp +++ b/Source/Glitch64/OGLEScombiner.cpp @@ -32,7 +32,7 @@ void vbo_draw(); static int fct[4], source0[4], operand0[4], source1[4], operand1[4], source2[4], operand2[4]; -static int fcta[4],sourcea0[4],operanda0[4],sourcea1[4],operanda1[4],sourcea2[4],operanda2[4]; +static int fcta[4], sourcea0[4], operanda0[4], sourcea1[4], operanda1[4], sourcea2[4], operanda2[4]; static int alpha_ref, alpha_func; bool alpha_test = 0; @@ -48,7 +48,7 @@ static int dither_enabled; int blackandwhite0; int blackandwhite1; -float fogStart,fogEnd; +float fogStart, fogEnd; float fogColor[4]; #ifdef _WIN32 @@ -174,7 +174,7 @@ SHADER_HEADER "attribute highp vec4 aMultiTexCoord1; \n" "attribute float aFog; \n" "uniform vec3 vertexOffset; \n" //Moved some calculations from grDrawXXX to shader -"uniform vec4 textureSizes; \n" +"uniform vec4 textureSizes; \n" "uniform vec3 fogModeEndScale; \n" //0 = Mode, 1 = gl_Fog.end, 2 = gl_Fog.scale SHADER_VARYING " \n" @@ -200,9 +200,9 @@ SHADER_VARYING " float f = (fogModeEndScale[1] - fogV) * fogModeEndScale[2]; \n" " f = clamp(f, 0.0, 1.0); \n" " gl_TexCoord[0].b = f; \n" -" gl_TexCoord[2].b = aVertex.x; \n" -" gl_TexCoord[2].a = aVertex.y; \n" -"} \n" +" gl_TexCoord[2].b = aVertex.x; \n" +" gl_TexCoord[2].a = aVertex.y; \n" +"} \n" ; static char fragment_shader_color_combiner[1024]; @@ -214,211 +214,211 @@ static char shader_log[2048]; void check_compile(GLuint shader) { - GLint success; - glGetShaderiv(shader,GL_COMPILE_STATUS,&success); - if(!success) - { - char log[1024]; - glGetShaderInfoLog(shader,1024,NULL,log); - LOGINFO(log); - } + GLint success; + glGetShaderiv(shader, GL_COMPILE_STATUS, &success); + if (!success) + { + char log[1024]; + glGetShaderInfoLog(shader, 1024, NULL, log); + LOGINFO(log); + } } void check_link(GLuint program) { - GLint success; - glGetProgramiv(program,GL_LINK_STATUS,&success); - if(!success) -{ - char log[1024]; - glGetProgramInfoLog(program,1024,NULL,log); - LOGINFO(log); - } + GLint success; + glGetProgramiv(program, GL_LINK_STATUS, &success); + if (!success) + { + char log[1024]; + glGetProgramInfoLog(program, 1024, NULL, log); + LOGINFO(log); + } } void init_combiner() { - int texture[4] = {0, 0, 0, 0}; + int texture[4] = { 0, 0, 0, 0 }; - glActiveTexture(GL_TEXTURE0); - glEnable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE0); + glEnable(GL_TEXTURE_2D); - // creating a fake texture - glBindTexture(GL_TEXTURE_2D, default_texture); - glTexImage2D(GL_TEXTURE_2D, 0, 3, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + // creating a fake texture + glBindTexture(GL_TEXTURE_2D, default_texture); + glTexImage2D(GL_TEXTURE_2D, 0, 3, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, default_texture); - glEnable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, default_texture); + glEnable(GL_TEXTURE_2D); - int texture0_location; - int texture1_location; - char *fragment_shader; - int log_length; + int texture0_location; + int texture1_location; + char *fragment_shader; + int log_length; #ifndef ANDROID - // depth shader - fragment_depth_shader_object = glCreateShader(GL_FRAGMENT_SHADER); + // depth shader + fragment_depth_shader_object = glCreateShader(GL_FRAGMENT_SHADER); - char s[128]; - // ZIGGY convert a 565 texture into depth component - sprintf(s, "gl_FragDepth = dot(texture2D(texture0, vec2(gl_TexCoord[0])), vec4(31*64*32, 63*32, 31, 0))*%g + %g; \n", zscale/2/65535.0, 1-zscale/2); - fragment_shader = (char*)malloc(strlen(fragment_shader_header)+ - strlen(s)+ - strlen(fragment_shader_end)+1); - strcpy(fragment_shader, fragment_shader_header); - strcat(fragment_shader, s); - strcat(fragment_shader, fragment_shader_end); - glShaderSource(fragment_depth_shader_object, 1, (const GLchar**)&fragment_shader, NULL); - free(fragment_shader); + char s[128]; + // ZIGGY convert a 565 texture into depth component + sprintf(s, "gl_FragDepth = dot(texture2D(texture0, vec2(gl_TexCoord[0])), vec4(31*64*32, 63*32, 31, 0))*%g + %g; \n", zscale / 2 / 65535.0, 1 - zscale / 2); + fragment_shader = (char*)malloc(strlen(fragment_shader_header) + + strlen(s) + + strlen(fragment_shader_end) + 1); + strcpy(fragment_shader, fragment_shader_header); + strcat(fragment_shader, s); + strcat(fragment_shader, fragment_shader_end); + glShaderSource(fragment_depth_shader_object, 1, (const GLchar**)&fragment_shader, NULL); + free(fragment_shader); - glCompileShader(fragment_depth_shader_object); - check_compile(fragment_depth_shader_object); + glCompileShader(fragment_depth_shader_object); + check_compile(fragment_depth_shader_object); #endif - // default shader - fragment_shader_object = glCreateShader(GL_FRAGMENT_SHADER); + // default shader + fragment_shader_object = glCreateShader(GL_FRAGMENT_SHADER); - fragment_shader = (char*)malloc(strlen(fragment_shader_header)+ - strlen(fragment_shader_default)+ - strlen(fragment_shader_end)+1); - strcpy(fragment_shader, fragment_shader_header); - strcat(fragment_shader, fragment_shader_default); - strcat(fragment_shader, fragment_shader_end); - glShaderSource(fragment_shader_object, 1, (const GLchar**)&fragment_shader, NULL); - free(fragment_shader); + fragment_shader = (char*)malloc(strlen(fragment_shader_header) + + strlen(fragment_shader_default) + + strlen(fragment_shader_end) + 1); + strcpy(fragment_shader, fragment_shader_header); + strcat(fragment_shader, fragment_shader_default); + strcat(fragment_shader, fragment_shader_end); + glShaderSource(fragment_shader_object, 1, (const GLchar**)&fragment_shader, NULL); + free(fragment_shader); - glCompileShader(fragment_shader_object); - check_compile(fragment_shader_object); + glCompileShader(fragment_shader_object); + check_compile(fragment_shader_object); - vertex_shader_object = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(vertex_shader_object, 1, &vertex_shader, NULL); - glCompileShader(vertex_shader_object); - check_compile(vertex_shader_object); + vertex_shader_object = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vertex_shader_object, 1, &vertex_shader, NULL); + glCompileShader(vertex_shader_object); + check_compile(vertex_shader_object); - // depth program - program_object = glCreateProgram(); - program_object_depth = program_object; - glAttachShader(program_object, fragment_depth_shader_object); - glAttachShader(program_object, vertex_shader_object); + // depth program + program_object = glCreateProgram(); + program_object_depth = program_object; + glAttachShader(program_object, fragment_depth_shader_object); + glAttachShader(program_object, vertex_shader_object); - glBindAttribLocation(program_object,POSITION_ATTR,"aPosition"); - glBindAttribLocation(program_object,COLOUR_ATTR,"aColor"); - glBindAttribLocation(program_object,TEXCOORD_0_ATTR,"aMultiTexCoord0"); - glBindAttribLocation(program_object,TEXCOORD_1_ATTR,"aMultiTexCoord1"); - glBindAttribLocation(program_object,FOG_ATTR,"aFog"); + glBindAttribLocation(program_object, POSITION_ATTR, "aPosition"); + glBindAttribLocation(program_object, COLOUR_ATTR, "aColor"); + glBindAttribLocation(program_object, TEXCOORD_0_ATTR, "aMultiTexCoord0"); + glBindAttribLocation(program_object, TEXCOORD_1_ATTR, "aMultiTexCoord1"); + glBindAttribLocation(program_object, FOG_ATTR, "aFog"); - glLinkProgram(program_object); - check_link(program_object); - glUseProgram(program_object); + glLinkProgram(program_object); + check_link(program_object); + glUseProgram(program_object); - texture0_location = glGetUniformLocation(program_object, "texture0"); - texture1_location = glGetUniformLocation(program_object, "texture1"); - glUniform1i(texture0_location, 0); - glUniform1i(texture1_location, 1); + texture0_location = glGetUniformLocation(program_object, "texture0"); + texture1_location = glGetUniformLocation(program_object, "texture1"); + glUniform1i(texture0_location, 0); + glUniform1i(texture1_location, 1); - // default program - program_object = glCreateProgram(); - program_object_default = program_object; - glAttachShader(program_object, fragment_shader_object); - glAttachShader(program_object, vertex_shader_object); + // default program + program_object = glCreateProgram(); + program_object_default = program_object; + glAttachShader(program_object, fragment_shader_object); + glAttachShader(program_object, vertex_shader_object); - glBindAttribLocation(program_object,POSITION_ATTR,"aPosition"); - glBindAttribLocation(program_object,COLOUR_ATTR,"aColor"); - glBindAttribLocation(program_object,TEXCOORD_0_ATTR,"aMultiTexCoord0"); - glBindAttribLocation(program_object,TEXCOORD_1_ATTR,"aMultiTexCoord1"); - glBindAttribLocation(program_object,FOG_ATTR,"aFog"); + glBindAttribLocation(program_object, POSITION_ATTR, "aPosition"); + glBindAttribLocation(program_object, COLOUR_ATTR, "aColor"); + glBindAttribLocation(program_object, TEXCOORD_0_ATTR, "aMultiTexCoord0"); + glBindAttribLocation(program_object, TEXCOORD_1_ATTR, "aMultiTexCoord1"); + glBindAttribLocation(program_object, FOG_ATTR, "aFog"); - glLinkProgram(program_object); - check_link(program_object); - glUseProgram(program_object); + glLinkProgram(program_object); + check_link(program_object); + glUseProgram(program_object); - texture0_location = glGetUniformLocation(program_object, "texture0"); - texture1_location = glGetUniformLocation(program_object, "texture1"); - glUniform1i(texture0_location, 0); - glUniform1i(texture1_location, 1); + texture0_location = glGetUniformLocation(program_object, "texture0"); + texture1_location = glGetUniformLocation(program_object, "texture1"); + glUniform1i(texture0_location, 0); + glUniform1i(texture1_location, 1); - strcpy(fragment_shader_color_combiner, ""); - strcpy(fragment_shader_alpha_combiner, ""); - strcpy(fragment_shader_texture1, "vec4 ctexture1 = texture2D(texture0, vec2(gl_TexCoord[0])); \n"); - strcpy(fragment_shader_texture0, ""); + strcpy(fragment_shader_color_combiner, ""); + strcpy(fragment_shader_alpha_combiner, ""); + strcpy(fragment_shader_texture1, "vec4 ctexture1 = texture2D(texture0, vec2(gl_TexCoord[0])); \n"); + strcpy(fragment_shader_texture0, ""); - first_color = 1; - first_alpha = 1; - first_texture0 = 1; - first_texture1 = 1; - need_to_compile = 0; - fog_enabled = 0; - chroma_enabled = 0; - dither_enabled = 0; - blackandwhite0 = 0; - blackandwhite1 = 0; + first_color = 1; + first_alpha = 1; + first_texture0 = 1; + first_texture1 = 1; + need_to_compile = 0; + fog_enabled = 0; + chroma_enabled = 0; + dither_enabled = 0; + blackandwhite0 = 0; + blackandwhite1 = 0; } void compile_chroma_shader() { - strcpy(fragment_shader_chroma, "\nvoid test_chroma(vec4 ctexture1)\n{\n"); + strcpy(fragment_shader_chroma, "\nvoid test_chroma(vec4 ctexture1)\n{\n"); - switch(chroma_other_alpha) - { - case GR_COMBINE_OTHER_ITERATED: - strcat(fragment_shader_chroma, "float alpha = gl_Color.a; \n"); - break; - case GR_COMBINE_OTHER_TEXTURE: - strcat(fragment_shader_chroma, "float alpha = ctexture1.a; \n"); - break; - case GR_COMBINE_OTHER_CONSTANT: - strcat(fragment_shader_chroma, "float alpha = constant_color.a; \n"); - break; - default: - display_warning("unknown compile_choma_shader_alpha : %x", chroma_other_alpha); - } + switch (chroma_other_alpha) + { + case GR_COMBINE_OTHER_ITERATED: + strcat(fragment_shader_chroma, "float alpha = gl_Color.a; \n"); + break; + case GR_COMBINE_OTHER_TEXTURE: + strcat(fragment_shader_chroma, "float alpha = ctexture1.a; \n"); + break; + case GR_COMBINE_OTHER_CONSTANT: + strcat(fragment_shader_chroma, "float alpha = constant_color.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown compile_choma_shader_alpha : %x", chroma_other_alpha); + } - switch(chroma_other_color) - { - case GR_COMBINE_OTHER_ITERATED: - strcat(fragment_shader_chroma, "vec4 color = vec4(vec3(gl_Color),alpha); \n"); - break; - case GR_COMBINE_OTHER_TEXTURE: - strcat(fragment_shader_chroma, "vec4 color = vec4(vec3(ctexture1),alpha); \n"); - break; - case GR_COMBINE_OTHER_CONSTANT: - strcat(fragment_shader_chroma, "vec4 color = vec4(vec3(constant_color),alpha); \n"); - break; - default: - display_warning("unknown compile_choma_shader_alpha : %x", chroma_other_color); - } + switch (chroma_other_color) + { + case GR_COMBINE_OTHER_ITERATED: + strcat(fragment_shader_chroma, "vec4 color = vec4(vec3(gl_Color),alpha); \n"); + break; + case GR_COMBINE_OTHER_TEXTURE: + strcat(fragment_shader_chroma, "vec4 color = vec4(vec3(ctexture1),alpha); \n"); + break; + case GR_COMBINE_OTHER_CONSTANT: + strcat(fragment_shader_chroma, "vec4 color = vec4(vec3(constant_color),alpha); \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown compile_choma_shader_alpha : %x", chroma_other_color); + } - strcat(fragment_shader_chroma, "if (color.rgb == chroma_color.rgb) discard; \n"); - strcat(fragment_shader_chroma, "}"); + strcat(fragment_shader_chroma, "if (color.rgb == chroma_color.rgb) discard; \n"); + strcat(fragment_shader_chroma, "}"); } typedef struct _shader_program_key { - int color_combiner; - int alpha_combiner; - int texture0_combiner; - int texture1_combiner; - int texture0_combinera; - int texture1_combinera; - int fog_enabled; - int chroma_enabled; - int dither_enabled; - int blackandwhite0; - int blackandwhite1; - GLuint fragment_shader_object; - GLuint program_object; - int texture0_location; - int texture1_location; - int vertexOffset_location; - int textureSizes_location; - int fogModeEndScale_location; - int fogColor_location; - int alphaRef_location; - int ditherTex_location; - int chroma_color_location; + int color_combiner; + int alpha_combiner; + int texture0_combiner; + int texture1_combiner; + int texture0_combinera; + int texture1_combinera; + int fog_enabled; + int chroma_enabled; + int dither_enabled; + int blackandwhite0; + int blackandwhite1; + GLuint fragment_shader_object; + GLuint program_object; + int texture0_location; + int texture1_location; + int vertexOffset_location; + int textureSizes_location; + int fogModeEndScale_location; + int fogColor_location; + int alphaRef_location; + int ditherTex_location; + int chroma_color_location; } shader_program_key; static shader_program_key* shader_programs = NULL; @@ -432,2377 +432,2376 @@ static int texture1_combinera_key; void update_uniforms(shader_program_key prog) { - glUniform1i(prog.texture0_location, 0); - glUniform1i(prog.texture1_location, 1); + glUniform1i(prog.texture0_location, 0); + glUniform1i(prog.texture1_location, 1); - glUniform3f(prog.vertexOffset_location,widtho,heighto,inverted_culling ? -1.0f : 1.0f); - glUniform4f(prog.textureSizes_location,tex0_width,tex0_height,tex1_width,tex1_height); + glUniform3f(prog.vertexOffset_location, widtho, heighto, inverted_culling ? -1.0f : 1.0f); + glUniform4f(prog.textureSizes_location, tex0_width, tex0_height, tex1_width, tex1_height); - glUniform3f(prog.fogModeEndScale_location, - fog_enabled != 2 ? 0.0f : 1.0f, - fogEnd, - 1.0f / (fogEnd - fogStart) - ); + glUniform3f(prog.fogModeEndScale_location, + fog_enabled != 2 ? 0.0f : 1.0f, + fogEnd, + 1.0f / (fogEnd - fogStart) + ); - if(prog.fogColor_location != -1) + if (prog.fogColor_location != -1) { - glUniform3f(prog.fogColor_location,fogColor[0],fogColor[1],fogColor[2]); - } + glUniform3f(prog.fogColor_location, fogColor[0], fogColor[1], fogColor[2]); + } - glUniform1f(prog.alphaRef_location,alpha_test ? alpha_ref/255.0f : -1.0f); + glUniform1f(prog.alphaRef_location, alpha_test ? alpha_ref / 255.0f : -1.0f); - constant_color_location = glGetUniformLocation(program_object, "constant_color"); - glUniform4f(constant_color_location, texture_env_color[0], texture_env_color[1], + constant_color_location = glGetUniformLocation(program_object, "constant_color"); + glUniform4f(constant_color_location, texture_env_color[0], texture_env_color[1], texture_env_color[2], texture_env_color[3]); - ccolor0_location = glGetUniformLocation(program_object, "ccolor0"); - glUniform4f(ccolor0_location, ccolor0[0], ccolor0[1], ccolor0[2], ccolor0[3]); + ccolor0_location = glGetUniformLocation(program_object, "ccolor0"); + glUniform4f(ccolor0_location, ccolor0[0], ccolor0[1], ccolor0[2], ccolor0[3]); - ccolor1_location = glGetUniformLocation(program_object, "ccolor1"); - glUniform4f(ccolor1_location, ccolor1[0], ccolor1[1], ccolor1[2], ccolor1[3]); + ccolor1_location = glGetUniformLocation(program_object, "ccolor1"); + glUniform4f(ccolor1_location, ccolor1[0], ccolor1[1], ccolor1[2], ccolor1[3]); - glUniform4f(prog.chroma_color_location, chroma_color[0], chroma_color[1], + glUniform4f(prog.chroma_color_location, chroma_color[0], chroma_color[1], chroma_color[2], chroma_color[3]); - if(dither_enabled) - { - glUniform1i(prog.ditherTex_location, 2); - } + if (dither_enabled) + { + glUniform1i(prog.ditherTex_location, 2); + } - set_lambda(); + set_lambda(); } -void disable_textureSizes() +void disable_textureSizes() { - int textureSizes_location = glGetUniformLocation(program_object_default,"textureSizes"); - glUniform4f(textureSizes_location,1,1,1,1); + int textureSizes_location = glGetUniformLocation(program_object_default, "textureSizes"); + glUniform4f(textureSizes_location, 1, 1, 1, 1); } void compile_shader() { - int texture0_location; - int texture1_location; - int ditherTex_location; - int vertexOffset_location; - int textureSizes_location; - char *fragment_shader; - int i; - int chroma_color_location; - int log_length; + int texture0_location; + int texture1_location; + int ditherTex_location; + int vertexOffset_location; + int textureSizes_location; + char *fragment_shader; + int i; + int chroma_color_location; + int log_length; - need_to_compile = 0; + need_to_compile = 0; - for(i=0; i> 24) & 0xFF) / 255.0f; - texture_env_color[0] = ((value >> 16) & 0xFF) / 255.0f; - texture_env_color[1] = ((value >> 8) & 0xFF) / 255.0f; - texture_env_color[2] = (value & 0xFF) / 255.0f; - break; - case GR_COLORFORMAT_RGBA: - texture_env_color[0] = ((value >> 24) & 0xFF) / 255.0f; - texture_env_color[1] = ((value >> 16) & 0xFF) / 255.0f; - texture_env_color[2] = ((value >> 8) & 0xFF) / 255.0f; - texture_env_color[3] = (value & 0xFF) / 255.0f; - break; - default: - display_warning("grConstantColorValue: unknown color format : %x", lfb_color_fmt); - } + LOG("grConstantColorValue(%d)\r\n", value); + switch (lfb_color_fmt) + { + case GR_COLORFORMAT_ARGB: + texture_env_color[3] = ((value >> 24) & 0xFF) / 255.0f; + texture_env_color[0] = ((value >> 16) & 0xFF) / 255.0f; + texture_env_color[1] = ((value >> 8) & 0xFF) / 255.0f; + texture_env_color[2] = (value & 0xFF) / 255.0f; + break; + case GR_COLORFORMAT_RGBA: + texture_env_color[0] = ((value >> 24) & 0xFF) / 255.0f; + texture_env_color[1] = ((value >> 16) & 0xFF) / 255.0f; + texture_env_color[2] = ((value >> 8) & 0xFF) / 255.0f; + texture_env_color[3] = (value & 0xFF) / 255.0f; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grConstantColorValue: unknown color format : %x", lfb_color_fmt); + } - vbo_draw(); + vbo_draw(); - constant_color_location = glGetUniformLocation(program_object, "constant_color"); - glUniform4f(constant_color_location, texture_env_color[0], texture_env_color[1], - texture_env_color[2], texture_env_color[3]); + constant_color_location = glGetUniformLocation(program_object, "constant_color"); + glUniform4f(constant_color_location, texture_env_color[0], texture_env_color[1], + texture_env_color[2], texture_env_color[3]); } void writeGLSLColorOther(int other) { - switch(other) - { - case GR_COMBINE_OTHER_ITERATED: - strcat(fragment_shader_color_combiner, "vec4 color_other = gl_Color; \n"); - break; - case GR_COMBINE_OTHER_TEXTURE: - strcat(fragment_shader_color_combiner, "vec4 color_other = ctexture1; \n"); - break; - case GR_COMBINE_OTHER_CONSTANT: - strcat(fragment_shader_color_combiner, "vec4 color_other = constant_color; \n"); - break; - default: - display_warning("unknown writeGLSLColorOther : %x", other); - } + switch (other) + { + case GR_COMBINE_OTHER_ITERATED: + strcat(fragment_shader_color_combiner, "vec4 color_other = gl_Color; \n"); + break; + case GR_COMBINE_OTHER_TEXTURE: + strcat(fragment_shader_color_combiner, "vec4 color_other = ctexture1; \n"); + break; + case GR_COMBINE_OTHER_CONSTANT: + strcat(fragment_shader_color_combiner, "vec4 color_other = constant_color; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLColorOther : %x", other); + } } void writeGLSLColorLocal(int local) { - switch(local) - { - case GR_COMBINE_LOCAL_ITERATED: - strcat(fragment_shader_color_combiner, "vec4 color_local = gl_Color; \n"); - break; - case GR_COMBINE_LOCAL_CONSTANT: - strcat(fragment_shader_color_combiner, "vec4 color_local = constant_color; \n"); - break; - default: - display_warning("unknown writeGLSLColorLocal : %x", local); - } + switch (local) + { + case GR_COMBINE_LOCAL_ITERATED: + strcat(fragment_shader_color_combiner, "vec4 color_local = gl_Color; \n"); + break; + case GR_COMBINE_LOCAL_CONSTANT: + strcat(fragment_shader_color_combiner, "vec4 color_local = constant_color; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLColorLocal : %x", local); + } } void writeGLSLColorFactor(int factor, int local, int need_local, int other, int need_other) { - switch(factor) - { - case GR_COMBINE_FACTOR_ZERO: - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(0.0); \n"); - break; - case GR_COMBINE_FACTOR_LOCAL: - if(need_local) writeGLSLColorLocal(local); - strcat(fragment_shader_color_combiner, "vec4 color_factor = color_local; \n"); - break; - case GR_COMBINE_FACTOR_OTHER_ALPHA: - if(need_other) writeGLSLColorOther(other); - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(color_other.a); \n"); - break; - case GR_COMBINE_FACTOR_LOCAL_ALPHA: - if(need_local) writeGLSLColorLocal(local); - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(color_local.a); \n"); - break; - case GR_COMBINE_FACTOR_TEXTURE_ALPHA: - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(ctexture1.a); \n"); - break; - case GR_COMBINE_FACTOR_TEXTURE_RGB: - strcat(fragment_shader_color_combiner, "vec4 color_factor = ctexture1; \n"); - break; - case GR_COMBINE_FACTOR_ONE: - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0); \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL: - if(need_local) writeGLSLColorLocal(local); - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - color_local; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA: - if(need_other) writeGLSLColorOther(other); - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - vec4(color_other.a); \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA: - if(need_local) writeGLSLColorLocal(local); - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - vec4(color_local.a); \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_TEXTURE_ALPHA: - strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - vec4(ctexture1.a); \n"); - break; - default: - display_warning("unknown writeGLSLColorFactor : %x", factor); - } + switch (factor) + { + case GR_COMBINE_FACTOR_ZERO: + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(0.0); \n"); + break; + case GR_COMBINE_FACTOR_LOCAL: + if (need_local) writeGLSLColorLocal(local); + strcat(fragment_shader_color_combiner, "vec4 color_factor = color_local; \n"); + break; + case GR_COMBINE_FACTOR_OTHER_ALPHA: + if (need_other) writeGLSLColorOther(other); + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(color_other.a); \n"); + break; + case GR_COMBINE_FACTOR_LOCAL_ALPHA: + if (need_local) writeGLSLColorLocal(local); + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(color_local.a); \n"); + break; + case GR_COMBINE_FACTOR_TEXTURE_ALPHA: + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(ctexture1.a); \n"); + break; + case GR_COMBINE_FACTOR_TEXTURE_RGB: + strcat(fragment_shader_color_combiner, "vec4 color_factor = ctexture1; \n"); + break; + case GR_COMBINE_FACTOR_ONE: + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0); \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL: + if (need_local) writeGLSLColorLocal(local); + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - color_local; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA: + if (need_other) writeGLSLColorOther(other); + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - vec4(color_other.a); \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA: + if (need_local) writeGLSLColorLocal(local); + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - vec4(color_local.a); \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_TEXTURE_ALPHA: + strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - vec4(ctexture1.a); \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLColorFactor : %x", factor); + } } -FX_ENTRY void FX_CALL +FX_ENTRY void FX_CALL grColorCombine( - GrCombineFunction_t function, GrCombineFactor_t factor, - GrCombineLocal_t local, GrCombineOther_t other, - FxBool invert ) +GrCombineFunction_t function, GrCombineFactor_t factor, +GrCombineLocal_t local, GrCombineOther_t other, +FxBool invert) { - LOG("grColorCombine(%d,%d,%d,%d,%d)\r\n", function, factor, local, other, invert); - static int last_function = 0; - static int last_factor = 0; - static int last_local = 0; - static int last_other = 0; + LOG("grColorCombine(%d,%d,%d,%d,%d)\r\n", function, factor, local, other, invert); + static int last_function = 0; + static int last_factor = 0; + static int last_local = 0; + static int last_other = 0; - if(last_function == function && last_factor == factor && - last_local == local && last_other == other && first_color == 0 && !c_combiner_ext) return; - first_color = 0; - c_combiner_ext = 0; + if (last_function == function && last_factor == factor && + last_local == local && last_other == other && first_color == 0 && !c_combiner_ext) return; + first_color = 0; + c_combiner_ext = 0; - last_function = function; - last_factor = factor; - last_local = local; - last_other = other; + last_function = function; + last_factor = factor; + last_local = local; + last_other = other; - if (invert) display_warning("grColorCombine : inverted result"); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grColorCombine : inverted result"); - color_combiner_key = function | (factor << 4) | (local << 8) | (other << 10); - chroma_other_color = other; + color_combiner_key = function | (factor << 4) | (local << 8) | (other << 10); + chroma_other_color = other; - strcpy(fragment_shader_color_combiner, ""); - switch(function) - { - case GR_COMBINE_FUNCTION_ZERO: - strcat(fragment_shader_color_combiner, "gl_FragColor = vec4(0.0); \n"); - break; - case GR_COMBINE_FUNCTION_LOCAL: - writeGLSLColorLocal(local); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_local; \n"); - break; - case GR_COMBINE_FUNCTION_LOCAL_ALPHA: - writeGLSLColorLocal(local); - strcat(fragment_shader_color_combiner, "gl_FragColor = vec4(color_local.a); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER: - writeGLSLColorOther(other); - writeGLSLColorFactor(factor,local,1,other,0); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * color_other; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL: - writeGLSLColorLocal(local); - writeGLSLColorOther(other); - writeGLSLColorFactor(factor,local,0,other,0); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * color_other + color_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA: - writeGLSLColorLocal(local); - writeGLSLColorOther(other); - writeGLSLColorFactor(factor,local,0,other,0); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * color_other + vec4(color_local.a); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL: - writeGLSLColorLocal(local); - writeGLSLColorOther(other); - writeGLSLColorFactor(factor,local,0,other,0); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (color_other - color_local); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL: - writeGLSLColorLocal(local); - writeGLSLColorOther(other); - writeGLSLColorFactor(factor,local,0,other,0); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (color_other - color_local) + color_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA: - writeGLSLColorLocal(local); - writeGLSLColorOther(other); - writeGLSLColorFactor(factor,local,0,other,0); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (color_other - color_local) + vec4(color_local.a); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL: - writeGLSLColorLocal(local); - writeGLSLColorFactor(factor,local,0,other,1); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (-color_local) + color_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA: - writeGLSLColorLocal(local); - writeGLSLColorFactor(factor,local,0,other,1); - strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (-color_local) + vec4(color_local.a); \n"); - break; - default: - strcpy(fragment_shader_color_combiner, fragment_shader_default); - display_warning("grColorCombine : unknown function : %x", function); - } - //compile_shader(); - need_to_compile = 1; + strcpy(fragment_shader_color_combiner, ""); + switch (function) + { + case GR_COMBINE_FUNCTION_ZERO: + strcat(fragment_shader_color_combiner, "gl_FragColor = vec4(0.0); \n"); + break; + case GR_COMBINE_FUNCTION_LOCAL: + writeGLSLColorLocal(local); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_local; \n"); + break; + case GR_COMBINE_FUNCTION_LOCAL_ALPHA: + writeGLSLColorLocal(local); + strcat(fragment_shader_color_combiner, "gl_FragColor = vec4(color_local.a); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER: + writeGLSLColorOther(other); + writeGLSLColorFactor(factor, local, 1, other, 0); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * color_other; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL: + writeGLSLColorLocal(local); + writeGLSLColorOther(other); + writeGLSLColorFactor(factor, local, 0, other, 0); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * color_other + color_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA: + writeGLSLColorLocal(local); + writeGLSLColorOther(other); + writeGLSLColorFactor(factor, local, 0, other, 0); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * color_other + vec4(color_local.a); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL: + writeGLSLColorLocal(local); + writeGLSLColorOther(other); + writeGLSLColorFactor(factor, local, 0, other, 0); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (color_other - color_local); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL: + writeGLSLColorLocal(local); + writeGLSLColorOther(other); + writeGLSLColorFactor(factor, local, 0, other, 0); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (color_other - color_local) + color_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA: + writeGLSLColorLocal(local); + writeGLSLColorOther(other); + writeGLSLColorFactor(factor, local, 0, other, 0); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (color_other - color_local) + vec4(color_local.a); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL: + writeGLSLColorLocal(local); + writeGLSLColorFactor(factor, local, 0, other, 1); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (-color_local) + color_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA: + writeGLSLColorLocal(local); + writeGLSLColorFactor(factor, local, 0, other, 1); + strcat(fragment_shader_color_combiner, "gl_FragColor = color_factor * (-color_local) + vec4(color_local.a); \n"); + break; + default: + strcpy(fragment_shader_color_combiner, fragment_shader_default); + WriteTrace(TraceGlitch, TraceWarning, "grColorCombine : unknown function : %x", function); + } + //compile_shader(); + need_to_compile = 1; } /* int setOtherAlphaSource(int other) { - switch(other) - { - case GR_COMBINE_OTHER_ITERATED: - return GL_PRIMARY_COLOR_ARB; - break; - case GR_COMBINE_OTHER_TEXTURE: - return GL_PREVIOUS_ARB; - break; - case GR_COMBINE_OTHER_CONSTANT: - return GL_CONSTANT_ARB; - break; - default: - display_warning("unknwown other alpha source : %x", other); - } - return 0; +switch(other) +{ +case GR_COMBINE_OTHER_ITERATED: +return GL_PRIMARY_COLOR_ARB; +break; +case GR_COMBINE_OTHER_TEXTURE: +return GL_PREVIOUS_ARB; +break; +case GR_COMBINE_OTHER_CONSTANT: +return GL_CONSTANT_ARB; +break; +default: +WriteTrace(TraceGlitch, TraceWarning, "unknwown other alpha source : %x", other); +} +return 0; } int setLocalAlphaSource(int local) { - switch(local) - { - case GR_COMBINE_LOCAL_ITERATED: - return GL_PRIMARY_COLOR_ARB; - break; - case GR_COMBINE_LOCAL_CONSTANT: - return GL_CONSTANT_ARB; - break; - default: - display_warning("unknwown local alpha source : %x", local); - } - return 0; +switch(local) +{ +case GR_COMBINE_LOCAL_ITERATED: +return GL_PRIMARY_COLOR_ARB; +break; +case GR_COMBINE_LOCAL_CONSTANT: +return GL_CONSTANT_ARB; +break; +default: +WriteTrace(TraceGlitch, TraceWarning, "unknwown local alpha source : %x", local); +} +return 0; } */ void writeGLSLAlphaOther(int other) { - switch(other) - { - case GR_COMBINE_OTHER_ITERATED: - strcat(fragment_shader_alpha_combiner, "float alpha_other = gl_Color.a; \n"); - break; - case GR_COMBINE_OTHER_TEXTURE: - strcat(fragment_shader_alpha_combiner, "float alpha_other = ctexture1.a; \n"); - break; - case GR_COMBINE_OTHER_CONSTANT: - strcat(fragment_shader_alpha_combiner, "float alpha_other = constant_color.a; \n"); - break; - default: - display_warning("unknown writeGLSLAlphaOther : %x", other); - } + switch (other) + { + case GR_COMBINE_OTHER_ITERATED: + strcat(fragment_shader_alpha_combiner, "float alpha_other = gl_Color.a; \n"); + break; + case GR_COMBINE_OTHER_TEXTURE: + strcat(fragment_shader_alpha_combiner, "float alpha_other = ctexture1.a; \n"); + break; + case GR_COMBINE_OTHER_CONSTANT: + strcat(fragment_shader_alpha_combiner, "float alpha_other = constant_color.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLAlphaOther : %x", other); + } } void writeGLSLAlphaLocal(int local) { - switch(local) - { - case GR_COMBINE_LOCAL_ITERATED: - strcat(fragment_shader_alpha_combiner, "float alpha_local = gl_Color.a; \n"); - break; - case GR_COMBINE_LOCAL_CONSTANT: - strcat(fragment_shader_alpha_combiner, "float alpha_local = constant_color.a; \n"); - break; - default: - display_warning("unknown writeGLSLAlphaLocal : %x", local); - } + switch (local) + { + case GR_COMBINE_LOCAL_ITERATED: + strcat(fragment_shader_alpha_combiner, "float alpha_local = gl_Color.a; \n"); + break; + case GR_COMBINE_LOCAL_CONSTANT: + strcat(fragment_shader_alpha_combiner, "float alpha_local = constant_color.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLAlphaLocal : %x", local); + } } void writeGLSLAlphaFactor(int factor, int local, int need_local, int other, int need_other) { - switch(factor) - { - case GR_COMBINE_FACTOR_ZERO: - strcat(fragment_shader_alpha_combiner, "float alpha_factor = 0.0; \n"); - break; - case GR_COMBINE_FACTOR_LOCAL: - if(need_local) writeGLSLAlphaLocal(local); - strcat(fragment_shader_alpha_combiner, "float alpha_factor = alpha_local; \n"); - break; - case GR_COMBINE_FACTOR_OTHER_ALPHA: - if(need_other) writeGLSLAlphaOther(other); - strcat(fragment_shader_alpha_combiner, "float alpha_factor = alpha_other; \n"); - break; - case GR_COMBINE_FACTOR_LOCAL_ALPHA: - if(need_local) writeGLSLAlphaLocal(local); - strcat(fragment_shader_alpha_combiner, "float alpha_factor = alpha_local; \n"); - break; - case GR_COMBINE_FACTOR_TEXTURE_ALPHA: - strcat(fragment_shader_alpha_combiner, "float alpha_factor = ctexture1.a; \n"); - break; - case GR_COMBINE_FACTOR_ONE: - strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL: - if(need_local) writeGLSLAlphaLocal(local); - strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - alpha_local; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA: - if(need_other) writeGLSLAlphaOther(other); - strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - alpha_other; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA: - if(need_local) writeGLSLAlphaLocal(local); - strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - alpha_local; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_TEXTURE_ALPHA: - strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - ctexture1.a; \n"); - break; - default: - display_warning("unknown writeGLSLAlphaFactor : %x", factor); - } + switch (factor) + { + case GR_COMBINE_FACTOR_ZERO: + strcat(fragment_shader_alpha_combiner, "float alpha_factor = 0.0; \n"); + break; + case GR_COMBINE_FACTOR_LOCAL: + if (need_local) writeGLSLAlphaLocal(local); + strcat(fragment_shader_alpha_combiner, "float alpha_factor = alpha_local; \n"); + break; + case GR_COMBINE_FACTOR_OTHER_ALPHA: + if (need_other) writeGLSLAlphaOther(other); + strcat(fragment_shader_alpha_combiner, "float alpha_factor = alpha_other; \n"); + break; + case GR_COMBINE_FACTOR_LOCAL_ALPHA: + if (need_local) writeGLSLAlphaLocal(local); + strcat(fragment_shader_alpha_combiner, "float alpha_factor = alpha_local; \n"); + break; + case GR_COMBINE_FACTOR_TEXTURE_ALPHA: + strcat(fragment_shader_alpha_combiner, "float alpha_factor = ctexture1.a; \n"); + break; + case GR_COMBINE_FACTOR_ONE: + strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL: + if (need_local) writeGLSLAlphaLocal(local); + strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - alpha_local; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA: + if (need_other) writeGLSLAlphaOther(other); + strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - alpha_other; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA: + if (need_local) writeGLSLAlphaLocal(local); + strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - alpha_local; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_TEXTURE_ALPHA: + strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - ctexture1.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLAlphaFactor : %x", factor); + } } FX_ENTRY void FX_CALL grAlphaCombine( - GrCombineFunction_t function, GrCombineFactor_t factor, - GrCombineLocal_t local, GrCombineOther_t other, - FxBool invert - ) +GrCombineFunction_t function, GrCombineFactor_t factor, +GrCombineLocal_t local, GrCombineOther_t other, +FxBool invert +) { - LOG("grAlphaCombine(%d,%d,%d,%d,%d)\r\n", function, factor, local, other, invert); - static int last_function = 0; - static int last_factor = 0; - static int last_local = 0; - static int last_other = 0; + LOG("grAlphaCombine(%d,%d,%d,%d,%d)\r\n", function, factor, local, other, invert); + static int last_function = 0; + static int last_factor = 0; + static int last_local = 0; + static int last_other = 0; - if(last_function == function && last_factor == factor && - last_local == local && last_other == other && first_alpha == 0 && !a_combiner_ext) return; - first_alpha = 0; - a_combiner_ext = 0; + if (last_function == function && last_factor == factor && + last_local == local && last_other == other && first_alpha == 0 && !a_combiner_ext) return; + first_alpha = 0; + a_combiner_ext = 0; - last_function = function; - last_factor = factor; - last_local = local; - last_other = other; + last_function = function; + last_factor = factor; + last_local = local; + last_other = other; - if (invert) display_warning("grAlphaCombine : inverted result"); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombine : inverted result"); - alpha_combiner_key = function | (factor << 4) | (local << 8) | (other << 10); - chroma_other_alpha = other; + alpha_combiner_key = function | (factor << 4) | (local << 8) | (other << 10); + chroma_other_alpha = other; - strcpy(fragment_shader_alpha_combiner, ""); + strcpy(fragment_shader_alpha_combiner, ""); - switch(function) - { - case GR_COMBINE_FUNCTION_ZERO: - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = 0.0; \n"); - break; - case GR_COMBINE_FUNCTION_LOCAL: - writeGLSLAlphaLocal(local); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_local; \n"); - break; - case GR_COMBINE_FUNCTION_LOCAL_ALPHA: - writeGLSLAlphaLocal(local); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER: - writeGLSLAlphaOther(other); - writeGLSLAlphaFactor(factor,local,1,other,0); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * alpha_other; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL: - writeGLSLAlphaLocal(local); - writeGLSLAlphaOther(other); - writeGLSLAlphaFactor(factor,local,0,other,0); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * alpha_other + alpha_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA: - writeGLSLAlphaLocal(local); - writeGLSLAlphaOther(other); - writeGLSLAlphaFactor(factor,local,0,other,0); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * alpha_other + alpha_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL: - writeGLSLAlphaLocal(local); - writeGLSLAlphaOther(other); - writeGLSLAlphaFactor(factor,local,0,other,0); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (alpha_other - alpha_local); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL: - writeGLSLAlphaLocal(local); - writeGLSLAlphaOther(other); - writeGLSLAlphaFactor(factor,local,0,other,0); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (alpha_other - alpha_local) + alpha_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA: - writeGLSLAlphaLocal(local); - writeGLSLAlphaOther(other); - writeGLSLAlphaFactor(factor,local,0,other,0); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (alpha_other - alpha_local) + alpha_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL: - writeGLSLAlphaLocal(local); - writeGLSLAlphaFactor(factor,local,0,other,1); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (-alpha_local) + alpha_local; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA: - writeGLSLAlphaLocal(local); - writeGLSLAlphaFactor(factor,local,0,other,1); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (-alpha_local) + alpha_local; \n"); - break; - default: - display_warning("grAlphaCombine : unknown function : %x", function); - } + switch (function) + { + case GR_COMBINE_FUNCTION_ZERO: + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = 0.0; \n"); + break; + case GR_COMBINE_FUNCTION_LOCAL: + writeGLSLAlphaLocal(local); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_local; \n"); + break; + case GR_COMBINE_FUNCTION_LOCAL_ALPHA: + writeGLSLAlphaLocal(local); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER: + writeGLSLAlphaOther(other); + writeGLSLAlphaFactor(factor, local, 1, other, 0); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * alpha_other; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL: + writeGLSLAlphaLocal(local); + writeGLSLAlphaOther(other); + writeGLSLAlphaFactor(factor, local, 0, other, 0); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * alpha_other + alpha_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA: + writeGLSLAlphaLocal(local); + writeGLSLAlphaOther(other); + writeGLSLAlphaFactor(factor, local, 0, other, 0); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * alpha_other + alpha_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL: + writeGLSLAlphaLocal(local); + writeGLSLAlphaOther(other); + writeGLSLAlphaFactor(factor, local, 0, other, 0); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (alpha_other - alpha_local); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL: + writeGLSLAlphaLocal(local); + writeGLSLAlphaOther(other); + writeGLSLAlphaFactor(factor, local, 0, other, 0); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (alpha_other - alpha_local) + alpha_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA: + writeGLSLAlphaLocal(local); + writeGLSLAlphaOther(other); + writeGLSLAlphaFactor(factor, local, 0, other, 0); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (alpha_other - alpha_local) + alpha_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL: + writeGLSLAlphaLocal(local); + writeGLSLAlphaFactor(factor, local, 0, other, 1); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (-alpha_local) + alpha_local; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA: + writeGLSLAlphaLocal(local); + writeGLSLAlphaFactor(factor, local, 0, other, 1); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (-alpha_local) + alpha_local; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombine : unknown function : %x", function); + } - //compile_shader(); - need_to_compile = 1; + //compile_shader(); + need_to_compile = 1; } void writeGLSLTextureColorFactor(int num_tex, int factor) { - switch(factor) - { - case GR_COMBINE_FACTOR_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(0.0); \n"); - break; - case GR_COMBINE_FACTOR_LOCAL: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = readtex1; \n"); - break; - case GR_COMBINE_FACTOR_OTHER_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(ctexture0.a); \n"); - break; - case GR_COMBINE_FACTOR_LOCAL_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(readtex1.a); \n"); - break; - case GR_COMBINE_FACTOR_DETAIL_FACTOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(lambda); \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(lambda); \n"); - break; - case GR_COMBINE_FACTOR_ONE: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0); \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0) - readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - readtex1; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0) - vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - vec4(ctexture0.a); \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0) - vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - vec4(readtex1.a); \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_DETAIL_FACTOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0) - vec4(lambda); \n"); - else - strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - vec4(lambda); \n"); - break; - default: - display_warning("unknown writeGLSLTextureColorFactor : %x", factor); - } + switch (factor) + { + case GR_COMBINE_FACTOR_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(0.0); \n"); + break; + case GR_COMBINE_FACTOR_LOCAL: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = readtex1; \n"); + break; + case GR_COMBINE_FACTOR_OTHER_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(ctexture0.a); \n"); + break; + case GR_COMBINE_FACTOR_LOCAL_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(readtex1.a); \n"); + break; + case GR_COMBINE_FACTOR_DETAIL_FACTOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(lambda); \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(lambda); \n"); + break; + case GR_COMBINE_FACTOR_ONE: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0); \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0) - readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - readtex1; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0) - vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - vec4(ctexture0.a); \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0) - vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - vec4(readtex1.a); \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_DETAIL_FACTOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 texture0_color_factor = vec4(1.0) - vec4(lambda); \n"); + else + strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - vec4(lambda); \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLTextureColorFactor : %x", factor); + } } void writeGLSLTextureAlphaFactor(int num_tex, int factor) { - switch(factor) - { - case GR_COMBINE_FACTOR_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = 0.0; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = 0.0; \n"); - break; - case GR_COMBINE_FACTOR_LOCAL: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = readtex1.a; \n"); - break; - case GR_COMBINE_FACTOR_OTHER_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = 0.0; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = ctexture0.a; \n"); - break; - case GR_COMBINE_FACTOR_LOCAL_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = readtex1.a; \n"); - break; - case GR_COMBINE_FACTOR_DETAIL_FACTOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = lambda; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = lambda; \n"); - break; - case GR_COMBINE_FACTOR_ONE: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0 - readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - readtex1.a; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0 - 0.0; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - ctexture0.a; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0 - readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - readtex1.a; \n"); - break; - case GR_COMBINE_FACTOR_ONE_MINUS_DETAIL_FACTOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0 - lambda; \n"); - else - strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - lambda; \n"); - break; - default: - display_warning("unknown writeGLSLTextureAlphaFactor : %x", factor); - } + switch (factor) + { + case GR_COMBINE_FACTOR_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = 0.0; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = 0.0; \n"); + break; + case GR_COMBINE_FACTOR_LOCAL: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = readtex1.a; \n"); + break; + case GR_COMBINE_FACTOR_OTHER_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = 0.0; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = ctexture0.a; \n"); + break; + case GR_COMBINE_FACTOR_LOCAL_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = readtex1.a; \n"); + break; + case GR_COMBINE_FACTOR_DETAIL_FACTOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = lambda; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = lambda; \n"); + break; + case GR_COMBINE_FACTOR_ONE: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0 - readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - readtex1.a; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_OTHER_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0 - 0.0; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - ctexture0.a; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_LOCAL_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0 - readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - readtex1.a; \n"); + break; + case GR_COMBINE_FACTOR_ONE_MINUS_DETAIL_FACTOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "float texture0_alpha_factor = 1.0 - lambda; \n"); + else + strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - lambda; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLTextureAlphaFactor : %x", factor); + } } -FX_ENTRY void FX_CALL +FX_ENTRY void FX_CALL grTexCombine( - GrChipID_t tmu, - GrCombineFunction_t rgb_function, - GrCombineFactor_t rgb_factor, - GrCombineFunction_t alpha_function, - GrCombineFactor_t alpha_factor, - FxBool rgb_invert, - FxBool alpha_invert - ) +GrChipID_t tmu, +GrCombineFunction_t rgb_function, +GrCombineFactor_t rgb_factor, +GrCombineFunction_t alpha_function, +GrCombineFactor_t alpha_factor, +FxBool rgb_invert, +FxBool alpha_invert +) { - LOG("grTexCombine(%d,%d,%d,%d,%d,%d,%d)\r\n", tmu, rgb_function, rgb_factor, alpha_function, alpha_factor, rgb_invert, alpha_invert); - int num_tex; + LOG("grTexCombine(%d,%d,%d,%d,%d,%d,%d)\r\n", tmu, rgb_function, rgb_factor, alpha_function, alpha_factor, rgb_invert, alpha_invert); + int num_tex; - if (tmu == GR_TMU0) num_tex = 1; - else num_tex = 0; + if (tmu == GR_TMU0) num_tex = 1; + else num_tex = 0; - if(num_tex == 0) - { - static int last_function = 0; - static int last_factor = 0; - static int last_afunction = 0; - static int last_afactor = 0; - static int last_rgb_invert = 0; + if (num_tex == 0) + { + static int last_function = 0; + static int last_factor = 0; + static int last_afunction = 0; + static int last_afactor = 0; + static int last_rgb_invert = 0; - if(last_function == rgb_function && last_factor == rgb_factor && - last_afunction == alpha_function && last_afactor == alpha_factor && - last_rgb_invert == rgb_invert && first_texture0 == 0 && !tex0_combiner_ext) return; - first_texture0 = 0; - tex0_combiner_ext = 0; + if (last_function == rgb_function && last_factor == rgb_factor && + last_afunction == alpha_function && last_afactor == alpha_factor && + last_rgb_invert == rgb_invert && first_texture0 == 0 && !tex0_combiner_ext) return; + first_texture0 = 0; + tex0_combiner_ext = 0; - last_function = rgb_function; - last_factor = rgb_factor; - last_afunction = alpha_function; - last_afactor = alpha_factor; - last_rgb_invert= rgb_invert; - texture0_combiner_key = rgb_function | (rgb_factor << 4) | - (alpha_function << 8) | (alpha_factor << 12) | - (rgb_invert << 16); - texture0_combinera_key = 0; - strcpy(fragment_shader_texture0, ""); - } - else - { - static int last_function = 0; - static int last_factor = 0; - static int last_afunction = 0; - static int last_afactor = 0; - static int last_rgb_invert = 0; + last_function = rgb_function; + last_factor = rgb_factor; + last_afunction = alpha_function; + last_afactor = alpha_factor; + last_rgb_invert = rgb_invert; + texture0_combiner_key = rgb_function | (rgb_factor << 4) | + (alpha_function << 8) | (alpha_factor << 12) | + (rgb_invert << 16); + texture0_combinera_key = 0; + strcpy(fragment_shader_texture0, ""); + } + else + { + static int last_function = 0; + static int last_factor = 0; + static int last_afunction = 0; + static int last_afactor = 0; + static int last_rgb_invert = 0; - if(last_function == rgb_function && last_factor == rgb_factor && - last_afunction == alpha_function && last_afactor == alpha_factor && - last_rgb_invert == rgb_invert && first_texture1 == 0 && !tex1_combiner_ext) return; - first_texture1 = 0; - tex1_combiner_ext = 0; + if (last_function == rgb_function && last_factor == rgb_factor && + last_afunction == alpha_function && last_afactor == alpha_factor && + last_rgb_invert == rgb_invert && first_texture1 == 0 && !tex1_combiner_ext) return; + first_texture1 = 0; + tex1_combiner_ext = 0; - last_function = rgb_function; - last_factor = rgb_factor; - last_afunction = alpha_function; - last_afactor = alpha_factor; - last_rgb_invert = rgb_invert; + last_function = rgb_function; + last_factor = rgb_factor; + last_afunction = alpha_function; + last_afactor = alpha_factor; + last_rgb_invert = rgb_invert; - texture1_combiner_key = rgb_function | (rgb_factor << 4) | - (alpha_function << 8) | (alpha_factor << 12) | - (rgb_invert << 16); - texture1_combinera_key = 0; - strcpy(fragment_shader_texture1, ""); - } + texture1_combiner_key = rgb_function | (rgb_factor << 4) | + (alpha_function << 8) | (alpha_factor << 12) | + (rgb_invert << 16); + texture1_combinera_key = 0; + strcpy(fragment_shader_texture1, ""); + } - switch(rgb_function) - { - case GR_COMBINE_FUNCTION_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = vec4(0.0); \n"); - break; - case GR_COMBINE_FUNCTION_LOCAL: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = readtex1; \n"); - break; - case GR_COMBINE_FUNCTION_LOCAL_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = vec4(readtex1.a); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER: - writeGLSLTextureColorFactor(num_tex, rgb_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * ctexture0; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL: - writeGLSLTextureColorFactor(num_tex, rgb_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * vec4(0.0) + readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * ctexture0 + readtex1; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA: - writeGLSLTextureColorFactor(num_tex, rgb_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * vec4(0.0) + vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * ctexture0 + vec4(readtex1.a); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL: - writeGLSLTextureColorFactor(num_tex, rgb_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (vec4(0.0) - readtex0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (ctexture0 - readtex1); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL: - writeGLSLTextureColorFactor(num_tex, rgb_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (vec4(0.0) - readtex0) + readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (ctexture0 - readtex1) + readtex1; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA: - writeGLSLTextureColorFactor(num_tex, rgb_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (vec4(0.0) - readtex0) + vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (ctexture0 - readtex1) + vec4(readtex1.a); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL: - writeGLSLTextureColorFactor(num_tex, rgb_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (-readtex0) + readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (-readtex1) + readtex1; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA: - writeGLSLTextureColorFactor(num_tex, rgb_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (-readtex0) + vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (-readtex1) + vec4(readtex1.a); \n"); - break; - default: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = readtex1; \n"); - display_warning("grTextCombine : unknown rgb function : %x", rgb_function); - } + switch (rgb_function) + { + case GR_COMBINE_FUNCTION_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = vec4(0.0); \n"); + break; + case GR_COMBINE_FUNCTION_LOCAL: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = readtex1; \n"); + break; + case GR_COMBINE_FUNCTION_LOCAL_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = vec4(readtex1.a); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER: + writeGLSLTextureColorFactor(num_tex, rgb_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * ctexture0; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL: + writeGLSLTextureColorFactor(num_tex, rgb_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * vec4(0.0) + readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * ctexture0 + readtex1; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA: + writeGLSLTextureColorFactor(num_tex, rgb_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * vec4(0.0) + vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * ctexture0 + vec4(readtex1.a); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL: + writeGLSLTextureColorFactor(num_tex, rgb_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (vec4(0.0) - readtex0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (ctexture0 - readtex1); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL: + writeGLSLTextureColorFactor(num_tex, rgb_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (vec4(0.0) - readtex0) + readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (ctexture0 - readtex1) + readtex1; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA: + writeGLSLTextureColorFactor(num_tex, rgb_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (vec4(0.0) - readtex0) + vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (ctexture0 - readtex1) + vec4(readtex1.a); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL: + writeGLSLTextureColorFactor(num_tex, rgb_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (-readtex0) + readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (-readtex1) + readtex1; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA: + writeGLSLTextureColorFactor(num_tex, rgb_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = texture0_color_factor * (-readtex0) + vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = texture1_color_factor * (-readtex1) + vec4(readtex1.a); \n"); + break; + default: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = readtex1; \n"); + WriteTrace(TraceGlitch, TraceWarning, "grTextCombine : unknown rgb function : %x", rgb_function); + } - if (rgb_invert) - { - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0 = vec4(1.0) - ctexture0; \n"); - else - strcat(fragment_shader_texture1, "ctexture1 = vec4(1.0) - ctexture1; \n"); - } + if (rgb_invert) + { + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0 = vec4(1.0) - ctexture0; \n"); + else + strcat(fragment_shader_texture1, "ctexture1 = vec4(1.0) - ctexture1; \n"); + } - switch(alpha_function) - { - case GR_COMBINE_FACTOR_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = 0.0; \n"); - break; - case GR_COMBINE_FUNCTION_LOCAL: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = readtex1.a; \n"); - break; - case GR_COMBINE_FUNCTION_LOCAL_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = readtex1.a; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER: - writeGLSLTextureAlphaFactor(num_tex, alpha_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * ctexture0.a; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL: - writeGLSLTextureAlphaFactor(num_tex, alpha_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * 0.0 + readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * ctexture0.a + readtex1.a; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA: - writeGLSLTextureAlphaFactor(num_tex, alpha_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * 0.0 + readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * ctexture0.a + readtex1.a; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL: - writeGLSLTextureAlphaFactor(num_tex, alpha_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (0.0 - readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (ctexture0.a - readtex1.a); \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL: - writeGLSLTextureAlphaFactor(num_tex, alpha_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (0.0 - readtex0.a) + readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (ctexture0.a - readtex1.a) + readtex1.a; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA: - writeGLSLTextureAlphaFactor(num_tex, alpha_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (0.0 - readtex0.a) + readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (ctexture0.a - readtex1.a) + readtex1.a; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL: - writeGLSLTextureAlphaFactor(num_tex, alpha_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (-readtex0.a) + readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (-readtex1.a) + readtex1.a; \n"); - break; - case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA: - writeGLSLTextureAlphaFactor(num_tex, alpha_factor); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (-readtex0.a) + readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (-readtex1.a) + readtex1.a; \n"); - break; - default: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = ctexture0.a; \n"); - display_warning("grTextCombine : unknown alpha function : %x", alpha_function); - } + switch (alpha_function) + { + case GR_COMBINE_FACTOR_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = 0.0; \n"); + break; + case GR_COMBINE_FUNCTION_LOCAL: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = readtex1.a; \n"); + break; + case GR_COMBINE_FUNCTION_LOCAL_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = readtex1.a; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER: + writeGLSLTextureAlphaFactor(num_tex, alpha_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * ctexture0.a; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL: + writeGLSLTextureAlphaFactor(num_tex, alpha_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * 0.0 + readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * ctexture0.a + readtex1.a; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA: + writeGLSLTextureAlphaFactor(num_tex, alpha_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * 0.0 + readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * ctexture0.a + readtex1.a; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL: + writeGLSLTextureAlphaFactor(num_tex, alpha_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (0.0 - readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (ctexture0.a - readtex1.a); \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL: + writeGLSLTextureAlphaFactor(num_tex, alpha_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (0.0 - readtex0.a) + readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (ctexture0.a - readtex1.a) + readtex1.a; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_OTHER_MINUS_LOCAL_ADD_LOCAL_ALPHA: + writeGLSLTextureAlphaFactor(num_tex, alpha_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (0.0 - readtex0.a) + readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (ctexture0.a - readtex1.a) + readtex1.a; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL: + writeGLSLTextureAlphaFactor(num_tex, alpha_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (-readtex0.a) + readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (-readtex1.a) + readtex1.a; \n"); + break; + case GR_COMBINE_FUNCTION_SCALE_MINUS_LOCAL_ADD_LOCAL_ALPHA: + writeGLSLTextureAlphaFactor(num_tex, alpha_factor); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = texture0_alpha_factor * (-readtex0.a) + readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = texture1_alpha_factor * (-readtex1.a) + readtex1.a; \n"); + break; + default: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = ctexture0.a; \n"); + WriteTrace(TraceGlitch, TraceWarning, "grTextCombine : unknown alpha function : %x", alpha_function); + } - if (alpha_invert) - { - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = 1.0 - ctexture0.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = 1.0 - ctexture1.a; \n"); - } - need_to_compile = 1; + if (alpha_invert) + { + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = 1.0 - ctexture0.a; \n"); + else + strcat(fragment_shader_texture1, "ctexture1.a = 1.0 - ctexture1.a; \n"); + } + need_to_compile = 1; } FX_ENTRY void FX_CALL grAlphaBlendFunction( - GrAlphaBlendFnc_t rgb_sf, GrAlphaBlendFnc_t rgb_df, - GrAlphaBlendFnc_t alpha_sf, GrAlphaBlendFnc_t alpha_df - ) +GrAlphaBlendFnc_t rgb_sf, GrAlphaBlendFnc_t rgb_df, +GrAlphaBlendFnc_t alpha_sf, GrAlphaBlendFnc_t alpha_df +) { - int sfactorRGB = 0, dfactorRGB = 0, sfactorAlpha = 0, dfactorAlpha = 0; - LOG("grAlphaBlendFunction(%d,%d,%d,%d)\r\n", rgb_sf, rgb_df, alpha_sf, alpha_df); + int sfactorRGB = 0, dfactorRGB = 0, sfactorAlpha = 0, dfactorAlpha = 0; + LOG("grAlphaBlendFunction(%d,%d,%d,%d)\r\n", rgb_sf, rgb_df, alpha_sf, alpha_df); - switch(rgb_sf) - { - case GR_BLEND_ZERO: - sfactorRGB = GL_ZERO; - break; - case GR_BLEND_SRC_ALPHA: - sfactorRGB = GL_SRC_ALPHA; - break; - case GR_BLEND_ONE: - sfactorRGB = GL_ONE; - break; - case GR_BLEND_ONE_MINUS_SRC_ALPHA: - sfactorRGB = GL_ONE_MINUS_SRC_ALPHA; - break; - default: - display_warning("grAlphaBlendFunction : rgb_sf = %x", rgb_sf); - } + switch (rgb_sf) + { + case GR_BLEND_ZERO: + sfactorRGB = GL_ZERO; + break; + case GR_BLEND_SRC_ALPHA: + sfactorRGB = GL_SRC_ALPHA; + break; + case GR_BLEND_ONE: + sfactorRGB = GL_ONE; + break; + case GR_BLEND_ONE_MINUS_SRC_ALPHA: + sfactorRGB = GL_ONE_MINUS_SRC_ALPHA; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaBlendFunction : rgb_sf = %x", rgb_sf); + } - switch(rgb_df) - { - case GR_BLEND_ZERO: - dfactorRGB = GL_ZERO; - break; - case GR_BLEND_SRC_ALPHA: - dfactorRGB = GL_SRC_ALPHA; - break; - case GR_BLEND_ONE: - dfactorRGB = GL_ONE; - break; - case GR_BLEND_ONE_MINUS_SRC_ALPHA: - dfactorRGB = GL_ONE_MINUS_SRC_ALPHA; - break; - default: - display_warning("grAlphaBlendFunction : rgb_df = %x", rgb_df); - } + switch (rgb_df) + { + case GR_BLEND_ZERO: + dfactorRGB = GL_ZERO; + break; + case GR_BLEND_SRC_ALPHA: + dfactorRGB = GL_SRC_ALPHA; + break; + case GR_BLEND_ONE: + dfactorRGB = GL_ONE; + break; + case GR_BLEND_ONE_MINUS_SRC_ALPHA: + dfactorRGB = GL_ONE_MINUS_SRC_ALPHA; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaBlendFunction : rgb_df = %x", rgb_df); + } - switch(alpha_sf) - { - case GR_BLEND_ZERO: - sfactorAlpha = GL_ZERO; - break; - case GR_BLEND_ONE: - sfactorAlpha = GL_ONE; - break; - default: - display_warning("grAlphaBlendFunction : alpha_sf = %x", alpha_sf); - } + switch (alpha_sf) + { + case GR_BLEND_ZERO: + sfactorAlpha = GL_ZERO; + break; + case GR_BLEND_ONE: + sfactorAlpha = GL_ONE; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaBlendFunction : alpha_sf = %x", alpha_sf); + } - switch(alpha_df) - { - case GR_BLEND_ZERO: - dfactorAlpha = GL_ZERO; - break; - case GR_BLEND_ONE: - dfactorAlpha = GL_ONE; - break; - default: - display_warning("grAlphaBlendFunction : alpha_df = %x", alpha_df); - } - glEnable(GL_BLEND); - glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); -/* - if (blend_func_separate_support) - glBlendFuncSeparateEXT(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); - else - glBlendFunc(sfactorRGB, dfactorRGB); -*/ + switch (alpha_df) + { + case GR_BLEND_ZERO: + dfactorAlpha = GL_ZERO; + break; + case GR_BLEND_ONE: + dfactorAlpha = GL_ONE; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaBlendFunction : alpha_df = %x", alpha_df); + } + glEnable(GL_BLEND); + glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); + /* + if (blend_func_separate_support) + glBlendFuncSeparateEXT(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); + else + glBlendFunc(sfactorRGB, dfactorRGB); + */ } FX_ENTRY void FX_CALL -grAlphaTestReferenceValue( GrAlpha_t value ) +grAlphaTestReferenceValue(GrAlpha_t value) { - LOG("grAlphaTestReferenceValue(%d)\r\n", value); - alpha_ref = value; - grAlphaTestFunction(alpha_func); + LOG("grAlphaTestReferenceValue(%d)\r\n", value); + alpha_ref = value; + grAlphaTestFunction(alpha_func); } FX_ENTRY void FX_CALL -grAlphaTestFunction( GrCmpFnc_t function ) +grAlphaTestFunction(GrCmpFnc_t function) { - LOG("grAlphaTestFunction(%d)\r\n", function); - alpha_func = function; - switch(function) - { - case GR_CMP_GREATER: - //glAlphaFunc(GL_GREATER, alpha_ref/255.0f); - break; - case GR_CMP_GEQUAL: - //glAlphaFunc(GL_GEQUAL, alpha_ref/255.0f); - break; - case GR_CMP_ALWAYS: - //glAlphaFunc(GL_ALWAYS, alpha_ref/255.0f); - //glDisable(GL_ALPHA_TEST); - alpha_test = false; - return; - break; - default: - display_warning("grAlphaTestFunction : unknown function : %x", function); - } - //glEnable(GL_ALPHA_TEST); - alpha_test = true; + LOG("grAlphaTestFunction(%d)\r\n", function); + alpha_func = function; + switch (function) + { + case GR_CMP_GREATER: + //glAlphaFunc(GL_GREATER, alpha_ref/255.0f); + break; + case GR_CMP_GEQUAL: + //glAlphaFunc(GL_GEQUAL, alpha_ref/255.0f); + break; + case GR_CMP_ALWAYS: + //glAlphaFunc(GL_ALWAYS, alpha_ref/255.0f); + //glDisable(GL_ALPHA_TEST); + alpha_test = false; + return; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaTestFunction : unknown function : %x", function); + } + //glEnable(GL_ALPHA_TEST); + alpha_test = true; } // fog -FX_ENTRY void FX_CALL -grFogMode( GrFogMode_t mode ) +FX_ENTRY void FX_CALL +grFogMode(GrFogMode_t mode) { - LOG("grFogMode(%d)\r\n", mode); - switch(mode) - { - case GR_FOG_DISABLE: - //glDisable(GL_FOG); - fog_enabled = 0; - break; - case GR_FOG_WITH_TABLE_ON_Q: - //glEnable(GL_FOG); - //glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); - fog_enabled = 1; - break; - case GR_FOG_WITH_TABLE_ON_FOGCOORD_EXT: - //glEnable(GL_FOG); - //glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); - fog_enabled = 2; - break; - default: - display_warning("grFogMode : unknown mode : %x", mode); - } - need_to_compile = 1; + LOG("grFogMode(%d)\r\n", mode); + switch (mode) + { + case GR_FOG_DISABLE: + //glDisable(GL_FOG); + fog_enabled = 0; + break; + case GR_FOG_WITH_TABLE_ON_Q: + //glEnable(GL_FOG); + //glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); + fog_enabled = 1; + break; + case GR_FOG_WITH_TABLE_ON_FOGCOORD_EXT: + //glEnable(GL_FOG); + //glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); + fog_enabled = 2; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grFogMode : unknown mode : %x", mode); + } + need_to_compile = 1; } FX_ENTRY float FX_CALL -guFogTableIndexToW( int i ) +guFogTableIndexToW(int i) { - LOG("guFogTableIndexToW(%d)\r\n", i); - return (float)(pow(2.0, 3.0+(double)(i>>2)) / (8-(i&3))); + LOG("guFogTableIndexToW(%d)\r\n", i); + return (float)(pow(2.0, 3.0 + (double)(i >> 2)) / (8 - (i & 3))); } FX_ENTRY void FX_CALL guFogGenerateLinear(GrFog_t *fogtable, - float nearZ, float farZ ) +float nearZ, float farZ) { - LOG("guFogGenerateLinear(%f,%f)\r\n", nearZ, farZ); -/* - glFogi(GL_FOG_MODE, GL_LINEAR); - glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); - glFogf(GL_FOG_START, nearZ / 255.0f); - glFogf(GL_FOG_END, farZ / 255.0f); -*/ - fogStart = nearZ / 255.0f; - fogEnd = farZ / 255.0f; + LOG("guFogGenerateLinear(%f,%f)\r\n", nearZ, farZ); + /* + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); + glFogf(GL_FOG_START, nearZ / 255.0f); + glFogf(GL_FOG_END, farZ / 255.0f); + */ + fogStart = nearZ / 255.0f; + fogEnd = farZ / 255.0f; } -FX_ENTRY void FX_CALL -grFogTable( const GrFog_t ft[] ) +FX_ENTRY void FX_CALL +grFogTable(const GrFog_t ft[]) { - LOG("grFogTable()\r\n"); + LOG("grFogTable()\r\n"); } -FX_ENTRY void FX_CALL -grFogColorValue( GrColor_t fogcolor ) +FX_ENTRY void FX_CALL +grFogColorValue(GrColor_t fogcolor) { - LOG("grFogColorValue(%x)\r\n", fogcolor); + LOG("grFogColorValue(%x)\r\n", fogcolor); - switch(lfb_color_fmt) - { - case GR_COLORFORMAT_ARGB: - fogColor[3] = ((fogcolor >> 24) & 0xFF) / 255.0f; - fogColor[0] = ((fogcolor >> 16) & 0xFF) / 255.0f; - fogColor[1] = ((fogcolor >> 8) & 0xFF) / 255.0f; - fogColor[2] = (fogcolor & 0xFF) / 255.0f; - break; - case GR_COLORFORMAT_RGBA: - fogColor[0] = ((fogcolor >> 24) & 0xFF) / 255.0f; - fogColor[1] = ((fogcolor >> 16) & 0xFF) / 255.0f; - fogColor[2] = ((fogcolor >> 8) & 0xFF) / 255.0f; - fogColor[3] = (fogcolor & 0xFF) / 255.0f; - break; - default: - display_warning("grFogColorValue: unknown color format : %x", lfb_color_fmt); - } + switch (lfb_color_fmt) + { + case GR_COLORFORMAT_ARGB: + fogColor[3] = ((fogcolor >> 24) & 0xFF) / 255.0f; + fogColor[0] = ((fogcolor >> 16) & 0xFF) / 255.0f; + fogColor[1] = ((fogcolor >> 8) & 0xFF) / 255.0f; + fogColor[2] = (fogcolor & 0xFF) / 255.0f; + break; + case GR_COLORFORMAT_RGBA: + fogColor[0] = ((fogcolor >> 24) & 0xFF) / 255.0f; + fogColor[1] = ((fogcolor >> 16) & 0xFF) / 255.0f; + fogColor[2] = ((fogcolor >> 8) & 0xFF) / 255.0f; + fogColor[3] = (fogcolor & 0xFF) / 255.0f; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grFogColorValue: unknown color format : %x", lfb_color_fmt); + } - //glFogfv(GL_FOG_COLOR, color); + //glFogfv(GL_FOG_COLOR, color); } // chroma -FX_ENTRY void FX_CALL -grChromakeyMode( GrChromakeyMode_t mode ) +FX_ENTRY void FX_CALL +grChromakeyMode(GrChromakeyMode_t mode) { - LOG("grChromakeyMode(%d)\r\n", mode); - switch(mode) - { - case GR_CHROMAKEY_DISABLE: - chroma_enabled = 0; - break; - case GR_CHROMAKEY_ENABLE: - chroma_enabled = 1; - break; - default: - display_warning("grChromakeyMode : unknown mode : %x", mode); - } - need_to_compile = 1; + LOG("grChromakeyMode(%d)\r\n", mode); + switch (mode) + { + case GR_CHROMAKEY_DISABLE: + chroma_enabled = 0; + break; + case GR_CHROMAKEY_ENABLE: + chroma_enabled = 1; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grChromakeyMode : unknown mode : %x", mode); + } + need_to_compile = 1; } -FX_ENTRY void FX_CALL -grChromakeyValue( GrColor_t value ) +FX_ENTRY void FX_CALL +grChromakeyValue(GrColor_t value) { - LOG("grChromakeyValue(%x)\r\n", value); - int chroma_color_location; + LOG("grChromakeyValue(%x)\r\n", value); + int chroma_color_location; - switch(lfb_color_fmt) - { - case GR_COLORFORMAT_ARGB: - chroma_color[3] = 1.0;//((value >> 24) & 0xFF) / 255.0f; - chroma_color[0] = ((value >> 16) & 0xFF) / 255.0f; - chroma_color[1] = ((value >> 8) & 0xFF) / 255.0f; - chroma_color[2] = (value & 0xFF) / 255.0f; - break; - case GR_COLORFORMAT_RGBA: - chroma_color[0] = ((value >> 24) & 0xFF) / 255.0f; - chroma_color[1] = ((value >> 16) & 0xFF) / 255.0f; - chroma_color[2] = ((value >> 8) & 0xFF) / 255.0f; - chroma_color[3] = 1.0;//(value & 0xFF) / 255.0f; - break; - default: - display_warning("grChromakeyValue: unknown color format : %x", lfb_color_fmt); - } - vbo_draw(); - chroma_color_location = glGetUniformLocation(program_object, "chroma_color"); - glUniform4f(chroma_color_location, chroma_color[0], chroma_color[1], - chroma_color[2], chroma_color[3]); + switch (lfb_color_fmt) + { + case GR_COLORFORMAT_ARGB: + chroma_color[3] = 1.0;//((value >> 24) & 0xFF) / 255.0f; + chroma_color[0] = ((value >> 16) & 0xFF) / 255.0f; + chroma_color[1] = ((value >> 8) & 0xFF) / 255.0f; + chroma_color[2] = (value & 0xFF) / 255.0f; + break; + case GR_COLORFORMAT_RGBA: + chroma_color[0] = ((value >> 24) & 0xFF) / 255.0f; + chroma_color[1] = ((value >> 16) & 0xFF) / 255.0f; + chroma_color[2] = ((value >> 8) & 0xFF) / 255.0f; + chroma_color[3] = 1.0;//(value & 0xFF) / 255.0f; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grChromakeyValue: unknown color format : %x", lfb_color_fmt); + } + vbo_draw(); + chroma_color_location = glGetUniformLocation(program_object, "chroma_color"); + glUniform4f(chroma_color_location, chroma_color[0], chroma_color[1], + chroma_color[2], chroma_color[3]); } static void setPattern() { - int i; - GLubyte stip[32*4]; - for(i=0; i<32; i++) - { - unsigned int val = (rand() << 17) | ((rand() & 1) << 16) | (rand() << 1) | (rand() & 1); - stip[i*4+0] = (val >> 24) & 0xFF; - stip[i*4+1] = (val >> 16) & 0xFF; - stip[i*4+2] = (val >> 8) & 0xFF; - stip[i*4+3] = val & 0xFF; - } - GLubyte texture[32*32*4]; - for(i=0; i<32; i++) - { - int j; - for(j=0; j<4; j++) + int i; + GLubyte stip[32 * 4]; + for (i = 0; i < 32; i++) { - texture[(i*32+j*8+0)*4+3] = ((stip[i*4+j] >> 7) & 1) ? 255 : 0; - texture[(i*32+j*8+1)*4+3] = ((stip[i*4+j] >> 6) & 1) ? 255 : 0; - texture[(i*32+j*8+2)*4+3] = ((stip[i*4+j] >> 5) & 1) ? 255 : 0; - texture[(i*32+j*8+3)*4+3] = ((stip[i*4+j] >> 4) & 1) ? 255 : 0; - texture[(i*32+j*8+4)*4+3] = ((stip[i*4+j] >> 3) & 1) ? 255 : 0; - texture[(i*32+j*8+5)*4+3] = ((stip[i*4+j] >> 2) & 1) ? 255 : 0; - texture[(i*32+j*8+6)*4+3] = ((stip[i*4+j] >> 1) & 1) ? 255 : 0; - texture[(i*32+j*8+7)*4+3] = ((stip[i*4+j] >> 0) & 1) ? 255 : 0; + unsigned int val = (rand() << 17) | ((rand() & 1) << 16) | (rand() << 1) | (rand() & 1); + stip[i * 4 + 0] = (val >> 24) & 0xFF; + stip[i * 4 + 1] = (val >> 16) & 0xFF; + stip[i * 4 + 2] = (val >> 8) & 0xFF; + stip[i * 4 + 3] = val & 0xFF; } - } - glActiveTexture(GL_TEXTURE2); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, 33*1024*1024); - glTexImage2D(GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glDisable(GL_TEXTURE_2D); + GLubyte texture[32 * 32 * 4]; + for (i = 0; i < 32; i++) + { + int j; + for (j = 0; j < 4; j++) + { + texture[(i * 32 + j * 8 + 0) * 4 + 3] = ((stip[i * 4 + j] >> 7) & 1) ? 255 : 0; + texture[(i * 32 + j * 8 + 1) * 4 + 3] = ((stip[i * 4 + j] >> 6) & 1) ? 255 : 0; + texture[(i * 32 + j * 8 + 2) * 4 + 3] = ((stip[i * 4 + j] >> 5) & 1) ? 255 : 0; + texture[(i * 32 + j * 8 + 3) * 4 + 3] = ((stip[i * 4 + j] >> 4) & 1) ? 255 : 0; + texture[(i * 32 + j * 8 + 4) * 4 + 3] = ((stip[i * 4 + j] >> 3) & 1) ? 255 : 0; + texture[(i * 32 + j * 8 + 5) * 4 + 3] = ((stip[i * 4 + j] >> 2) & 1) ? 255 : 0; + texture[(i * 32 + j * 8 + 6) * 4 + 3] = ((stip[i * 4 + j] >> 1) & 1) ? 255 : 0; + texture[(i * 32 + j * 8 + 7) * 4 + 3] = ((stip[i * 4 + j] >> 0) & 1) ? 255 : 0; + } + } + glActiveTexture(GL_TEXTURE2); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 33 * 1024 * 1024); + glTexImage2D(GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glDisable(GL_TEXTURE_2D); } FX_ENTRY void FX_CALL grStipplePattern( - GrStipplePattern_t stipple) +GrStipplePattern_t stipple) { - LOG("grStipplePattern(%x)\r\n", stipple); - srand(stipple); - setPattern(); + LOG("grStipplePattern(%x)\r\n", stipple); + srand(stipple); + setPattern(); } FX_ENTRY void FX_CALL -grStippleMode( GrStippleMode_t mode ) +grStippleMode(GrStippleMode_t mode) { - LOG("grStippleMode(%d)\r\n", mode); - switch(mode) - { - case GR_STIPPLE_DISABLE: - dither_enabled = 0; - glActiveTexture(GL_TEXTURE2); - glDisable(GL_TEXTURE_2D); - break; - case GR_STIPPLE_PATTERN: - setPattern(); - dither_enabled = 1; - glActiveTexture(GL_TEXTURE2); - glEnable(GL_TEXTURE_2D); - break; - case GR_STIPPLE_ROTATE: - setPattern(); - dither_enabled = 1; - glActiveTexture(GL_TEXTURE2); - glEnable(GL_TEXTURE_2D); - break; - default: - display_warning("grStippleMode:%x", mode); - } - need_to_compile = 1; + LOG("grStippleMode(%d)\r\n", mode); + switch (mode) + { + case GR_STIPPLE_DISABLE: + dither_enabled = 0; + glActiveTexture(GL_TEXTURE2); + glDisable(GL_TEXTURE_2D); + break; + case GR_STIPPLE_PATTERN: + setPattern(); + dither_enabled = 1; + glActiveTexture(GL_TEXTURE2); + glEnable(GL_TEXTURE_2D); + break; + case GR_STIPPLE_ROTATE: + setPattern(); + dither_enabled = 1; + glActiveTexture(GL_TEXTURE2); + glEnable(GL_TEXTURE_2D); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grStippleMode:%x", mode); + } + need_to_compile = 1; } -FX_ENTRY void FX_CALL +FX_ENTRY void FX_CALL grColorCombineExt(GrCCUColor_t a, GrCombineMode_t a_mode, - GrCCUColor_t b, GrCombineMode_t b_mode, - GrCCUColor_t c, FxBool c_invert, - GrCCUColor_t d, FxBool d_invert, - FxU32 shift, FxBool invert) +GrCCUColor_t b, GrCombineMode_t b_mode, +GrCCUColor_t c, FxBool c_invert, +GrCCUColor_t d, FxBool d_invert, +FxU32 shift, FxBool invert) { - LOG("grColorCombineExt(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d)\r\n", a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); - if (invert) display_warning("grColorCombineExt : inverted result"); - if (shift) display_warning("grColorCombineExt : shift = %d", shift); + LOG("grColorCombineExt(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d)\r\n", a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : inverted result"); + if (shift) WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : shift = %d", shift); - color_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | - ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | - ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | - ((d & 0x1F) << 20) | ((d_invert & 1) << 25); - c_combiner_ext = 1; - strcpy(fragment_shader_color_combiner, ""); + color_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | + ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | + ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | + ((d & 0x1F) << 20) | ((d_invert & 1) << 25); + c_combiner_ext = 1; + strcpy(fragment_shader_color_combiner, ""); - switch(a) - { - case GR_CMBX_ZERO: - strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(0.0); \n"); - break; - case GR_CMBX_TEXTURE_ALPHA: - strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(ctexture1.a); \n"); - break; - case GR_CMBX_CONSTANT_ALPHA: - strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(constant_color.a); \n"); - break; - case GR_CMBX_CONSTANT_COLOR: - strcat(fragment_shader_color_combiner, "vec4 cs_a = constant_color; \n"); - break; - case GR_CMBX_ITALPHA: - strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(gl_Color.a); \n"); - break; - case GR_CMBX_ITRGB: - strcat(fragment_shader_color_combiner, "vec4 cs_a = gl_Color; \n"); - break; - case GR_CMBX_TEXTURE_RGB: - strcat(fragment_shader_color_combiner, "vec4 cs_a = ctexture1; \n"); - break; - default: - display_warning("grColorCombineExt : a = %x", a); - strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(0.0); \n"); - } + switch (a) + { + case GR_CMBX_ZERO: + strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(0.0); \n"); + break; + case GR_CMBX_TEXTURE_ALPHA: + strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(ctexture1.a); \n"); + break; + case GR_CMBX_CONSTANT_ALPHA: + strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(constant_color.a); \n"); + break; + case GR_CMBX_CONSTANT_COLOR: + strcat(fragment_shader_color_combiner, "vec4 cs_a = constant_color; \n"); + break; + case GR_CMBX_ITALPHA: + strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(gl_Color.a); \n"); + break; + case GR_CMBX_ITRGB: + strcat(fragment_shader_color_combiner, "vec4 cs_a = gl_Color; \n"); + break; + case GR_CMBX_TEXTURE_RGB: + strcat(fragment_shader_color_combiner, "vec4 cs_a = ctexture1; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : a = %x", a); + strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(0.0); \n"); + } - switch(a_mode) - { - case GR_FUNC_MODE_ZERO: - strcat(fragment_shader_color_combiner, "vec4 c_a = vec4(0.0); \n"); - break; - case GR_FUNC_MODE_X: - strcat(fragment_shader_color_combiner, "vec4 c_a = cs_a; \n"); - break; - case GR_FUNC_MODE_ONE_MINUS_X: - strcat(fragment_shader_color_combiner, "vec4 c_a = vec4(1.0) - cs_a; \n"); - break; - case GR_FUNC_MODE_NEGATIVE_X: - strcat(fragment_shader_color_combiner, "vec4 c_a = -cs_a; \n"); - break; - default: - display_warning("grColorCombineExt : a_mode = %x", a_mode); - strcat(fragment_shader_color_combiner, "vec4 c_a = vec4(0.0); \n"); - } + switch (a_mode) + { + case GR_FUNC_MODE_ZERO: + strcat(fragment_shader_color_combiner, "vec4 c_a = vec4(0.0); \n"); + break; + case GR_FUNC_MODE_X: + strcat(fragment_shader_color_combiner, "vec4 c_a = cs_a; \n"); + break; + case GR_FUNC_MODE_ONE_MINUS_X: + strcat(fragment_shader_color_combiner, "vec4 c_a = vec4(1.0) - cs_a; \n"); + break; + case GR_FUNC_MODE_NEGATIVE_X: + strcat(fragment_shader_color_combiner, "vec4 c_a = -cs_a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : a_mode = %x", a_mode); + strcat(fragment_shader_color_combiner, "vec4 c_a = vec4(0.0); \n"); + } - switch(b) - { - case GR_CMBX_ZERO: - strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(0.0); \n"); - break; - case GR_CMBX_TEXTURE_ALPHA: - strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(ctexture1.a); \n"); - break; - case GR_CMBX_CONSTANT_ALPHA: - strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(constant_color.a); \n"); - break; - case GR_CMBX_CONSTANT_COLOR: - strcat(fragment_shader_color_combiner, "vec4 cs_b = constant_color; \n"); - break; - case GR_CMBX_ITALPHA: - strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(gl_Color.a); \n"); - break; - case GR_CMBX_ITRGB: - strcat(fragment_shader_color_combiner, "vec4 cs_b = gl_Color; \n"); - break; - case GR_CMBX_TEXTURE_RGB: - strcat(fragment_shader_color_combiner, "vec4 cs_b = ctexture1; \n"); - break; - default: - display_warning("grColorCombineExt : b = %x", b); - strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(0.0); \n"); - } + switch (b) + { + case GR_CMBX_ZERO: + strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(0.0); \n"); + break; + case GR_CMBX_TEXTURE_ALPHA: + strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(ctexture1.a); \n"); + break; + case GR_CMBX_CONSTANT_ALPHA: + strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(constant_color.a); \n"); + break; + case GR_CMBX_CONSTANT_COLOR: + strcat(fragment_shader_color_combiner, "vec4 cs_b = constant_color; \n"); + break; + case GR_CMBX_ITALPHA: + strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(gl_Color.a); \n"); + break; + case GR_CMBX_ITRGB: + strcat(fragment_shader_color_combiner, "vec4 cs_b = gl_Color; \n"); + break; + case GR_CMBX_TEXTURE_RGB: + strcat(fragment_shader_color_combiner, "vec4 cs_b = ctexture1; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : b = %x", b); + strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(0.0); \n"); + } - switch(b_mode) - { - case GR_FUNC_MODE_ZERO: - strcat(fragment_shader_color_combiner, "vec4 c_b = vec4(0.0); \n"); - break; - case GR_FUNC_MODE_X: - strcat(fragment_shader_color_combiner, "vec4 c_b = cs_b; \n"); - break; - case GR_FUNC_MODE_ONE_MINUS_X: - strcat(fragment_shader_color_combiner, "vec4 c_b = vec4(1.0) - cs_b; \n"); - break; - case GR_FUNC_MODE_NEGATIVE_X: - strcat(fragment_shader_color_combiner, "vec4 c_b = -cs_b; \n"); - break; - default: - display_warning("grColorCombineExt : b_mode = %x", b_mode); - strcat(fragment_shader_color_combiner, "vec4 c_b = vec4(0.0); \n"); - } + switch (b_mode) + { + case GR_FUNC_MODE_ZERO: + strcat(fragment_shader_color_combiner, "vec4 c_b = vec4(0.0); \n"); + break; + case GR_FUNC_MODE_X: + strcat(fragment_shader_color_combiner, "vec4 c_b = cs_b; \n"); + break; + case GR_FUNC_MODE_ONE_MINUS_X: + strcat(fragment_shader_color_combiner, "vec4 c_b = vec4(1.0) - cs_b; \n"); + break; + case GR_FUNC_MODE_NEGATIVE_X: + strcat(fragment_shader_color_combiner, "vec4 c_b = -cs_b; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : b_mode = %x", b_mode); + strcat(fragment_shader_color_combiner, "vec4 c_b = vec4(0.0); \n"); + } - switch(c) - { - case GR_CMBX_ZERO: - strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(0.0); \n"); - break; - case GR_CMBX_TEXTURE_ALPHA: - strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(ctexture1.a); \n"); - break; - case GR_CMBX_ALOCAL: - strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(c_b.a); \n"); - break; - case GR_CMBX_AOTHER: - strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(c_a.a); \n"); - break; - case GR_CMBX_B: - strcat(fragment_shader_color_combiner, "vec4 c_c = cs_b; \n"); - break; - case GR_CMBX_CONSTANT_ALPHA: - strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(constant_color.a); \n"); - break; - case GR_CMBX_CONSTANT_COLOR: - strcat(fragment_shader_color_combiner, "vec4 c_c = constant_color; \n"); - break; - case GR_CMBX_ITALPHA: - strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(gl_Color.a); \n"); - break; - case GR_CMBX_ITRGB: - strcat(fragment_shader_color_combiner, "vec4 c_c = gl_Color; \n"); - break; - case GR_CMBX_TEXTURE_RGB: - strcat(fragment_shader_color_combiner, "vec4 c_c = ctexture1; \n"); - break; - default: - display_warning("grColorCombineExt : c = %x", c); - strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(0.0); \n"); - } + switch (c) + { + case GR_CMBX_ZERO: + strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(0.0); \n"); + break; + case GR_CMBX_TEXTURE_ALPHA: + strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(ctexture1.a); \n"); + break; + case GR_CMBX_ALOCAL: + strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(c_b.a); \n"); + break; + case GR_CMBX_AOTHER: + strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(c_a.a); \n"); + break; + case GR_CMBX_B: + strcat(fragment_shader_color_combiner, "vec4 c_c = cs_b; \n"); + break; + case GR_CMBX_CONSTANT_ALPHA: + strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(constant_color.a); \n"); + break; + case GR_CMBX_CONSTANT_COLOR: + strcat(fragment_shader_color_combiner, "vec4 c_c = constant_color; \n"); + break; + case GR_CMBX_ITALPHA: + strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(gl_Color.a); \n"); + break; + case GR_CMBX_ITRGB: + strcat(fragment_shader_color_combiner, "vec4 c_c = gl_Color; \n"); + break; + case GR_CMBX_TEXTURE_RGB: + strcat(fragment_shader_color_combiner, "vec4 c_c = ctexture1; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : c = %x", c); + strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(0.0); \n"); + } - if(c_invert) - strcat(fragment_shader_color_combiner, "c_c = vec4(1.0) - c_c; \n"); + if (c_invert) + strcat(fragment_shader_color_combiner, "c_c = vec4(1.0) - c_c; \n"); - switch(d) - { - case GR_CMBX_ZERO: - strcat(fragment_shader_color_combiner, "vec4 c_d = vec4(0.0); \n"); - break; - case GR_CMBX_ALOCAL: - strcat(fragment_shader_color_combiner, "vec4 c_d = vec4(c_b.a); \n"); - break; - case GR_CMBX_B: - strcat(fragment_shader_color_combiner, "vec4 c_d = cs_b; \n"); - break; - case GR_CMBX_TEXTURE_RGB: - strcat(fragment_shader_color_combiner, "vec4 c_d = ctexture1; \n"); - break; - case GR_CMBX_ITRGB: - strcat(fragment_shader_color_combiner, "vec4 c_d = gl_Color; \n"); - break; - default: - display_warning("grColorCombineExt : d = %x", d); - strcat(fragment_shader_color_combiner, "vec4 c_d = vec4(0.0); \n"); - } + switch (d) + { + case GR_CMBX_ZERO: + strcat(fragment_shader_color_combiner, "vec4 c_d = vec4(0.0); \n"); + break; + case GR_CMBX_ALOCAL: + strcat(fragment_shader_color_combiner, "vec4 c_d = vec4(c_b.a); \n"); + break; + case GR_CMBX_B: + strcat(fragment_shader_color_combiner, "vec4 c_d = cs_b; \n"); + break; + case GR_CMBX_TEXTURE_RGB: + strcat(fragment_shader_color_combiner, "vec4 c_d = ctexture1; \n"); + break; + case GR_CMBX_ITRGB: + strcat(fragment_shader_color_combiner, "vec4 c_d = gl_Color; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : d = %x", d); + strcat(fragment_shader_color_combiner, "vec4 c_d = vec4(0.0); \n"); + } - if(d_invert) - strcat(fragment_shader_color_combiner, "c_d = vec4(1.0) - c_d; \n"); + if (d_invert) + strcat(fragment_shader_color_combiner, "c_d = vec4(1.0) - c_d; \n"); - strcat(fragment_shader_color_combiner, "gl_FragColor = (c_a + c_b) * c_c + c_d; \n"); + strcat(fragment_shader_color_combiner, "gl_FragColor = (c_a + c_b) * c_c + c_d; \n"); - need_to_compile = 1; + need_to_compile = 1; } FX_ENTRY void FX_CALL grAlphaCombineExt(GrACUColor_t a, GrCombineMode_t a_mode, - GrACUColor_t b, GrCombineMode_t b_mode, - GrACUColor_t c, FxBool c_invert, - GrACUColor_t d, FxBool d_invert, - FxU32 shift, FxBool invert) +GrACUColor_t b, GrCombineMode_t b_mode, +GrACUColor_t c, FxBool c_invert, +GrACUColor_t d, FxBool d_invert, +FxU32 shift, FxBool invert) { - LOG("grAlphaCombineExt(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\r\n", a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); - if (invert) display_warning("grAlphaCombineExt : inverted result"); - if (shift) display_warning("grAlphaCombineExt : shift = %d", shift); + LOG("grAlphaCombineExt(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\r\n", a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : inverted result"); + if (shift) WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : shift = %d", shift); - alpha_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | - ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | - ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | - ((d & 0x1F) << 20) | ((d_invert & 1) << 25); - a_combiner_ext = 1; - strcpy(fragment_shader_alpha_combiner, ""); + alpha_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | + ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | + ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | + ((d & 0x1F) << 20) | ((d_invert & 1) << 25); + a_combiner_ext = 1; + strcpy(fragment_shader_alpha_combiner, ""); - switch(a) - { - case GR_CMBX_ZERO: - strcat(fragment_shader_alpha_combiner, "float as_a = 0.0; \n"); - break; - case GR_CMBX_TEXTURE_ALPHA: - strcat(fragment_shader_alpha_combiner, "float as_a = ctexture1.a; \n"); - break; - case GR_CMBX_CONSTANT_ALPHA: - strcat(fragment_shader_alpha_combiner, "float as_a = constant_color.a; \n"); - break; - case GR_CMBX_ITALPHA: - strcat(fragment_shader_alpha_combiner, "float as_a = gl_Color.a; \n"); - break; - default: - display_warning("grAlphaCombineExt : a = %x", a); - strcat(fragment_shader_alpha_combiner, "float as_a = 0.0; \n"); - } + switch (a) + { + case GR_CMBX_ZERO: + strcat(fragment_shader_alpha_combiner, "float as_a = 0.0; \n"); + break; + case GR_CMBX_TEXTURE_ALPHA: + strcat(fragment_shader_alpha_combiner, "float as_a = ctexture1.a; \n"); + break; + case GR_CMBX_CONSTANT_ALPHA: + strcat(fragment_shader_alpha_combiner, "float as_a = constant_color.a; \n"); + break; + case GR_CMBX_ITALPHA: + strcat(fragment_shader_alpha_combiner, "float as_a = gl_Color.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : a = %x", a); + strcat(fragment_shader_alpha_combiner, "float as_a = 0.0; \n"); + } - switch(a_mode) - { - case GR_FUNC_MODE_ZERO: - strcat(fragment_shader_alpha_combiner, "float a_a = 0.0; \n"); - break; - case GR_FUNC_MODE_X: - strcat(fragment_shader_alpha_combiner, "float a_a = as_a; \n"); - break; - case GR_FUNC_MODE_ONE_MINUS_X: - strcat(fragment_shader_alpha_combiner, "float a_a = 1.0 - as_a; \n"); - break; - case GR_FUNC_MODE_NEGATIVE_X: - strcat(fragment_shader_alpha_combiner, "float a_a = -as_a; \n"); - break; - default: - display_warning("grAlphaCombineExt : a_mode = %x", a_mode); - strcat(fragment_shader_alpha_combiner, "float a_a = 0.0; \n"); - } + switch (a_mode) + { + case GR_FUNC_MODE_ZERO: + strcat(fragment_shader_alpha_combiner, "float a_a = 0.0; \n"); + break; + case GR_FUNC_MODE_X: + strcat(fragment_shader_alpha_combiner, "float a_a = as_a; \n"); + break; + case GR_FUNC_MODE_ONE_MINUS_X: + strcat(fragment_shader_alpha_combiner, "float a_a = 1.0 - as_a; \n"); + break; + case GR_FUNC_MODE_NEGATIVE_X: + strcat(fragment_shader_alpha_combiner, "float a_a = -as_a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : a_mode = %x", a_mode); + strcat(fragment_shader_alpha_combiner, "float a_a = 0.0; \n"); + } - switch(b) - { - case GR_CMBX_ZERO: - strcat(fragment_shader_alpha_combiner, "float as_b = 0.0; \n"); - break; - case GR_CMBX_TEXTURE_ALPHA: - strcat(fragment_shader_alpha_combiner, "float as_b = ctexture1.a; \n"); - break; - case GR_CMBX_CONSTANT_ALPHA: - strcat(fragment_shader_alpha_combiner, "float as_b = constant_color.a; \n"); - break; - case GR_CMBX_ITALPHA: - strcat(fragment_shader_alpha_combiner, "float as_b = gl_Color.a; \n"); - break; - default: - display_warning("grAlphaCombineExt : b = %x", b); - strcat(fragment_shader_alpha_combiner, "float as_b = 0.0; \n"); - } + switch (b) + { + case GR_CMBX_ZERO: + strcat(fragment_shader_alpha_combiner, "float as_b = 0.0; \n"); + break; + case GR_CMBX_TEXTURE_ALPHA: + strcat(fragment_shader_alpha_combiner, "float as_b = ctexture1.a; \n"); + break; + case GR_CMBX_CONSTANT_ALPHA: + strcat(fragment_shader_alpha_combiner, "float as_b = constant_color.a; \n"); + break; + case GR_CMBX_ITALPHA: + strcat(fragment_shader_alpha_combiner, "float as_b = gl_Color.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : b = %x", b); + strcat(fragment_shader_alpha_combiner, "float as_b = 0.0; \n"); + } - switch(b_mode) - { - case GR_FUNC_MODE_ZERO: - strcat(fragment_shader_alpha_combiner, "float a_b = 0.0; \n"); - break; - case GR_FUNC_MODE_X: - strcat(fragment_shader_alpha_combiner, "float a_b = as_b; \n"); - break; - case GR_FUNC_MODE_ONE_MINUS_X: - strcat(fragment_shader_alpha_combiner, "float a_b = 1.0 - as_b; \n"); - break; - case GR_FUNC_MODE_NEGATIVE_X: - strcat(fragment_shader_alpha_combiner, "float a_b = -as_b; \n"); - break; - default: - display_warning("grAlphaCombineExt : b_mode = %x", b_mode); - strcat(fragment_shader_alpha_combiner, "float a_b = 0.0; \n"); - } + switch (b_mode) + { + case GR_FUNC_MODE_ZERO: + strcat(fragment_shader_alpha_combiner, "float a_b = 0.0; \n"); + break; + case GR_FUNC_MODE_X: + strcat(fragment_shader_alpha_combiner, "float a_b = as_b; \n"); + break; + case GR_FUNC_MODE_ONE_MINUS_X: + strcat(fragment_shader_alpha_combiner, "float a_b = 1.0 - as_b; \n"); + break; + case GR_FUNC_MODE_NEGATIVE_X: + strcat(fragment_shader_alpha_combiner, "float a_b = -as_b; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : b_mode = %x", b_mode); + strcat(fragment_shader_alpha_combiner, "float a_b = 0.0; \n"); + } - switch(c) - { - case GR_CMBX_ZERO: - strcat(fragment_shader_alpha_combiner, "float a_c = 0.0; \n"); - break; - case GR_CMBX_TEXTURE_ALPHA: - strcat(fragment_shader_alpha_combiner, "float a_c = ctexture1.a; \n"); - break; - case GR_CMBX_ALOCAL: - strcat(fragment_shader_alpha_combiner, "float a_c = as_b; \n"); - break; - case GR_CMBX_AOTHER: - strcat(fragment_shader_alpha_combiner, "float a_c = as_a; \n"); - break; - case GR_CMBX_B: - strcat(fragment_shader_alpha_combiner, "float a_c = as_b; \n"); - break; - case GR_CMBX_CONSTANT_ALPHA: - strcat(fragment_shader_alpha_combiner, "float a_c = constant_color.a; \n"); - break; - case GR_CMBX_ITALPHA: - strcat(fragment_shader_alpha_combiner, "float a_c = gl_Color.a; \n"); - break; - default: - display_warning("grAlphaCombineExt : c = %x", c); - strcat(fragment_shader_alpha_combiner, "float a_c = 0.0; \n"); - } + switch (c) + { + case GR_CMBX_ZERO: + strcat(fragment_shader_alpha_combiner, "float a_c = 0.0; \n"); + break; + case GR_CMBX_TEXTURE_ALPHA: + strcat(fragment_shader_alpha_combiner, "float a_c = ctexture1.a; \n"); + break; + case GR_CMBX_ALOCAL: + strcat(fragment_shader_alpha_combiner, "float a_c = as_b; \n"); + break; + case GR_CMBX_AOTHER: + strcat(fragment_shader_alpha_combiner, "float a_c = as_a; \n"); + break; + case GR_CMBX_B: + strcat(fragment_shader_alpha_combiner, "float a_c = as_b; \n"); + break; + case GR_CMBX_CONSTANT_ALPHA: + strcat(fragment_shader_alpha_combiner, "float a_c = constant_color.a; \n"); + break; + case GR_CMBX_ITALPHA: + strcat(fragment_shader_alpha_combiner, "float a_c = gl_Color.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : c = %x", c); + strcat(fragment_shader_alpha_combiner, "float a_c = 0.0; \n"); + } - if(c_invert) - strcat(fragment_shader_alpha_combiner, "a_c = 1.0 - a_c; \n"); + if (c_invert) + strcat(fragment_shader_alpha_combiner, "a_c = 1.0 - a_c; \n"); - switch(d) - { - case GR_CMBX_ZERO: - strcat(fragment_shader_alpha_combiner, "float a_d = 0.0; \n"); - break; - case GR_CMBX_TEXTURE_ALPHA: - strcat(fragment_shader_alpha_combiner, "float a_d = ctexture1.a; \n"); - break; - case GR_CMBX_ALOCAL: - strcat(fragment_shader_alpha_combiner, "float a_d = as_b; \n"); - break; - case GR_CMBX_B: - strcat(fragment_shader_alpha_combiner, "float a_d = as_b; \n"); - break; - default: - display_warning("grAlphaCombineExt : d = %x", d); - strcat(fragment_shader_alpha_combiner, "float a_d = 0.0; \n"); - } + switch (d) + { + case GR_CMBX_ZERO: + strcat(fragment_shader_alpha_combiner, "float a_d = 0.0; \n"); + break; + case GR_CMBX_TEXTURE_ALPHA: + strcat(fragment_shader_alpha_combiner, "float a_d = ctexture1.a; \n"); + break; + case GR_CMBX_ALOCAL: + strcat(fragment_shader_alpha_combiner, "float a_d = as_b; \n"); + break; + case GR_CMBX_B: + strcat(fragment_shader_alpha_combiner, "float a_d = as_b; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : d = %x", d); + strcat(fragment_shader_alpha_combiner, "float a_d = 0.0; \n"); + } - if(d_invert) - strcat(fragment_shader_alpha_combiner, "a_d = 1.0 - a_d; \n"); + if (d_invert) + strcat(fragment_shader_alpha_combiner, "a_d = 1.0 - a_d; \n"); - strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = (a_a + a_b) * a_c + a_d; \n"); + strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = (a_a + a_b) * a_c + a_d; \n"); - need_to_compile = 1; + need_to_compile = 1; } -FX_ENTRY void FX_CALL +FX_ENTRY void FX_CALL grTexColorCombineExt(GrChipID_t tmu, - GrTCCUColor_t a, GrCombineMode_t a_mode, - GrTCCUColor_t b, GrCombineMode_t b_mode, - GrTCCUColor_t c, FxBool c_invert, - GrTCCUColor_t d, FxBool d_invert, - FxU32 shift, FxBool invert) +GrTCCUColor_t a, GrCombineMode_t a_mode, +GrTCCUColor_t b, GrCombineMode_t b_mode, +GrTCCUColor_t c, FxBool c_invert, +GrTCCUColor_t d, FxBool d_invert, +FxU32 shift, FxBool invert) { - int num_tex; - LOG("grTexColorCombineExt(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\r\n", tmu, a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); + int num_tex; + LOG("grTexColorCombineExt(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\r\n", tmu, a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); - if (invert) display_warning("grTexColorCombineExt : inverted result"); - if (shift) display_warning("grTexColorCombineExt : shift = %d", shift); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : inverted result"); + if (shift) WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : shift = %d", shift); - if (tmu == GR_TMU0) num_tex = 1; - else num_tex = 0; + if (tmu == GR_TMU0) num_tex = 1; + else num_tex = 0; - if(num_tex == 0) - { - texture0_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | - ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | - ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | - ((d & 0x1F) << 20) | ((d_invert & 1) << 25); - tex0_combiner_ext = 1; - strcpy(fragment_shader_texture0, ""); - } - else - { - texture1_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | - ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | - ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | - ((d & 0x1F) << 20) | ((d_invert & 1) << 25); - tex1_combiner_ext = 1; - strcpy(fragment_shader_texture1, ""); - } + if (num_tex == 0) + { + texture0_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | + ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | + ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | + ((d & 0x1F) << 20) | ((d_invert & 1) << 25); + tex0_combiner_ext = 1; + strcpy(fragment_shader_texture0, ""); + } + else + { + texture1_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | + ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | + ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | + ((d & 0x1F) << 20) | ((d_invert & 1) << 25); + tex1_combiner_ext = 1; + strcpy(fragment_shader_texture1, ""); + } - switch(a) - { - case GR_CMBX_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(0.0); \n"); - break; - case GR_CMBX_ITALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(gl_Color.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(gl_Color.a); \n"); - break; - case GR_CMBX_ITRGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = gl_Color; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = gl_Color; \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(readtex1.a); \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_RGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = readtex1; \n"); - break; - case GR_CMBX_OTHER_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(ctexture0.a); \n"); - break; - case GR_CMBX_OTHER_TEXTURE_RGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = ctexture0; \n"); - break; - case GR_CMBX_TMU_CCOLOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = ccolor0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = ccolor1; \n"); - break; - case GR_CMBX_TMU_CALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(ccolor0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(ccolor1.a); \n"); - break; - default: - display_warning("grTexColorCombineExt : a = %x", a); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(0.0); \n"); - } + switch (a) + { + case GR_CMBX_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(0.0); \n"); + break; + case GR_CMBX_ITALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(gl_Color.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(gl_Color.a); \n"); + break; + case GR_CMBX_ITRGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = gl_Color; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = gl_Color; \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(readtex1.a); \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_RGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = readtex1; \n"); + break; + case GR_CMBX_OTHER_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(ctexture0.a); \n"); + break; + case GR_CMBX_OTHER_TEXTURE_RGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = ctexture0; \n"); + break; + case GR_CMBX_TMU_CCOLOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = ccolor0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = ccolor1; \n"); + break; + case GR_CMBX_TMU_CALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(ccolor0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(ccolor1.a); \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : a = %x", a); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(0.0); \n"); + } - switch(a_mode) - { - case GR_FUNC_MODE_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_a = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_a = vec4(0.0); \n"); - break; - case GR_FUNC_MODE_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_a = ctex0s_a; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_a = ctex1s_a; \n"); - break; - case GR_FUNC_MODE_ONE_MINUS_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_a = vec4(1.0) - ctex0s_a; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_a = vec4(1.0) - ctex1s_a; \n"); - break; - case GR_FUNC_MODE_NEGATIVE_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_a = -ctex0s_a; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_a = -ctex1s_a; \n"); - break; - default: - display_warning("grTexColorCombineExt : a_mode = %x", a_mode); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_a = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_a = vec4(0.0); \n"); - } + switch (a_mode) + { + case GR_FUNC_MODE_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_a = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_a = vec4(0.0); \n"); + break; + case GR_FUNC_MODE_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_a = ctex0s_a; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_a = ctex1s_a; \n"); + break; + case GR_FUNC_MODE_ONE_MINUS_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_a = vec4(1.0) - ctex0s_a; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_a = vec4(1.0) - ctex1s_a; \n"); + break; + case GR_FUNC_MODE_NEGATIVE_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_a = -ctex0s_a; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_a = -ctex1s_a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : a_mode = %x", a_mode); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_a = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_a = vec4(0.0); \n"); + } - switch(b) - { - case GR_CMBX_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(0.0); \n"); - break; - case GR_CMBX_ITALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(gl_Color.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(gl_Color.a); \n"); - break; - case GR_CMBX_ITRGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = gl_Color; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = gl_Color; \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(readtex1.a); \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_RGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = readtex1; \n"); - break; - case GR_CMBX_OTHER_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(ctexture0.a); \n"); - break; - case GR_CMBX_OTHER_TEXTURE_RGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = ctexture0; \n"); - break; - case GR_CMBX_TMU_CALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(ccolor0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(ccolor1.a); \n"); - break; - case GR_CMBX_TMU_CCOLOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = ccolor0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = ccolor1; \n"); - break; - default: - display_warning("grTexColorCombineExt : b = %x", b); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(0.0); \n"); - } + switch (b) + { + case GR_CMBX_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(0.0); \n"); + break; + case GR_CMBX_ITALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(gl_Color.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(gl_Color.a); \n"); + break; + case GR_CMBX_ITRGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = gl_Color; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = gl_Color; \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(readtex1.a); \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_RGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = readtex1; \n"); + break; + case GR_CMBX_OTHER_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(ctexture0.a); \n"); + break; + case GR_CMBX_OTHER_TEXTURE_RGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = ctexture0; \n"); + break; + case GR_CMBX_TMU_CALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(ccolor0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(ccolor1.a); \n"); + break; + case GR_CMBX_TMU_CCOLOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = ccolor0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = ccolor1; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : b = %x", b); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1s_b = vec4(0.0); \n"); + } - switch(b_mode) - { - case GR_FUNC_MODE_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_b = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_b = vec4(0.0); \n"); - break; - case GR_FUNC_MODE_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_b = ctex0s_b; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_b = ctex1s_b; \n"); - break; - case GR_FUNC_MODE_ONE_MINUS_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_b = vec4(1.0) - ctex0s_b; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_b = vec4(1.0) - ctex1s_b; \n"); - break; - case GR_FUNC_MODE_NEGATIVE_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_b = -ctex0s_b; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_b = -ctex1s_b; \n"); - break; - default: - display_warning("grTexColorCombineExt : b_mode = %x", b_mode); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_b = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_b = vec4(0.0); \n"); - } + switch (b_mode) + { + case GR_FUNC_MODE_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_b = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_b = vec4(0.0); \n"); + break; + case GR_FUNC_MODE_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_b = ctex0s_b; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_b = ctex1s_b; \n"); + break; + case GR_FUNC_MODE_ONE_MINUS_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_b = vec4(1.0) - ctex0s_b; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_b = vec4(1.0) - ctex1s_b; \n"); + break; + case GR_FUNC_MODE_NEGATIVE_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_b = -ctex0s_b; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_b = -ctex1s_b; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : b_mode = %x", b_mode); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_b = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_b = vec4(0.0); \n"); + } - switch(c) - { - case GR_CMBX_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(0.0); \n"); - break; - case GR_CMBX_B: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = ctex0s_b; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = ctex1s_b; \n"); - break; - case GR_CMBX_DETAIL_FACTOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(lambda); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(lambda); \n"); - break; - case GR_CMBX_ITRGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = gl_Color; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = gl_Color; \n"); - break; - case GR_CMBX_ITALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(gl_Color.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(gl_Color.a); \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(readtex1.a); \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_RGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = readtex0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = readtex1; \n"); - break; - case GR_CMBX_OTHER_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(ctexture0.a); \n"); - break; - case GR_CMBX_OTHER_TEXTURE_RGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = ctexture0; \n"); - break; - case GR_CMBX_TMU_CALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(ccolor0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(ccolor1.a); \n"); - break; - case GR_CMBX_TMU_CCOLOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = ccolor0; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = ccolor1; \n"); - break; - default: - display_warning("grTexColorCombineExt : c = %x", c); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(0.0); \n"); - } + switch (c) + { + case GR_CMBX_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(0.0); \n"); + break; + case GR_CMBX_B: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = ctex0s_b; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = ctex1s_b; \n"); + break; + case GR_CMBX_DETAIL_FACTOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(lambda); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(lambda); \n"); + break; + case GR_CMBX_ITRGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = gl_Color; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = gl_Color; \n"); + break; + case GR_CMBX_ITALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(gl_Color.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(gl_Color.a); \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(readtex1.a); \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_RGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = readtex0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = readtex1; \n"); + break; + case GR_CMBX_OTHER_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(ctexture0.a); \n"); + break; + case GR_CMBX_OTHER_TEXTURE_RGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = ctexture0; \n"); + break; + case GR_CMBX_TMU_CALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(ccolor0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(ccolor1.a); \n"); + break; + case GR_CMBX_TMU_CCOLOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = ccolor0; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = ccolor1; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : c = %x", c); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_c = vec4(0.0); \n"); + } - if(c_invert) - { - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c = vec4(1.0) - ctex0_c; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c = vec4(1.0) - ctex1_c; \n"); - } + if (c_invert) + { + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c = vec4(1.0) - ctex0_c; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c = vec4(1.0) - ctex1_c; \n"); + } - switch(d) - { - case GR_CMBX_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_d = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_d = vec4(0.0); \n"); - break; - case GR_CMBX_B: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_d = ctex0s_b; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_d = ctex1s_b; \n"); - break; - case GR_CMBX_ITRGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_d = gl_Color; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_d = gl_Color; \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_d = vec4(readtex0.a); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_d = vec4(readtex1.a); \n"); - break; - default: - display_warning("grTexColorCombineExt : d = %x", d); - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctex0_d = vec4(0.0); \n"); - else - strcat(fragment_shader_texture1, "vec4 ctex1_d = vec4(0.0); \n"); - } + switch (d) + { + case GR_CMBX_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_d = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_d = vec4(0.0); \n"); + break; + case GR_CMBX_B: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_d = ctex0s_b; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_d = ctex1s_b; \n"); + break; + case GR_CMBX_ITRGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_d = gl_Color; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_d = gl_Color; \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_d = vec4(readtex0.a); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_d = vec4(readtex1.a); \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : d = %x", d); + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctex0_d = vec4(0.0); \n"); + else + strcat(fragment_shader_texture1, "vec4 ctex1_d = vec4(0.0); \n"); + } - if(d_invert) - { - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_d = vec4(1.0) - ctex0_d; \n"); - else - strcat(fragment_shader_texture1, "ctex1_d = vec4(1.0) - ctex1_d; \n"); - } + if (d_invert) + { + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_d = vec4(1.0) - ctex0_d; \n"); + else + strcat(fragment_shader_texture1, "ctex1_d = vec4(1.0) - ctex1_d; \n"); + } - if(num_tex == 0) - strcat(fragment_shader_texture0, "vec4 ctexture0 = (ctex0_a + ctex0_b) * ctex0_c + ctex0_d; \n"); - else - strcat(fragment_shader_texture1, "vec4 ctexture1 = (ctex1_a + ctex1_b) * ctex1_c + ctex1_d; \n"); - need_to_compile = 1; + if (num_tex == 0) + strcat(fragment_shader_texture0, "vec4 ctexture0 = (ctex0_a + ctex0_b) * ctex0_c + ctex0_d; \n"); + else + strcat(fragment_shader_texture1, "vec4 ctexture1 = (ctex1_a + ctex1_b) * ctex1_c + ctex1_d; \n"); + need_to_compile = 1; } -FX_ENTRY void FX_CALL +FX_ENTRY void FX_CALL grTexAlphaCombineExt(GrChipID_t tmu, - GrTACUColor_t a, GrCombineMode_t a_mode, - GrTACUColor_t b, GrCombineMode_t b_mode, - GrTACUColor_t c, FxBool c_invert, - GrTACUColor_t d, FxBool d_invert, - FxU32 shift, FxBool invert) +GrTACUColor_t a, GrCombineMode_t a_mode, +GrTACUColor_t b, GrCombineMode_t b_mode, +GrTACUColor_t c, FxBool c_invert, +GrTACUColor_t d, FxBool d_invert, +FxU32 shift, FxBool invert) { - int num_tex; - LOG("grTexAlphaCombineExt(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\r\n", tmu, a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); + int num_tex; + LOG("grTexAlphaCombineExt(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\r\n", tmu, a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); - if (invert) display_warning("grTexAlphaCombineExt : inverted result"); - if (shift) display_warning("grTexAlphaCombineExt : shift = %d", shift); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : inverted result"); + if (shift) WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : shift = %d", shift); - if (tmu == GR_TMU0) num_tex = 1; - else num_tex = 0; + if (tmu == GR_TMU0) num_tex = 1; + else num_tex = 0; - if(num_tex == 0) - { - texture0_combinera_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | - ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | - ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | - ((d & 0x1F) << 20) | ((d_invert & 1) << 25); - } - else - { - texture1_combinera_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | - ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | - ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | - ((d & 0x1F) << 20) | ((d_invert & 1) << 25); - } + if (num_tex == 0) + { + texture0_combinera_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | + ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | + ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | + ((d & 0x1F) << 20) | ((d_invert & 1) << 25); + } + else + { + texture1_combinera_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | + ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | + ((c & 0x1F) << 14) | ((c_invert & 1) << 19) | + ((d & 0x1F) << 20) | ((d_invert & 1) << 25); + } - switch(a) - { - case GR_CMBX_ITALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_a.a = gl_Color.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_a.a = gl_Color.a; \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_a.a = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_a.a = readtex1.a; \n"); - break; - case GR_CMBX_OTHER_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_a.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_a.a = ctexture0.a; \n"); - break; - case GR_CMBX_TMU_CALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_a.a = ccolor0.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_a.a = ccolor1.a; \n"); - break; - default: - display_warning("grTexAlphaCombineExt : a = %x", a); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_a.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_a.a = 0.0; \n"); - } + switch (a) + { + case GR_CMBX_ITALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_a.a = gl_Color.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_a.a = gl_Color.a; \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_a.a = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_a.a = readtex1.a; \n"); + break; + case GR_CMBX_OTHER_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_a.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_a.a = ctexture0.a; \n"); + break; + case GR_CMBX_TMU_CALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_a.a = ccolor0.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_a.a = ccolor1.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : a = %x", a); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_a.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_a.a = 0.0; \n"); + } - switch(a_mode) - { - case GR_FUNC_MODE_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_a.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_a.a = 0.0; \n"); - break; - case GR_FUNC_MODE_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_a.a = ctex0s_a.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_a.a = ctex1s_a.a; \n"); - break; - case GR_FUNC_MODE_ONE_MINUS_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_a.a = 1.0 - ctex0s_a.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_a.a = 1.0 - ctex1s_a.a; \n"); - break; - case GR_FUNC_MODE_NEGATIVE_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_a.a = -ctex0s_a.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_a.a = -ctex1s_a.a; \n"); - break; - default: - display_warning("grTexAlphaCombineExt : a_mode = %x", a_mode); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_a.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_a.a = 0.0; \n"); - } + switch (a_mode) + { + case GR_FUNC_MODE_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_a.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_a.a = 0.0; \n"); + break; + case GR_FUNC_MODE_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_a.a = ctex0s_a.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_a.a = ctex1s_a.a; \n"); + break; + case GR_FUNC_MODE_ONE_MINUS_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_a.a = 1.0 - ctex0s_a.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_a.a = 1.0 - ctex1s_a.a; \n"); + break; + case GR_FUNC_MODE_NEGATIVE_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_a.a = -ctex0s_a.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_a.a = -ctex1s_a.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : a_mode = %x", a_mode); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_a.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_a.a = 0.0; \n"); + } - switch(b) - { - case GR_CMBX_ITALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_b.a = gl_Color.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_b.a = gl_Color.a; \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_b.a = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_b.a = readtex1.a; \n"); - break; - case GR_CMBX_OTHER_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_b.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_b.a = ctexture0.a; \n"); - break; - case GR_CMBX_TMU_CALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_b.a = ccolor0.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_b.a = ccolor1.a; \n"); - break; - default: - display_warning("grTexAlphaCombineExt : b = %x", b); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0s_b.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1s_b.a = 0.0; \n"); - } + switch (b) + { + case GR_CMBX_ITALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_b.a = gl_Color.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_b.a = gl_Color.a; \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_b.a = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_b.a = readtex1.a; \n"); + break; + case GR_CMBX_OTHER_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_b.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_b.a = ctexture0.a; \n"); + break; + case GR_CMBX_TMU_CALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_b.a = ccolor0.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_b.a = ccolor1.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : b = %x", b); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0s_b.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1s_b.a = 0.0; \n"); + } - switch(b_mode) - { - case GR_FUNC_MODE_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_b.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_b.a = 0.0; \n"); - break; - case GR_FUNC_MODE_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_b.a = ctex0s_b.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_b.a = ctex1s_b.a; \n"); - break; - case GR_FUNC_MODE_ONE_MINUS_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_b.a = 1.0 - ctex0s_b.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_b.a = 1.0 - ctex1s_b.a; \n"); - break; - case GR_FUNC_MODE_NEGATIVE_X: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_b.a = -ctex0s_b.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_b.a = -ctex1s_b.a; \n"); - break; - default: - display_warning("grTexAlphaCombineExt : b_mode = %x", b_mode); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_b.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_b.a = 0.0; \n"); - } + switch (b_mode) + { + case GR_FUNC_MODE_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_b.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_b.a = 0.0; \n"); + break; + case GR_FUNC_MODE_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_b.a = ctex0s_b.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_b.a = ctex1s_b.a; \n"); + break; + case GR_FUNC_MODE_ONE_MINUS_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_b.a = 1.0 - ctex0s_b.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_b.a = 1.0 - ctex1s_b.a; \n"); + break; + case GR_FUNC_MODE_NEGATIVE_X: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_b.a = -ctex0s_b.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_b.a = -ctex1s_b.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : b_mode = %x", b_mode); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_b.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_b.a = 0.0; \n"); + } - switch(c) - { - case GR_CMBX_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = 0.0; \n"); - break; - case GR_CMBX_B: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = ctex0s_b.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = ctex1s_b.a; \n"); - break; - case GR_CMBX_DETAIL_FACTOR: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = lambda; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = lambda; \n"); - break; - case GR_CMBX_ITALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = gl_Color.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = gl_Color.a; \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = readtex1.a; \n"); - break; - case GR_CMBX_OTHER_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = ctexture0.a; \n"); - break; - case GR_CMBX_TMU_CALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = ccolor0.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = ccolor1.a; \n"); - break; - default: - display_warning("grTexAlphaCombineExt : c = %x", c); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = 0.0; \n"); - } + switch (c) + { + case GR_CMBX_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = 0.0; \n"); + break; + case GR_CMBX_B: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = ctex0s_b.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = ctex1s_b.a; \n"); + break; + case GR_CMBX_DETAIL_FACTOR: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = lambda; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = lambda; \n"); + break; + case GR_CMBX_ITALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = gl_Color.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = gl_Color.a; \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = readtex1.a; \n"); + break; + case GR_CMBX_OTHER_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = ctexture0.a; \n"); + break; + case GR_CMBX_TMU_CALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = ccolor0.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = ccolor1.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : c = %x", c); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = 0.0; \n"); + } - if(c_invert) - { - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_c.a = 1.0 - ctex0_c.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_c.a = 1.0 - ctex1_c.a; \n"); - } + if (c_invert) + { + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_c.a = 1.0 - ctex0_c.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_c.a = 1.0 - ctex1_c.a; \n"); + } - switch(d) - { - case GR_CMBX_ZERO: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_d.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_d.a = 0.0; \n"); - break; - case GR_CMBX_B: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_d.a = ctex0s_b.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_d.a = ctex1s_b.a; \n"); - break; - case GR_CMBX_ITALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_d.a = gl_Color.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_d.a = gl_Color.a; \n"); - break; - case GR_CMBX_ITRGB: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_d.a = gl_Color.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_d.a = gl_Color.a; \n"); - break; - case GR_CMBX_LOCAL_TEXTURE_ALPHA: - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_d.a = readtex0.a; \n"); - else - strcat(fragment_shader_texture1, "ctex1_d.a = readtex1.a; \n"); - break; - default: - display_warning("grTexAlphaCombineExt : d = %x", d); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_d.a = 0.0; \n"); - else - strcat(fragment_shader_texture1, "ctex1_d.a = 0.0; \n"); - } + switch (d) + { + case GR_CMBX_ZERO: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_d.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_d.a = 0.0; \n"); + break; + case GR_CMBX_B: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_d.a = ctex0s_b.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_d.a = ctex1s_b.a; \n"); + break; + case GR_CMBX_ITALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_d.a = gl_Color.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_d.a = gl_Color.a; \n"); + break; + case GR_CMBX_ITRGB: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_d.a = gl_Color.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_d.a = gl_Color.a; \n"); + break; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_d.a = readtex0.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_d.a = readtex1.a; \n"); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : d = %x", d); + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_d.a = 0.0; \n"); + else + strcat(fragment_shader_texture1, "ctex1_d.a = 0.0; \n"); + } - if(d_invert) - { - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctex0_d.a = 1.0 - ctex0_d.a; \n"); + if (d_invert) + { + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctex0_d.a = 1.0 - ctex0_d.a; \n"); + else + strcat(fragment_shader_texture1, "ctex1_d.a = 1.0 - ctex1_d.a; \n"); + } + + if (num_tex == 0) + strcat(fragment_shader_texture0, "ctexture0.a = (ctex0_a.a + ctex0_b.a) * ctex0_c.a + ctex0_d.a; \n"); else - strcat(fragment_shader_texture1, "ctex1_d.a = 1.0 - ctex1_d.a; \n"); - } + strcat(fragment_shader_texture1, "ctexture1.a = (ctex1_a.a + ctex1_b.a) * ctex1_c.a + ctex1_d.a; \n"); - if(num_tex == 0) - strcat(fragment_shader_texture0, "ctexture0.a = (ctex0_a.a + ctex0_b.a) * ctex0_c.a + ctex0_d.a; \n"); - else - strcat(fragment_shader_texture1, "ctexture1.a = (ctex1_a.a + ctex1_b.a) * ctex1_c.a + ctex1_d.a; \n"); - - need_to_compile = 1; + need_to_compile = 1; } FX_ENTRY void FX_CALL grConstantColorValueExt(GrChipID_t tmu, - GrColor_t value) +GrColor_t value) { - int num_tex; - LOG("grConstantColorValueExt(%d,%d)\r\n", tmu, value); + int num_tex; + LOG("grConstantColorValueExt(%d,%d)\r\n", tmu, value); - if (tmu == GR_TMU0) num_tex = 1; - else num_tex = 0; + if (tmu == GR_TMU0) num_tex = 1; + else num_tex = 0; - switch(lfb_color_fmt) - { - case GR_COLORFORMAT_ARGB: - if(num_tex == 0) + switch (lfb_color_fmt) { - ccolor0[3] = ((value >> 24) & 0xFF) / 255.0f; - ccolor0[0] = ((value >> 16) & 0xFF) / 255.0f; - ccolor0[1] = ((value >> 8) & 0xFF) / 255.0f; - ccolor0[2] = (value & 0xFF) / 255.0f; + case GR_COLORFORMAT_ARGB: + if (num_tex == 0) + { + ccolor0[3] = ((value >> 24) & 0xFF) / 255.0f; + ccolor0[0] = ((value >> 16) & 0xFF) / 255.0f; + ccolor0[1] = ((value >> 8) & 0xFF) / 255.0f; + ccolor0[2] = (value & 0xFF) / 255.0f; + } + else + { + ccolor1[3] = ((value >> 24) & 0xFF) / 255.0f; + ccolor1[0] = ((value >> 16) & 0xFF) / 255.0f; + ccolor1[1] = ((value >> 8) & 0xFF) / 255.0f; + ccolor1[2] = (value & 0xFF) / 255.0f; + } + break; + case GR_COLORFORMAT_RGBA: + if (num_tex == 0) + { + ccolor0[0] = ((value >> 24) & 0xFF) / 255.0f; + ccolor0[1] = ((value >> 16) & 0xFF) / 255.0f; + ccolor0[2] = ((value >> 8) & 0xFF) / 255.0f; + ccolor0[3] = (value & 0xFF) / 255.0f; + } + else + { + ccolor1[0] = ((value >> 24) & 0xFF) / 255.0f; + ccolor1[1] = ((value >> 16) & 0xFF) / 255.0f; + ccolor1[2] = ((value >> 8) & 0xFF) / 255.0f; + ccolor1[3] = (value & 0xFF) / 255.0f; + } + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grConstantColorValue: unknown color format : %x", lfb_color_fmt); + } + + vbo_draw(); + if (num_tex == 0) + { + ccolor0_location = glGetUniformLocation(program_object, "ccolor0"); + glUniform4f(ccolor0_location, ccolor0[0], ccolor0[1], ccolor0[2], ccolor0[3]); } else { - ccolor1[3] = ((value >> 24) & 0xFF) / 255.0f; - ccolor1[0] = ((value >> 16) & 0xFF) / 255.0f; - ccolor1[1] = ((value >> 8) & 0xFF) / 255.0f; - ccolor1[2] = (value & 0xFF) / 255.0f; + ccolor1_location = glGetUniformLocation(program_object, "ccolor1"); + glUniform4f(ccolor1_location, ccolor1[0], ccolor1[1], ccolor1[2], ccolor1[3]); } - break; - case GR_COLORFORMAT_RGBA: - if(num_tex == 0) - { - ccolor0[0] = ((value >> 24) & 0xFF) / 255.0f; - ccolor0[1] = ((value >> 16) & 0xFF) / 255.0f; - ccolor0[2] = ((value >> 8) & 0xFF) / 255.0f; - ccolor0[3] = (value & 0xFF) / 255.0f; - } - else - { - ccolor1[0] = ((value >> 24) & 0xFF) / 255.0f; - ccolor1[1] = ((value >> 16) & 0xFF) / 255.0f; - ccolor1[2] = ((value >> 8) & 0xFF) / 255.0f; - ccolor1[3] = (value & 0xFF) / 255.0f; - } - break; - default: - display_warning("grConstantColorValue: unknown color format : %x", lfb_color_fmt); - } - - vbo_draw(); - if(num_tex == 0) - { - ccolor0_location = glGetUniformLocation(program_object, "ccolor0"); - glUniform4f(ccolor0_location, ccolor0[0], ccolor0[1], ccolor0[2], ccolor0[3]); - } - else - { - ccolor1_location = glGetUniformLocation(program_object, "ccolor1"); - glUniform4f(ccolor1_location, ccolor1[0], ccolor1[1], ccolor1[2], ccolor1[3]); - } -} +} \ No newline at end of file diff --git a/Source/Glitch64/OGLESgeometry.cpp b/Source/Glitch64/OGLESgeometry.cpp index b2208c682..7e7a81bac 100644 --- a/Source/Glitch64/OGLESgeometry.cpp +++ b/Source/Glitch64/OGLESgeometry.cpp @@ -173,7 +173,7 @@ grCoordinateSpace( GrCoordinateSpaceMode_t mode ) case GR_WINDOW_COORDS: break; default: - display_warning("unknwown coordinate space : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "unknwown coordinate space : %x", mode); } } @@ -212,7 +212,7 @@ grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode) st1_off = offset; break; default: - display_warning("unknown grVertexLayout parameter : %x", param); + WriteTrace(TraceGlitch, TraceWarning, "unknown grVertexLayout parameter : %x", param); } } @@ -246,7 +246,7 @@ grCullMode( GrCullMode_t mode ) glEnable(GL_CULL_FACE); break; default: - display_warning("unknown cull mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "unknown cull mode : %x", mode); } } @@ -273,7 +273,7 @@ grDepthBufferMode( GrDepthBufferMode_t mode ) w_buffer_mode = 0; break; default: - display_warning("unknown depth buffer mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "unknown depth buffer mode : %x", mode); } } @@ -321,7 +321,7 @@ grDepthBufferFunction( GrCmpFnc_t function ) break; default: - display_warning("unknown depth buffer function : %x", function); + WriteTrace(TraceGlitch, TraceWarning, "unknown depth buffer function : %x", function); } } @@ -600,7 +600,7 @@ grDrawVertexArray(FxU32 mode, FxU32 Count, void *pointers2) if(mode != GR_TRIANGLE_FAN) { - display_warning("grDrawVertexArray : unknown mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "grDrawVertexArray : unknown mode : %x", mode); } vbo_enable(); @@ -638,6 +638,6 @@ grDrawVertexArrayContiguous(FxU32 mode, FxU32 Count, void *pointers, FxU32 strid vbo_buffer(GL_TRIANGLE_FAN,0,Count,pointers); break; default: - display_warning("grDrawVertexArrayContiguous : unknown mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "grDrawVertexArrayContiguous : unknown mode : %x", mode); } } diff --git a/Source/Glitch64/OGLESglitchmain.cpp b/Source/Glitch64/OGLESglitchmain.cpp index d634af00b..d3314cb39 100644 --- a/Source/Glitch64/OGLESglitchmain.cpp +++ b/Source/Glitch64/OGLESglitchmain.cpp @@ -48,49 +48,48 @@ #include #endif -extern void (*renderCallback)(int); +extern void(*renderCallback)(int); -wrapper_config config = {0, 0, 0, 0}; +wrapper_config config = { 0, 0, 0, 0 }; int screen_width, screen_height; /* static inline void opt_glCopyTexImage2D( GLenum target, - GLint level, - GLenum internalFormat, - GLint x, - GLint y, - GLsizei width, - GLsizei height, - GLint border ) +GLint level, +GLenum internalFormat, +GLint x, +GLint y, +GLsizei width, +GLsizei height, +GLint border ) { - int w, h, fmt; - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt); - //printf("copyteximage %dx%d fmt %x oldfmt %x\n", width, height, internalFormat, fmt); - if (w == (int) width && h == (int) height && fmt == (int) internalFormat) { - if (x+width >= screen_width) { - width = screen_width - x; - //printf("resizing w --> %d\n", width); - } - if (y+height >= screen_height+viewport_offset) { - height = screen_height+viewport_offset - y; - //printf("resizing h --> %d\n", height); - } - glCopyTexSubImage2D(target, level, 0, 0, x, y, width, height); - } else { - //printf("copyteximage %dx%d fmt %x old %dx%d oldfmt %x\n", width, height, internalFormat, w, h, fmt); - // glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, internalFormat, GL_UNSIGNED_BYTE, 0); - // glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt); - // printf("--> %dx%d newfmt %x\n", width, height, fmt); - glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); - } +int w, h, fmt; +glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); +glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); +glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt); +//printf("copyteximage %dx%d fmt %x oldfmt %x\n", width, height, internalFormat, fmt); +if (w == (int) width && h == (int) height && fmt == (int) internalFormat) { +if (x+width >= screen_width) { +width = screen_width - x; +//printf("resizing w --> %d\n", width); +} +if (y+height >= screen_height+viewport_offset) { +height = screen_height+viewport_offset - y; +//printf("resizing h --> %d\n", height); +} +glCopyTexSubImage2D(target, level, 0, 0, x, y, width, height); +} else { +//printf("copyteximage %dx%d fmt %x old %dx%d oldfmt %x\n", width, height, internalFormat, w, h, fmt); +// glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, internalFormat, GL_UNSIGNED_BYTE, 0); +// glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt); +// printf("--> %dx%d newfmt %x\n", width, height, fmt); +glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); +} } #define glCopyTexImage2D opt_glCopyTexImage2D */ - #ifdef _WIN32 PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; PFNGLBLENDFUNCSEPARATEEXTPROC glBlendFuncSeparateEXT; @@ -136,17 +135,15 @@ PFNGLSECONDARYCOLOR3FPROC glSecondaryColor3f; PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2DARB; #endif // _WIN32 - - typedef struct { - unsigned int address; - int width; - int height; - unsigned int fbid; - unsigned int zbid; - unsigned int texid; - int buff_clear; + unsigned int address; + int width; + int height; + unsigned int fbid; + unsigned int zbid; + unsigned int texid; + int buff_clear; } fb; int nbTextureUnits; @@ -196,63 +193,46 @@ static fb fbs[100]; static int nb_fb = 0; static unsigned int curBufferAddr = 0; -struct TMU_USAGE { int min, max; } tmu_usage[2] = { {0xfffffff, 0}, {0xfffffff, 0} }; +struct TMU_USAGE { int min, max; } tmu_usage[2] = { { 0xfffffff, 0 }, { 0xfffffff, 0 } }; struct texbuf_t { - FxU32 start, end; - int fmt; + FxU32 start, end; + int fmt; }; #define NB_TEXBUFS 128 // MUST be a power of two static texbuf_t texbufs[NB_TEXBUFS]; static int texbuf_i; -unsigned short frameBuffer[2048*2048]; -unsigned short depthBuffer[2048*2048]; +unsigned short frameBuffer[2048 * 2048]; +unsigned short depthBuffer[2048 * 2048]; //#define VOODOO1 -void display_warning(const char *text, ...) -{ - static int first_message = 100; - if (first_message) - { - char buf[4096]; - - va_list ap; - - va_start(ap, text); - vsprintf(buf, text, ap); - va_end(ap); - first_message--; - LOGINFO(buf); - } -} - #ifdef _WIN32 void display_error() { - LPVOID lpMsgBuf; - if (!FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL )) - { - // Handle the error. - return; - } - // Process any inserts in lpMsgBuf. - // ... - // Display the string. - MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); + LPVOID lpMsgBuf; + if (!FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR)&lpMsgBuf, + 0, + NULL)) + { + // Handle the error. + return; + } + // Process any inserts in lpMsgBuf. + // ... + // Display the string. + MessageBox(NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION); - // Free the buffer. - LocalFree( lpMsgBuf ); + // Free the buffer. + LocalFree(lpMsgBuf); } #endif // _WIN32 @@ -263,45 +243,45 @@ std::ofstream log_file; void OPEN_LOG() { - if (!log_open) - { - log_file.open ("wrapper_log.txt", std::ios_base::out|std::ios_base::app); - log_open = true; - } + if (!log_open) + { + log_file.open ("wrapper_log.txt", std::ios_base::out|std::ios_base::app); + log_open = true; + } } void CLOSE_LOG() { - if (log_open) - { - log_file.close(); - log_open = false; - } + if (log_open) + { + log_file.close(); + log_open = false; + } } void LOG(const char *text, ...) { #ifdef VPDEBUG - if (!dumping) return; + if (!dumping) return; #endif - if (!log_open) - return; - va_list ap; - va_start(ap, text); - vsprintf(out_buf, text, ap); - log_file << out_buf; - log_file.flush(); - va_end(ap); + if (!log_open) + return; + va_list ap; + va_start(ap, text); + vsprintf(out_buf, text, ap); + log_file << out_buf; + log_file.flush(); + va_end(ap); } class LogManager { public: - LogManager() { - OPEN_LOG(); - } - ~LogManager() { - CLOSE_LOG(); - } + LogManager() { + OPEN_LOG(); + } + ~LogManager() { + CLOSE_LOG(); + } }; LogManager logManager; @@ -315,126 +295,127 @@ LogManager logManager; FX_ENTRY void FX_CALL grSstOrigin(GrOriginLocation_t origin) { - LOG("grSstOrigin(%d)\r\n", origin); - if (origin != GR_ORIGIN_UPPER_LEFT) - display_warning("grSstOrigin : %x", origin); + LOG("grSstOrigin(%d)\r\n", origin); + if (origin != GR_ORIGIN_UPPER_LEFT) + WriteTrace(TraceGlitch, TraceWarning, "grSstOrigin : %x", origin); } FX_ENTRY void FX_CALL -grClipWindow( FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy ) +grClipWindow(FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy) { - LOG("grClipWindow(%d,%d,%d,%d)\r\n", minx, miny, maxx, maxy); + LOG("grClipWindow(%d,%d,%d,%d)\r\n", minx, miny, maxx, maxy); - if (use_fbo && render_to_texture) { - if (int(minx) < 0) minx = 0; - if (int(miny) < 0) miny = 0; - if (maxx < minx) maxx = minx; - if (maxy < miny) maxy = miny; - glScissor(minx, miny, maxx - minx, maxy - miny); + if (use_fbo && render_to_texture) { + if (int(minx) < 0) minx = 0; + if (int(miny) < 0) miny = 0; + if (maxx < minx) maxx = minx; + if (maxy < miny) maxy = miny; + glScissor(minx, miny, maxx - minx, maxy - miny); + glEnable(GL_SCISSOR_TEST); + return; + } + + if (!use_fbo) { + int th = height; + if (th > screen_height) + th = screen_height; + maxy = th - maxy; + miny = th - miny; + FxU32 tmp = maxy; maxy = miny; miny = tmp; + if (maxx > (FxU32)width) maxx = width; + if (maxy > (FxU32)height) maxy = height; + if (int(minx) < 0) minx = 0; + if (int(miny) < 0) miny = 0; + if (maxx < minx) maxx = minx; + if (maxy < miny) maxy = miny; + glScissor(minx, miny + viewport_offset, maxx - minx, maxy - miny); + //printf("gl scissor %d %d %d %d\n", minx, miny, maxx, maxy); + } + else { + glScissor(minx, (viewport_offset)+height - maxy, maxx - minx, maxy - miny); + } glEnable(GL_SCISSOR_TEST); - return; - } - - if (!use_fbo) { - int th = height; - if (th > screen_height) - th = screen_height; - maxy = th - maxy; - miny = th - miny; - FxU32 tmp = maxy; maxy = miny; miny = tmp; - if (maxx > (FxU32) width) maxx = width; - if (maxy > (FxU32) height) maxy = height; - if (int(minx) < 0) minx = 0; - if (int(miny) < 0) miny = 0; - if (maxx < minx) maxx = minx; - if (maxy < miny) maxy = miny; - glScissor(minx, miny+viewport_offset, maxx - minx, maxy - miny); - //printf("gl scissor %d %d %d %d\n", minx, miny, maxx, maxy); - } else { - glScissor(minx, (viewport_offset)+height-maxy, maxx - minx, maxy - miny); - } - glEnable(GL_SCISSOR_TEST); } FX_ENTRY void FX_CALL -grColorMask( FxBool rgb, FxBool a ) +grColorMask(FxBool rgb, FxBool a) { - LOG("grColorMask(%d, %d)\r\n", rgb, a); - glColorMask(rgb, rgb, rgb, a); + LOG("grColorMask(%d, %d)\r\n", rgb, a); + glColorMask(rgb, rgb, rgb, a); } FX_ENTRY void FX_CALL -grGlideInit( void ) +grGlideInit(void) { - LOG("grGlideInit()\r\n"); + LOG("grGlideInit()\r\n"); } FX_ENTRY void FX_CALL -grSstSelect( int which_sst ) +grSstSelect(int which_sst) { - LOG("grSstSelect(%d)\r\n", which_sst); + LOG("grSstSelect(%d)\r\n", which_sst); } int isExtensionSupported(const char *extension) { - return 0; - const GLubyte *extensions = NULL; - const GLubyte *start; - GLubyte *where, *terminator; - - where = (GLubyte *)strchr(extension, ' '); - if (where || *extension == '\0') return 0; + const GLubyte *extensions = NULL; + const GLubyte *start; + GLubyte *where, *terminator; - extensions = glGetString(GL_EXTENSIONS); + where = (GLubyte *)strchr(extension, ' '); + if (where || *extension == '\0') + return 0; - start = extensions; - for (;;) - { - where = (GLubyte *) strstr((const char *) start, extension); - if (!where) - break; + extensions = glGetString(GL_EXTENSIONS); - terminator = where + strlen(extension); - if (where == start || *(where - 1) == ' ') - if (*terminator == ' ' || *terminator == '\0') - return 1; + start = extensions; + for (;;) + { + where = (GLubyte *)strstr((const char *)start, extension); + if (!where) + break; - start = terminator; - } + terminator = where + strlen(extension); + if (where == start || *(where - 1) == ' ') + if (*terminator == ' ' || *terminator == '\0') + return 1; - return 0; + start = terminator; + } + + return 0; } #ifdef _WIN32 int isWglExtensionSupported(const char *extension) { - const GLubyte *extensions = NULL; - const GLubyte *start; - GLubyte *where, *terminator; + const GLubyte *extensions = NULL; + const GLubyte *start; + GLubyte *where, *terminator; + + where = (GLubyte *)strchr(extension, ' '); + if (where || *extension == '\0') + return 0; + + extensions = (GLubyte*)wglGetExtensionsStringARB(wglGetCurrentDC()); + + start = extensions; + for (;;) + { + where = (GLubyte *)strstr((const char *)start, extension); + if (!where) + break; + + terminator = where + strlen(extension); + if (where == start || *(where - 1) == ' ') + if (*terminator == ' ' || *terminator == '\0') + return 1; + + start = terminator; + } - where = (GLubyte *)strchr(extension, ' '); - if (where || *extension == '\0') return 0; - - extensions = (GLubyte*)wglGetExtensionsStringARB(wglGetCurrentDC()); - - start = extensions; - for (;;) - { - where = (GLubyte *) strstr((const char *) start, extension); - if (!where) - break; - - terminator = where + strlen(extension); - if (where == start || *(where - 1) == ' ') - if (*terminator == ' ' || *terminator == '\0') - return 1; - - start = terminator; - } - - return 0; } #endif // _WIN32 @@ -442,18 +423,18 @@ int isWglExtensionSupported(const char *extension) FX_ENTRY GrContext_t FX_CALL grSstWinOpenExt( - HWND hWnd, - GrScreenResolution_t screen_resolution, - GrScreenRefresh_t refresh_rate, - GrColorFormat_t color_format, - GrOriginLocation_t origin_location, - GrPixelFormat_t pixelformat, - int nColBuffers, - int nAuxBuffers) +HWND hWnd, +GrScreenResolution_t screen_resolution, +GrScreenRefresh_t refresh_rate, +GrColorFormat_t color_format, +GrOriginLocation_t origin_location, +GrPixelFormat_t pixelformat, +int nColBuffers, +int nAuxBuffers) { - LOG("grSstWinOpenExt(%d, %d, %d, %d, %d, %d %d)\r\n", hWnd, screen_resolution, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers); - return grSstWinOpen(hWnd, screen_resolution, refresh_rate, color_format, - origin_location, nColBuffers, nAuxBuffers); + LOG("grSstWinOpenExt(%d, %d, %d, %d, %d, %d %d)\r\n", hWnd, screen_resolution, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers); + return grSstWinOpen(hWnd, screen_resolution, refresh_rate, color_format, + origin_location, nColBuffers, nAuxBuffers); } #ifdef WIN32 @@ -465,1620 +446,1620 @@ grSstWinOpenExt( FX_ENTRY GrContext_t FX_CALL grSstWinOpen( - HWND hWnd, - GrScreenResolution_t screen_resolution, - GrScreenRefresh_t refresh_rate, - GrColorFormat_t color_format, - GrOriginLocation_t origin_location, - int nColBuffers, - int nAuxBuffers) +HWND hWnd, +GrScreenResolution_t screen_resolution, +GrScreenRefresh_t refresh_rate, +GrColorFormat_t color_format, +GrOriginLocation_t origin_location, +int nColBuffers, +int nAuxBuffers) { - static int show_warning = 1; + static int show_warning = 1; - // ZIGGY - // allocate static texture names - // the initial value should be big enough to support the maximal resolution - free_texture = 32*2048*2048; - default_texture = free_texture++; - color_texture = free_texture++; - depth_texture = free_texture++; + // ZIGGY + // allocate static texture names + // the initial value should be big enough to support the maximal resolution + free_texture = 32 * 2048 * 2048; + default_texture = free_texture++; + color_texture = free_texture++; + depth_texture = free_texture++; - LOG("grSstWinOpen(%08lx, %d, %d, %d, %d, %d %d)\r\n", hWnd, screen_resolution&~0x80000000, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers); + LOG("grSstWinOpen(%08lx, %d, %d, %d, %d, %d %d)\r\n", hWnd, screen_resolution&~0x80000000, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers); #ifdef _WIN32 - if ((HWND)hWnd == NULL) hWnd = GetActiveWindow(); - hwnd_win = (HWND)hWnd; + if ((HWND)hWnd == NULL) hWnd = GetActiveWindow(); + hwnd_win = (HWND)hWnd; #endif // _WIN32 - width = height = 0; + width = height = 0; - m64p_handle video_general_section; - printf("&ConfigOpenSection is %p\n", &ConfigOpenSection); - if (ConfigOpenSection("Video-General", &video_general_section) != M64ERR_SUCCESS) - { - printf("Could not open video settings"); - return false; - } - width = ConfigGetParamInt(video_general_section, "ScreenWidth"); - height = ConfigGetParamInt(video_general_section, "ScreenHeight"); - fullscreen = ConfigGetParamBool(video_general_section, "Fullscreen"); - int vsync = ConfigGetParamBool(video_general_section, "VerticalSync"); - //viewport_offset = ((screen_resolution>>2) > 20) ? screen_resolution >> 2 : 20; - // ZIGGY viewport_offset is WIN32 specific, with SDL just set it to zero - viewport_offset = 0; //-10 //-20; - - CoreVideo_Init(); - CoreVideo_GL_SetAttribute(M64P_GL_DOUBLEBUFFER, 1); - CoreVideo_GL_SetAttribute(M64P_GL_SWAP_CONTROL, vsync); - CoreVideo_GL_SetAttribute(M64P_GL_BUFFER_SIZE, 16); - // SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); - // SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - // SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - // SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - // SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - CoreVideo_GL_SetAttribute(M64P_GL_DEPTH_SIZE, 16); - - printf("(II) Setting video mode %dx%d...\n", width, height); - if(CoreVideo_SetVideoMode(width, height, 0, fullscreen ? M64VIDEO_FULLSCREEN : M64VIDEO_WINDOWED, (m64p_video_flags) 0) != M64ERR_SUCCESS) - { - printf("(EE) Error setting videomode %dx%d\n", width, height); - return false; - } - - char caption[500]; -# ifdef _DEBUG - sprintf(caption, "Glide64mk2 debug"); -# else // _DEBUG - sprintf(caption, "Glide64mk2"); -# endif // _DEBUG - CoreVideo_SetCaption(caption); - - glViewport(0, viewport_offset, width, height); - lfb_color_fmt = color_format; - if (origin_location != GR_ORIGIN_UPPER_LEFT) display_warning("origin must be in upper left corner"); - if (nColBuffers != 2) display_warning("number of color buffer is not 2"); - if (nAuxBuffers != 1) display_warning("number of auxiliary buffer is not 1"); - - if (isExtensionSupported("GL_ARB_texture_env_combine") == 0 && - isExtensionSupported("GL_EXT_texture_env_combine") == 0 && - show_warning) - display_warning("Your video card doesn't support GL_ARB_texture_env_combine extension"); - if (isExtensionSupported("GL_ARB_multitexture") == 0 && show_warning) - display_warning("Your video card doesn't support GL_ARB_multitexture extension"); - if (isExtensionSupported("GL_ARB_texture_mirrored_repeat") == 0 && show_warning) - display_warning("Your video card doesn't support GL_ARB_texture_mirrored_repeat extension"); - show_warning = 0; - -#ifdef _WIN32 - glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress("glActiveTextureARB"); - glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC)wglGetProcAddress("glMultiTexCoord2fARB"); -#endif // _WIN32 - - nbTextureUnits = 4; - //glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &nbTextureUnits); - if (nbTextureUnits == 1) display_warning("You need a video card that has at least 2 texture units"); - - nbAuxBuffers = 4; - //glGetIntegerv(GL_AUX_BUFFERS, &nbAuxBuffers); - if (nbAuxBuffers > 0) - printf("Congratulations, you have %d auxilliary buffers, we'll use them wisely !\n", nbAuxBuffers); -#ifdef VOODOO1 - nbTextureUnits = 2; -#endif - - blend_func_separate_support = 1; - packed_pixels_support = 0; -/* - if (isExtensionSupported("GL_EXT_blend_func_separate") == 0) - blend_func_separate_support = 0; - else - blend_func_separate_support = 1; - - if (isExtensionSupported("GL_EXT_packed_pixels") == 0) - packed_pixels_support = 0; - else { - printf("packed pixels extension used\n"); - packed_pixels_support = 1; - } -*/ - - if (isExtensionSupported("GL_ARB_texture_non_power_of_two") == 0) - npot_support = 0; - else { - printf("NPOT extension used\n"); - npot_support = 1; - } - -#ifdef _WIN32 - glBlendFuncSeparateEXT = (PFNGLBLENDFUNCSEPARATEEXTPROC)wglGetProcAddress("glBlendFuncSeparateEXT"); -#endif // _WIN32 - - if (isExtensionSupported("GL_EXT_fog_coord") == 0) - fog_coord_support = 0; - else - fog_coord_support = 1; - -#ifdef _WIN32 - glFogCoordfEXT = (PFNGLFOGCOORDFPROC)wglGetProcAddress("glFogCoordfEXT"); -#endif // _WIN32 - -#ifdef _WIN32 - wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); -#endif // _WIN32 - -#ifdef _WIN32 - glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)wglGetProcAddress("glBindFramebufferEXT"); - glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)wglGetProcAddress("glFramebufferTexture2DEXT"); - glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)wglGetProcAddress("glGenFramebuffersEXT"); - glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)wglGetProcAddress("glCheckFramebufferStatusEXT"); - glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)wglGetProcAddress("glDeleteFramebuffersEXT"); - - glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)wglGetProcAddress("glBindRenderbufferEXT"); - glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)wglGetProcAddress("glDeleteRenderbuffersEXT"); - glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)wglGetProcAddress("glGenRenderbuffersEXT"); - glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)wglGetProcAddress("glRenderbufferStorageEXT"); - glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)wglGetProcAddress("glFramebufferRenderbufferEXT"); - use_fbo = config.fbo && (glFramebufferRenderbufferEXT != NULL); -#else - use_fbo = config.fbo; -#endif // _WIN32 - - LOGINFO("use_fbo %d\n", use_fbo); - - if (isExtensionSupported("GL_ARB_shading_language_100") && - isExtensionSupported("GL_ARB_shader_objects") && - isExtensionSupported("GL_ARB_fragment_shader") && - isExtensionSupported("GL_ARB_vertex_shader")) - { - -#ifdef _WIN32 - glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)wglGetProcAddress("glCreateShaderObjectARB"); - glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB"); - glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)wglGetProcAddress("glCompileShaderARB"); - glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)wglGetProcAddress("glCreateProgramObjectARB"); - glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)wglGetProcAddress("glAttachObjectARB"); - glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)wglGetProcAddress("glLinkProgramARB"); - glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)wglGetProcAddress("glUseProgramObjectARB"); - glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)wglGetProcAddress("glGetUniformLocationARB"); - glUniform1iARB = (PFNGLUNIFORM1IARBPROC)wglGetProcAddress("glUniform1iARB"); - glUniform4iARB = (PFNGLUNIFORM4IARBPROC)wglGetProcAddress("glUniform4iARB"); - glUniform4fARB = (PFNGLUNIFORM4FARBPROC)wglGetProcAddress("glUniform4fARB"); - glUniform1fARB = (PFNGLUNIFORM1FARBPROC)wglGetProcAddress("glUniform1fARB"); - glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)wglGetProcAddress("glDeleteObjectARB"); - glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)wglGetProcAddress("glGetInfoLogARB"); - glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)wglGetProcAddress("glGetObjectParameterivARB"); - - glSecondaryColor3f = (PFNGLSECONDARYCOLOR3FPROC)wglGetProcAddress("glSecondaryColor3f"); -#endif // _WIN32 - } - - if (isExtensionSupported("GL_EXT_texture_compression_s3tc") == 0 && show_warning) - display_warning("Your video card doesn't support GL_EXT_texture_compression_s3tc extension"); - if (isExtensionSupported("GL_3DFX_texture_compression_FXT1") == 0 && show_warning) - display_warning("Your video card doesn't support GL_3DFX_texture_compression_FXT1 extension"); - -#ifdef _WIN32 - glCompressedTexImage2DARB = (PFNGLCOMPRESSEDTEXIMAGE2DPROC)wglGetProcAddress("glCompressedTexImage2DARB"); -#endif - - -#ifdef _WIN32 - glViewport(0, viewport_offset, width, height); - viewport_width = width; - viewport_height = height; - nvidia_viewport_hack = 1; -#else - glViewport(0, viewport_offset, width, height); - viewport_width = width; - viewport_height = height; -#endif // _WIN32 - - // void do_benchmarks(); - // do_benchmarks(); - - // VP try to resolve z precision issues -// glMatrixMode(GL_MODELVIEW); -// glLoadIdentity(); -// glTranslatef(0, 0, 1-zscale); -// glScalef(1, 1, zscale); - - widtho = width/2; - heighto = height/2; - - pBufferWidth = pBufferHeight = -1; - - current_buffer = GL_BACK; - - texture_unit = GL_TEXTURE0; - - { - int i; - for (i=0; i>2) > 20) ? screen_resolution >> 2 : 20; + // ZIGGY viewport_offset is WIN32 specific, with SDL just set it to zero + viewport_offset = 0; //-10 //-20; - //void FindBestDepthBias(); - //FindBestDepthBias(); + CoreVideo_Init(); + CoreVideo_GL_SetAttribute(M64P_GL_DOUBLEBUFFER, 1); + CoreVideo_GL_SetAttribute(M64P_GL_SWAP_CONTROL, vsync); + CoreVideo_GL_SetAttribute(M64P_GL_BUFFER_SIZE, 16); + // SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); + // SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + // SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + // SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + // SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + CoreVideo_GL_SetAttribute(M64P_GL_DEPTH_SIZE, 16); - init_geometry(); - init_textures(); - init_combiner(); + printf("(II) Setting video mode %dx%d...\n", width, height); + if (CoreVideo_SetVideoMode(width, height, 0, fullscreen ? M64VIDEO_FULLSCREEN : M64VIDEO_WINDOWED, (m64p_video_flags)0) != M64ERR_SUCCESS) + { + printf("(EE) Error setting videomode %dx%d\n", width, height); + return false; + } -/* - // Aniso filter check - if (config.anisofilter > 0 ) - glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest_supported_anisotropy); + char caption[500]; +# ifdef _DEBUG + sprintf(caption, "Glide64mk2 debug"); +# else // _DEBUG + sprintf(caption, "Glide64mk2"); +# endif // _DEBUG + CoreVideo_SetCaption(caption); - // ATI hack - certain texture formats are slow on ATI? - // Hmm, perhaps the internal format need to be specified explicitly... - { - GLint ifmt; - glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); - glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &ifmt); - if (ifmt != GL_RGB5_A1) { - display_warning("ATI SUCKS %x\n", ifmt); + glViewport(0, viewport_offset, width, height); + lfb_color_fmt = color_format; + if (origin_location != GR_ORIGIN_UPPER_LEFT) WriteTrace(TraceGlitch, TraceWarning, "origin must be in upper left corner"); + if (nColBuffers != 2) WriteTrace(TraceGlitch, TraceWarning, "number of color buffer is not 2"); + if (nAuxBuffers != 1) WriteTrace(TraceGlitch, TraceWarning, "number of auxiliary buffer is not 1"); + + if (isExtensionSupported("GL_ARB_texture_env_combine") == 0 && + isExtensionSupported("GL_EXT_texture_env_combine") == 0 && + show_warning) + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_ARB_texture_env_combine extension"); + if (isExtensionSupported("GL_ARB_multitexture") == 0 && show_warning) + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_ARB_multitexture extension"); + if (isExtensionSupported("GL_ARB_texture_mirrored_repeat") == 0 && show_warning) + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_ARB_texture_mirrored_repeat extension"); + show_warning = 0; + +#ifdef _WIN32 + glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress("glActiveTextureARB"); + glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC)wglGetProcAddress("glMultiTexCoord2fARB"); +#endif // _WIN32 + + nbTextureUnits = 4; + //glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &nbTextureUnits); + if (nbTextureUnits == 1) WriteTrace(TraceGlitch, TraceWarning, "You need a video card that has at least 2 texture units"); + + nbAuxBuffers = 4; + //glGetIntegerv(GL_AUX_BUFFERS, &nbAuxBuffers); + if (nbAuxBuffers > 0) + printf("Congratulations, you have %d auxilliary buffers, we'll use them wisely !\n", nbAuxBuffers); +#ifdef VOODOO1 + nbTextureUnits = 2; +#endif + + blend_func_separate_support = 1; + packed_pixels_support = 0; + /* + if (isExtensionSupported("GL_EXT_blend_func_separate") == 0) + blend_func_separate_support = 0; + else + blend_func_separate_support = 1; + + if (isExtensionSupported("GL_EXT_packed_pixels") == 0) + packed_pixels_support = 0; + else { + printf("packed pixels extension used\n"); + packed_pixels_support = 1; + } + */ + + if (isExtensionSupported("GL_ARB_texture_non_power_of_two") == 0) + npot_support = 0; + else { + printf("NPOT extension used\n"); + npot_support = 1; + } + +#ifdef _WIN32 + glBlendFuncSeparateEXT = (PFNGLBLENDFUNCSEPARATEEXTPROC)wglGetProcAddress("glBlendFuncSeparateEXT"); +#endif // _WIN32 + + if (isExtensionSupported("GL_EXT_fog_coord") == 0) + fog_coord_support = 0; + else + fog_coord_support = 1; + +#ifdef _WIN32 + glFogCoordfEXT = (PFNGLFOGCOORDFPROC)wglGetProcAddress("glFogCoordfEXT"); +#endif // _WIN32 + +#ifdef _WIN32 + wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); +#endif // _WIN32 + +#ifdef _WIN32 + glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)wglGetProcAddress("glBindFramebufferEXT"); + glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)wglGetProcAddress("glFramebufferTexture2DEXT"); + glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)wglGetProcAddress("glGenFramebuffersEXT"); + glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)wglGetProcAddress("glCheckFramebufferStatusEXT"); + glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)wglGetProcAddress("glDeleteFramebuffersEXT"); + + glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)wglGetProcAddress("glBindRenderbufferEXT"); + glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)wglGetProcAddress("glDeleteRenderbuffersEXT"); + glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)wglGetProcAddress("glGenRenderbuffersEXT"); + glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)wglGetProcAddress("glRenderbufferStorageEXT"); + glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)wglGetProcAddress("glFramebufferRenderbufferEXT"); + use_fbo = config.fbo && (glFramebufferRenderbufferEXT != NULL); +#else + use_fbo = config.fbo; +#endif // _WIN32 + + LOGINFO("use_fbo %d\n", use_fbo); + + if (isExtensionSupported("GL_ARB_shading_language_100") && + isExtensionSupported("GL_ARB_shader_objects") && + isExtensionSupported("GL_ARB_fragment_shader") && + isExtensionSupported("GL_ARB_vertex_shader")) + { +#ifdef _WIN32 + glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)wglGetProcAddress("glCreateShaderObjectARB"); + glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB"); + glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)wglGetProcAddress("glCompileShaderARB"); + glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)wglGetProcAddress("glCreateProgramObjectARB"); + glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)wglGetProcAddress("glAttachObjectARB"); + glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)wglGetProcAddress("glLinkProgramARB"); + glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)wglGetProcAddress("glUseProgramObjectARB"); + glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)wglGetProcAddress("glGetUniformLocationARB"); + glUniform1iARB = (PFNGLUNIFORM1IARBPROC)wglGetProcAddress("glUniform1iARB"); + glUniform4iARB = (PFNGLUNIFORM4IARBPROC)wglGetProcAddress("glUniform4iARB"); + glUniform4fARB = (PFNGLUNIFORM4FARBPROC)wglGetProcAddress("glUniform4fARB"); + glUniform1fARB = (PFNGLUNIFORM1FARBPROC)wglGetProcAddress("glUniform1fARB"); + glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)wglGetProcAddress("glDeleteObjectARB"); + glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)wglGetProcAddress("glGetInfoLogARB"); + glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)wglGetProcAddress("glGetObjectParameterivARB"); + + glSecondaryColor3f = (PFNGLSECONDARYCOLOR3FPROC)wglGetProcAddress("glSecondaryColor3f"); +#endif // _WIN32 + } + + if (isExtensionSupported("GL_EXT_texture_compression_s3tc") == 0 && show_warning) + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_EXT_texture_compression_s3tc extension"); + if (isExtensionSupported("GL_3DFX_texture_compression_FXT1") == 0 && show_warning) + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_3DFX_texture_compression_FXT1 extension"); + +#ifdef _WIN32 + glCompressedTexImage2DARB = (PFNGLCOMPRESSEDTEXIMAGE2DPROC)wglGetProcAddress("glCompressedTexImage2DARB"); +#endif + +#ifdef _WIN32 + glViewport(0, viewport_offset, width, height); + viewport_width = width; + viewport_height = height; + nvidia_viewport_hack = 1; +#else + glViewport(0, viewport_offset, width, height); + viewport_width = width; + viewport_height = height; +#endif // _WIN32 + + // void do_benchmarks(); + // do_benchmarks(); + + // VP try to resolve z precision issues + // glMatrixMode(GL_MODELVIEW); + // glLoadIdentity(); + // glTranslatef(0, 0, 1-zscale); + // glScalef(1, 1, zscale); + + widtho = width / 2; + heighto = height / 2; + + pBufferWidth = pBufferHeight = -1; + + current_buffer = GL_BACK; + + texture_unit = GL_TEXTURE0; + + { + int i; + for (i = 0; i < NB_TEXBUFS; i++) + texbufs[i].start = texbufs[i].end = 0xffffffff; + } + + if (!use_fbo && nbAuxBuffers == 0) { + // create the framebuffer saving texture + int w = width, h = height; + glBindTexture(GL_TEXTURE_2D, color_texture); + if (!npot_support) { + w = h = 1; + while (w < width) w *= 2; + while (h < height) h *= 2; + } + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); + glBindTexture(GL_TEXTURE_2D, 0); + save_w = save_h = 0; + } + + //void FindBestDepthBias(); + //FindBestDepthBias(); + + init_geometry(); + init_textures(); + init_combiner(); + + /* + // Aniso filter check + if (config.anisofilter > 0 ) + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest_supported_anisotropy); + + // ATI hack - certain texture formats are slow on ATI? + // Hmm, perhaps the internal format need to be specified explicitly... + { + GLint ifmt; + glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); + glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &ifmt); + if (ifmt != GL_RGB5_A1) { + WriteTrace(TraceGlitch, TraceWarning, "ATI SUCKS %x\n", ifmt); ati_sucks = 1; - } else + } else ati_sucks = 0; - } -*/ + } + */ - return 1; + return 1; } FX_ENTRY void FX_CALL -grGlideShutdown( void ) +grGlideShutdown(void) { - LOG("grGlideShutdown\r\n"); + LOG("grGlideShutdown\r\n"); } FX_ENTRY FxBool FX_CALL -grSstWinClose( GrContext_t context ) +grSstWinClose(GrContext_t context) { - int i, clear_texbuff = use_fbo; - LOG("grSstWinClose(%d)\r\n", context); + int i, clear_texbuff = use_fbo; + LOG("grSstWinClose(%d)\r\n", context); - for (i=0; i<2; i++) { - tmu_usage[i].min = 0xfffffff; - tmu_usage[i].max = 0; - invtex[i] = 0; - } - - free_combiners(); -#ifndef WIN32 - try // I don't know why, but opengl can be killed before this function call when emulator is closed (Gonetz). - // ZIGGY : I found the problem : it is a function pointer, when the extension isn't supported , it is then zero, so just need to check the pointer prior to do the call. - { - if (use_fbo) - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - } - catch (...) - { - clear_texbuff = 0; - } - - if (clear_texbuff) - { - for (i=0; i> -aspect; + } + else + { + pBufferWidth = 1 << lodmin; + pBufferHeight = pBufferWidth >> aspect; + } - if (aspect < 0) - { - pBufferHeight = 1 << lodmin; - pBufferWidth = pBufferHeight >> -aspect; - } - else - { - pBufferWidth = 1 << lodmin; - pBufferHeight = pBufferWidth >> aspect; - } - - if (curBufferAddr && startAddress+1 != curBufferAddr) - updateTexture(); + if (curBufferAddr && startAddress + 1 != curBufferAddr) + updateTexture(); #ifdef SAVE_CBUFFER - //printf("saving %dx%d\n", pBufferWidth, pBufferHeight); - // save color buffer - if (nbAuxBuffers > 0) { - //glDrawBuffer(GL_AUX0); - //current_buffer = GL_AUX0; - } else { - int tw, th; - if (pBufferWidth < screen_width) - tw = pBufferWidth; - else - tw = screen_width; - if (pBufferHeight < screen_height) - th = pBufferHeight; - else - th = screen_height; - //glReadBuffer(GL_BACK); - glActiveTexture(texture_unit); - glBindTexture(GL_TEXTURE_2D, color_texture); - // save incrementally the framebuffer - if (save_w) { - if (tw > save_w && th > save_h) { - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, save_h, - 0, viewport_offset+save_h, tw, th-save_h); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, save_w, 0, - save_w, viewport_offset, tw-save_w, save_h); - save_w = tw; - save_h = th; - } else if (tw > save_w) { - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, save_w, 0, - save_w, viewport_offset, tw-save_w, save_h); - save_w = tw; - } else if (th > save_h) { - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, save_h, - 0, viewport_offset+save_h, save_w, th-save_h); - save_h = th; + //printf("saving %dx%d\n", pBufferWidth, pBufferHeight); + // save color buffer + if (nbAuxBuffers > 0) { + //glDrawBuffer(GL_AUX0); + //current_buffer = GL_AUX0; + } + else { + int tw, th; + if (pBufferWidth < screen_width) + tw = pBufferWidth; + else + tw = screen_width; + if (pBufferHeight < screen_height) + th = pBufferHeight; + else + th = screen_height; + //glReadBuffer(GL_BACK); + glActiveTexture(texture_unit); + glBindTexture(GL_TEXTURE_2D, color_texture); + // save incrementally the framebuffer + if (save_w) { + if (tw > save_w && th > save_h) { + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, save_h, + 0, viewport_offset + save_h, tw, th - save_h); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, save_w, 0, + save_w, viewport_offset, tw - save_w, save_h); + save_w = tw; + save_h = th; + } + else if (tw > save_w) { + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, save_w, 0, + save_w, viewport_offset, tw - save_w, save_h); + save_w = tw; + } + else if (th > save_h) { + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, save_h, + 0, viewport_offset + save_h, save_w, th - save_h); + save_h = th; + } + } + else { + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, + 0, viewport_offset, tw, th); + save_w = tw; + save_h = th; + } + glBindTexture(GL_TEXTURE_2D, default_texture); } - } else { - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, - 0, viewport_offset, tw, th); - save_w = tw; - save_h = th; - } - glBindTexture(GL_TEXTURE_2D, default_texture); - } #endif - if (startAddress+1 != curBufferAddr || - (curBufferAddr == 0L && nbAuxBuffers == 0)) - buffer_cleared = 0; + if (startAddress + 1 != curBufferAddr || + (curBufferAddr == 0L && nbAuxBuffers == 0)) + buffer_cleared = 0; - curBufferAddr = pBufferAddress = startAddress+1; - pBufferFmt = fmt; + curBufferAddr = pBufferAddress = startAddress + 1; + pBufferFmt = fmt; - int rtmu = startAddress < grTexMinAddress(GR_TMU1)? 0 : 1; - int size = pBufferWidth*pBufferHeight*2; //grTexFormatSize(fmt); - if ((unsigned int) tmu_usage[rtmu].min > pBufferAddress) - tmu_usage[rtmu].min = pBufferAddress; - if ((unsigned int) tmu_usage[rtmu].max < pBufferAddress+size) - tmu_usage[rtmu].max = pBufferAddress+size; - // printf("tmu %d usage now %gMb - %gMb\n", - // rtmu, tmu_usage[rtmu].min/1024.0f, tmu_usage[rtmu].max/1024.0f); + int rtmu = startAddress < grTexMinAddress(GR_TMU1) ? 0 : 1; + int size = pBufferWidth*pBufferHeight * 2; //grTexFormatSize(fmt); + if ((unsigned int)tmu_usage[rtmu].min > pBufferAddress) + tmu_usage[rtmu].min = pBufferAddress; + if ((unsigned int)tmu_usage[rtmu].max < pBufferAddress + size) + tmu_usage[rtmu].max = pBufferAddress + size; + // printf("tmu %d usage now %gMb - %gMb\n", + // rtmu, tmu_usage[rtmu].min/1024.0f, tmu_usage[rtmu].max/1024.0f); + width = pBufferWidth; + height = pBufferHeight; - width = pBufferWidth; - height = pBufferHeight; + widtho = width / 2; + heighto = height / 2; - widtho = width/2; - heighto = height/2; + // this could be improved, but might be enough as long as the set of + // texture buffer addresses stay small + for (i = (texbuf_i - 1)&(NB_TEXBUFS - 1); i != texbuf_i; i = (i - 1)&(NB_TEXBUFS - 1)) + if (texbufs[i].start == pBufferAddress) + break; + texbufs[i].start = pBufferAddress; + texbufs[i].end = pBufferAddress + size; + texbufs[i].fmt = fmt; + if (i == texbuf_i) + texbuf_i = (texbuf_i + 1)&(NB_TEXBUFS - 1); + //printf("texbuf %x fmt %x\n", pBufferAddress, fmt); - // this could be improved, but might be enough as long as the set of - // texture buffer addresses stay small - for (i=(texbuf_i-1)&(NB_TEXBUFS-1) ; i!=texbuf_i; i=(i-1)&(NB_TEXBUFS-1)) - if (texbufs[i].start == pBufferAddress) - break; - texbufs[i].start = pBufferAddress; - texbufs[i].end = pBufferAddress + size; - texbufs[i].fmt = fmt; - if (i == texbuf_i) - texbuf_i = (texbuf_i+1)&(NB_TEXBUFS-1); - //printf("texbuf %x fmt %x\n", pBufferAddress, fmt); + // ZIGGY it speeds things up to not delete the buffers + // a better thing would be to delete them *sometimes* + // remove_tex(pBufferAddress+1, pBufferAddress + size); + add_tex(pBufferAddress); - // ZIGGY it speeds things up to not delete the buffers - // a better thing would be to delete them *sometimes* - // remove_tex(pBufferAddress+1, pBufferAddress + size); - add_tex(pBufferAddress); - - //printf("viewport %dx%d\n", width, height); - if (height > screen_height) { - glViewport( 0, viewport_offset + screen_height - height, width, height); - } else - glViewport( 0, viewport_offset, width, height); - - glScissor(0, viewport_offset, width, height); - - - } else { - if (!render_to_texture) //initialization - { - if(!fbs_init) - { - for(i=0; i<100; i++) fbs[i].address = 0; - fbs_init = 1; - nb_fb = 0; - } - return; //no need to allocate FBO if render buffer is not texture buffer - } - - render_to_texture = 2; - - if (aspect < 0) - { - pBufferHeight = 1 << lodmin; - pBufferWidth = pBufferHeight >> -aspect; - } - else - { - pBufferWidth = 1 << lodmin; - pBufferHeight = pBufferWidth >> aspect; - } - pBufferAddress = startAddress+1; - - width = pBufferWidth; - height = pBufferHeight; - - widtho = width/2; - heighto = height/2; - - for (i=0; i screen_height) { + glViewport(0, viewport_offset + screen_height - height, width, height); } - else //create new FBO at the same address, delete old one - { - glDeleteFramebuffers( 1, &(fbs[i].fbid) ); - glDeleteRenderbuffers( 1, &(fbs[i].zbid) ); - if (nb_fb > 1) - memmove(&(fbs[i]), &(fbs[i+1]), sizeof(fb)*(nb_fb-i)); - nb_fb--; - break; - } - } + else + glViewport(0, viewport_offset, width, height); + + glScissor(0, viewport_offset, width, height); } + else { + if (!render_to_texture) //initialization + { + if (!fbs_init) + { + for (i = 0; i < 100; i++) fbs[i].address = 0; + fbs_init = 1; + nb_fb = 0; + } + return; //no need to allocate FBO if render buffer is not texture buffer + } - remove_tex(pBufferAddress, pBufferAddress + width*height*2/*grTexFormatSize(fmt)*/); - //create new FBO - glGenFramebuffers( 1, &(fbs[nb_fb].fbid) ); - glGenRenderbuffers( 1, &(fbs[nb_fb].zbid) ); - glBindRenderbuffer( GL_RENDERBUFFER, fbs[nb_fb].zbid ); - glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); - fbs[nb_fb].address = pBufferAddress; - fbs[nb_fb].width = width; - fbs[nb_fb].height = height; - fbs[nb_fb].texid = pBufferAddress; - fbs[nb_fb].buff_clear = 0; - add_tex(fbs[nb_fb].texid); - glBindTexture(GL_TEXTURE_2D, fbs[nb_fb].texid); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, - GL_RGB, GL_UNSIGNED_BYTE, NULL); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + render_to_texture = 2; - glBindFramebuffer( GL_FRAMEBUFFER, fbs[nb_fb].fbid); - glFramebufferTexture2D(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbs[nb_fb].texid, 0); - glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbs[nb_fb].zbid ); - glViewport(0,0,width,height); - glScissor(0,0,width,height); - glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); - glDepthMask(1); - glClear( GL_DEPTH_BUFFER_BIT ); - CHECK_FRAMEBUFFER_STATUS(); - curBufferAddr = pBufferAddress; - nb_fb++; - } + if (aspect < 0) + { + pBufferHeight = 1 << lodmin; + pBufferWidth = pBufferHeight >> -aspect; + } + else + { + pBufferWidth = 1 << lodmin; + pBufferHeight = pBufferWidth >> aspect; + } + pBufferAddress = startAddress + 1; + + width = pBufferWidth; + height = pBufferHeight; + + widtho = width / 2; + heighto = height / 2; + + for (i = 0; i < nb_fb; i++) + { + if (fbs[i].address == pBufferAddress) + { + if (fbs[i].width == width && fbs[i].height == height) //select already allocated FBO + { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, fbs[i].fbid); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbs[i].texid, 0); + glBindRenderbuffer(GL_RENDERBUFFER, fbs[i].zbid); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbs[i].zbid); + glViewport(0, 0, width, height); + glScissor(0, 0, width, height); + if (fbs[i].buff_clear) + { + glDepthMask(1); + glClear(GL_DEPTH_BUFFER_BIT); //clear z-buffer only. we may need content, stored in the frame buffer + fbs[i].buff_clear = 0; + } + CHECK_FRAMEBUFFER_STATUS(); + curBufferAddr = pBufferAddress; + return; + } + else //create new FBO at the same address, delete old one + { + glDeleteFramebuffers(1, &(fbs[i].fbid)); + glDeleteRenderbuffers(1, &(fbs[i].zbid)); + if (nb_fb > 1) + memmove(&(fbs[i]), &(fbs[i + 1]), sizeof(fb)*(nb_fb - i)); + nb_fb--; + break; + } + } + } + + remove_tex(pBufferAddress, pBufferAddress + width*height * 2/*grTexFormatSize(fmt)*/); + //create new FBO + glGenFramebuffers(1, &(fbs[nb_fb].fbid)); + glGenRenderbuffers(1, &(fbs[nb_fb].zbid)); + glBindRenderbuffer(GL_RENDERBUFFER, fbs[nb_fb].zbid); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); + fbs[nb_fb].address = pBufferAddress; + fbs[nb_fb].width = width; + fbs[nb_fb].height = height; + fbs[nb_fb].texid = pBufferAddress; + fbs[nb_fb].buff_clear = 0; + add_tex(fbs[nb_fb].texid); + glBindTexture(GL_TEXTURE_2D, fbs[nb_fb].texid); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, + GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glBindFramebuffer(GL_FRAMEBUFFER, fbs[nb_fb].fbid); + glFramebufferTexture2D(GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbs[nb_fb].texid, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbs[nb_fb].zbid); + glViewport(0, 0, width, height); + glScissor(0, 0, width, height); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glDepthMask(1); + glClear(GL_DEPTH_BUFFER_BIT); + CHECK_FRAMEBUFFER_STATUS(); + curBufferAddr = pBufferAddress; + nb_fb++; + } } -int CheckTextureBufferFormat(GrChipID_t tmu, FxU32 startAddress, GrTexInfo *info ) +int CheckTextureBufferFormat(GrChipID_t tmu, FxU32 startAddress, GrTexInfo *info) { - int found, i; - if (!use_fbo) { - for (found=i=0; i<2; i++) - if ((FxU32) tmu_usage[i].min <= startAddress && (FxU32) tmu_usage[i].max > startAddress) { - //printf("tmu %d == framebuffer %x\n", tmu, startAddress); - found = 1; - break; - } - } else { - found = i = 0; - while (i < nb_fb) - { - unsigned int end = fbs[i].address + fbs[i].width*fbs[i].height*2; - if (startAddress >= fbs[i].address && startAddress < end) - { - found = 1; - break; - } - i++; + int found, i; + if (!use_fbo) { + for (found = i = 0; i < 2; i++) + if ((FxU32)tmu_usage[i].min <= startAddress && (FxU32)tmu_usage[i].max > startAddress) { + //printf("tmu %d == framebuffer %x\n", tmu, startAddress); + found = 1; + break; + } + } + else { + found = i = 0; + while (i < nb_fb) + { + unsigned int end = fbs[i].address + fbs[i].width*fbs[i].height * 2; + if (startAddress >= fbs[i].address && startAddress < end) + { + found = 1; + break; + } + i++; + } } - } - if (!use_fbo && found) { - int tw, th, rh, cw, ch; - if (info->aspectRatioLog2 < 0) - { - th = 1 << info->largeLodLog2; - tw = th >> -info->aspectRatioLog2; + if (!use_fbo && found) { + int tw, th, rh, cw, ch; + if (info->aspectRatioLog2 < 0) + { + th = 1 << info->largeLodLog2; + tw = th >> -info->aspectRatioLog2; + } + else + { + tw = 1 << info->largeLodLog2; + th = tw >> info->aspectRatioLog2; + } + + if (info->aspectRatioLog2 < 0) + { + ch = 256; + cw = ch >> -info->aspectRatioLog2; + } + else + { + cw = 256; + ch = cw >> info->aspectRatioLog2; + } + + if (use_fbo || th < screen_height) + rh = th; + else + rh = screen_height; + + //printf("th %d rh %d ch %d\n", th, rh, ch); + + invtex[tmu] = 1.0f - (th - rh) / (float)th; } else - { - tw = 1 << info->largeLodLog2; - th = tw >> info->aspectRatioLog2; - } + invtex[tmu] = 0; - if (info->aspectRatioLog2 < 0) - { - ch = 256; - cw = ch >> -info->aspectRatioLog2; + if (info->format == GR_TEXFMT_ALPHA_INTENSITY_88) { + if (!found) { + return 0; + } + if (tmu == 0) + { + if (blackandwhite1 != found) + { + blackandwhite1 = found; + need_to_compile = 1; + } + } + else + { + if (blackandwhite0 != found) + { + blackandwhite0 = found; + need_to_compile = 1; + } + } + return 1; } - else - { - cw = 256; - ch = cw >> info->aspectRatioLog2; - } - - if (use_fbo || th < screen_height) - rh = th; - else - rh = screen_height; - - //printf("th %d rh %d ch %d\n", th, rh, ch); - - invtex[tmu] = 1.0f - (th - rh) / (float)th; - } else - invtex[tmu] = 0; - - if (info->format == GR_TEXFMT_ALPHA_INTENSITY_88 ) { - if (!found) { - return 0; - } - if(tmu == 0) - { - if(blackandwhite1 != found) - { - blackandwhite1 = found; - need_to_compile = 1; - } - } - else - { - if(blackandwhite0 != found) - { - blackandwhite0 = found; - need_to_compile = 1; - } - } - return 1; - } - return 0; - + return 0; } - FX_ENTRY void FX_CALL -grTextureAuxBufferExt( GrChipID_t tmu, - FxU32 startAddress, - GrLOD_t thisLOD, - GrLOD_t largeLOD, - GrAspectRatio_t aspectRatio, - GrTextureFormat_t format, - FxU32 odd_even_mask ) +grTextureAuxBufferExt(GrChipID_t tmu, +FxU32 startAddress, +GrLOD_t thisLOD, +GrLOD_t largeLOD, +GrAspectRatio_t aspectRatio, +GrTextureFormat_t format, +FxU32 odd_even_mask) { - LOG("grTextureAuxBufferExt(%d, %d, %d, %d %d, %d, %d)\r\n", tmu, startAddress, thisLOD, largeLOD, aspectRatio, format, odd_even_mask); - //display_warning("grTextureAuxBufferExt"); + LOG("grTextureAuxBufferExt(%d, %d, %d, %d %d, %d, %d)\r\n", tmu, startAddress, thisLOD, largeLOD, aspectRatio, format, odd_even_mask); + //WriteTrace(TraceGlitch, TraceWarning, "grTextureAuxBufferExt"); } -FX_ENTRY void FX_CALL grAuxBufferExt( GrBuffer_t buffer ); +FX_ENTRY void FX_CALL grAuxBufferExt(GrBuffer_t buffer); FX_ENTRY GrProc FX_CALL -grGetProcAddress( char *procName ) +grGetProcAddress(char *procName) { - LOG("grGetProcAddress(%s)\r\n", procName); - if(!strcmp(procName, "grSstWinOpenExt")) - return (GrProc)grSstWinOpenExt; - if(!strcmp(procName, "grTextureBufferExt")) - return (GrProc)grTextureBufferExt; - if(!strcmp(procName, "grChromaRangeExt")) - return (GrProc)grChromaRangeExt; - if(!strcmp(procName, "grChromaRangeModeExt")) - return (GrProc)grChromaRangeModeExt; - if(!strcmp(procName, "grTexChromaRangeExt")) - return (GrProc)grTexChromaRangeExt; - if(!strcmp(procName, "grTexChromaModeExt")) - return (GrProc)grTexChromaModeExt; - // ZIGGY framebuffer copy extension - if(!strcmp(procName, "grFramebufferCopyExt")) - return (GrProc)grFramebufferCopyExt; - if(!strcmp(procName, "grColorCombineExt")) - return (GrProc)grColorCombineExt; - if(!strcmp(procName, "grAlphaCombineExt")) - return (GrProc)grAlphaCombineExt; - if(!strcmp(procName, "grTexColorCombineExt")) - return (GrProc)grTexColorCombineExt; - if(!strcmp(procName, "grTexAlphaCombineExt")) - return (GrProc)grTexAlphaCombineExt; - if(!strcmp(procName, "grConstantColorValueExt")) - return (GrProc)grConstantColorValueExt; - if(!strcmp(procName, "grTextureAuxBufferExt")) - return (GrProc)grTextureAuxBufferExt; - if(!strcmp(procName, "grAuxBufferExt")) - return (GrProc)grAuxBufferExt; - if(!strcmp(procName, "grWrapperFullScreenResolutionExt")) - return (GrProc)grWrapperFullScreenResolutionExt; - if(!strcmp(procName, "grConfigWrapperExt")) - return (GrProc)grConfigWrapperExt; - if(!strcmp(procName, "grKeyPressedExt")) - return (GrProc)grKeyPressedExt; - if(!strcmp(procName, "grQueryResolutionsExt")) - return (GrProc)grQueryResolutionsExt; - if(!strcmp(procName, "grGetGammaTableExt")) - return (GrProc)grGetGammaTableExt; - display_warning("grGetProcAddress : %s", procName); - return 0; + LOG("grGetProcAddress(%s)\r\n", procName); + if (!strcmp(procName, "grSstWinOpenExt")) + return (GrProc)grSstWinOpenExt; + if (!strcmp(procName, "grTextureBufferExt")) + return (GrProc)grTextureBufferExt; + if (!strcmp(procName, "grChromaRangeExt")) + return (GrProc)grChromaRangeExt; + if (!strcmp(procName, "grChromaRangeModeExt")) + return (GrProc)grChromaRangeModeExt; + if (!strcmp(procName, "grTexChromaRangeExt")) + return (GrProc)grTexChromaRangeExt; + if (!strcmp(procName, "grTexChromaModeExt")) + return (GrProc)grTexChromaModeExt; + // ZIGGY framebuffer copy extension + if (!strcmp(procName, "grFramebufferCopyExt")) + return (GrProc)grFramebufferCopyExt; + if (!strcmp(procName, "grColorCombineExt")) + return (GrProc)grColorCombineExt; + if (!strcmp(procName, "grAlphaCombineExt")) + return (GrProc)grAlphaCombineExt; + if (!strcmp(procName, "grTexColorCombineExt")) + return (GrProc)grTexColorCombineExt; + if (!strcmp(procName, "grTexAlphaCombineExt")) + return (GrProc)grTexAlphaCombineExt; + if (!strcmp(procName, "grConstantColorValueExt")) + return (GrProc)grConstantColorValueExt; + if (!strcmp(procName, "grTextureAuxBufferExt")) + return (GrProc)grTextureAuxBufferExt; + if (!strcmp(procName, "grAuxBufferExt")) + return (GrProc)grAuxBufferExt; + if (!strcmp(procName, "grWrapperFullScreenResolutionExt")) + return (GrProc)grWrapperFullScreenResolutionExt; + if (!strcmp(procName, "grConfigWrapperExt")) + return (GrProc)grConfigWrapperExt; + if (!strcmp(procName, "grKeyPressedExt")) + return (GrProc)grKeyPressedExt; + if (!strcmp(procName, "grQueryResolutionsExt")) + return (GrProc)grQueryResolutionsExt; + if (!strcmp(procName, "grGetGammaTableExt")) + return (GrProc)grGetGammaTableExt; + WriteTrace(TraceGlitch, TraceWarning, "grGetProcAddress : %s", procName); + return 0; } FX_ENTRY FxU32 FX_CALL -grGet( FxU32 pname, FxU32 plength, FxI32 *params ) +grGet(FxU32 pname, FxU32 plength, FxI32 *params) { - LOG("grGet(%d,%d)\r\n", pname, plength); - switch(pname) - { - case GR_MAX_TEXTURE_SIZE: - if (plength < 4 || params == NULL) return 0; - params[0] = 2048; - return 4; - break; - case GR_NUM_TMU: - if (plength < 4 || params == NULL) return 0; - if (!nbTextureUnits) + LOG("grGet(%d,%d)\r\n", pname, plength); + switch (pname) { - grSstWinOpen((unsigned long)NULL, GR_RESOLUTION_640x480 | 0x80000000, 0, GR_COLORFORMAT_ARGB, - GR_ORIGIN_UPPER_LEFT, 2, 1); - grSstWinClose(0); - } + case GR_MAX_TEXTURE_SIZE: + if (plength < 4 || params == NULL) return 0; + params[0] = 2048; + return 4; + break; + case GR_NUM_TMU: + if (plength < 4 || params == NULL) return 0; + if (!nbTextureUnits) + { + grSstWinOpen((unsigned long)NULL, GR_RESOLUTION_640x480 | 0x80000000, 0, GR_COLORFORMAT_ARGB, + GR_ORIGIN_UPPER_LEFT, 2, 1); + grSstWinClose(0); + } #ifdef VOODOO1 - params[0] = 1; + params[0] = 1; #else - if (nbTextureUnits > 2) - params[0] = 2; - else - params[0] = 1; + if (nbTextureUnits > 2) + params[0] = 2; + else + params[0] = 1; #endif - return 4; - break; - case GR_NUM_BOARDS: - case GR_NUM_FB: - case GR_REVISION_FB: - case GR_REVISION_TMU: - if (plength < 4 || params == NULL) return 0; - params[0] = 1; - return 4; - break; - case GR_MEMORY_FB: - if (plength < 4 || params == NULL) return 0; - params[0] = 16*1024*1024; - return 4; - break; - case GR_MEMORY_TMU: - if (plength < 4 || params == NULL) return 0; - params[0] = 16*1024*1024; - return 4; - break; - case GR_MEMORY_UMA: - if (plength < 4 || params == NULL) return 0; - params[0] = 16*1024*1024*nbTextureUnits; - return 4; - break; - case GR_BITS_RGBA: - if (plength < 16 || params == NULL) return 0; - params[0] = 8; - params[1] = 8; - params[2] = 8; - params[3] = 8; - return 16; - break; - case GR_BITS_DEPTH: - if (plength < 4 || params == NULL) return 0; - params[0] = 16; - return 4; - break; - case GR_BITS_GAMMA: - if (plength < 4 || params == NULL) return 0; - params[0] = 8; - return 4; - break; - case GR_GAMMA_TABLE_ENTRIES: - if (plength < 4 || params == NULL) return 0; - params[0] = 256; - return 4; - break; - case GR_FOG_TABLE_ENTRIES: - if (plength < 4 || params == NULL) return 0; - params[0] = 64; - return 4; - break; - case GR_WDEPTH_MIN_MAX: - if (plength < 8 || params == NULL) return 0; - params[0] = 0; - params[1] = 65528; - return 8; - break; - case GR_ZDEPTH_MIN_MAX: - if (plength < 8 || params == NULL) return 0; - params[0] = 0; - params[1] = 65535; - return 8; - break; - case GR_LFB_PIXEL_PIPE: - if (plength < 4 || params == NULL) return 0; - params[0] = FXFALSE; - return 4; - break; - case GR_MAX_TEXTURE_ASPECT_RATIO: - if (plength < 4 || params == NULL) return 0; - params[0] = 3; - return 4; - break; - case GR_NON_POWER_OF_TWO_TEXTURES: - if (plength < 4 || params == NULL) return 0; - params[0] = FXFALSE; - return 4; - break; - case GR_TEXTURE_ALIGN: - if (plength < 4 || params == NULL) return 0; - params[0] = 0; - return 4; - break; - default: - display_warning("unknown pname in grGet : %x", pname); - } - return 0; + return 4; + break; + case GR_NUM_BOARDS: + case GR_NUM_FB: + case GR_REVISION_FB: + case GR_REVISION_TMU: + if (plength < 4 || params == NULL) return 0; + params[0] = 1; + return 4; + break; + case GR_MEMORY_FB: + if (plength < 4 || params == NULL) return 0; + params[0] = 16 * 1024 * 1024; + return 4; + break; + case GR_MEMORY_TMU: + if (plength < 4 || params == NULL) return 0; + params[0] = 16 * 1024 * 1024; + return 4; + break; + case GR_MEMORY_UMA: + if (plength < 4 || params == NULL) return 0; + params[0] = 16 * 1024 * 1024 * nbTextureUnits; + return 4; + break; + case GR_BITS_RGBA: + if (plength < 16 || params == NULL) return 0; + params[0] = 8; + params[1] = 8; + params[2] = 8; + params[3] = 8; + return 16; + break; + case GR_BITS_DEPTH: + if (plength < 4 || params == NULL) return 0; + params[0] = 16; + return 4; + break; + case GR_BITS_GAMMA: + if (plength < 4 || params == NULL) return 0; + params[0] = 8; + return 4; + break; + case GR_GAMMA_TABLE_ENTRIES: + if (plength < 4 || params == NULL) return 0; + params[0] = 256; + return 4; + break; + case GR_FOG_TABLE_ENTRIES: + if (plength < 4 || params == NULL) return 0; + params[0] = 64; + return 4; + break; + case GR_WDEPTH_MIN_MAX: + if (plength < 8 || params == NULL) return 0; + params[0] = 0; + params[1] = 65528; + return 8; + break; + case GR_ZDEPTH_MIN_MAX: + if (plength < 8 || params == NULL) return 0; + params[0] = 0; + params[1] = 65535; + return 8; + break; + case GR_LFB_PIXEL_PIPE: + if (plength < 4 || params == NULL) return 0; + params[0] = FXFALSE; + return 4; + break; + case GR_MAX_TEXTURE_ASPECT_RATIO: + if (plength < 4 || params == NULL) return 0; + params[0] = 3; + return 4; + break; + case GR_NON_POWER_OF_TWO_TEXTURES: + if (plength < 4 || params == NULL) return 0; + params[0] = FXFALSE; + return 4; + break; + case GR_TEXTURE_ALIGN: + if (plength < 4 || params == NULL) return 0; + params[0] = 0; + return 4; + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown pname in grGet : %x", pname); + } + return 0; } FX_ENTRY const char * FX_CALL -grGetString( FxU32 pname ) +grGetString(FxU32 pname) { - LOG("grGetString(%d)\r\n", pname); - switch(pname) - { - case GR_EXTENSION: + LOG("grGetString(%d)\r\n", pname); + switch (pname) { - static char extension[] = "CHROMARANGE TEXCHROMA TEXMIRROR PALETTE6666 FOGCOORD EVOODOO TEXTUREBUFFER TEXUMA TEXFMT COMBINE GETGAMMA"; - return extension; + case GR_EXTENSION: + { + static char extension[] = "CHROMARANGE TEXCHROMA TEXMIRROR PALETTE6666 FOGCOORD EVOODOO TEXTUREBUFFER TEXUMA TEXFMT COMBINE GETGAMMA"; + return extension; } break; - case GR_HARDWARE: + case GR_HARDWARE: { - static char hardware[] = "Voodoo5 (tm)"; - return hardware; + static char hardware[] = "Voodoo5 (tm)"; + return hardware; } break; - case GR_VENDOR: + case GR_VENDOR: { - static char vendor[] = "3Dfx Interactive"; - return vendor; + static char vendor[] = "3Dfx Interactive"; + return vendor; } break; - case GR_RENDERER: + case GR_RENDERER: { - static char renderer[] = "Glide"; - return renderer; + static char renderer[] = "Glide"; + return renderer; } break; - case GR_VERSION: + case GR_VERSION: { - static char version[] = "3.0"; - return version; + static char version[] = "3.0"; + return version; } break; - default: - display_warning("unknown grGetString selector : %x", pname); - } - return NULL; + default: + WriteTrace(TraceGlitch, TraceWarning, "unknown grGetString selector : %x", pname); + } + return NULL; } static void render_rectangle(int texture_number, - int dst_x, int dst_y, - int src_width, int src_height, - int tex_width, int tex_height, int invert) + int dst_x, int dst_y, + int src_width, int src_height, + int tex_width, int tex_height, int invert) { - LOGINFO("render_rectangle(%d,%d,%d,%d,%d,%d,%d,%d)",texture_number,dst_x,dst_y,src_width,src_height,tex_width,tex_height,invert); - int vertexOffset_location; - int textureSizes_location; - static float data[] = { - (float)((int)dst_x), //X 0 - (float)(invert*-((int)dst_y)), //Y 0 - 0.0f, //U 0 - 0.0f, //V 0 + LOGINFO("render_rectangle(%d,%d,%d,%d,%d,%d,%d,%d)", texture_number, dst_x, dst_y, src_width, src_height, tex_width, tex_height, invert); + int vertexOffset_location; + int textureSizes_location; + static float data[] = { + (float)((int)dst_x), //X 0 + (float)(invert*-((int)dst_y)), //Y 0 + 0.0f, //U 0 + 0.0f, //V 0 - (float)((int)dst_x), //X 1 - (float)(invert*-((int)dst_y + (int)src_height)), //Y 1 - 0.0f, //U 1 - (float)src_height / (float)tex_height, //V 1 + (float)((int)dst_x), //X 1 + (float)(invert*-((int)dst_y + (int)src_height)), //Y 1 + 0.0f, //U 1 + (float)src_height / (float)tex_height, //V 1 - (float)((int)dst_x + (int)src_width), - (float)(invert*-((int)dst_y + (int)src_height)), - (float)src_width / (float)tex_width, - (float)src_height / (float)tex_height, + (float)((int)dst_x + (int)src_width), + (float)(invert*-((int)dst_y + (int)src_height)), + (float)src_width / (float)tex_width, + (float)src_height / (float)tex_height, - (float)((int)dst_x), - (float)(invert*-((int)dst_y)), - 0.0f, - 0.0f - }; + (float)((int)dst_x), + (float)(invert*-((int)dst_y)), + 0.0f, + 0.0f + }; - vbo_disable(); - glDisableVertexAttribArray(COLOUR_ATTR); - glDisableVertexAttribArray(TEXCOORD_1_ATTR); - glDisableVertexAttribArray(FOG_ATTR); + vbo_disable(); + glDisableVertexAttribArray(COLOUR_ATTR); + glDisableVertexAttribArray(TEXCOORD_1_ATTR); + glDisableVertexAttribArray(FOG_ATTR); - glVertexAttribPointer(POSITION_ATTR,2,GL_FLOAT,false,2,data); //Position - glVertexAttribPointer(TEXCOORD_0_ATTR,2,GL_FLOAT,false,2,&data[2]); //Tex + glVertexAttribPointer(POSITION_ATTR, 2, GL_FLOAT, false, 2, data); //Position + glVertexAttribPointer(TEXCOORD_0_ATTR, 2, GL_FLOAT, false, 2, &data[2]); //Tex - glEnableVertexAttribArray(COLOUR_ATTR); - glEnableVertexAttribArray(TEXCOORD_1_ATTR); - glEnableVertexAttribArray(FOG_ATTR); + glEnableVertexAttribArray(COLOUR_ATTR); + glEnableVertexAttribArray(TEXCOORD_1_ATTR); + glEnableVertexAttribArray(FOG_ATTR); + disable_textureSizes(); - disable_textureSizes(); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + vbo_enable(); - glDrawArrays(GL_TRIANGLE_STRIP,0,4); - vbo_enable(); + /* + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glBegin(GL_QUADS); + glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); + glVertex2f(((int)dst_x - widtho) / (float)(width/2), + invert*-((int)dst_y - heighto) / (float)(height/2)); + glMultiTexCoord2fARB(texture_number, 0.0f, (float)src_height / (float)tex_height); + glVertex2f(((int)dst_x - widtho) / (float)(width/2), + invert*-((int)dst_y + (int)src_height - heighto) / (float)(height/2)); + glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, (float)src_height / (float)tex_height); + glVertex2f(((int)dst_x + (int)src_width - widtho) / (float)(width/2), + invert*-((int)dst_y + (int)src_height - heighto) / (float)(height/2)); + glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, 0.0f); + glVertex2f(((int)dst_x + (int)src_width - widtho) / (float)(width/2), + invert*-((int)dst_y - heighto) / (float)(height/2)); + glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); + glVertex2f(((int)dst_x - widtho) / (float)(width/2), + invert*-((int)dst_y - heighto) / (float)(height/2)); + glEnd(); + */ + compile_shader(); -/* - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glBegin(GL_QUADS); - glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); - glMultiTexCoord2fARB(texture_number, 0.0f, (float)src_height / (float)tex_height); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y + (int)src_height - heighto) / (float)(height/2)); - glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, (float)src_height / (float)tex_height); - glVertex2f(((int)dst_x + (int)src_width - widtho) / (float)(width/2), - invert*-((int)dst_y + (int)src_height - heighto) / (float)(height/2)); - glMultiTexCoord2fARB(texture_number, (float)src_width / (float)tex_width, 0.0f); - glVertex2f(((int)dst_x + (int)src_width - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); - glMultiTexCoord2fARB(texture_number, 0.0f, 0.0f); - glVertex2f(((int)dst_x - widtho) / (float)(width/2), - invert*-((int)dst_y - heighto) / (float)(height/2)); - glEnd(); -*/ - - compile_shader(); - - glEnable(GL_DEPTH_TEST); - glEnable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + glEnable(GL_BLEND); } void reloadTexture() { - if (use_fbo || !render_to_texture || buffer_cleared) - return; + if (use_fbo || !render_to_texture || buffer_cleared) + return; - LOG("reload texture %dx%d\n", width, height); - //printf("reload texture %dx%d\n", width, height); + LOG("reload texture %dx%d\n", width, height); + //printf("reload texture %dx%d\n", width, height); - buffer_cleared = 1; + buffer_cleared = 1; - //glPushAttrib(GL_ALL_ATTRIB_BITS); - glActiveTexture(texture_unit); - glBindTexture(GL_TEXTURE_2D, pBufferAddress); - //glDisable(GL_ALPHA_TEST); - //glDrawBuffer(current_buffer); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - set_copy_shader(); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - int w = 0, h = 0; - if (height > screen_height) h = screen_height - height; - render_rectangle(texture_unit, - -w, -h, - width, height, - width, height, -1); - glBindTexture(GL_TEXTURE_2D, default_texture); - //glPopAttrib(); + //glPushAttrib(GL_ALL_ATTRIB_BITS); + glActiveTexture(texture_unit); + glBindTexture(GL_TEXTURE_2D, pBufferAddress); + //glDisable(GL_ALPHA_TEST); + //glDrawBuffer(current_buffer); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + set_copy_shader(); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + int w = 0, h = 0; + if (height > screen_height) h = screen_height - height; + render_rectangle(texture_unit, + -w, -h, + width, height, + width, height, -1); + glBindTexture(GL_TEXTURE_2D, default_texture); + //glPopAttrib(); } void updateTexture() { - if (!use_fbo && render_to_texture == 2) { - LOG("update texture %x\n", pBufferAddress); - //printf("update texture %x\n", pBufferAddress); + if (!use_fbo && render_to_texture == 2) { + LOG("update texture %x\n", pBufferAddress); + //printf("update texture %x\n", pBufferAddress); - // nothing changed, don't update the texture - if (!buffer_cleared) { - LOG("update cancelled\n", pBufferAddress); - return; + // nothing changed, don't update the texture + if (!buffer_cleared) { + LOG("update cancelled\n", pBufferAddress); + return; + } + + //glPushAttrib(GL_ALL_ATTRIB_BITS); + + // save result of render to texture into actual texture + //glReadBuffer(current_buffer); + glActiveTexture(texture_unit); + // ZIGGY + // deleting the texture before resampling it increases speed on certain old + // nvidia cards (geforce 2 for example), unfortunatly it slows down a lot + // on newer cards. + //glDeleteTextures( 1, &pBufferAddress ); + glBindTexture(GL_TEXTURE_2D, pBufferAddress); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, + 0, viewport_offset, width, height, 0); + + glBindTexture(GL_TEXTURE_2D, default_texture); + //glPopAttrib(); } - - //glPushAttrib(GL_ALL_ATTRIB_BITS); - - // save result of render to texture into actual texture - //glReadBuffer(current_buffer); - glActiveTexture(texture_unit); - // ZIGGY - // deleting the texture before resampling it increases speed on certain old - // nvidia cards (geforce 2 for example), unfortunatly it slows down a lot - // on newer cards. - //glDeleteTextures( 1, &pBufferAddress ); - glBindTexture(GL_TEXTURE_2D, pBufferAddress); - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, - 0, viewport_offset, width, height, 0); - - glBindTexture(GL_TEXTURE_2D, default_texture); - //glPopAttrib(); - } } FX_ENTRY void FX_CALL grFramebufferCopyExt(int x, int y, int w, int h, - int from, int to, int mode) + int from, int to, int mode) { - if (mode == GR_FBCOPY_MODE_DEPTH) { + if (mode == GR_FBCOPY_MODE_DEPTH) { + int tw = 1, th = 1; + if (npot_support) { + tw = width; th = height; + } + else { + while (tw < width) tw <<= 1; + while (th < height) th <<= 1; + } - int tw = 1, th = 1; - if (npot_support) { - tw = width; th = height; - } else { - while (tw < width) tw <<= 1; - while (th < height) th <<= 1; + if (from == GR_FBCOPY_BUFFER_BACK && to == GR_FBCOPY_BUFFER_FRONT) { + //printf("save depth buffer %d\n", render_to_texture); + // save the depth image in a texture + //glReadBuffer(current_buffer); + glBindTexture(GL_TEXTURE_2D, depth_texture); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, + 0, viewport_offset, tw, th, 0); + glBindTexture(GL_TEXTURE_2D, default_texture); + return; + } + if (from == GR_FBCOPY_BUFFER_FRONT && to == GR_FBCOPY_BUFFER_BACK) { + //printf("writing to depth buffer %d\n", render_to_texture); + //glPushAttrib(GL_ALL_ATTRIB_BITS); + //glDisable(GL_ALPHA_TEST); + //glDrawBuffer(current_buffer); + glActiveTexture(texture_unit); + glBindTexture(GL_TEXTURE_2D, depth_texture); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + set_depth_shader(); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); + glDisable(GL_CULL_FACE); + render_rectangle(texture_unit, + 0, 0, + width, height, + tw, th, -1); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glBindTexture(GL_TEXTURE_2D, default_texture); + //glPopAttrib(); + return; + } } - - if (from == GR_FBCOPY_BUFFER_BACK && to == GR_FBCOPY_BUFFER_FRONT) { - //printf("save depth buffer %d\n", render_to_texture); - // save the depth image in a texture - //glReadBuffer(current_buffer); - glBindTexture(GL_TEXTURE_2D, depth_texture); - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, - 0, viewport_offset, tw, th, 0); - glBindTexture(GL_TEXTURE_2D, default_texture); - return; - } - if (from == GR_FBCOPY_BUFFER_FRONT && to == GR_FBCOPY_BUFFER_BACK) { - //printf("writing to depth buffer %d\n", render_to_texture); - //glPushAttrib(GL_ALL_ATTRIB_BITS); - //glDisable(GL_ALPHA_TEST); - //glDrawBuffer(current_buffer); - glActiveTexture(texture_unit); - glBindTexture(GL_TEXTURE_2D, depth_texture); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - set_depth_shader(); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); - glDisable(GL_CULL_FACE); - render_rectangle(texture_unit, - 0, 0, - width, height, - tw, th, -1); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glBindTexture(GL_TEXTURE_2D, default_texture); - //glPopAttrib(); - return; - } - - } } FX_ENTRY void FX_CALL -grRenderBuffer( GrBuffer_t buffer ) +grRenderBuffer(GrBuffer_t buffer) { #ifdef _WIN32 - static HANDLE region = NULL; - int realWidth = pBufferWidth, realHeight = pBufferHeight; + static HANDLE region = NULL; + int realWidth = pBufferWidth, realHeight = pBufferHeight; #endif // _WIN32 - LOG("grRenderBuffer(%d)\r\n", buffer); - //printf("grRenderBuffer(%d)\n", buffer); + LOG("grRenderBuffer(%d)\r\n", buffer); + //printf("grRenderBuffer(%d)\n", buffer); - switch(buffer) - { - case GR_BUFFER_BACKBUFFER: - if(render_to_texture) + switch (buffer) { - updateTexture(); + case GR_BUFFER_BACKBUFFER: + if (render_to_texture) + { + updateTexture(); - // VP z fix - //glMatrixMode(GL_MODELVIEW); - //glLoadIdentity(); - //glTranslatef(0, 0, 1-zscale); - //glScalef(1, 1, zscale); - inverted_culling = 0; - grCullMode(culling_mode); + // VP z fix + //glMatrixMode(GL_MODELVIEW); + //glLoadIdentity(); + //glTranslatef(0, 0, 1-zscale); + //glScalef(1, 1, zscale); + inverted_culling = 0; + grCullMode(culling_mode); - width = savedWidth; - height = savedHeight; - widtho = savedWidtho; - heighto = savedHeighto; - if (use_fbo) { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glBindRenderbuffer( GL_RENDERBUFFER, 0 ); - } - curBufferAddr = 0; + width = savedWidth; + height = savedHeight; + widtho = savedWidtho; + heighto = savedHeighto; + if (use_fbo) { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + curBufferAddr = 0; - glViewport(0, viewport_offset, width, viewport_height); - glScissor(0, viewport_offset, width, height); + glViewport(0, viewport_offset, width, viewport_height); + glScissor(0, viewport_offset, width, height); #ifdef SAVE_CBUFFER - if (!use_fbo && render_to_texture == 2) { - // restore color buffer - if (nbAuxBuffers > 0) { - //glDrawBuffer(GL_BACK); - current_buffer = GL_BACK; - } else if (save_w) { - int tw = 1, th = 1; - //printf("restore %dx%d\n", save_w, save_h); - if (npot_support) { - tw = screen_width; - th = screen_height; - } else { - while (tw < screen_width) tw <<= 1; - while (th < screen_height) th <<= 1; - } + if (!use_fbo && render_to_texture == 2) { + // restore color buffer + if (nbAuxBuffers > 0) { + //glDrawBuffer(GL_BACK); + current_buffer = GL_BACK; + } + else if (save_w) { + int tw = 1, th = 1; + //printf("restore %dx%d\n", save_w, save_h); + if (npot_support) { + tw = screen_width; + th = screen_height; + } + else { + while (tw < screen_width) tw <<= 1; + while (th < screen_height) th <<= 1; + } - //glPushAttrib(GL_ALL_ATTRIB_BITS); - //glDisable(GL_ALPHA_TEST); - //glDrawBuffer(GL_BACK); - glActiveTexture(texture_unit); - glBindTexture(GL_TEXTURE_2D, color_texture); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - set_copy_shader(); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - render_rectangle(texture_unit, - 0, 0, - save_w, save_h, - tw, th, -1); - glBindTexture(GL_TEXTURE_2D, default_texture); - //glPopAttrib(); + //glPushAttrib(GL_ALL_ATTRIB_BITS); + //glDisable(GL_ALPHA_TEST); + //glDrawBuffer(GL_BACK); + glActiveTexture(texture_unit); + glBindTexture(GL_TEXTURE_2D, color_texture); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + set_copy_shader(); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + render_rectangle(texture_unit, + 0, 0, + save_w, save_h, + tw, th, -1); + glBindTexture(GL_TEXTURE_2D, default_texture); + //glPopAttrib(); - save_w = save_h = 0; - } - } + save_w = save_h = 0; + } + } #endif - render_to_texture = 0; - } - //glDrawBuffer(GL_BACK); - break; - case 6: // RENDER TO TEXTURE - if(!render_to_texture) - { - savedWidth = width; - savedHeight = height; - savedWidtho = widtho; - savedHeighto = heighto; - } + render_to_texture = 0; + } + //glDrawBuffer(GL_BACK); + break; + case 6: // RENDER TO TEXTURE + if (!render_to_texture) + { + savedWidth = width; + savedHeight = height; + savedWidtho = widtho; + savedHeighto = heighto; + } { - if (!use_fbo) { - //glMatrixMode(GL_MODELVIEW); - //glLoadIdentity(); - //glTranslatef(0, 0, 1-zscale); - //glScalef(1, 1, zscale); - inverted_culling = 0; - } else { -/* - float m[4*4] = {1.0f, 0.0f, 0.0f, 0.0f, - 0.0f,-1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f}; - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(m); - // VP z fix - glTranslatef(0, 0, 1-zscale); - glScalef(1, 1*1, zscale); -*/ - inverted_culling = 1; - grCullMode(culling_mode); - } + if (!use_fbo) { + //glMatrixMode(GL_MODELVIEW); + //glLoadIdentity(); + //glTranslatef(0, 0, 1-zscale); + //glScalef(1, 1, zscale); + inverted_culling = 0; + } + else { + /* + float m[4*4] = {1.0f, 0.0f, 0.0f, 0.0f, + 0.0f,-1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf(m); + // VP z fix + glTranslatef(0, 0, 1-zscale); + glScalef(1, 1*1, zscale); + */ + inverted_culling = 1; + grCullMode(culling_mode); + } } render_to_texture = 1; break; - default: - display_warning("grRenderBuffer : unknown buffer : %x", buffer); - } + default: + WriteTrace(TraceGlitch, TraceWarning, "grRenderBuffer : unknown buffer : %x", buffer); + } } FX_ENTRY void FX_CALL -grAuxBufferExt( GrBuffer_t buffer ) +grAuxBufferExt(GrBuffer_t buffer) { - LOG("grAuxBufferExt(%d)\r\n", buffer); - //display_warning("grAuxBufferExt"); + LOG("grAuxBufferExt(%d)\r\n", buffer); + //WriteTrace(TraceGlitch, TraceWarning, "grAuxBufferExt"); - if (buffer == GR_BUFFER_AUXBUFFER) { - invtex[0] = 0; - invtex[1] = 0; - need_to_compile = 0; - set_depth_shader(); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); - glDisable(GL_CULL_FACE); - //glDisable(GL_ALPHA_TEST); - glDepthMask(GL_TRUE); - grTexFilterMode(GR_TMU1, GR_TEXTUREFILTER_POINT_SAMPLED, GR_TEXTUREFILTER_POINT_SAMPLED); - } else { - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - need_to_compile = 1; - } + if (buffer == GR_BUFFER_AUXBUFFER) { + invtex[0] = 0; + invtex[1] = 0; + need_to_compile = 0; + set_depth_shader(); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); + glDisable(GL_CULL_FACE); + //glDisable(GL_ALPHA_TEST); + glDepthMask(GL_TRUE); + grTexFilterMode(GR_TMU1, GR_TEXTUREFILTER_POINT_SAMPLED, GR_TEXTUREFILTER_POINT_SAMPLED); + } + else { + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + need_to_compile = 1; + } } void vbo_draw(); FX_ENTRY void FX_CALL -grBufferClear( GrColor_t color, GrAlpha_t alpha, FxU32 depth ) +grBufferClear(GrColor_t color, GrAlpha_t alpha, FxU32 depth) { - vbo_draw(); - LOG("grBufferClear(%d,%d,%d)\r\n", color, alpha, depth); - switch(lfb_color_fmt) - { - case GR_COLORFORMAT_ARGB: - glClearColor(((color >> 16) & 0xFF) / 255.0f, - ((color >> 8) & 0xFF) / 255.0f, - ( color & 0xFF) / 255.0f, - alpha / 255.0f); - break; - case GR_COLORFORMAT_RGBA: - glClearColor(((color >> 24) & 0xFF) / 255.0f, - ((color >> 16) & 0xFF) / 255.0f, - (color & 0xFF) / 255.0f, - alpha / 255.0f); - break; - default: - display_warning("grBufferClear: unknown color format : %x", lfb_color_fmt); - } + vbo_draw(); + LOG("grBufferClear(%d,%d,%d)\r\n", color, alpha, depth); + switch (lfb_color_fmt) + { + case GR_COLORFORMAT_ARGB: + glClearColor(((color >> 16) & 0xFF) / 255.0f, + ((color >> 8) & 0xFF) / 255.0f, + (color & 0xFF) / 255.0f, + alpha / 255.0f); + break; + case GR_COLORFORMAT_RGBA: + glClearColor(((color >> 24) & 0xFF) / 255.0f, + ((color >> 16) & 0xFF) / 255.0f, + (color & 0xFF) / 255.0f, + alpha / 255.0f); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grBufferClear: unknown color format : %x", lfb_color_fmt); + } - if (w_buffer_mode) - glClearDepthf(1.0f - ((1.0f + (depth >> 4) / 4096.0f) * (1 << (depth & 0xF))) / 65528.0); - else - glClearDepthf(depth / 65535.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // ZIGGY TODO check that color mask is on - buffer_cleared = 1; + if (w_buffer_mode) + glClearDepthf(1.0f - ((1.0f + (depth >> 4) / 4096.0f) * (1 << (depth & 0xF))) / 65528.0); + else + glClearDepthf(depth / 65535.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + // ZIGGY TODO check that color mask is on + buffer_cleared = 1; } // #include FX_ENTRY void FX_CALL -grBufferSwap( FxU32 swap_interval ) +grBufferSwap(FxU32 swap_interval) { -// GLuint program; + // GLuint program; - vbo_draw(); -// glFinish(); -// printf("rendercallback is %p\n", renderCallback); - if(renderCallback) { -// glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*) &program); -// glUseProgramObjectARB(0); - (*renderCallback)(1); -// if (program) -// glUseProgramObjectARB(program); - } - int i; - LOG("grBufferSwap(%d)\r\n", swap_interval); - //printf("swap\n"); - if (render_to_texture) { - display_warning("swap while render_to_texture\n"); - return; - } - - CoreVideo_GL_SwapBuffers(); - for (i = 0; i < nb_fb; i++) - fbs[i].buff_clear = 1; - - // VP debugging -#ifdef VPDEBUG - dump_stop(); - SDL_Event event; - while (SDL_PollEvent(&event)) { - switch (event.type) { -case SDL_KEYDOWN: - switch (event.key.keysym.sym) { -case 'd': - printf("Dumping !\n"); - dump_start(); - break; -case 'w': { - static int wireframe; - wireframe = !wireframe; - glPolygonMode(GL_FRONT_AND_BACK, wireframe? GL_LINE : GL_FILL); - break; - } - } - break; + vbo_draw(); + // glFinish(); + // printf("rendercallback is %p\n", renderCallback); + if (renderCallback) { + // glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*) &program); + // glUseProgramObjectARB(0); + (*renderCallback)(1); + // if (program) + // glUseProgramObjectARB(program); + } + int i; + LOG("grBufferSwap(%d)\r\n", swap_interval); + //printf("swap\n"); + if (render_to_texture) { + WriteTrace(TraceGlitch, TraceWarning, "swap while render_to_texture\n"); + return; + } + + CoreVideo_GL_SwapBuffers(); + for (i = 0; i < nb_fb; i++) + fbs[i].buff_clear = 1; + + // VP debugging +#ifdef VPDEBUG + dump_stop(); + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case 'd': + printf("Dumping !\n"); + dump_start(); + break; + case 'w': { + static int wireframe; + wireframe = !wireframe; + glPolygonMode(GL_FRONT_AND_BACK, wireframe? GL_LINE : GL_FILL); + break; + } + } + break; + } } - } #endif } // frame buffer FX_ENTRY FxBool FX_CALL -grLfbLock( GrLock_t type, GrBuffer_t buffer, GrLfbWriteMode_t writeMode, - GrOriginLocation_t origin, FxBool pixelPipeline, - GrLfbInfo_t *info ) +grLfbLock(GrLock_t type, GrBuffer_t buffer, GrLfbWriteMode_t writeMode, +GrOriginLocation_t origin, FxBool pixelPipeline, +GrLfbInfo_t *info) { - LOG("grLfbLock(%d,%d,%d,%d,%d)\r\n", type, buffer, writeMode, origin, pixelPipeline); - if (type == GR_LFB_WRITE_ONLY) - { - display_warning("grLfbLock : write only"); - } - else - { - unsigned char *buf; - int i,j; - - switch(buffer) + LOG("grLfbLock(%d,%d,%d,%d,%d)\r\n", type, buffer, writeMode, origin, pixelPipeline); + if (type == GR_LFB_WRITE_ONLY) { - case GR_BUFFER_FRONTBUFFER: - //glReadBuffer(GL_FRONT); - break; - case GR_BUFFER_BACKBUFFER: - //glReadBuffer(GL_BACK); - break; - default: - display_warning("grLfbLock : unknown buffer : %x", buffer); - } - - if(buffer != GR_BUFFER_AUXBUFFER) - { - if (writeMode == GR_LFBWRITEMODE_888) { - //printf("LfbLock GR_LFBWRITEMODE_888\n"); - info->lfbPtr = frameBuffer; - info->strideInBytes = width*4; - info->writeMode = GR_LFBWRITEMODE_888; - info->origin = origin; - //glReadPixels(0, viewport_offset, width, height, GL_BGRA, GL_UNSIGNED_BYTE, frameBuffer); - } else { - buf = (unsigned char*)malloc(width*height*4); - - info->lfbPtr = frameBuffer; - info->strideInBytes = width*2; - info->writeMode = GR_LFBWRITEMODE_565; - info->origin = origin; - glReadPixels(0, viewport_offset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buf); - - for (j=0; j> 3) << 11) | - ((buf[j*width*4+i*4+1] >> 2) << 5) | - (buf[j*width*4+i*4+2] >> 3); - } - } - free(buf); - } + WriteTrace(TraceGlitch, TraceWarning, "grLfbLock : write only"); } else { - info->lfbPtr = depthBuffer; - info->strideInBytes = width*2; - info->writeMode = GR_LFBWRITEMODE_ZA16; - info->origin = origin; - glReadPixels(0, viewport_offset, width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, depthBuffer); - } - } + unsigned char *buf; + int i, j; - return FXTRUE; + switch (buffer) + { + case GR_BUFFER_FRONTBUFFER: + //glReadBuffer(GL_FRONT); + break; + case GR_BUFFER_BACKBUFFER: + //glReadBuffer(GL_BACK); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grLfbLock : unknown buffer : %x", buffer); + } + + if (buffer != GR_BUFFER_AUXBUFFER) + { + if (writeMode == GR_LFBWRITEMODE_888) { + //printf("LfbLock GR_LFBWRITEMODE_888\n"); + info->lfbPtr = frameBuffer; + info->strideInBytes = width * 4; + info->writeMode = GR_LFBWRITEMODE_888; + info->origin = origin; + //glReadPixels(0, viewport_offset, width, height, GL_BGRA, GL_UNSIGNED_BYTE, frameBuffer); + } + else { + buf = (unsigned char*)malloc(width*height * 4); + + info->lfbPtr = frameBuffer; + info->strideInBytes = width * 2; + info->writeMode = GR_LFBWRITEMODE_565; + info->origin = origin; + glReadPixels(0, viewport_offset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buf); + + for (j = 0; j < height; j++) + { + for (i = 0; i < width; i++) + { + frameBuffer[(height - j - 1)*width + i] = + ((buf[j*width * 4 + i * 4 + 0] >> 3) << 11) | + ((buf[j*width * 4 + i * 4 + 1] >> 2) << 5) | + (buf[j*width * 4 + i * 4 + 2] >> 3); + } + } + free(buf); + } + } + else + { + info->lfbPtr = depthBuffer; + info->strideInBytes = width * 2; + info->writeMode = GR_LFBWRITEMODE_ZA16; + info->origin = origin; + glReadPixels(0, viewport_offset, width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, depthBuffer); + } + } + + return FXTRUE; } FX_ENTRY FxBool FX_CALL -grLfbUnlock( GrLock_t type, GrBuffer_t buffer ) +grLfbUnlock(GrLock_t type, GrBuffer_t buffer) { - LOG("grLfbUnlock(%d,%d)\r\n", type, buffer); - if (type == GR_LFB_WRITE_ONLY) - { - display_warning("grLfbUnlock : write only"); - } - return FXTRUE; + LOG("grLfbUnlock(%d,%d)\r\n", type, buffer); + if (type == GR_LFB_WRITE_ONLY) + { + WriteTrace(TraceGlitch, TraceWarning, "grLfbUnlock : write only"); + } + return FXTRUE; } FX_ENTRY FxBool FX_CALL -grLfbReadRegion( GrBuffer_t src_buffer, - FxU32 src_x, FxU32 src_y, - FxU32 src_width, FxU32 src_height, - FxU32 dst_stride, void *dst_data ) +grLfbReadRegion(GrBuffer_t src_buffer, +FxU32 src_x, FxU32 src_y, +FxU32 src_width, FxU32 src_height, +FxU32 dst_stride, void *dst_data) { - unsigned char *buf; - unsigned int i,j; - unsigned short *frameBuffer = (unsigned short*)dst_data; - unsigned short *depthBuffer = (unsigned short*)dst_data; - LOG("grLfbReadRegion(%d,%d,%d,%d,%d,%d)\r\n", src_buffer, src_x, src_y, src_width, src_height, dst_stride); + unsigned char *buf; + unsigned int i, j; + unsigned short *frameBuffer = (unsigned short*)dst_data; + unsigned short *depthBuffer = (unsigned short*)dst_data; + LOG("grLfbReadRegion(%d,%d,%d,%d,%d,%d)\r\n", src_buffer, src_x, src_y, src_width, src_height, dst_stride); - switch(src_buffer) - { - case GR_BUFFER_FRONTBUFFER: - //glReadBuffer(GL_FRONT); - break; - case GR_BUFFER_BACKBUFFER: - //glReadBuffer(GL_BACK); - break; - /*case GR_BUFFER_AUXBUFFER: - glReadBuffer(current_buffer); - break;*/ - default: - display_warning("grReadRegion : unknown buffer : %x", src_buffer); - } - - if(src_buffer != GR_BUFFER_AUXBUFFER) - { - buf = (unsigned char*)malloc(src_width*src_height*4); - - glReadPixels(src_x, (viewport_offset)+height-src_y-src_height, src_width, src_height, GL_RGBA, GL_UNSIGNED_BYTE, buf); - - for (j=0; j> 3) << 11) | - ((buf[(src_height-j-1)*src_width*4+i*4+1] >> 2) << 5) | - (buf[(src_height-j-1)*src_width*4+i*4+2] >> 3); - } - } - free(buf); - } - else - { - buf = (unsigned char*)malloc(src_width*src_height*2); - - glReadPixels(src_x, (viewport_offset)+height-src_y-src_height, src_width, src_height, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, depthBuffer); - - for (j=0;j>10)&0x1F)<<3; - buf[j*tex_width*4+i*4+1]=((col>>5)&0x1F)<<3; - buf[j*tex_width*4+i*4+2]=((col>>0)&0x1F)<<3; - buf[j*tex_width*4+i*4+3]= (col>>15) ? 0xFF : 0; - } - } - break; - case GR_LFBWRITEMODE_555: - for (j=0; j>10)&0x1F)<<3; - buf[j*tex_width*4+i*4+1]=((col>>5)&0x1F)<<3; - buf[j*tex_width*4+i*4+2]=((col>>0)&0x1F)<<3; - buf[j*tex_width*4+i*4+3]=0xFF; - } - } - break; - case GR_LFBWRITEMODE_565: - for (j=0; j>11)&0x1F)<<3; - buf[j*tex_width*4+i*4+1]=((col>>5)&0x3F)<<2; - buf[j*tex_width*4+i*4+2]=((col>>0)&0x1F)<<3; - buf[j*tex_width*4+i*4+3]=0xFF; - } - } - break; + case GR_BUFFER_FRONTBUFFER: + //glReadBuffer(GL_FRONT); + break; + case GR_BUFFER_BACKBUFFER: + //glReadBuffer(GL_BACK); + break; + /*case GR_BUFFER_AUXBUFFER: + glReadBuffer(current_buffer); + break;*/ default: - display_warning("grLfbWriteRegion : unknown format : %d", src_format); + WriteTrace(TraceGlitch, TraceWarning, "grReadRegion : unknown buffer : %x", src_buffer); } -#ifdef VPDEBUG - if (dumping) { - ilTexImage(tex_width, tex_height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, buf); - char name[128]; - static int id; - sprintf(name, "dump/writecolor%d.png", id++); - ilSaveImage(name); - //printf("dumped gdLfbWriteRegion %s\n", name); - } -#endif - - glBindTexture(GL_TEXTURE_2D, default_texture); - glTexImage2D(GL_TEXTURE_2D, 0, 4, tex_width, tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); - free(buf); - - set_copy_shader(); - - glDisable(GL_DEPTH_TEST); - glDisable(GL_BLEND); - render_rectangle(texture_number, - dst_x, dst_y, - src_width, src_height, - tex_width, tex_height, +1); - - } - else - { - float *buf = (float*)malloc(src_width*(src_height+(viewport_offset))*sizeof(float)); - - if (src_format != GR_LFBWRITEMODE_ZA16) - display_warning("unknown depth buffer write format:%x", src_format); - - if(dst_x || dst_y) - display_warning("dst_x:%d, dst_y:%d\n",dst_x, dst_y); - - for (j=0; j> 3) << 11) | + ((buf[(src_height - j - 1)*src_width * 4 + i * 4 + 1] >> 2) << 5) | + (buf[(src_height - j - 1)*src_width * 4 + i * 4 + 2] >> 3); + } + } + free(buf); } + else + { + buf = (unsigned char*)malloc(src_width*src_height * 2); + + glReadPixels(src_x, (viewport_offset)+height - src_y - src_height, src_width, src_height, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, depthBuffer); + + for (j = 0; j < src_height; j++) + { + for (i = 0; i < src_width; i++) + { + depthBuffer[j*(dst_stride / 2) + i] = + ((unsigned short*)buf)[(src_height - j - 1)*src_width * 4 + i * 4]; + } + } + free(buf); + } + + return FXTRUE; +} + +FX_ENTRY FxBool FX_CALL +grLfbWriteRegion(GrBuffer_t dst_buffer, +FxU32 dst_x, FxU32 dst_y, +GrLfbSrcFmt_t src_format, +FxU32 src_width, FxU32 src_height, +FxBool pixelPipeline, +FxI32 src_stride, void *src_data) +{ + unsigned char *buf; + unsigned int i, j; + unsigned short *frameBuffer = (unsigned short*)src_data; + int texture_number; + unsigned int tex_width = 1, tex_height = 1; + LOG("grLfbWriteRegion(%d,%d,%d,%d,%d,%d,%d,%d)\r\n", dst_buffer, dst_x, dst_y, src_format, src_width, src_height, pixelPipeline, src_stride); + + //glPushAttrib(GL_ALL_ATTRIB_BITS); + + while (tex_width < src_width) tex_width <<= 1; + while (tex_height < src_height) tex_height <<= 1; + + switch (dst_buffer) + { + case GR_BUFFER_BACKBUFFER: + //glDrawBuffer(GL_BACK); + break; + case GR_BUFFER_AUXBUFFER: + //glDrawBuffer(current_buffer); + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grLfbWriteRegion : unknown buffer : %x", dst_buffer); + } + + if (dst_buffer != GR_BUFFER_AUXBUFFER) + { + buf = (unsigned char*)malloc(tex_width*tex_height * 4); + + texture_number = GL_TEXTURE0; + glActiveTexture(texture_number); + + const unsigned int half_stride = src_stride / 2; + switch (src_format) + { + case GR_LFB_SRC_FMT_1555: + for (j = 0; j < src_height; j++) + { + for (i = 0; i < src_width; i++) + { + const unsigned int col = frameBuffer[j*half_stride + i]; + buf[j*tex_width * 4 + i * 4 + 0] = ((col >> 10) & 0x1F) << 3; + buf[j*tex_width * 4 + i * 4 + 1] = ((col >> 5) & 0x1F) << 3; + buf[j*tex_width * 4 + i * 4 + 2] = ((col >> 0) & 0x1F) << 3; + buf[j*tex_width * 4 + i * 4 + 3] = (col >> 15) ? 0xFF : 0; + } + } + break; + case GR_LFBWRITEMODE_555: + for (j = 0; j < src_height; j++) + { + for (i = 0; i < src_width; i++) + { + const unsigned int col = frameBuffer[j*half_stride + i]; + buf[j*tex_width * 4 + i * 4 + 0] = ((col >> 10) & 0x1F) << 3; + buf[j*tex_width * 4 + i * 4 + 1] = ((col >> 5) & 0x1F) << 3; + buf[j*tex_width * 4 + i * 4 + 2] = ((col >> 0) & 0x1F) << 3; + buf[j*tex_width * 4 + i * 4 + 3] = 0xFF; + } + } + break; + case GR_LFBWRITEMODE_565: + for (j = 0; j < src_height; j++) + { + for (i = 0; i < src_width; i++) + { + const unsigned int col = frameBuffer[j*half_stride + i]; + buf[j*tex_width * 4 + i * 4 + 0] = ((col >> 11) & 0x1F) << 3; + buf[j*tex_width * 4 + i * 4 + 1] = ((col >> 5) & 0x3F) << 2; + buf[j*tex_width * 4 + i * 4 + 2] = ((col >> 0) & 0x1F) << 3; + buf[j*tex_width * 4 + i * 4 + 3] = 0xFF; + } + } + break; + default: + WriteTrace(TraceGlitch, TraceWarning, "grLfbWriteRegion : unknown format : %d", src_format); + } #ifdef VPDEBUG - if (dumping) { - unsigned char * buf2 = (unsigned char *)malloc(src_width*(src_height+(viewport_offset))); - for (i=0; iresolution != GR_QUERY_ANY) - { - res_inf = res_sup = resTemplate->resolution; - } - if ((unsigned int)resTemplate->refresh == GR_QUERY_ANY) display_warning("querying any refresh rate"); - if ((unsigned int)resTemplate->numAuxBuffers == GR_QUERY_ANY) display_warning("querying any numAuxBuffers"); - if ((unsigned int)resTemplate->numColorBuffers == GR_QUERY_ANY) display_warning("querying any numColorBuffers"); + int res_inf = 0; + int res_sup = 0xf; + int i; + int n = 0; + LOG("grQueryResolutions\r\n"); + WriteTrace(TraceGlitch, TraceWarning, "grQueryResolutions"); + if ((unsigned int)resTemplate->resolution != GR_QUERY_ANY) + { + res_inf = res_sup = resTemplate->resolution; + } + if ((unsigned int)resTemplate->refresh == GR_QUERY_ANY) WriteTrace(TraceGlitch, TraceWarning, "querying any refresh rate"); + if ((unsigned int)resTemplate->numAuxBuffers == GR_QUERY_ANY) WriteTrace(TraceGlitch, TraceWarning, "querying any numAuxBuffers"); + if ((unsigned int)resTemplate->numColorBuffers == GR_QUERY_ANY) WriteTrace(TraceGlitch, TraceWarning, "querying any numColorBuffers"); - if (output == NULL) return res_sup - res_inf + 1; - for (i=res_inf; i<=res_sup; i++) - { - output[n].resolution = i; - output[n].refresh = resTemplate->refresh; - output[n].numAuxBuffers = resTemplate->numAuxBuffers; - output[n].numColorBuffers = resTemplate->numColorBuffers; - n++; - } - return res_sup - res_inf + 1; + if (output == NULL) return res_sup - res_inf + 1; + for (i = res_inf; i <= res_sup; i++) + { + output[n].resolution = i; + output[n].refresh = resTemplate->refresh; + output[n].numAuxBuffers = resTemplate->numAuxBuffers; + output[n].numColorBuffers = resTemplate->numColorBuffers; + n++; + } + return res_sup - res_inf + 1; } FX_ENTRY FxBool FX_CALL -grReset( FxU32 what ) +grReset(FxU32 what) { - display_warning("grReset"); - return 1; + WriteTrace(TraceGlitch, TraceWarning, "grReset"); + return 1; } FX_ENTRY void FX_CALL -grEnable( GrEnableMode_t mode ) +grEnable(GrEnableMode_t mode) { - LOG("grEnable(%d)\r\n", mode); - if (mode == GR_TEXTURE_UMA_EXT) - UMAmode = 1; + LOG("grEnable(%d)\r\n", mode); + if (mode == GR_TEXTURE_UMA_EXT) + UMAmode = 1; } FX_ENTRY void FX_CALL -grDisable( GrEnableMode_t mode ) +grDisable(GrEnableMode_t mode) { - LOG("grDisable(%d)\r\n", mode); - if (mode == GR_TEXTURE_UMA_EXT) - UMAmode = 0; + LOG("grDisable(%d)\r\n", mode); + if (mode == GR_TEXTURE_UMA_EXT) + UMAmode = 0; } FX_ENTRY void FX_CALL -grDisableAllEffects( void ) +grDisableAllEffects(void) { - display_warning("grDisableAllEffects"); + WriteTrace(TraceGlitch, TraceWarning, "grDisableAllEffects"); } FX_ENTRY void FX_CALL -grErrorSetCallback( GrErrorCallbackFnc_t fnc ) +grErrorSetCallback(GrErrorCallbackFnc_t fnc) { - display_warning("grErrorSetCallback"); + WriteTrace(TraceGlitch, TraceWarning, "grErrorSetCallback"); } FX_ENTRY void FX_CALL grFinish(void) { - display_warning("grFinish"); + WriteTrace(TraceGlitch, TraceWarning, "grFinish"); } FX_ENTRY void FX_CALL grFlush(void) { - display_warning("grFlush"); + WriteTrace(TraceGlitch, TraceWarning, "grFlush"); } FX_ENTRY void FX_CALL -grTexMultibase( GrChipID_t tmu, - FxBool enable ) +grTexMultibase(GrChipID_t tmu, +FxBool enable) { - display_warning("grTexMultibase"); + WriteTrace(TraceGlitch, TraceWarning, "grTexMultibase"); } FX_ENTRY void FX_CALL -grTexMipMapMode( GrChipID_t tmu, - GrMipMapMode_t mode, - FxBool lodBlend ) +grTexMipMapMode(GrChipID_t tmu, +GrMipMapMode_t mode, +FxBool lodBlend) { - display_warning("grTexMipMapMode"); + WriteTrace(TraceGlitch, TraceWarning, "grTexMipMapMode"); } FX_ENTRY void FX_CALL -grTexDownloadTablePartial( GrTexTable_t type, - void *data, - int start, - int end ) +grTexDownloadTablePartial(GrTexTable_t type, +void *data, +int start, +int end) { - display_warning("grTexDownloadTablePartial"); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadTablePartial"); } FX_ENTRY void FX_CALL -grTexDownloadTable( GrTexTable_t type, - void *data ) +grTexDownloadTable(GrTexTable_t type, +void *data) { - display_warning("grTexDownloadTable"); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadTable"); } FX_ENTRY FxBool FX_CALL -grTexDownloadMipMapLevelPartial( GrChipID_t tmu, - FxU32 startAddress, - GrLOD_t thisLod, - GrLOD_t largeLod, - GrAspectRatio_t aspectRatio, - GrTextureFormat_t format, - FxU32 evenOdd, - void *data, - int start, - int end ) +grTexDownloadMipMapLevelPartial(GrChipID_t tmu, +FxU32 startAddress, +GrLOD_t thisLod, +GrLOD_t largeLod, +GrAspectRatio_t aspectRatio, +GrTextureFormat_t format, +FxU32 evenOdd, +void *data, +int start, +int end) { - display_warning("grTexDownloadMipMapLevelPartial"); - return 1; + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMapLevelPartial"); + return 1; } FX_ENTRY void FX_CALL -grTexDownloadMipMapLevel( GrChipID_t tmu, - FxU32 startAddress, - GrLOD_t thisLod, - GrLOD_t largeLod, - GrAspectRatio_t aspectRatio, - GrTextureFormat_t format, - FxU32 evenOdd, - void *data ) +grTexDownloadMipMapLevel(GrChipID_t tmu, +FxU32 startAddress, +GrLOD_t thisLod, +GrLOD_t largeLod, +GrAspectRatio_t aspectRatio, +GrTextureFormat_t format, +FxU32 evenOdd, +void *data) { - display_warning("grTexDownloadMipMapLevel"); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMapLevel"); } FX_ENTRY void FX_CALL -grTexNCCTable( GrNCCTable_t table ) +grTexNCCTable(GrNCCTable_t table) { - display_warning("grTexNCCTable"); + WriteTrace(TraceGlitch, TraceWarning, "grTexNCCTable"); } FX_ENTRY void FX_CALL -grViewport( FxI32 x, FxI32 y, FxI32 width, FxI32 height ) +grViewport(FxI32 x, FxI32 y, FxI32 width, FxI32 height) { - display_warning("grViewport"); + WriteTrace(TraceGlitch, TraceWarning, "grViewport"); } FX_ENTRY void FX_CALL -grDepthRange( FxFloat n, FxFloat f ) +grDepthRange(FxFloat n, FxFloat f) { - display_warning("grDepthRange"); + WriteTrace(TraceGlitch, TraceWarning, "grDepthRange"); } FX_ENTRY void FX_CALL grSplash(float x, float y, float width, float height, FxU32 frame) { - display_warning("grSplash"); + WriteTrace(TraceGlitch, TraceWarning, "grSplash"); } FX_ENTRY FxBool FX_CALL -grSelectContext( GrContext_t context ) +grSelectContext(GrContext_t context) { - display_warning("grSelectContext"); - return 1; + WriteTrace(TraceGlitch, TraceWarning, "grSelectContext"); + return 1; } FX_ENTRY void FX_CALL grAADrawTriangle( - const void *a, const void *b, const void *c, - FxBool ab_antialias, FxBool bc_antialias, FxBool ca_antialias - ) +const void *a, const void *b, const void *c, +FxBool ab_antialias, FxBool bc_antialias, FxBool ca_antialias +) { - display_warning("grAADrawTriangle"); + WriteTrace(TraceGlitch, TraceWarning, "grAADrawTriangle"); } FX_ENTRY void FX_CALL -grAlphaControlsITRGBLighting( FxBool enable ) +grAlphaControlsITRGBLighting(FxBool enable) { - display_warning("grAlphaControlsITRGBLighting"); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaControlsITRGBLighting"); } FX_ENTRY void FX_CALL -grGlideSetVertexLayout( const void *layout ) +grGlideSetVertexLayout(const void *layout) { - display_warning("grGlideSetVertexLayout"); + WriteTrace(TraceGlitch, TraceWarning, "grGlideSetVertexLayout"); } FX_ENTRY void FX_CALL -grGlideGetVertexLayout( void *layout ) +grGlideGetVertexLayout(void *layout) { - display_warning("grGlideGetVertexLayout"); + WriteTrace(TraceGlitch, TraceWarning, "grGlideGetVertexLayout"); } FX_ENTRY void FX_CALL -grGlideSetState( const void *state ) +grGlideSetState(const void *state) { - display_warning("grGlideSetState"); + WriteTrace(TraceGlitch, TraceWarning, "grGlideSetState"); } FX_ENTRY void FX_CALL -grGlideGetState( void *state ) +grGlideGetState(void *state) { - display_warning("grGlideGetState"); + WriteTrace(TraceGlitch, TraceWarning, "grGlideGetState"); } FX_ENTRY void FX_CALL grLfbWriteColorFormat(GrColorFormat_t colorFormat) { - display_warning("grLfbWriteColorFormat"); + WriteTrace(TraceGlitch, TraceWarning, "grLfbWriteColorFormat"); } FX_ENTRY void FX_CALL grLfbWriteColorSwizzle(FxBool swizzleBytes, FxBool swapWords) { - display_warning("grLfbWriteColorSwizzle"); + WriteTrace(TraceGlitch, TraceWarning, "grLfbWriteColorSwizzle"); } FX_ENTRY void FX_CALL -grLfbConstantDepth( FxU32 depth ) +grLfbConstantDepth(FxU32 depth) { - display_warning("grLfbConstantDepth"); + WriteTrace(TraceGlitch, TraceWarning, "grLfbConstantDepth"); } FX_ENTRY void FX_CALL -grLfbConstantAlpha( GrAlpha_t alpha ) +grLfbConstantAlpha(GrAlpha_t alpha) { - display_warning("grLfbConstantAlpha"); + WriteTrace(TraceGlitch, TraceWarning, "grLfbConstantAlpha"); } FX_ENTRY void FX_CALL -grTexMultibaseAddress( GrChipID_t tmu, - GrTexBaseRange_t range, - FxU32 startAddress, - FxU32 evenOdd, - GrTexInfo *info ) +grTexMultibaseAddress(GrChipID_t tmu, +GrTexBaseRange_t range, +FxU32 startAddress, +FxU32 evenOdd, +GrTexInfo *info) { - display_warning("grTexMultibaseAddress"); + WriteTrace(TraceGlitch, TraceWarning, "grTexMultibaseAddress"); } /* inline void MySleep(FxU32 ms) { #ifdef _WIN32 - Sleep(ms); +Sleep(ms); #else - SDL_Delay(ms); +SDL_Delay(ms); #endif } */ @@ -2396,108 +2377,108 @@ inline void MySleep(FxU32 ms) #ifdef _WIN32 static void CorrectGamma(LPVOID apGammaRamp) { - HDC hdc = GetDC(NULL); - if (hdc != NULL) - { - SetDeviceGammaRamp(hdc, apGammaRamp); - ReleaseDC(NULL, hdc); - } + HDC hdc = GetDC(NULL); + if (hdc != NULL) + { + SetDeviceGammaRamp(hdc, apGammaRamp); + ReleaseDC(NULL, hdc); + } } #else static void CorrectGamma(const FxU16 aGammaRamp[3][256]) { - //TODO? - //int res = SDL_SetGammaRamp(aGammaRamp[0], aGammaRamp[1], aGammaRamp[2]); - //LOG("SDL_SetGammaRamp returned %d\r\n", res); + //TODO? + //int res = SDL_SetGammaRamp(aGammaRamp[0], aGammaRamp[1], aGammaRamp[2]); + //LOG("SDL_SetGammaRamp returned %d\r\n", res); } #endif FX_ENTRY void FX_CALL -grLoadGammaTable( FxU32 nentries, FxU32 *red, FxU32 *green, FxU32 *blue) +grLoadGammaTable(FxU32 nentries, FxU32 *red, FxU32 *green, FxU32 *blue) { - LOG("grLoadGammaTable\r\n"); - if (!fullscreen) - return; - FxU16 aGammaRamp[3][256]; - for (int i = 0; i < 256; i++) - { - aGammaRamp[0][i] = (FxU16)((red[i] << 8) & 0xFFFF); - aGammaRamp[1][i] = (FxU16)((green[i] << 8) & 0xFFFF); - aGammaRamp[2][i] = (FxU16)((blue[i] << 8) & 0xFFFF); - } - CorrectGamma(aGammaRamp); - //MySleep(1000); //workaround for Mupen64 + LOG("grLoadGammaTable\r\n"); + if (!fullscreen) + return; + FxU16 aGammaRamp[3][256]; + for (int i = 0; i < 256; i++) + { + aGammaRamp[0][i] = (FxU16)((red[i] << 8) & 0xFFFF); + aGammaRamp[1][i] = (FxU16)((green[i] << 8) & 0xFFFF); + aGammaRamp[2][i] = (FxU16)((blue[i] << 8) & 0xFFFF); + } + CorrectGamma(aGammaRamp); + //MySleep(1000); //workaround for Mupen64 } FX_ENTRY void FX_CALL grGetGammaTableExt(FxU32 nentries, FxU32 *red, FxU32 *green, FxU32 *blue) { - return; - //TODO? - /* - LOG("grGetGammaTableExt()\r\n"); - FxU16 aGammaRamp[3][256]; -#ifdef _WIN32 - HDC hdc = GetDC(NULL); - if (hdc == NULL) return; - if (GetDeviceGammaRamp(hdc, aGammaRamp) == TRUE) - { + //TODO? + /* + LOG("grGetGammaTableExt()\r\n"); + FxU16 aGammaRamp[3][256]; + #ifdef _WIN32 + HDC hdc = GetDC(NULL); + if (hdc == NULL) + return; + if (GetDeviceGammaRamp(hdc, aGammaRamp) == TRUE) + { ReleaseDC(NULL, hdc); -#else - if (SDL_GetGammaRamp(aGammaRamp[0], aGammaRamp[1], aGammaRamp[2]) != -1) - { -#endif + #else + if (SDL_GetGammaRamp(aGammaRamp[0], aGammaRamp[1], aGammaRamp[2]) != -1) + { + #endif for (int i = 0; i < 256; i++) { - red[i] = aGammaRamp[0][i] >> 8; - green[i] = aGammaRamp[1][i] >> 8; - blue[i] = aGammaRamp[2][i] >> 8; + red[i] = aGammaRamp[0][i] >> 8; + green[i] = aGammaRamp[1][i] >> 8; + blue[i] = aGammaRamp[2][i] >> 8; } - } - */ + } + */ } FX_ENTRY void FX_CALL -guGammaCorrectionRGB( FxFloat gammaR, FxFloat gammaG, FxFloat gammaB ) +guGammaCorrectionRGB(FxFloat gammaR, FxFloat gammaG, FxFloat gammaB) { - LOG("guGammaCorrectionRGB()\r\n"); - if (!fullscreen) - return; - FxU16 aGammaRamp[3][256]; - for (int i = 0; i < 256; i++) - { - aGammaRamp[0][i] = (((FxU16)((pow(i/255.0F, 1.0F/gammaR)) * 255.0F + 0.5F)) << 8) & 0xFFFF; - aGammaRamp[1][i] = (((FxU16)((pow(i/255.0F, 1.0F/gammaG)) * 255.0F + 0.5F)) << 8) & 0xFFFF; - aGammaRamp[2][i] = (((FxU16)((pow(i/255.0F, 1.0F/gammaB)) * 255.0F + 0.5F)) << 8) & 0xFFFF; - } - CorrectGamma(aGammaRamp); + LOG("guGammaCorrectionRGB()\r\n"); + if (!fullscreen) + return; + FxU16 aGammaRamp[3][256]; + for (int i = 0; i < 256; i++) + { + aGammaRamp[0][i] = (((FxU16)((pow(i / 255.0F, 1.0F / gammaR)) * 255.0F + 0.5F)) << 8) & 0xFFFF; + aGammaRamp[1][i] = (((FxU16)((pow(i / 255.0F, 1.0F / gammaG)) * 255.0F + 0.5F)) << 8) & 0xFFFF; + aGammaRamp[2][i] = (((FxU16)((pow(i / 255.0F, 1.0F / gammaB)) * 255.0F + 0.5F)) << 8) & 0xFFFF; + } + CorrectGamma(aGammaRamp); } FX_ENTRY void FX_CALL -grDitherMode( GrDitherMode_t mode ) +grDitherMode(GrDitherMode_t mode) { - display_warning("grDitherMode"); + WriteTrace(TraceGlitch, TraceWarning, "grDitherMode"); } void grChromaRangeExt(GrColor_t color0, GrColor_t color1, FxU32 mode) { - display_warning("grChromaRangeExt"); + WriteTrace(TraceGlitch, TraceWarning, "grChromaRangeExt"); } void grChromaRangeModeExt(GrChromakeyMode_t mode) { - display_warning("grChromaRangeModeExt"); + WriteTrace(TraceGlitch, TraceWarning, "grChromaRangeModeExt"); } void grTexChromaRangeExt(GrChipID_t tmu, GrColor_t color0, GrColor_t color1, GrTexChromakeyMode_t mode) { - display_warning("grTexChromaRangeExt"); + WriteTrace(TraceGlitch, TraceWarning, "grTexChromaRangeExt"); } void grTexChromaModeExt(GrChipID_t tmu, GrChromakeyMode_t mode) { - display_warning("grTexChromaRangeModeExt"); + WriteTrace(TraceGlitch, TraceWarning, "grTexChromaRangeModeExt"); } // VP debug @@ -2508,97 +2489,97 @@ static int tl[10240]; void dump_start() { - static int init; - if (!init) { - init = 1; - ilInit(); - ilEnable(IL_FILE_OVERWRITE); - } - dumping = 1; - tl_i = 0; + static int init; + if (!init) { + init = 1; + ilInit(); + ilEnable(IL_FILE_OVERWRITE); + } + dumping = 1; + tl_i = 0; } void dump_stop() { - if (!dumping) return; + if (!dumping) return; - int i, j; - for (i=0; i>8; - ( (unsigned char *)frameBuffer )[(i+j*width)*3+2] = c&0xff; + int i, j; + for (i=0; i>8; + ( (unsigned char *)frameBuffer )[(i+j*width)*3+2] = c&0xff; + } } - char name[128]; - // sprintf(name, "mkdir -p dump ; rm -f dump/tex%04d.png", i); - // system(name); - sprintf(name, "dump/tex%04d.png", i); - fprintf(stderr, "Writing '%s'\n", name); - ilSaveImage(name); + ilTexImage(width, height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, frameBuffer); + ilSaveImage("dump/framedepth.png"); - // SDL_FreeSurface(surf); - free(pixels); - } - glBindTexture(GL_TEXTURE_2D, default_texture); + for (i=0; ilargeLodLog2 != info->smallLodLog2) display_warning("grTexTextureMemRequired : loading more than one LOD"); + if (info->largeLodLog2 != info->smallLodLog2) WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : loading more than one LOD"); if (info->aspectRatioLog2 < 0) { @@ -221,7 +221,7 @@ grTexTextureMemRequired( FxU32 evenOdd, case GR_TEXFMT_ARGB_CMP_FXT1: return ((((width+0x7)&~0x7)*((height+0x3)&~0x3))>>1); default: - display_warning("grTexTextureMemRequired : unknown texture format: %x", info->format); + WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : unknown texture format: %x", info->format); } return 0; } @@ -233,7 +233,7 @@ grTexCalcMemRequired( { int width, height; LOG("grTexCalcMemRequired(%d, %d, %d, %d)\r\n", lodmin, lodmax, aspect, fmt); - if (lodmax != lodmin) display_warning("grTexCalcMemRequired : loading more than one LOD"); + if (lodmax != lodmin) WriteTrace(TraceGlitch, TraceWarning, "grTexCalcMemRequired : loading more than one LOD"); if (aspect < 0) { @@ -271,7 +271,7 @@ grTexCalcMemRequired( case GR_TEXFMT_ARGB_CMP_FXT1: return ((((width+0x7)&~0x7)*((height+0x3)&~0x3))>>1); default: - display_warning("grTexTextureMemRequired : unknown texture format: %x", fmt); + WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : unknown texture format: %x", fmt); } return 0; } @@ -315,7 +315,7 @@ int grTexFormatSize(int fmt) factor = 8; break; default: - display_warning("grTexFormatSize : unknown texture format: %x", fmt); + WriteTrace(TraceGlitch, TraceWarning, "grTexFormatSize : unknown texture format: %x", fmt); } return factor; } @@ -401,7 +401,7 @@ int grTexFormat2GLPackedFmt(int fmt, int * gltexfmt, int * glpixfmt, int * glpac *glpackfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; // XXX: what should we do about GL_COMPRESSED_RGB_FXT1_3DFX? break; default: - display_warning("grTexFormat2GLPackedFmt : unknown texture format: %x", fmt); + WriteTrace(TraceGlitch, TraceWarning, "grTexFormat2GLPackedFmt : unknown texture format: %x", fmt); } return factor; */ @@ -418,7 +418,7 @@ grTexDownloadMipMap( GrChipID_t tmu, int glformat = 0; int gltexfmt, glpixfmt, glpackfmt; LOG("grTexDownloadMipMap(%d,%d,%d)\r\n", tmu, startAddress, evenOdd); - if (info->largeLodLog2 != info->smallLodLog2) display_warning("grTexDownloadMipMap : loading more than one LOD"); + if (info->largeLodLog2 != info->smallLodLog2) WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMap : loading more than one LOD"); if (info->aspectRatioLog2 < 0) { @@ -622,7 +622,7 @@ grTexDownloadMipMap( GrChipID_t tmu, break; */ default: - display_warning("grTexDownloadMipMap : unknown texture format: %x", info->format); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMap : unknown texture format: %x", info->format); factor = 0; } } @@ -767,14 +767,14 @@ grTexDetailControl( { if (!lod_bias && !detail_scale && !detail_max) return; else - display_warning("grTexDetailControl : %d, %d, %f", lod_bias, detail_scale, detail_max); + WriteTrace(TraceGlitch, TraceWarning, "grTexDetailControl : %d, %d, %f", lod_bias, detail_scale, detail_max); } lambda = detail_max; if(lambda > 1.0f) { lambda = 1.0f - (255.0f - lambda); } - if(lambda > 1.0f) display_warning("lambda:%f", lambda); + if(lambda > 1.0f) WriteTrace(TraceGlitch, TraceWarning, "lambda:%f", lambda); set_lambda(); } @@ -843,7 +843,7 @@ grTexClampMode( wrap_s0 = GL_MIRRORED_REPEAT; break; default: - display_warning("grTexClampMode : unknown s_clampmode : %x", s_clampmode); + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown s_clampmode : %x", s_clampmode); } switch(t_clampmode) { @@ -857,7 +857,7 @@ grTexClampMode( wrap_t0 = GL_MIRRORED_REPEAT; break; default: - display_warning("grTexClampMode : unknown t_clampmode : %x", t_clampmode); + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown t_clampmode : %x", t_clampmode); } glActiveTexture(GL_TEXTURE0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s0); @@ -877,7 +877,7 @@ grTexClampMode( wrap_s1 = GL_MIRRORED_REPEAT; break; default: - display_warning("grTexClampMode : unknown s_clampmode : %x", s_clampmode); + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown s_clampmode : %x", s_clampmode); } switch(t_clampmode) { @@ -891,7 +891,7 @@ grTexClampMode( wrap_t1 = GL_MIRRORED_REPEAT; break; default: - display_warning("grTexClampMode : unknown t_clampmode : %x", t_clampmode); + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown t_clampmode : %x", t_clampmode); } glActiveTexture(GL_TEXTURE1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1); diff --git a/Source/Glitch64/OGLcombiner.cpp b/Source/Glitch64/OGLcombiner.cpp index ce38857ff..59e8cb175 100644 --- a/Source/Glitch64/OGLcombiner.cpp +++ b/Source/Glitch64/OGLcombiner.cpp @@ -243,11 +243,11 @@ void init_combiner() if (!log_length) { glGetInfoLogARB(fragment_shader_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); glGetInfoLogARB(vertex_shader_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); glGetInfoLogARB(program_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); } texture0_location = glGetUniformLocationARB(program_object, "texture0"); @@ -267,11 +267,11 @@ void init_combiner() if (!log_length) { glGetInfoLogARB(fragment_shader_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); glGetInfoLogARB(vertex_shader_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); glGetInfoLogARB(program_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); } texture0_location = glGetUniformLocationARB(program_object, "texture0"); @@ -314,7 +314,7 @@ void compile_chroma_shader() strcat(fragment_shader_chroma, "float alpha = constant_color.a; \n"); break; default: - display_warning("unknown compile_choma_shader_alpha : %x", chroma_other_alpha); + WriteTrace(TraceGlitch, TraceWarning, "unknown compile_choma_shader_alpha : %x", chroma_other_alpha); } switch (chroma_other_color) @@ -329,7 +329,7 @@ void compile_chroma_shader() strcat(fragment_shader_chroma, "vec4 color = vec4(vec3(constant_color),alpha); \n"); break; default: - display_warning("unknown compile_choma_shader_alpha : %x", chroma_other_color); + WriteTrace(TraceGlitch, TraceWarning, "unknown compile_choma_shader_alpha : %x", chroma_other_color); } strcat(fragment_shader_chroma, "if (color.rgb == chroma_color.rgb) discard; \n"); @@ -487,12 +487,12 @@ void compile_shader() { glGetInfoLogARB(shader_programs[number_of_programs].fragment_shader_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); glGetInfoLogARB(vertex_shader_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); glGetInfoLogARB(program_object, 2048, &log_length, shader_log); - if (log_length) display_warning(shader_log); + if (log_length) WriteTrace(TraceGlitch, TraceWarning, shader_log); } texture0_location = glGetUniformLocationARB(program_object, "texture0"); @@ -582,7 +582,7 @@ grConstantColorValue(GrColor_t value) texture_env_color[3] = (value & 0xFF) / 255.0f; break; default: - display_warning("grConstantColorValue: unknown color format : %x", lfb_color_fmt); + WriteTrace(TraceGlitch, TraceWarning, "grConstantColorValue: unknown color format : %x", lfb_color_fmt); } constant_color_location = glGetUniformLocationARB(program_object, "constant_color"); @@ -606,7 +606,7 @@ int setOtherColorSource(int other) return GL_CONSTANT_ARB; break; default: - display_warning("unknwown other color source : %x", other); + WriteTrace(TraceGlitch, TraceWarning, "unknown other color source : %x", other); } return 0; } @@ -622,7 +622,7 @@ int setLocalColorSource(int local) return GL_CONSTANT_ARB; break; default: - display_warning("unknwown local color source : %x", local); + WriteTrace(TraceGlitch, TraceWarning, "unknown local color source : %x", local); } return 0; } @@ -641,7 +641,7 @@ void writeGLSLColorOther(int other) strcat(fragment_shader_color_combiner, "vec4 color_other = constant_color; \n"); break; default: - display_warning("unknown writeGLSLColorOther : %x", other); + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLColorOther : %x", other); } } @@ -656,7 +656,7 @@ void writeGLSLColorLocal(int local) strcat(fragment_shader_color_combiner, "vec4 color_local = constant_color; \n"); break; default: - display_warning("unknown writeGLSLColorLocal : %x", local); + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLColorLocal : %x", local); } } @@ -704,7 +704,7 @@ void writeGLSLColorFactor(int factor, int local, int need_local, int other, int strcat(fragment_shader_color_combiner, "vec4 color_factor = vec4(1.0) - vec4(ctexture1.a); \n"); break; default: - display_warning("unknown writeGLSLColorFactor : %x", factor); + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLColorFactor : %x", factor); } } @@ -731,7 +731,7 @@ FxBool invert) last_local = local; last_other = other; - if (invert) display_warning("grColorCombine : inverted result"); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "inverted result"); color_combiner_key = function | (factor << 4) | (local << 8) | (other << 10); chroma_other_color = other; @@ -797,7 +797,7 @@ FxBool invert) break; default: strcpy(fragment_shader_color_combiner, fragment_shader_default); - display_warning("grColorCombine : unknown function : %x", function); + WriteTrace(TraceGlitch, TraceWarning, "unknown function : %x", function); } //compile_shader(); need_to_compile = 1; @@ -817,7 +817,7 @@ int setOtherAlphaSource(int other) return GL_CONSTANT_ARB; break; default: - display_warning("unknwown other alpha source : %x", other); + WriteTrace(TraceGlitch, TraceWarning, "unknwown other alpha source : %x", other); } return 0; } @@ -833,7 +833,7 @@ int setLocalAlphaSource(int local) return GL_CONSTANT_ARB; break; default: - display_warning("unknwown local alpha source : %x", local); + WriteTrace(TraceGlitch, TraceWarning, "unknwown local alpha source : %x", local); } return 0; } @@ -852,7 +852,7 @@ void writeGLSLAlphaOther(int other) strcat(fragment_shader_alpha_combiner, "float alpha_other = constant_color.a; \n"); break; default: - display_warning("unknown writeGLSLAlphaOther : %x", other); + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLAlphaOther : %x", other); } } @@ -867,7 +867,7 @@ void writeGLSLAlphaLocal(int local) strcat(fragment_shader_alpha_combiner, "float alpha_local = constant_color.a; \n"); break; default: - display_warning("unknown writeGLSLAlphaLocal : %x", local); + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLAlphaLocal : %x", local); } } @@ -912,7 +912,7 @@ void writeGLSLAlphaFactor(int factor, int local, int need_local, int other, int strcat(fragment_shader_alpha_combiner, "float alpha_factor = 1.0 - ctexture1.a; \n"); break; default: - display_warning("unknown writeGLSLAlphaFactor : %x", factor); + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLAlphaFactor : %x", factor); } } @@ -939,7 +939,7 @@ FxBool invert last_local = local; last_other = other; - if (invert) display_warning("grAlphaCombine : inverted result"); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "inverted result"); alpha_combiner_key = function | (factor << 4) | (local << 8) | (other << 10); chroma_other_alpha = other; @@ -1005,7 +1005,7 @@ FxBool invert strcat(fragment_shader_alpha_combiner, "gl_FragColor.a = alpha_factor * (-alpha_local) + alpha_local; \n"); break; default: - display_warning("grAlphaCombine : unknown function : %x", function); + WriteTrace(TraceGlitch, TraceWarning, "unknown function : %x", function); } //compile_shader(); @@ -1077,7 +1077,7 @@ void writeGLSLTextureColorFactor(int num_tex, int factor) strcat(fragment_shader_texture1, "vec4 texture1_color_factor = vec4(1.0) - vec4(lambda); \n"); break; default: - display_warning("unknown writeGLSLTextureColorFactor : %x", factor); + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLTextureColorFactor : %x", factor); } } @@ -1146,7 +1146,7 @@ void writeGLSLTextureAlphaFactor(int num_tex, int factor) strcat(fragment_shader_texture1, "float texture1_alpha_factor = 1.0 - lambda; \n"); break; default: - display_warning("unknown writeGLSLTextureAlphaFactor : %x", factor); + WriteTrace(TraceGlitch, TraceWarning, "unknown writeGLSLTextureAlphaFactor : %x", factor); } } @@ -1300,7 +1300,7 @@ FxBool alpha_invert strcat(fragment_shader_texture0, "vec4 ctexture0 = readtex0; \n"); else strcat(fragment_shader_texture1, "vec4 ctexture1 = readtex1; \n"); - display_warning("grTextCombine : unknown rgb function : %x", rgb_function); + WriteTrace(TraceGlitch, TraceWarning, "grTextCombine : unknown rgb function : %x", rgb_function); } if (rgb_invert) @@ -1392,7 +1392,7 @@ FxBool alpha_invert strcat(fragment_shader_texture0, "ctexture0.a = readtex0.a; \n"); else strcat(fragment_shader_texture1, "ctexture1.a = ctexture0.a; \n"); - display_warning("grTextCombine : unknown alpha function : %x", alpha_function); + WriteTrace(TraceGlitch, TraceWarning, "grTextCombine : unknown alpha function : %x", alpha_function); } if (alpha_invert) @@ -1429,7 +1429,7 @@ GrAlphaBlendFnc_t alpha_sf, GrAlphaBlendFnc_t alpha_df sfactorRGB = GL_ONE_MINUS_SRC_ALPHA; break; default: - display_warning("grAlphaBlendFunction : rgb_sf = %x", rgb_sf); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaBlendFunction : rgb_sf = %x", rgb_sf); } switch (rgb_df) @@ -1447,7 +1447,7 @@ GrAlphaBlendFnc_t alpha_sf, GrAlphaBlendFnc_t alpha_df dfactorRGB = GL_ONE_MINUS_SRC_ALPHA; break; default: - display_warning("grAlphaBlendFunction : rgb_df = %x", rgb_df); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaBlendFunction : rgb_df = %x", rgb_df); } switch (alpha_sf) @@ -1459,7 +1459,7 @@ GrAlphaBlendFnc_t alpha_sf, GrAlphaBlendFnc_t alpha_df sfactorAlpha = GL_ONE; break; default: - display_warning("grAlphaBlendFunction : alpha_sf = %x", alpha_sf); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaBlendFunction : alpha_sf = %x", alpha_sf); } switch (alpha_df) @@ -1471,7 +1471,7 @@ GrAlphaBlendFnc_t alpha_sf, GrAlphaBlendFnc_t alpha_df dfactorAlpha = GL_ONE; break; default: - display_warning("grAlphaBlendFunction : alpha_df = %x", alpha_df); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaBlendFunction : alpha_df = %x", alpha_df); } glEnable(GL_BLEND); if (blend_func_separate_support) @@ -1510,7 +1510,7 @@ grAlphaTestFunction(GrCmpFnc_t function) return; break; default: - display_warning("grAlphaTestFunction : unknown function : %x", function); + WriteTrace(TraceGlitch, TraceWarning, "unknown function : %x", function); } glEnable(GL_ALPHA_TEST); @@ -1540,7 +1540,7 @@ grFogMode(GrFogMode_t mode) fog_enabled = 2; break; default: - display_warning("grFogMode : unknown mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "unknown mode : %x", mode); } need_to_compile = 1; @@ -1594,7 +1594,7 @@ grFogColorValue(GrColor_t fogcolor) color[3] = (fogcolor & 0xFF) / 255.0f; break; default: - display_warning("grFogColorValue: unknown color format : %x", lfb_color_fmt); + WriteTrace(TraceGlitch, TraceWarning, "unknown color format : %x", lfb_color_fmt); } glFogfv(GL_FOG_COLOR, color); @@ -1616,7 +1616,7 @@ grChromakeyMode(GrChromakeyMode_t mode) chroma_enabled = 1; break; default: - display_warning("grChromakeyMode : unknown mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "unknown mode : %x", mode); } need_to_compile = 1; } @@ -1642,7 +1642,7 @@ grChromakeyValue(GrColor_t value) chroma_color[3] = 1.0;//(value & 0xFF) / 255.0f; break; default: - display_warning("grChromakeyValue: unknown color format : %x", lfb_color_fmt); + WriteTrace(TraceGlitch, TraceWarning, "grChromakeyValue: unknown color format : %x", lfb_color_fmt); } chroma_color_location = glGetUniformLocationARB(program_object, "chroma_color"); @@ -1723,7 +1723,7 @@ grStippleMode(GrStippleMode_t mode) glEnable(GL_TEXTURE_2D); break; default: - display_warning("grStippleMode:%x", mode); + WriteTrace(TraceGlitch, TraceWarning, "grStippleMode:%x", mode); } need_to_compile = 1; @@ -1738,8 +1738,8 @@ GrCCUColor_t d, FxBool d_invert, FxU32 shift, FxBool invert) { WriteTrace(TraceResolution, TraceDebug, "a: %d a_mode: %d b: %d b_mode: %d c: %d c_invert: %d d: %d d_invert: %d shift: %d invert: %d", a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); - if (invert) display_warning("grColorCombineExt : inverted result"); - if (shift) display_warning("grColorCombineExt : shift = %d", shift); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : inverted result"); + if (shift) WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : shift = %d", shift); color_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | @@ -1772,7 +1772,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_color_combiner, "vec4 cs_a = ctexture1; \n"); break; default: - display_warning("grColorCombineExt : a = %x", a); + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : a = %x", a); strcat(fragment_shader_color_combiner, "vec4 cs_a = vec4(0.0); \n"); } @@ -1791,7 +1791,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_color_combiner, "vec4 c_a = -cs_a; \n"); break; default: - display_warning("grColorCombineExt : a_mode = %x", a_mode); + WriteTrace(TraceGlitch, TraceWarning, "a_mode = %x", a_mode); strcat(fragment_shader_color_combiner, "vec4 c_a = vec4(0.0); \n"); } @@ -1819,7 +1819,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_color_combiner, "vec4 cs_b = ctexture1; \n"); break; default: - display_warning("grColorCombineExt : b = %x", b); + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : b = %x", b); strcat(fragment_shader_color_combiner, "vec4 cs_b = vec4(0.0); \n"); } @@ -1838,7 +1838,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_color_combiner, "vec4 c_b = -cs_b; \n"); break; default: - display_warning("grColorCombineExt : b_mode = %x", b_mode); + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : b_mode = %x", b_mode); strcat(fragment_shader_color_combiner, "vec4 c_b = vec4(0.0); \n"); } @@ -1875,7 +1875,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_color_combiner, "vec4 c_c = ctexture1; \n"); break; default: - display_warning("grColorCombineExt : c = %x", c); + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : c = %x", c); strcat(fragment_shader_color_combiner, "vec4 c_c = vec4(0.0); \n"); } @@ -1900,7 +1900,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_color_combiner, "vec4 c_d = gl_Color; \n"); break; default: - display_warning("grColorCombineExt : d = %x", d); + WriteTrace(TraceGlitch, TraceWarning, "grColorCombineExt : d = %x", d); strcat(fragment_shader_color_combiner, "vec4 c_d = vec4(0.0); \n"); } @@ -1920,8 +1920,8 @@ GrACUColor_t d, FxBool d_invert, FxU32 shift, FxBool invert) { WriteTrace(TraceResolution, TraceDebug, "a: %d a_mode: %d b: %d b_mode: %d c: %d c_invert: %d d: %d d_invert: %d shift: %d invert: %d", a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); - if (invert) display_warning("grAlphaCombineExt : inverted result"); - if (shift) display_warning("grAlphaCombineExt : shift = %d", shift); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : inverted result"); + if (shift) WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : shift = %d", shift); alpha_combiner_key = 0x80000000 | (a & 0x1F) | ((a_mode & 3) << 5) | ((b & 0x1F) << 7) | ((b_mode & 3) << 12) | @@ -1945,7 +1945,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_alpha_combiner, "float as_a = gl_Color.a; \n"); break; default: - display_warning("grAlphaCombineExt : a = %x", a); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : a = %x", a); strcat(fragment_shader_alpha_combiner, "float as_a = 0.0; \n"); } @@ -1964,7 +1964,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_alpha_combiner, "float a_a = -as_a; \n"); break; default: - display_warning("grAlphaCombineExt : a_mode = %x", a_mode); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : a_mode = %x", a_mode); strcat(fragment_shader_alpha_combiner, "float a_a = 0.0; \n"); } @@ -1983,7 +1983,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_alpha_combiner, "float as_b = gl_Color.a; \n"); break; default: - display_warning("grAlphaCombineExt : b = %x", b); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : b = %x", b); strcat(fragment_shader_alpha_combiner, "float as_b = 0.0; \n"); } @@ -2002,7 +2002,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_alpha_combiner, "float a_b = -as_b; \n"); break; default: - display_warning("grAlphaCombineExt : b_mode = %x", b_mode); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : b_mode = %x", b_mode); strcat(fragment_shader_alpha_combiner, "float a_b = 0.0; \n"); } @@ -2030,7 +2030,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_alpha_combiner, "float a_c = gl_Color.a; \n"); break; default: - display_warning("grAlphaCombineExt : c = %x", c); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : c = %x", c); strcat(fragment_shader_alpha_combiner, "float a_c = 0.0; \n"); } @@ -2052,7 +2052,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_alpha_combiner, "float a_d = as_b; \n"); break; default: - display_warning("grAlphaCombineExt : d = %x", d); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaCombineExt : d = %x", d); strcat(fragment_shader_alpha_combiner, "float a_d = 0.0; \n"); } @@ -2075,8 +2075,8 @@ FxU32 shift, FxBool invert) int num_tex; WriteTrace(TraceResolution, TraceDebug, "tmu: %d a: %d a_mode: %d b: %d b_mode: %d c: %d c_invert: %d d: %d d_invert: %d shift: %d invert: %d", tmu, a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); - if (invert) display_warning("grTexColorCombineExt : inverted result"); - if (shift) display_warning("grTexColorCombineExt : shift = %d", shift); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : inverted result"); + if (shift) WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : shift = %d", shift); if (tmu == GR_TMU0) num_tex = 1; else num_tex = 0; @@ -2157,7 +2157,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "vec4 ctex1s_a = vec4(ccolor1.a); \n"); break; default: - display_warning("grTexColorCombineExt : a = %x", a); + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : a = %x", a); if (num_tex == 0) strcat(fragment_shader_texture0, "vec4 ctex0s_a = vec4(0.0); \n"); else @@ -2191,7 +2191,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "vec4 ctex1_a = -ctex1s_a; \n"); break; default: - display_warning("grTexColorCombineExt : a_mode = %x", a_mode); + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : a_mode = %x", a_mode); if (num_tex == 0) strcat(fragment_shader_texture0, "vec4 ctex0_a = vec4(0.0); \n"); else @@ -2255,7 +2255,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "vec4 ctex1s_b = ccolor1; \n"); break; default: - display_warning("grTexColorCombineExt : b = %x", b); + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : b = %x", b); if (num_tex == 0) strcat(fragment_shader_texture0, "vec4 ctex0s_b = vec4(0.0); \n"); else @@ -2289,7 +2289,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "vec4 ctex1_b = -ctex1s_b; \n"); break; default: - display_warning("grTexColorCombineExt : b_mode = %x", b_mode); + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : b_mode = %x", b_mode); if (num_tex == 0) strcat(fragment_shader_texture0, "vec4 ctex0_b = vec4(0.0); \n"); else @@ -2365,7 +2365,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "vec4 ctex1_c = ccolor1; \n"); break; default: - display_warning("grTexColorCombineExt : c = %x", c); + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : c = %x", c); if (num_tex == 0) strcat(fragment_shader_texture0, "vec4 ctex0_c = vec4(0.0); \n"); else @@ -2407,7 +2407,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "vec4 ctex1_d = vec4(readtex1.a); \n"); break; default: - display_warning("grTexColorCombineExt : d = %x", d); + WriteTrace(TraceGlitch, TraceWarning, "grTexColorCombineExt : d = %x", d); if (num_tex == 0) strcat(fragment_shader_texture0, "vec4 ctex0_d = vec4(0.0); \n"); else @@ -2440,8 +2440,8 @@ FxU32 shift, FxBool invert) int num_tex; WriteTrace(TraceResolution, TraceDebug, "tmu: %d a: %d a_mode: %d b: %d b_mode: %d c: %d c_invert: %d d: %d d_invert: %d shift, invert: %d", tmu, a, a_mode, b, b_mode, c, c_invert, d, d_invert, shift, invert); - if (invert) display_warning("grTexAlphaCombineExt : inverted result"); - if (shift) display_warning("grTexAlphaCombineExt : shift = %d", shift); + if (invert) WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : inverted result"); + if (shift) WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : shift = %d", shift); if (tmu == GR_TMU0) num_tex = 1; else num_tex = 0; @@ -2488,7 +2488,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "ctex1s_a.a = ccolor1.a; \n"); break; default: - display_warning("grTexAlphaCombineExt : a = %x", a); + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : a = %x", a); if (num_tex == 0) strcat(fragment_shader_texture0, "ctex0s_a.a = 0.0; \n"); else @@ -2522,7 +2522,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "ctex1_a.a = -ctex1s_a.a; \n"); break; default: - display_warning("grTexAlphaCombineExt : a_mode = %x", a_mode); + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : a_mode = %x", a_mode); if (num_tex == 0) strcat(fragment_shader_texture0, "ctex0_a.a = 0.0; \n"); else @@ -2556,7 +2556,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "ctex1s_b.a = ccolor1.a; \n"); break; default: - display_warning("grTexAlphaCombineExt : b = %x", b); + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : b = %x", b); if (num_tex == 0) strcat(fragment_shader_texture0, "ctex0s_b.a = 0.0; \n"); else @@ -2590,7 +2590,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "ctex1_b.a = -ctex1s_b.a; \n"); break; default: - display_warning("grTexAlphaCombineExt : b_mode = %x", b_mode); + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : b_mode = %x", b_mode); if (num_tex == 0) strcat(fragment_shader_texture0, "ctex0_b.a = 0.0; \n"); else @@ -2642,7 +2642,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "ctex1_c.a = ccolor1.a; \n"); break; default: - display_warning("grTexAlphaCombineExt : c = %x", c); + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : c = %x", c); if (num_tex == 0) strcat(fragment_shader_texture0, "ctex0_c.a = 0.0; \n"); else @@ -2690,7 +2690,7 @@ FxU32 shift, FxBool invert) strcat(fragment_shader_texture1, "ctex1_d.a = readtex1.a; \n"); break; default: - display_warning("grTexAlphaCombineExt : d = %x", d); + WriteTrace(TraceGlitch, TraceWarning, "grTexAlphaCombineExt : d = %x", d); if (num_tex == 0) strcat(fragment_shader_texture0, "ctex0_d.a = 0.0; \n"); else @@ -2758,7 +2758,7 @@ GrColor_t value) } break; default: - display_warning("grConstantColorValue: unknown color format : %x", lfb_color_fmt); + WriteTrace(TraceGlitch, TraceWarning, "grConstantColorValue: unknown color format : %x", lfb_color_fmt); } if (num_tex == 0) diff --git a/Source/Glitch64/OGLgeometry.cpp b/Source/Glitch64/OGLgeometry.cpp index 9c8397c45..baa73a82f 100644 --- a/Source/Glitch64/OGLgeometry.cpp +++ b/Source/Glitch64/OGLgeometry.cpp @@ -67,7 +67,7 @@ grCoordinateSpace(GrCoordinateSpaceMode_t mode) case GR_WINDOW_COORDS: break; default: - display_warning("unknwown coordinate space : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "unknwown coordinate space : %x", mode); } } @@ -106,7 +106,7 @@ grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode) st1_off = offset; break; default: - display_warning("unknown grVertexLayout parameter : %x", param); + WriteTrace(TraceGlitch, TraceWarning, "unknown grVertexLayout parameter : %x", param); } } @@ -140,7 +140,7 @@ grCullMode(GrCullMode_t mode) glEnable(GL_CULL_FACE); break; default: - display_warning("unknown cull mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "unknown cull mode : %x", mode); } grDisplayGLError("grCullMode"); } @@ -168,7 +168,7 @@ grDepthBufferMode(GrDepthBufferMode_t mode) w_buffer_mode = 0; break; default: - display_warning("unknown depth buffer mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "unknown depth buffer mode : %x", mode); } grDisplayGLError("grDepthBufferMode"); } @@ -217,7 +217,7 @@ grDepthBufferFunction(GrCmpFnc_t function) break; default: - display_warning("unknown depth buffer function : %x", function); + WriteTrace(TraceGlitch, TraceWarning, "unknown depth buffer function : %x", function); } grDisplayGLError("grDepthBufferFunction"); } @@ -625,7 +625,7 @@ grDrawVertexArray(FxU32 mode, FxU32 Count, void *pointers2) glBegin(GL_TRIANGLE_FAN); break; default: - display_warning("grDrawVertexArray : unknown mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "grDrawVertexArray : unknown mode : %x", mode); } for (i = 0; i < Count; i++) @@ -700,7 +700,7 @@ grDrawVertexArrayContiguous(FxU32 mode, FxU32 Count, void *pointers, FxU32 strid glBegin(GL_TRIANGLE_FAN); break; default: - display_warning("grDrawVertexArrayContiguous : unknown mode : %x", mode); + WriteTrace(TraceGlitch, TraceWarning, "grDrawVertexArrayContiguous : unknown mode : %x", mode); } for (i = 0; i < Count; i++) diff --git a/Source/Glitch64/OGLglitchmain.cpp b/Source/Glitch64/OGLglitchmain.cpp index 4db637b6d..cec5ae1a3 100644 --- a/Source/Glitch64/OGLglitchmain.cpp +++ b/Source/Glitch64/OGLglitchmain.cpp @@ -538,22 +538,6 @@ unsigned short depthBuffer[2048 * 2048]; //#define VOODOO1 -void display_warning(const char *text, ...) -{ - static int first_message = 100; - if (first_message) - { - char buf[1000]; - - va_list ap; - - va_start(ap, text); - vsprintf(buf, text, ap); - va_end(ap); - first_message--; - } -} - #ifdef _WIN32 void display_error() { @@ -572,7 +556,7 @@ grSstOrigin(GrOriginLocation_t origin) { WriteTrace(TraceGlitch, TraceDebug, "origin = %d", origin); if (origin != GR_ORIGIN_UPPER_LEFT) - display_warning("grSstOrigin : %x", origin); + WriteTrace(TraceGlitch, TraceWarning, "grSstOrigin : %x", origin); } FX_ENTRY void FX_CALL @@ -864,7 +848,7 @@ int nAuxBuffers) height = 2048; break; default: - display_warning("unknown SstWinOpen resolution : %x", screen_resolution); + WriteTrace(TraceGlitch, TraceWarning, "unknown SstWinOpen resolution : %x", screen_resolution); } } @@ -910,7 +894,7 @@ int nAuxBuffers) // primary monitor only if (!g_FullScreenResolutions.changeDisplaySettings(screen_resolution)) { - display_warning("can't change to fullscreen mode"); + WriteTrace(TraceGlitch, TraceWarning, "can't change to fullscreen mode"); } windowedMenu = GetMenu(hwnd_win); @@ -935,7 +919,7 @@ int nAuxBuffers) if ((hDC = GetDC(hwnd_win)) == NULL) { - display_warning("GetDC on main window failed"); + WriteTrace(TraceGlitch, TraceWarning, "GetDC on main window failed"); return FXFALSE; } @@ -946,18 +930,18 @@ int nAuxBuffers) } if (pfm == 0) { - display_warning("ChoosePixelFormat failed"); + WriteTrace(TraceGlitch, TraceWarning, "ChoosePixelFormat failed"); return FXFALSE; } if (SetPixelFormat(hDC, pfm, &pfd) == 0) { - display_warning("SetPixelFormat failed"); + WriteTrace(TraceGlitch, TraceWarning, "SetPixelFormat failed"); return FXFALSE; } if ((hGLRC = wglCreateContext(hDC)) == 0) { - display_warning("wglCreateContext failed!"); + WriteTrace(TraceGlitch, TraceWarning, "wglCreateContext failed!"); grSstWinClose(0); return FXFALSE; } @@ -968,7 +952,7 @@ int nAuxBuffers) { if (!wglMakeCurrent(hDC, hGLRC)) { - display_warning("wglMakeCurrent failed!"); + WriteTrace(TraceGlitch, TraceWarning, "wglMakeCurrent failed!"); grSstWinClose(0); return FXFALSE; } @@ -982,7 +966,7 @@ int nAuxBuffers) /* Initialize SDL */ printf("(II) Initializing SDL video subsystem...\n"); - if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) + if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { printf("(EE) Error initializing SDL video subsystem: %s\n", SDL_GetError()); return false; @@ -1058,18 +1042,18 @@ int nAuxBuffers) glViewport(0, viewport_offset, width, height); #endif // _WIN32 lfb_color_fmt = color_format; - if (origin_location != GR_ORIGIN_UPPER_LEFT) display_warning("origin must be in upper left corner"); - if (nColBuffers != 2) display_warning("number of color buffer is not 2"); - if (nAuxBuffers != 1) display_warning("number of auxiliary buffer is not 1"); + if (origin_location != GR_ORIGIN_UPPER_LEFT) WriteTrace(TraceGlitch, TraceWarning, "origin must be in upper left corner"); + if (nColBuffers != 2) WriteTrace(TraceGlitch, TraceWarning, "number of color buffer is not 2"); + if (nAuxBuffers != 1) WriteTrace(TraceGlitch, TraceWarning, "number of auxiliary buffer is not 1"); if (isExtensionSupported("GL_ARB_texture_env_combine") == 0 && isExtensionSupported("GL_EXT_texture_env_combine") == 0 && show_warning) - display_warning("Your video card doesn't support GL_ARB_texture_env_combine extension"); + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_ARB_texture_env_combine extension"); if (isExtensionSupported("GL_ARB_multitexture") == 0 && show_warning) - display_warning("Your video card doesn't support GL_ARB_multitexture extension"); + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_ARB_multitexture extension"); if (isExtensionSupported("GL_ARB_texture_mirrored_repeat") == 0 && show_warning) - display_warning("Your video card doesn't support GL_ARB_texture_mirrored_repeat extension"); + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_ARB_texture_mirrored_repeat extension"); show_warning = 0; #ifdef _WIN32 @@ -1084,7 +1068,7 @@ int nAuxBuffers) nbTextureUnits = 0; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &nbTextureUnits); - if (nbTextureUnits == 1) display_warning("You need a video card that has at least 2 texture units"); + if (nbTextureUnits == 1) WriteTrace(TraceGlitch, TraceWarning, "You need a video card that has at least 2 texture units"); nbAuxBuffers = 0; glGetIntegerv(GL_AUX_BUFFERS, &nbAuxBuffers); @@ -1204,9 +1188,9 @@ int nAuxBuffers) } if (isExtensionSupported("GL_EXT_texture_compression_s3tc") == 0 && show_warning) - display_warning("Your video card doesn't support GL_EXT_texture_compression_s3tc extension"); + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_EXT_texture_compression_s3tc extension"); if (isExtensionSupported("GL_3DFX_texture_compression_FXT1") == 0 && show_warning) - display_warning("Your video card doesn't support GL_3DFX_texture_compression_FXT1 extension"); + WriteTrace(TraceGlitch, TraceWarning, "Your video card doesn't support GL_3DFX_texture_compression_FXT1 extension"); #ifdef _WIN32 glCompressedTexImage2DARB = (PFNGLCOMPRESSEDTEXIMAGE2DPROC)wglGetProcAddress("glCompressedTexImage2DARB"); @@ -1315,7 +1299,7 @@ int nAuxBuffers) glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &ifmt); if (ifmt != GL_RGB5_A1) { - display_warning("ATI SUCKS %x\n", ifmt); + WriteTrace(TraceGlitch, TraceWarning, "ATI SUCKS %x\n", ifmt); ati_sucks = 1; } else @@ -1362,7 +1346,7 @@ grSstWinClose(GrContext_t context) if (clear_texbuff) { - for (i=0; iresolution != GR_QUERY_ANY) { res_inf = res_sup = resTemplate->resolution; } - if ((unsigned int)resTemplate->refresh == GR_QUERY_ANY) display_warning("querying any refresh rate"); - if ((unsigned int)resTemplate->numAuxBuffers == GR_QUERY_ANY) display_warning("querying any numAuxBuffers"); - if ((unsigned int)resTemplate->numColorBuffers == GR_QUERY_ANY) display_warning("querying any numColorBuffers"); + if ((unsigned int)resTemplate->refresh == GR_QUERY_ANY) WriteTrace(TraceGlitch, TraceWarning, "querying any refresh rate"); + if ((unsigned int)resTemplate->numAuxBuffers == GR_QUERY_ANY) WriteTrace(TraceGlitch, TraceWarning, "querying any numAuxBuffers"); + if ((unsigned int)resTemplate->numColorBuffers == GR_QUERY_ANY) WriteTrace(TraceGlitch, TraceWarning, "querying any numColorBuffers"); if (output == NULL) return res_sup - res_inf + 1; for (i = res_inf; i <= res_sup; i++) @@ -2732,7 +2716,7 @@ grQueryResolutions(const GrResolution *resTemplate, GrResolution *output) FX_ENTRY FxBool FX_CALL grReset(FxU32 /*what*/) { - display_warning("grReset"); + WriteTrace(TraceGlitch, TraceWarning, "grReset"); return 1; } @@ -2755,13 +2739,13 @@ grDisable(GrEnableMode_t mode) FX_ENTRY void FX_CALL grDisableAllEffects(void) { - display_warning("grDisableAllEffects"); + WriteTrace(TraceGlitch, TraceWarning, "grDisableAllEffects"); } FX_ENTRY void FX_CALL grErrorSetCallback(GrErrorCallbackFnc_t /*fnc*/) { - display_warning("grErrorSetCallback"); + WriteTrace(TraceGlitch, TraceWarning, "grErrorSetCallback"); } FX_ENTRY void FX_CALL @@ -2782,7 +2766,7 @@ FX_ENTRY void FX_CALL grTexMultibase(GrChipID_t /*tmu*/, FxBool /*enable*/) { - display_warning("grTexMultibase"); + WriteTrace(TraceGlitch, TraceWarning, "grTexMultibase"); } FX_ENTRY void FX_CALL @@ -2790,7 +2774,7 @@ grTexMipMapMode(GrChipID_t /*tmu*/, GrMipMapMode_t /*mode*/, FxBool /*lodBlend*/) { - display_warning("grTexMipMapMode"); + WriteTrace(TraceGlitch, TraceWarning, "grTexMipMapMode"); } FX_ENTRY void FX_CALL @@ -2799,14 +2783,14 @@ void * /*data*/, int /*start*/, int /*end*/) { - display_warning("grTexDownloadTablePartial"); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadTablePartial"); } FX_ENTRY void FX_CALL grTexDownloadTable(GrTexTable_t /*type*/, void * /*data*/) { - display_warning("grTexDownloadTable"); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadTable"); } FX_ENTRY FxBool FX_CALL @@ -2821,7 +2805,7 @@ void * /*data*/, int /*start*/, int /*end*/) { - display_warning("grTexDownloadMipMapLevelPartial"); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMapLevelPartial"); return 1; } @@ -2835,37 +2819,37 @@ GrTextureFormat_t /*format*/, FxU32 /*evenOdd*/, void * /*data*/) { - display_warning("grTexDownloadMipMapLevel"); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMapLevel"); } FX_ENTRY void FX_CALL grTexNCCTable(GrNCCTable_t /*table*/) { - display_warning("grTexNCCTable"); + WriteTrace(TraceGlitch, TraceWarning, "grTexNCCTable"); } FX_ENTRY void FX_CALL grViewport(FxI32 /*x*/, FxI32 /*y*/, FxI32 /*width*/, FxI32 /*height*/) { - display_warning("grViewport"); + WriteTrace(TraceGlitch, TraceWarning, "grViewport"); } FX_ENTRY void FX_CALL grDepthRange(FxFloat /*n*/, FxFloat /*f*/) { - display_warning("grDepthRange"); + WriteTrace(TraceGlitch, TraceWarning, "grDepthRange"); } FX_ENTRY void FX_CALL grSplash(float /*x*/, float /*y*/, float /*width*/, float /*height*/, FxU32 /*frame*/) { - display_warning("grSplash"); + WriteTrace(TraceGlitch, TraceWarning, "grSplash"); } FX_ENTRY FxBool FX_CALL grSelectContext(GrContext_t /*context*/) { - display_warning("grSelectContext"); + WriteTrace(TraceGlitch, TraceWarning, "grSelectContext"); return 1; } @@ -2875,61 +2859,61 @@ const void * /*a*/, const void * /*b*/, const void * /*c*/, FxBool /*ab_antialias*/, FxBool /*bc_antialias*/, FxBool /*ca_antialias*/ ) { - display_warning("grAADrawTriangle"); + WriteTrace(TraceGlitch, TraceWarning, "grAADrawTriangle"); } FX_ENTRY void FX_CALL grAlphaControlsITRGBLighting(FxBool /*enable*/) { - display_warning("grAlphaControlsITRGBLighting"); + WriteTrace(TraceGlitch, TraceWarning, "grAlphaControlsITRGBLighting"); } FX_ENTRY void FX_CALL grGlideSetVertexLayout(const void * /*layout*/) { - display_warning("grGlideSetVertexLayout"); + WriteTrace(TraceGlitch, TraceWarning, "grGlideSetVertexLayout"); } FX_ENTRY void FX_CALL grGlideGetVertexLayout(void * /*layout*/) { - display_warning("grGlideGetVertexLayout"); + WriteTrace(TraceGlitch, TraceWarning, "grGlideGetVertexLayout"); } FX_ENTRY void FX_CALL grGlideSetState(const void * /*state*/) { - display_warning("grGlideSetState"); + WriteTrace(TraceGlitch, TraceWarning, "grGlideSetState"); } FX_ENTRY void FX_CALL grGlideGetState(void * /*state*/) { - display_warning("grGlideGetState"); + WriteTrace(TraceGlitch, TraceWarning, "grGlideGetState"); } FX_ENTRY void FX_CALL grLfbWriteColorFormat(GrColorFormat_t /*colorFormat*/) { - display_warning("grLfbWriteColorFormat"); + WriteTrace(TraceGlitch, TraceWarning, "grLfbWriteColorFormat"); } FX_ENTRY void FX_CALL grLfbWriteColorSwizzle(FxBool /*swizzleBytes*/, FxBool /*swapWords*/) { - display_warning("grLfbWriteColorSwizzle"); + WriteTrace(TraceGlitch, TraceWarning, "grLfbWriteColorSwizzle"); } FX_ENTRY void FX_CALL grLfbConstantDepth(FxU32 /*depth*/) { - display_warning("grLfbConstantDepth"); + WriteTrace(TraceGlitch, TraceWarning, "grLfbConstantDepth"); } FX_ENTRY void FX_CALL grLfbConstantAlpha(GrAlpha_t /*alpha*/) { - display_warning("grLfbConstantAlpha"); + WriteTrace(TraceGlitch, TraceWarning, "grLfbConstantAlpha"); } FX_ENTRY void FX_CALL @@ -2939,7 +2923,7 @@ FxU32 /*startAddress*/, FxU32 /*evenOdd*/, GrTexInfo * /*info*/) { - display_warning("grTexMultibaseAddress"); + WriteTrace(TraceGlitch, TraceWarning, "grTexMultibaseAddress"); } inline void MySleep(FxU32 ms) @@ -2968,7 +2952,7 @@ static void CorrectGamma(const FxU16 aGammaRamp[3][256]) res = SDL_SetGammaRamp(aGammaRamp[0], aGammaRamp[1], aGammaRamp[2]); WriteTrace(TraceGlitch, TraceDebug, "SDL_SetGammaRamp returned %d\r\n", res); -} + } #endif FX_ENTRY void FX_CALL @@ -3011,7 +2995,7 @@ grGetGammaTableExt(FxU32 /*nentries*/, FxU32 *red, FxU32 *green, FxU32 *blue) blue[i] = aGammaRamp[2][i] >> 8; } } -} + } FX_ENTRY void FX_CALL guGammaCorrectionRGB(FxFloat gammaR, FxFloat gammaG, FxFloat gammaB) @@ -3032,27 +3016,27 @@ guGammaCorrectionRGB(FxFloat gammaR, FxFloat gammaG, FxFloat gammaB) FX_ENTRY void FX_CALL grDitherMode(GrDitherMode_t /*mode*/) { - display_warning("grDitherMode"); + WriteTrace(TraceGlitch, TraceWarning, "grDitherMode"); } void grChromaRangeExt(GrColor_t /*color0*/, GrColor_t /*color1*/, FxU32 /*mode*/) { - display_warning("grChromaRangeExt"); + WriteTrace(TraceGlitch, TraceWarning, "grChromaRangeExt"); } void grChromaRangeModeExt(GrChromakeyMode_t /*mode*/) { - display_warning("grChromaRangeModeExt"); + WriteTrace(TraceGlitch, TraceWarning, "grChromaRangeModeExt"); } void grTexChromaRangeExt(GrChipID_t /*tmu*/, GrColor_t /*color0*/, GrColor_t /*color1*/, GrTexChromakeyMode_t /*mode*/) { - display_warning("grTexChromaRangeExt"); + WriteTrace(TraceGlitch, TraceWarning, "grTexChromaRangeExt"); } void grTexChromaModeExt(GrChipID_t /*tmu*/, GrChromakeyMode_t /*mode*/) { - display_warning("grTexChromaRangeModeExt"); + WriteTrace(TraceGlitch, TraceWarning, "grTexChromaRangeModeExt"); } static const char * GL_errors[7 + 1] = { @@ -3124,7 +3108,7 @@ void dump_start() init = 1; ilInit(); ilEnable(IL_FILE_OVERWRITE); - } +} dumping = 1; tl_i = 0; } diff --git a/Source/Glitch64/OGLtextures.cpp b/Source/Glitch64/OGLtextures.cpp index a51cabc92..f178a21a2 100644 --- a/Source/Glitch64/OGLtextures.cpp +++ b/Source/Glitch64/OGLtextures.cpp @@ -164,7 +164,7 @@ GrTexInfo *info) { WriteTrace(TraceGlitch, TraceDebug, "evenOdd = %d", evenOdd); int width, height; - if (info->largeLodLog2 != info->smallLodLog2) display_warning("grTexTextureMemRequired : loading more than one LOD"); + if (info->largeLodLog2 != info->smallLodLog2) WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : loading more than one LOD"); if (info->aspectRatioLog2 < 0) { @@ -202,7 +202,7 @@ GrTexInfo *info) case GR_TEXFMT_ARGB_CMP_FXT1: return ((((width + 0x7)&~0x7)*((height + 0x3)&~0x3)) >> 1); default: - display_warning("grTexTextureMemRequired : unknown texture format: %x", info->format); + WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : unknown texture format: %x", info->format); } return 0; } @@ -214,7 +214,7 @@ GrAspectRatio_t aspect, GrTextureFormat_t fmt) { WriteTrace(TraceGlitch, TraceDebug, "lodmin = %d, lodmax: %d aspect: %d fmt: %d", lodmin, lodmax, aspect, fmt); int width, height; - if (lodmax != lodmin) display_warning("grTexCalcMemRequired : loading more than one LOD"); + if (lodmax != lodmin) WriteTrace(TraceGlitch, TraceWarning, "grTexCalcMemRequired : loading more than one LOD"); if (aspect < 0) { @@ -252,7 +252,7 @@ GrAspectRatio_t aspect, GrTextureFormat_t fmt) case GR_TEXFMT_ARGB_CMP_FXT1: return ((((width + 0x7)&~0x7)*((height + 0x3)&~0x3)) >> 1); default: - display_warning("grTexTextureMemRequired : unknown texture format: %x", fmt); + WriteTrace(TraceGlitch, TraceWarning, "grTexTextureMemRequired : unknown texture format: %x", fmt); } return 0; } @@ -296,7 +296,7 @@ int grTexFormatSize(int fmt) factor = 8; break; default: - display_warning("grTexFormatSize : unknown texture format: %x", fmt); + WriteTrace(TraceGlitch, TraceWarning, "grTexFormatSize : unknown texture format: %x", fmt); } return factor; } @@ -377,7 +377,7 @@ int grTexFormat2GLPackedFmt(int fmt, int * gltexfmt, int * glpixfmt, int * glpac *glpackfmt = GL_COMPRESSED_RGBA_FXT1_3DFX; // XXX: what should we do about GL_COMPRESSED_RGB_FXT1_3DFX? break; default: - display_warning("grTexFormat2GLPackedFmt : unknown texture format: %x", fmt); + WriteTrace(TraceGlitch, TraceWarning, "grTexFormat2GLPackedFmt : unknown texture format: %x", fmt); } return factor; } @@ -394,7 +394,7 @@ GrTexInfo *info) int factor; int glformat = 0; int gltexfmt = 0, glpixfmt = 0, glpackfmt = 0; - if (info->largeLodLog2 != info->smallLodLog2) display_warning("grTexDownloadMipMap : loading more than one LOD"); + if (info->largeLodLog2 != info->smallLodLog2) WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMap : loading more than one LOD"); if (info->aspectRatioLog2 < 0) { @@ -595,7 +595,7 @@ GrTexInfo *info) glformat = GL_COMPRESSED_RGBA_FXT1_3DFX; break; default: - display_warning("grTexDownloadMipMap : unknown texture format: %x", info->format); + WriteTrace(TraceGlitch, TraceWarning, "grTexDownloadMipMap : unknown texture format: %x", info->format); factor = 0; } } @@ -740,14 +740,14 @@ float detail_max { if (!lod_bias && !detail_scale && !detail_max) return; else - display_warning("grTexDetailControl : %d, %d, %f", lod_bias, detail_scale, detail_max); + WriteTrace(TraceGlitch, TraceWarning, "grTexDetailControl : %d, %d, %f", lod_bias, detail_scale, detail_max); } lambda = detail_max; if (lambda > 1.0f) { lambda = 1.0f - (255.0f - lambda); } - if (lambda > 1.0f) display_warning("lambda:%f", lambda); + if (lambda > 1.0f) WriteTrace(TraceGlitch, TraceWarning, "lambda:%f", lambda); set_lambda(); } @@ -817,7 +817,7 @@ GrTextureClampMode_t t_clampmode wrap_s0 = GL_MIRRORED_REPEAT_ARB; break; default: - display_warning("grTexClampMode : unknown s_clampmode : %x", s_clampmode); + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown s_clampmode : %x", s_clampmode); } switch (t_clampmode) { @@ -831,7 +831,7 @@ GrTextureClampMode_t t_clampmode wrap_t0 = GL_MIRRORED_REPEAT_ARB; break; default: - display_warning("grTexClampMode : unknown t_clampmode : %x", t_clampmode); + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown t_clampmode : %x", t_clampmode); } glActiveTextureARB(GL_TEXTURE0_ARB); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s0); @@ -851,7 +851,7 @@ GrTextureClampMode_t t_clampmode wrap_s1 = GL_MIRRORED_REPEAT_ARB; break; default: - display_warning("grTexClampMode : unknown s_clampmode : %x", s_clampmode); + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown s_clampmode : %x", s_clampmode); } switch (t_clampmode) { @@ -865,7 +865,7 @@ GrTextureClampMode_t t_clampmode wrap_t1 = GL_MIRRORED_REPEAT_ARB; break; default: - display_warning("grTexClampMode : unknown t_clampmode : %x", t_clampmode); + WriteTrace(TraceGlitch, TraceWarning, "grTexClampMode : unknown t_clampmode : %x", t_clampmode); } glActiveTextureARB(GL_TEXTURE1_ARB); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s1); diff --git a/Source/Glitch64/glitchmain.h b/Source/Glitch64/glitchmain.h index a6a238cbf..2c1e12d66 100644 --- a/Source/Glitch64/glitchmain.h +++ b/Source/Glitch64/glitchmain.h @@ -11,6 +11,8 @@ void dump_stop(); extern int dumping; #endif +#include + #define zscale 1.0f typedef struct _wrapper_config @@ -82,8 +84,6 @@ extern "C" { #endif // _WIN32 #include "glide.h" -void display_warning(const unsigned char *text, ...); -void display_warning(const char *text, ...); void init_geometry(); void init_textures(); void init_combiner(); @@ -242,49 +242,52 @@ FX_ENTRY void FX_CALL grConstantColorValueExt(GrChipID_t tmu, GrColor_t value); -#define CHECK_FRAMEBUFFER_STATUS() \ -{\ - GLenum status; \ - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); \ - /*display_warning("%x\n", status);*/\ - switch(status) { \ - case GL_FRAMEBUFFER_COMPLETE_EXT: \ - /*display_warning("framebuffer complete!\n");*/\ - break; \ - case GL_FRAMEBUFFER_UNSUPPORTED_EXT: \ - display_warning("framebuffer GL_FRAMEBUFFER_UNSUPPORTED_EXT\n");\ - /* you gotta choose different formats */ \ - /*assert(0);*/ \ - break; \ - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: \ - display_warning("framebuffer INCOMPLETE_ATTACHMENT\n");\ - break; \ - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: \ - display_warning("framebuffer FRAMEBUFFER_MISSING_ATTACHMENT\n");\ - break; \ - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: \ - display_warning("framebuffer FRAMEBUFFER_DIMENSIONS\n");\ - break; \ - /*case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: \ - display_warning("framebuffer INCOMPLETE_DUPLICATE_ATTACHMENT\n");\ - break;*/ \ - case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: \ - display_warning("framebuffer INCOMPLETE_FORMATS\n");\ - break; \ - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: \ - display_warning("framebuffer INCOMPLETE_DRAW_BUFFER\n");\ - break; \ - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: \ - display_warning("framebuffer INCOMPLETE_READ_BUFFER\n");\ - break; \ - case GL_FRAMEBUFFER_BINDING_EXT: \ - display_warning("framebuffer BINDING_EXT\n");\ - break; \ - default: \ - break; \ - /* programming error; will fail on all hardware */ \ - /*assert(0);*/ \ - }\ +static void CHECK_FRAMEBUFFER_STATUS(void) +{ + GLenum status; + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + + WriteTrace(TraceGlitch, TraceDebug, "status: %X", status); + switch (status) + { + case GL_FRAMEBUFFER_COMPLETE_EXT: + WriteTrace(TraceGlitch, TraceDebug, "framebuffer complete!"); + break; + case GL_FRAMEBUFFER_UNSUPPORTED_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer GL_FRAMEBUFFER_UNSUPPORTED_EXT"); + /* you gotta choose different formats */ + /*assert(0);*/ + break; + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer INCOMPLETE_ATTACHMENT"); + break; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer FRAMEBUFFER_MISSING_ATTACHMENT"); + break; + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer FRAMEBUFFER_DIMENSIONS"); + break; + /*case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer INCOMPLETE_DUPLICATE_ATTACHMENT"); + break;*/ + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer INCOMPLETE_FORMATS"); + break; + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer INCOMPLETE_DRAW_BUFFER"); + break; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer INCOMPLETE_READ_BUFFER"); + break; + case GL_FRAMEBUFFER_BINDING_EXT: + WriteTrace(TraceGlitch, TraceWarning, "framebuffer BINDING_EXT"); + break; + default: + WriteTrace(TraceGlitch, TraceError, "Unhandled status: %X", status); + break; + /* programming error; will fail on all hardware */ + /*assert(0);*/ + } } #endif