GL: add #if in shader for trilinear filtering

This commit is contained in:
Flyinghead 2018-11-23 22:33:51 +01:00
parent 24e7837eaa
commit 2ef90152c9
3 changed files with 37 additions and 23 deletions

View File

@ -169,7 +169,7 @@ __forceinline
ShaderUniforms.trilinear_alpha = 1.0 - ShaderUniforms.trilinear_alpha; ShaderUniforms.trilinear_alpha = 1.0 - ShaderUniforms.trilinear_alpha;
} }
else else
ShaderUniforms.trilinear_alpha = 1.0; ShaderUniforms.trilinear_alpha = 1.f;
bool color_clamp = gp->tsp.ColorClamp && (pvrrc.fog_clamp_min != 0 || pvrrc.fog_clamp_max != 0xffffffff); bool color_clamp = gp->tsp.ColorClamp && (pvrrc.fog_clamp_min != 0 || pvrrc.fog_clamp_max != 0xffffffff);
@ -184,7 +184,8 @@ __forceinline
gp->tsp.FogCtrl, gp->tsp.FogCtrl,
gp->pcw.Gouraud, gp->pcw.Gouraud,
gp->tcw.PixelFmt == PixelBumpMap, gp->tcw.PixelFmt == PixelBumpMap,
color_clamp)]; color_clamp,
ShaderUniforms.trilinear_alpha != 1.f)];
if (CurrentShader->program == -1) if (CurrentShader->program == -1)
CompilePipelineShader(CurrentShader); CompilePipelineShader(CurrentShader);
@ -1107,7 +1108,7 @@ void DrawFramebuffer(float w, float h)
ShaderUniforms.trilinear_alpha = 1.0; ShaderUniforms.trilinear_alpha = 1.0;
PipelineShader *shader = &gl.pogram_table[GetProgramID(0, 1, 1, 0, 1, 0, 0, 2, false, false, false)]; PipelineShader *shader = &gl.pogram_table[GetProgramID(0, 1, 1, 0, 1, 0, 0, 2, false, false, false, false)];
if (shader->program == -1) if (shader->program == -1)
CompilePipelineShader(shader); CompilePipelineShader(shader);
else else

View File

@ -155,6 +155,7 @@ const char* PixelPipelineShader =
#define pp_Gouraud %d \n\ #define pp_Gouraud %d \n\
#define pp_BumpMap %d \n\ #define pp_BumpMap %d \n\
#define FogClamping %d \n\ #define FogClamping %d \n\
#define pp_TriLinear %d \n\
#define PI 3.1415926 \n\ #define PI 3.1415926 \n\
\n\ \n\
#define GLES2 0 \n\ #define GLES2 0 \n\
@ -218,7 +219,7 @@ lowp float fog_mode2(highp float w) \n\
return fog_coef.FOG_CHANNEL; \n\ return fog_coef.FOG_CHANNEL; \n\
} \n\ } \n\
\n\ \n\
highp vec4 fog_clamp(highp vec4 col) \n\ highp vec4 fog_clamp(lowp vec4 col) \n\
{ \n\ { \n\
#if FogClamping == 1 \n\ #if FogClamping == 1 \n\
return clamp(col, fog_clamp_min, fog_clamp_max); \n\ return clamp(col, fog_clamp_min, fog_clamp_max); \n\
@ -310,7 +311,9 @@ void main() \n\
} \n\ } \n\
#endif\n\ #endif\n\
\n\ \n\
#if pp_TriLinear == 1 \n\
color *= trilinear_alpha; \n\ color *= trilinear_alpha; \n\
#endif \n\
\n\ \n\
#if cp_AlphaTest == 1 \n\ #if cp_AlphaTest == 1 \n\
color.a=1.0; \n\ color.a=1.0; \n\
@ -444,8 +447,11 @@ GLuint fogTextureId;
gl.setup.surface = eglCreateWindowSurface(gl.setup.display, config, (EGLNativeWindowType)wind, NULL); gl.setup.surface = eglCreateWindowSurface(gl.setup.display, config, (EGLNativeWindowType)wind, NULL);
if (eglCheck()) if (eglCheck() || gl.setup.surface == EGL_NO_SURFACE)
{
printf("EGL Error: eglCreateWindowSurface failed\n");
return false; return false;
}
eglBindAPI(EGL_OPENGL_ES_API); eglBindAPI(EGL_OPENGL_ES_API);
if (eglCheck()) if (eglCheck())
@ -857,7 +863,7 @@ GLuint gl_CompileAndLink(const char* VertexShader, const char* FragmentShader)
int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode, int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode,
u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset, u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset,
u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap, bool fog_clamping) u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap, bool fog_clamping, bool trilinear)
{ {
u32 rv=0; u32 rv=0;
@ -872,6 +878,7 @@ int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode,
rv<<=1; rv|=pp_Gouraud; rv<<=1; rv|=pp_Gouraud;
rv<<=1; rv|=pp_BumpMap; rv<<=1; rv|=pp_BumpMap;
rv<<=1; rv|=fog_clamping; rv<<=1; rv|=fog_clamping;
rv<<=1; rv|=trilinear;
return rv; return rv;
} }
@ -887,7 +894,7 @@ bool CompilePipelineShader( PipelineShader* s)
sprintf(pshader,PixelPipelineShader, gl.glsl_version_header, gl.gl_version, sprintf(pshader,PixelPipelineShader, gl.glsl_version_header, gl.gl_version,
s->cp_AlphaTest,s->pp_ClipTestMode,s->pp_UseAlpha, s->cp_AlphaTest,s->pp_ClipTestMode,s->pp_UseAlpha,
s->pp_Texture,s->pp_IgnoreTexA,s->pp_ShadInstr,s->pp_Offset,s->pp_FogCtrl, s->pp_Gouraud, s->pp_BumpMap, s->pp_Texture,s->pp_IgnoreTexA,s->pp_ShadInstr,s->pp_Offset,s->pp_FogCtrl, s->pp_Gouraud, s->pp_BumpMap,
s->fog_clamping); s->fog_clamping, s->trilinear);
s->program=gl_CompileAndLink(vshader, pshader); s->program=gl_CompileAndLink(vshader, pshader);
@ -1009,9 +1016,12 @@ bool gl_create_resources()
forl(pp_BumpMap,1) forl(pp_BumpMap,1)
{ {
forl(fog_clamping,1) forl(fog_clamping,1)
{
forl(trilinear,1)
{ {
dshader=&gl.pogram_table[GetProgramID(cp_AlphaTest,pp_ClipTestMode,pp_Texture,pp_UseAlpha,pp_IgnoreTexA, dshader=&gl.pogram_table[GetProgramID(cp_AlphaTest,pp_ClipTestMode,pp_Texture,pp_UseAlpha,pp_IgnoreTexA,
pp_ShadInstr,pp_Offset,pp_FogCtrl, (bool)pp_Gouraud, (bool)pp_BumpMap, (bool)fog_clamping)]; pp_ShadInstr,pp_Offset,pp_FogCtrl, (bool)pp_Gouraud, (bool)pp_BumpMap, (bool)fog_clamping,
(bool)trilinear)];
dshader->cp_AlphaTest = cp_AlphaTest; dshader->cp_AlphaTest = cp_AlphaTest;
dshader->pp_ClipTestMode = pp_ClipTestMode-1; dshader->pp_ClipTestMode = pp_ClipTestMode-1;
@ -1024,6 +1034,7 @@ bool gl_create_resources()
dshader->pp_Gouraud = pp_Gouraud; dshader->pp_Gouraud = pp_Gouraud;
dshader->pp_BumpMap = pp_BumpMap; dshader->pp_BumpMap = pp_BumpMap;
dshader->fog_clamping = fog_clamping; dshader->fog_clamping = fog_clamping;
dshader->trilinear = trilinear;
dshader->program = -1; dshader->program = -1;
} }
} }
@ -1036,6 +1047,7 @@ bool gl_create_resources()
} }
} }
} }
}
findGLVersion(); findGLVersion();

View File

@ -74,6 +74,7 @@ struct PipelineShader
u32 pp_Texture, pp_UseAlpha, pp_IgnoreTexA, pp_ShadInstr, pp_Offset, pp_FogCtrl; u32 pp_Texture, pp_UseAlpha, pp_IgnoreTexA, pp_ShadInstr, pp_Offset, pp_FogCtrl;
bool pp_Gouraud, pp_BumpMap; bool pp_Gouraud, pp_BumpMap;
bool fog_clamping; bool fog_clamping;
bool trilinear;
}; };
@ -100,7 +101,7 @@ struct gl_ctx
} modvol_shader; } modvol_shader;
PipelineShader pogram_table[12288]; PipelineShader pogram_table[24576];
struct struct
{ {
GLuint program,scale,depth_scale; GLuint program,scale,depth_scale;
@ -160,7 +161,7 @@ void OSD_HOOK();
void OSD_DRAW(GLuint shader_program); void OSD_DRAW(GLuint shader_program);
int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode, int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode,
u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset, u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset,
u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap, bool fog_clamping); u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap, bool fog_clamping, bool trilinear);
GLuint gl_CompileShader(const char* shader, GLuint type); GLuint gl_CompileShader(const char* shader, GLuint type);
GLuint gl_CompileAndLink(const char* VertexShader, const char* FragmentShader); GLuint gl_CompileAndLink(const char* VertexShader, const char* FragmentShader);