gl2shim: support more GLSL versions

This commit is contained in:
mittorn 2023-10-05 18:50:08 +03:00 committed by Alibek Omarov
parent 40dd6e0234
commit 8c88e82709
3 changed files with 57 additions and 18 deletions

View File

@ -1,10 +1,20 @@
R"(
#if VER <= 300
#define layout(x)
#endif
#if VER < 300
#define out attribute
#define in varying
#define texture texture2D
#endif
precision mediump float;
#if ATTR_TEXCOORD0
uniform sampler2D uTex0;
layout(location = 5) uniform sampler2D uTex0;
#endif
#if ATTR_TEXCOORD1
uniform sampler2D uTex1;
layout(location = 6) uniform sampler2D uTex1;
#endif
#if FEAT_ALPHA_TEST
uniform float uAlphaTest;
@ -12,7 +22,7 @@ uniform float uAlphaTest;
#if FEAT_FOG
uniform vec4 uFog;
#endif
uniform vec4 uColor;
layout(location = 2) uniform vec4 uColor;
#if ATTR_COLOR
in vec4 vColor;
#endif
@ -25,7 +35,11 @@ in vec2 vTexCoord1;
#if ATTR_NORMAL
in vec2 vNormal;
#endif
#if VER >= 300
out vec4 oFragColor;
#else
#define oFragColor gl_FragColor
#endif
void main()
{
#if ATTR_COLOR

View File

@ -18,8 +18,9 @@ GNU General Public License for more details.
this will only provide performance gains if vitaGL is built with DRAW_SPEEDHACK=1
since that makes it assume that all vertex data pointers are GPU-mapped
*/
#ifndef XASH_GL_STATIC
#include "gl_local.h"
#ifndef XASH_GL_STATIC
#include "gl2_shim.h"
#include <malloc.h>
//#include "xash3d_mathlib.h"
@ -142,24 +143,44 @@ static char *GL_PrintInfoLog( GLhandleARB object )
}
static GLuint GL2_GenerateShader( const gl2wrap_prog_t *prog, GLenum type )
static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type )
{
char *shader, shader_buf[MAX_SHADERLEN + 1];
char tmp[256];
int i;
GLint status, len;
GLuint id;
GLuint id, loc;
int version = 320;
shader = shader_buf;
//shader[0] = '\n';
shader[0] = 0;
Q_strncat(shader, "#version 300 es\n", MAX_SHADERLEN);
Q_snprintf(shader, MAX_SHADERLEN, "#version %d%s\n", version, version >= 300 && version < 330 ? " es":"");
Q_snprintf(tmp, sizeof( tmp ), "#define VER %d\n", version);
Q_strncat( shader, tmp, MAX_SHADERLEN );
for ( i = 0; i < GL2_FLAG_MAX; ++i )
{
Q_snprintf( tmp, sizeof( tmp ), "#define %s %d\n", gl2wrap_flag_name[i], prog->flags & ( 1 << i ) );
Q_strncat( shader, tmp, MAX_SHADERLEN );
}
loc = 0;
for ( i = 0; i < GL2_ATTR_MAX; ++i )
{
if ( prog->flags & ( 1 << i ) )
{
Q_snprintf( tmp, sizeof( tmp ), "#define LOC_%s %d\n", gl2wrap_flag_name[i], loc++ );
Q_strncat( shader, tmp, MAX_SHADERLEN );
prog->attridx[i] = loc;
}
else
{
prog->attridx[i] = -1;
}
}
if ( type == GL_FRAGMENT_SHADER_ARB )
Q_strncat( shader, gl2wrap_frag_src, MAX_SHADERLEN );

View File

@ -1,23 +1,27 @@
R"(
#if VER <= 300
#define layout(x)
//#define in attribute
//#define out varying
layout(location = 0) in vec3 inPosition;
#if ATTR_COLOR
layout(location = 1) in vec4 inColor;
#endif
#if ATTR_NORMAL
layout(location = 2) in vec3 inNormal;
#if VER < 300
#define in attribute
#define out varying
#endif
layout(location = LOC_ATTR_POSITION) in vec3 inPosition;
#if ATTR_COLOR
layout(location = LOC_ATTR_COLOR) in vec4 inColor;
#endif
#if ATTR_TEXCOORD0
layout(location = 3) in vec2 inTexCoord0;
layout(location = LOC_ATTR_TEXCOORD0) in vec2 inTexCoord0;
#endif
#if ATTR_TEXCOORD1
layout(location = 4) in vec2 inTexCoord1;
layout(location = LOC_ATTR_TEXCOORD1) in vec2 inTexCoord1;
#endif
#if ATTR_NORMAL
in vec3 inNormal;
#endif
#if ATTR_COLOR
out vec4 vColor;
#endif
@ -25,7 +29,7 @@ out vec4 vColor;
out vec2 vTexCoord0;
#endif
#if ATTR_TEXCOORD1
out vec2 vTexCoord0;
out vec2 vTexCoord1;
#endif
#if ATTR_NORMAL
out vec3 vNormal;