From 5bd5b98c3364f290fc8ec18a4ebc30fc09cc4795 Mon Sep 17 00:00:00 2001 From: Andy Nguyen Date: Sun, 18 Oct 2020 00:13:27 +0200 Subject: [PATCH] Fix shaders and add mempool reset --- src/engine.cpp | 1 + src/gl/gl3device.cpp | 12 ++++++++---- src/gl/shaders/default.vert | 2 +- src/gl/shaders/default_vs_gl3.inc | 2 +- src/gl/shaders/matfx_env.frag | 6 +++--- src/gl/shaders/matfx_env.vert | 4 ++-- src/gl/shaders/matfx_gl3.inc | 10 +++++----- src/gl/shaders/simple.frag | 2 +- src/gl/shaders/simple_fs_gl3.inc | 2 +- src/gl/shaders/skin.vert | 6 +++--- src/gl/shaders/skin_gl3.inc | 6 +++--- 11 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/engine.cpp b/src/engine.cpp index f1fabc5..7ad6afd 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -17,6 +17,7 @@ #include "gl/rwgl3.h" #include "gl/rwwdgl.h" + #define PLUGIN_ID 0 // on windows diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index 8791f47..debd235 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -1138,6 +1138,11 @@ showRaster(Raster *raster, uint32 flags) else vglWaitVblankStart(GL_FALSE); vglStopRendering(); + vglStartRendering(); + gVertexBuffer = gVertexBufferPtr; + gVertexBufferIm2D = gVertexBufferPtr + 0xC00000; + gIndices = gIndicesPtr; + gIndicesIm2D = gIndicesPtr + 0x300000; #endif } @@ -1298,6 +1303,8 @@ openGLFW(EngineOpenParams *openparams) glGlobals.winTitle = openparams->windowtitle; vglInitExtended(0x1400000, 960, 544, 0x100000, SCE_GXM_MULTISAMPLE_4X); + vglUseVram(GL_TRUE); + vglStartRendering(); makeVideoModeList(); @@ -1488,9 +1495,6 @@ deviceSystemGLFW(DeviceReq req, void *arg, int32 n) return 0; case DEVICESETVIDEOMODE: - if(n >= glGlobals.numModes) - return 0; - glGlobals.currentMode = n; return 1; case DEVICEGETVIDEOMODEINFO: @@ -1498,7 +1502,7 @@ deviceSystemGLFW(DeviceReq req, void *arg, int32 n) rwmode->width = 960; rwmode->height = 544; rwmode->depth = 32; - rwmode->flags = glGlobals.modes[n].flags; + rwmode->flags = VIDEOMODEEXCLUSIVE; return 1; default: diff --git a/src/gl/shaders/default.vert b/src/gl/shaders/default.vert index 79126fd..889bd82 100644 --- a/src/gl/shaders/default.vert +++ b/src/gl/shaders/default.vert @@ -19,7 +19,7 @@ void main( float4 out gl_Position : POSITION ) { float4 Vertex = mul(u_world, float4(in_pos, 1.0)); - gl_Position = mul(u_proj, mul(u_view, Vertex)); + gl_Position = mul(u_proj * u_view, Vertex); float3 Normal = mul(float3x3(u_world), in_normal); v_tex0 = in_tex0; diff --git a/src/gl/shaders/default_vs_gl3.inc b/src/gl/shaders/default_vs_gl3.inc index 064b3d0..7adbc56 100644 --- a/src/gl/shaders/default_vs_gl3.inc +++ b/src/gl/shaders/default_vs_gl3.inc @@ -20,7 +20,7 @@ const char *default_vert_src = " float4 out gl_Position : POSITION\n" ") {\n" " float4 Vertex = mul(u_world, float4(in_pos, 1.0));\n" -" gl_Position = mul(u_proj, mul(u_view, Vertex));\n" +" gl_Position = mul(u_proj * u_view, Vertex);\n" " float3 Normal = mul(float3x3(u_world), in_normal);\n" " v_tex0 = in_tex0;\n" diff --git a/src/gl/shaders/matfx_env.frag b/src/gl/shaders/matfx_env.frag index d81dcf4..03b1669 100644 --- a/src/gl/shaders/matfx_env.frag +++ b/src/gl/shaders/matfx_env.frag @@ -6,10 +6,10 @@ float4 main( float2 v_tex0 : TEXCOORD0, float2 v_tex1 : TEXCOORD1, float v_fog : FOG, - uniform float2 u_alpharef, + uniform float4 u_fogColor, + uniform float2 u_alphaRef, uniform float4 u_colorClamp, uniform float2 u_fxparams, - uniform float4 u_fogColor, uniform sampler2D tex0 : TEXUNIT0, uniform sampler2D tex1 : TEXUNIT1 ) { @@ -17,7 +17,7 @@ float4 main( float4 envColor = max(pass1, u_colorClamp); pass1 *= tex2D(tex0, float2(v_tex0.x, 1.0-v_tex0.y)); - vec4 pass2 = envColor*shininess*tex2D(tex1, float2(v_tex1.x, 1.0-v_tex1.y)); + float4 pass2 = envColor*shininess*tex2D(tex1, float2(v_tex1.x, 1.0-v_tex1.y)); pass1.rgb = lerp(u_fogColor.rgb, pass1.rgb, v_fog); pass2.rgb = lerp(float3(0.0, 0.0, 0.0), pass2.rgb, v_fog); diff --git a/src/gl/shaders/matfx_env.vert b/src/gl/shaders/matfx_env.vert index 79a69d5..1cc2567 100644 --- a/src/gl/shaders/matfx_env.vert +++ b/src/gl/shaders/matfx_env.vert @@ -21,11 +21,11 @@ void main( float4 out gl_Position : POSITION ) { float4 Vertex = mul(u_world, float4(in_pos, 1.0)); - gl_Position = mul(u_proj, mul(u_view, Vertex)); + gl_Position = mul(u_proj * u_view, Vertex); float3 Normal = mul(float3x3(u_world), in_normal); v_tex0 = in_tex0; - v_tex1 = (u_texMatrix * float4(Normal, 1.0)).xy; + v_tex1 = (mul(u_texMatrix, float4(Normal, 1.0))).xy; v_color = in_color; v_color.rgb += u_ambLight.rgb*surfAmbient; diff --git a/src/gl/shaders/matfx_gl3.inc b/src/gl/shaders/matfx_gl3.inc index ace70bf..78a1c55 100644 --- a/src/gl/shaders/matfx_gl3.inc +++ b/src/gl/shaders/matfx_gl3.inc @@ -22,11 +22,11 @@ const char *matfx_env_vert_src = " float4 out gl_Position : POSITION\n" ") {\n" " float4 Vertex = mul(u_world, float4(in_pos, 1.0));\n" -" gl_Position = mul(u_proj, mul(u_view, Vertex));\n" +" gl_Position = mul(u_proj * u_view, Vertex);\n" " float3 Normal = mul(float3x3(u_world), in_normal);\n" " v_tex0 = in_tex0;\n" -" v_tex1 = (u_texMatrix * float4(Normal, 1.0)).xy;\n" +" v_tex1 = (mul(u_texMatrix, float4(Normal, 1.0))).xy;\n" " v_color = in_color;\n" " v_color.rgb += u_ambLight.rgb*surfAmbient;\n" @@ -58,10 +58,10 @@ const char *matfx_env_frag_src = " float2 v_tex0 : TEXCOORD0,\n" " float2 v_tex1 : TEXCOORD1,\n" " float v_fog : FOG,\n" -" uniform float2 u_alpharef,\n" +" uniform float4 u_fogColor,\n" +" uniform float2 u_alphaRef,\n" " uniform float4 u_colorClamp,\n" " uniform float2 u_fxparams,\n" -" uniform float4 u_fogColor,\n" " uniform sampler2D tex0 : TEXUNIT0,\n" " uniform sampler2D tex1 : TEXUNIT1\n" ") {\n" @@ -69,7 +69,7 @@ const char *matfx_env_frag_src = " float4 envColor = max(pass1, u_colorClamp);\n" " pass1 *= tex2D(tex0, float2(v_tex0.x, 1.0-v_tex0.y));\n" -" vec4 pass2 = envColor*shininess*tex2D(tex1, float2(v_tex1.x, 1.0-v_tex1.y));\n" +" float4 pass2 = envColor*shininess*tex2D(tex1, float2(v_tex1.x, 1.0-v_tex1.y));\n" " pass1.rgb = lerp(u_fogColor.rgb, pass1.rgb, v_fog);\n" " pass2.rgb = lerp(float3(0.0, 0.0, 0.0), pass2.rgb, v_fog);\n" diff --git a/src/gl/shaders/simple.frag b/src/gl/shaders/simple.frag index 8af1608..97847bf 100644 --- a/src/gl/shaders/simple.frag +++ b/src/gl/shaders/simple.frag @@ -2,8 +2,8 @@ float4 main( float4 v_color : COLOR, float2 v_tex0 : TEXCOORD0, float v_fog : FOG, - uniform float2 u_alpharef, uniform float4 u_fogColor, + uniform float2 u_alphaRef, uniform sampler2D tex0 ) { float4 color = v_color*tex2D(tex0, float2(v_tex0.x, 1.0-v_tex0.y)); diff --git a/src/gl/shaders/simple_fs_gl3.inc b/src/gl/shaders/simple_fs_gl3.inc index ecd9512..c98213b 100644 --- a/src/gl/shaders/simple_fs_gl3.inc +++ b/src/gl/shaders/simple_fs_gl3.inc @@ -3,8 +3,8 @@ const char *simple_frag_src = " float4 v_color : COLOR,\n" " float2 v_tex0 : TEXCOORD0,\n" " float v_fog : FOG,\n" -" uniform float2 u_alpharef,\n" " uniform float4 u_fogColor,\n" +" uniform float2 u_alphaRef,\n" " uniform sampler2D tex0\n" ") {\n" " float4 color = v_color*tex2D(tex0, float2(v_tex0.x, 1.0-v_tex0.y));\n" diff --git a/src/gl/shaders/skin.vert b/src/gl/shaders/skin.vert index a9c4678..5b76d23 100644 --- a/src/gl/shaders/skin.vert +++ b/src/gl/shaders/skin.vert @@ -25,12 +25,12 @@ void main( float3 SkinVertex = float3(0.0, 0.0, 0.0); float3 SkinNormal = float3(0.0, 0.0, 0.0); for(int i = 0; i < 4; i++){ - SkinVertex += (u_boneMatrices[int(in_indices[i])] * float4(in_pos, 1.0)).xyz * in_weights[i]; - SkinNormal += (float3x3(u_boneMatrices[int(in_indices[i])]) * in_normal) * in_weights[i]; + SkinVertex += (mul(u_boneMatrices[int(in_indices[i])], float4(in_pos, 1.0))).xyz * in_weights[i]; + SkinNormal += (mul(float3x3(u_boneMatrices[int(in_indices[i])]), in_normal)) * in_weights[i]; } float4 Vertex = mul(u_world, float4(SkinVertex, 1.0)); - gl_Position = u_proj * mul(u_view, Vertex); + gl_Position = mul(u_proj * u_view, Vertex); float3 Normal = mul(float3x3(u_world), SkinNormal); v_tex0 = in_tex0; diff --git a/src/gl/shaders/skin_gl3.inc b/src/gl/shaders/skin_gl3.inc index 70f847a..74229b5 100644 --- a/src/gl/shaders/skin_gl3.inc +++ b/src/gl/shaders/skin_gl3.inc @@ -26,12 +26,12 @@ const char *skin_vert_src = " float3 SkinVertex = float3(0.0, 0.0, 0.0);\n" " float3 SkinNormal = float3(0.0, 0.0, 0.0);\n" " for(int i = 0; i < 4; i++){\n" -" SkinVertex += (u_boneMatrices[int(in_indices[i])] * float4(in_pos, 1.0)).xyz * in_weights[i];\n" -" SkinNormal += (float3x3(u_boneMatrices[int(in_indices[i])]) * in_normal) * in_weights[i];\n" +" SkinVertex += (mul(u_boneMatrices[int(in_indices[i])], float4(in_pos, 1.0))).xyz * in_weights[i];\n" +" SkinNormal += (mul(float3x3(u_boneMatrices[int(in_indices[i])]), in_normal)) * in_weights[i];\n" " }\n" " float4 Vertex = mul(u_world, float4(SkinVertex, 1.0));\n" -" gl_Position = u_proj * mul(u_view, Vertex);\n" +" gl_Position = mul(u_proj * u_view, Vertex);\n" " float3 Normal = mul(float3x3(u_world), SkinNormal);\n" " v_tex0 = in_tex0;\n"