mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-26 23:04:21 +00:00
ref_gl: allow enabling XASH_GLES without wrapper, add ref_gles3compat, wrap gles functions in gl2wrap when XASH_GLES enabled
This commit is contained in:
parent
97489635af
commit
7e0bd86b65
@ -18,7 +18,7 @@ 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -167,7 +167,7 @@ static GLuint GL2_GenerateShader( const gl2wrap_prog_t *prog, GLenum type )
|
||||
shader = shader_buf;
|
||||
//shader[0] = '\n';
|
||||
shader[0] = 0;
|
||||
Q_strncat(shader, "#version 130\n", MAX_SHADERLEN);
|
||||
Q_strncat(shader, "#version 300 es\n", MAX_SHADERLEN);
|
||||
|
||||
for ( i = 0; i < GL2_FLAG_MAX; ++i )
|
||||
{
|
||||
@ -182,7 +182,7 @@ static GLuint GL2_GenerateShader( const gl2wrap_prog_t *prog, GLenum type )
|
||||
|
||||
id = pglCreateShaderObjectARB( type );
|
||||
len = Q_strlen( shader );
|
||||
pglShaderSourceARB( id, 1, (const void *)&shader, &len );
|
||||
pglShaderSourceARB( id, 1, (void *)&shader, &len );
|
||||
pglCompileShaderARB( id );
|
||||
pglGetObjectParameterivARB( id, GL_OBJECT_COMPILE_STATUS_ARB, &status );
|
||||
//pglGetOShaderiv( id, GL_OBJECT_COMPILE_STATUS_ARB, &status );
|
||||
@ -412,6 +412,13 @@ void GL2_Begin( GLenum prim )
|
||||
pglDisableVertexAttribArrayARB( i );
|
||||
}
|
||||
|
||||
unsigned short triquads_array[] =
|
||||
{
|
||||
0, 1, 2, 0, 2, 3,
|
||||
4, 5, 6, 4, 6, 7,
|
||||
8, 9, 10, 8, 10, 11
|
||||
};
|
||||
|
||||
void GL2_End( void )
|
||||
{
|
||||
int i;
|
||||
@ -444,7 +451,16 @@ void GL2_End( void )
|
||||
}
|
||||
}
|
||||
|
||||
pglDrawArrays( gl2wrap.prim, 0, count );
|
||||
#ifdef XASH_GLES
|
||||
if(gl2wrap.prim == GL_QUADS)
|
||||
{
|
||||
pglDrawElements(GL_TRIANGLES, Q_min(count / 4 * 6,sizeof(triquads_array)/2), GL_UNSIGNED_SHORT, triquads_array);
|
||||
}
|
||||
else if( gl2wrap.prim == GL_POLYGON )
|
||||
pglDrawArrays( GL_TRIANGLE_FAN, 0, count );
|
||||
else
|
||||
#endif
|
||||
pglDrawArrays( gl2wrap.prim, 0, count );
|
||||
|
||||
_leave:
|
||||
gl2wrap.prim = GL_NONE;
|
||||
@ -452,6 +468,67 @@ _leave:
|
||||
gl2wrap.cur_flags = 0;
|
||||
}
|
||||
|
||||
#ifdef XASH_GLES
|
||||
void (*rpglTexImage2D)( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels );
|
||||
void GL2_TexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
|
||||
{
|
||||
void *data = (void*)pixels;
|
||||
if( pixels && format == GL_RGBA && (
|
||||
internalformat == GL_RGB ||
|
||||
internalformat == GL_RGB8 ||
|
||||
internalformat == GL_RGB5 ||
|
||||
internalformat == GL_LUMINANCE ||
|
||||
internalformat == GL_LUMINANCE8 ||
|
||||
internalformat == GL_LUMINANCE4 )) // strip alpha from texture
|
||||
{
|
||||
unsigned char *in = data, *out;
|
||||
int i = 0, size = width * height * 4;
|
||||
|
||||
data = out = (unsigned char*)malloc( size );
|
||||
|
||||
for( i = 0; i < size; i += 4, in += 4, out += 4 )
|
||||
{
|
||||
memcpy( out, in, 3 );
|
||||
out[3] = 255;
|
||||
}
|
||||
internalformat = format;
|
||||
}
|
||||
if( internalformat == GL_LUMINANCE8_ALPHA8 )
|
||||
internalformat = GL_RGBA;
|
||||
rpglTexImage2D( target, level, internalformat, width, height, border, format, type, data );
|
||||
if( data != pixels )
|
||||
free(data);
|
||||
}
|
||||
void (*rpglTexParameteri)( GLenum target, GLenum pname, GLint param );
|
||||
void GL2_TexParameteri( GLenum target, GLenum pname, GLint param )
|
||||
{
|
||||
if ( pname == GL_TEXTURE_BORDER_COLOR )
|
||||
{
|
||||
return; // not supported by opengl es
|
||||
}
|
||||
if ( ( pname == GL_TEXTURE_WRAP_S ||
|
||||
pname == GL_TEXTURE_WRAP_T ) &&
|
||||
param == GL_CLAMP )
|
||||
{
|
||||
param = 0x812F;
|
||||
}
|
||||
|
||||
rpglTexParameteri( target, pname, param );
|
||||
}
|
||||
|
||||
|
||||
GLboolean (*rpglIsEnabled)(GLenum e);
|
||||
GLboolean GL2_IsEnabled(GLenum e)
|
||||
{
|
||||
if(e == GL_FOG)
|
||||
return fogging;
|
||||
return rpglIsEnabled(e);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void GL2_Vertex3f( GLfloat x, GLfloat y, GLfloat z )
|
||||
{
|
||||
GLfloat *p = gl2wrap.attrbuf[GL2_ATTR_POS] + gl2wrap.end * 3;
|
||||
@ -586,6 +663,10 @@ void GL2_Hint( GLenum hint, GLenum val )
|
||||
|
||||
void GL2_Enable( GLenum e )
|
||||
{
|
||||
#ifdef XASH_GLES
|
||||
if( e == GL_TEXTURE_2D )
|
||||
return;
|
||||
#endif
|
||||
if( e == GL_FOG )
|
||||
fogging = 1;
|
||||
else if( e == GL_ALPHA_TEST )
|
||||
@ -595,6 +676,10 @@ void GL2_Enable( GLenum e )
|
||||
|
||||
void GL2_Disable( GLenum e )
|
||||
{
|
||||
#ifdef XASH_GLES
|
||||
if( e == GL_TEXTURE_2D )
|
||||
return;
|
||||
#endif
|
||||
if( e == GL_FOG )
|
||||
fogging = 0;
|
||||
else if( e == GL_ALPHA_TEST )
|
||||
@ -736,4 +821,13 @@ void GL2_ShimInstall( void )
|
||||
GL2_OVERRIDE_PTR( LoadMatrixf )
|
||||
GL2_OVERRIDE_PTR( Scalef )
|
||||
GL2_OVERRIDE_PTR( Translatef )
|
||||
#ifdef XASH_GLES
|
||||
rpglTexImage2D = pglTexImage2D;
|
||||
rpglTexParameteri = pglTexParameteri;
|
||||
rpglIsEnabled = pglIsEnabled;
|
||||
GL2_OVERRIDE_PTR( TexParameteri )
|
||||
GL2_OVERRIDE_PTR( TexImage2D )
|
||||
GL2_OVERRIDE_PTR( IsEnabled )
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
@ -1,8 +1,8 @@
|
||||
R"(
|
||||
|
||||
#define layout(x)
|
||||
#define in attribute
|
||||
#define out varying
|
||||
//#define in attribute
|
||||
//#define out varying
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
#if ATTR_COLOR
|
||||
|
@ -27,6 +27,8 @@ GNU General Public License for more details.
|
||||
#define XASH_GLES
|
||||
#define XASH_GL_STATIC
|
||||
#define REF_GL_KEEP_MANGLED_FUNCTIONS
|
||||
#elif defined XASH_GLES3COMPAT
|
||||
#define XASH_GLES
|
||||
#endif
|
||||
|
||||
typedef uint GLenum;
|
||||
@ -1358,7 +1360,7 @@ APIENTRY_LINKAGE void GL_FUNCTION( glGenVertexArrays )( GLsizei n, const GLuint
|
||||
APIENTRY_LINKAGE GLboolean GL_FUNCTION( glIsVertexArray )( GLuint array );
|
||||
APIENTRY_LINKAGE void GL_FUNCTION( glSwapInterval ) ( int interval );
|
||||
|
||||
#if !defined( XASH_GLES ) && !defined( XASH_GL4ES )
|
||||
#if !defined( XASH_GL_STATIC ) || (!defined( XASH_GLES ) && !defined( XASH_GL4ES ))
|
||||
APIENTRY_LINKAGE void GL_FUNCTION( glTexImage2DMultisample )(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
|
||||
#endif /* !XASH_GLES && !XASH_GL4ES */
|
||||
|
||||
|
@ -1070,7 +1070,7 @@ static void GL_TextureImageRAW( gl_texture_t *tex, GLint side, GLint level, GLin
|
||||
}
|
||||
else if( tex->target == GL_TEXTURE_2D_MULTISAMPLE )
|
||||
{
|
||||
#if !defined( XASH_GLES ) && !defined( XASH_GL4ES )
|
||||
#if !defined( XASH_GL_STATIC ) || (!defined( XASH_GLES ) && !defined( XASH_GL4ES ))
|
||||
samplesCount = (GLsizei)gEngfuncs.pfnGetCvarFloat("gl_msaa_samples");
|
||||
switch (samplesCount)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ int VGL_ShimInit( void );
|
||||
void VGL_ShimShutdown( void );
|
||||
void VGL_ShimEndFrame( void );
|
||||
#endif
|
||||
#if !defined(XASH_GLES) && !defined(XASH_GL_STATIC)
|
||||
#if !defined(XASH_GL_STATIC)
|
||||
#include "gl2_shim/gl2_shim.h"
|
||||
#endif
|
||||
|
||||
@ -620,7 +620,7 @@ enum
|
||||
GL_DRAW_RANGEELEMENTS_EXT,
|
||||
GL_TEXTURE_MULTISAMPLE,
|
||||
GL_ARB_TEXTURE_COMPRESSION_BPTC,
|
||||
R_SHADER_OBJECTS_EXT,
|
||||
GL_SHADER_OBJECTS_EXT,
|
||||
GL_EXTCOUNT, // must be last
|
||||
};
|
||||
|
||||
|
@ -304,6 +304,62 @@ static dllfunc_t shaderobjectsfuncs[] =
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static dllfunc_t shaderobjectsfuncs_gles[] =
|
||||
{
|
||||
{ "glDeleteShader" , (void **)&pglDeleteObjectARB },
|
||||
//{ "glGetHandleARB" , (void **)&pglGetHandleARB },
|
||||
{ "glDetachShader" , (void **)&pglDetachObjectARB },
|
||||
{ "glCreateShader" , (void **)&pglCreateShaderObjectARB },
|
||||
{ "glShaderSource" , (void **)&pglShaderSourceARB },
|
||||
{ "glCompileShader" , (void **)&pglCompileShaderARB },
|
||||
{ "glCreateProgram" , (void **)&pglCreateProgramObjectARB },
|
||||
{ "glAttachShader" , (void **)&pglAttachObjectARB },
|
||||
{ "glLinkProgram" , (void **)&pglLinkProgramARB },
|
||||
{ "glUseProgram" , (void **)&pglUseProgramObjectARB },
|
||||
{ "glValidateProgram" , (void **)&pglValidateProgramARB },
|
||||
{ "glUniform1f" , (void **)&pglUniform1fARB },
|
||||
{ "glUniform2f" , (void **)&pglUniform2fARB },
|
||||
{ "glUniform3f" , (void **)&pglUniform3fARB },
|
||||
{ "glUniform4f" , (void **)&pglUniform4fARB },
|
||||
{ "glUniform1i" , (void **)&pglUniform1iARB },
|
||||
{ "glUniform2i" , (void **)&pglUniform2iARB },
|
||||
{ "glUniform3i" , (void **)&pglUniform3iARB },
|
||||
{ "glUniform4i" , (void **)&pglUniform4iARB },
|
||||
{ "glUniform1f" , (void **)&pglUniform1fvARB },
|
||||
{ "glUniform2fv" , (void **)&pglUniform2fvARB },
|
||||
{ "glUniform3fv" , (void **)&pglUniform3fvARB },
|
||||
{ "glUniform4fv" , (void **)&pglUniform4fvARB },
|
||||
{ "glUniform1iv" , (void **)&pglUniform1ivARB },
|
||||
{ "glUniform2iv" , (void **)&pglUniform2ivARB },
|
||||
{ "glUniform3iv" , (void **)&pglUniform3ivARB },
|
||||
{ "glUniform4iv" , (void **)&pglUniform4ivARB },
|
||||
{ "glUniformMatrix2fv" , (void **)&pglUniformMatrix2fvARB },
|
||||
{ "glUniformMatrix3fv" , (void **)&pglUniformMatrix3fvARB },
|
||||
{ "glUniformMatrix4fv" , (void **)&pglUniformMatrix4fvARB },
|
||||
{ "glGetShaderfv" , (void **)&pglGetObjectParameterfvARB },
|
||||
{ "glGetShaderiv" , (void **)&pglGetObjectParameterivARB },
|
||||
{ "glGetShaderInfoLog" , (void **)&pglGetInfoLogARB },
|
||||
{ "glGetAttachedObjects" , (void **)&pglGetAttachedObjectsARB },
|
||||
{ "glGetUniformLocation" , (void **)&pglGetUniformLocationARB },
|
||||
{ "glGetActiveUniform" , (void **)&pglGetActiveUniformARB },
|
||||
{ "glGetUniformfv" , (void **)&pglGetUniformfvARB },
|
||||
{ "glGetUniformiv" , (void **)&pglGetUniformivARB },
|
||||
{ "glGetShaderSource" , (void **)&pglGetShaderSourceARB },
|
||||
{ "glVertexAttribPointer" , (void **)&pglVertexAttribPointerARB },
|
||||
{ "glEnableVertexAttribArray" , (void **)&pglEnableVertexAttribArrayARB },
|
||||
{ "glDisableVertexAttribArray" , (void **)&pglDisableVertexAttribArrayARB },
|
||||
{ "glBindAttribLocation" , (void **)&pglBindAttribLocationARB },
|
||||
{ "glGetActiveAttrib" , (void **)&pglGetActiveAttribARB },
|
||||
{ "glGetAttribLocation" , (void **)&pglGetAttribLocationARB },
|
||||
{ "glVertexAttrib2f" , (void **)&pglVertexAttrib2fARB },
|
||||
{ "glVertexAttrib2fv" , (void **)&pglVertexAttrib2fvARB },
|
||||
{ "glVertexAttrib3fv" , (void **)&pglVertexAttrib3fvARB },
|
||||
//{ "glVertexAttrib4f" , (void **)&pglVertexAttrib4fARB },
|
||||
//{ "glVertexAttrib4fv" , (void **)&pglVertexAttrib4fvARB },
|
||||
//{ "glVertexAttrib4ubv" , (void **)&pglVertexAttrib4ubvARB },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
========================
|
||||
@ -603,7 +659,11 @@ void GL_InitExtensionsGLES( void )
|
||||
#elif defined( XASH_WES )
|
||||
glConfig.context = CONTEXT_TYPE_GLES_2_X;
|
||||
glConfig.wrapper = GLES_WRAPPER_WES;
|
||||
#elif defined( XASH_GLES3COMPAT )
|
||||
glConfig.context = CONTEXT_TYPE_GLES_2_X;
|
||||
glConfig.wrapper = GLES_WRAPPER_NONE;
|
||||
#else
|
||||
|
||||
#error "unknown gles wrapper"
|
||||
#endif
|
||||
|
||||
@ -644,6 +704,10 @@ void GL_InitExtensionsGLES( void )
|
||||
case GL_ARB_TEXTURE_NPOT_EXT:
|
||||
GL_CheckExtension( "GL_OES_texture_npot", NULL, "gl_texture_npot", extid );
|
||||
break;
|
||||
case GL_SHADER_OBJECTS_EXT:
|
||||
GL_CheckExtension( "ES2 Shaders", shaderobjectsfuncs_gles, "gl_shaderobjects", extid );
|
||||
break;
|
||||
|
||||
case GL_DEBUG_OUTPUT:
|
||||
if( glw_state.extended )
|
||||
GL_CheckExtension( "GL_KHR_debug", NULL, NULL, extid );
|
||||
@ -665,6 +729,7 @@ void GL_InitExtensionsGLES( void )
|
||||
GL_SetExtension( extid, false );
|
||||
}
|
||||
}
|
||||
GL2_ShimInit();
|
||||
}
|
||||
#else
|
||||
void GL_InitExtensionsBigGL( void )
|
||||
@ -761,7 +826,7 @@ void GL_InitExtensionsBigGL( void )
|
||||
GL_CheckExtension( "GL_ARB_vertex_buffer_object", vbofuncs, "gl_vertex_buffer_object", GL_ARB_VERTEX_BUFFER_OBJECT_EXT );
|
||||
GL_CheckExtension( "GL_ARB_texture_multisample", multisampletexfuncs, "gl_texture_multisample", GL_TEXTURE_MULTISAMPLE );
|
||||
GL_CheckExtension( "GL_ARB_texture_compression_bptc", NULL, "gl_texture_bptc_compression", GL_ARB_TEXTURE_COMPRESSION_BPTC );
|
||||
GL_CheckExtension( "GL_ARB_shader_objects", shaderobjectsfuncs, "gl_shaderobjects", R_SHADER_OBJECTS_EXT );
|
||||
GL_CheckExtension( "GL_ARB_shader_objects", shaderobjectsfuncs, "gl_shaderobjects", GL_SHADER_OBJECTS_EXT );
|
||||
if( GL_CheckExtension( "GL_ARB_shading_language_100", NULL, NULL, GL_SHADER_GLSL100_EXT ))
|
||||
{
|
||||
pglGetIntegerv( GL_MAX_TEXTURE_COORDS_ARB, &glConfig.max_texture_coords );
|
||||
|
@ -1128,7 +1128,7 @@ void R_EndFrame( void )
|
||||
#if XASH_PSVITA
|
||||
VGL_ShimEndFrame();
|
||||
#endif
|
||||
#if !defined(XASH_GLES) && !defined(XASH_GL_STATIC)
|
||||
#if !defined( XASH_GL_STATIC )
|
||||
GL2_ShimEndFrame();
|
||||
#endif
|
||||
// flush any remaining 2D bits
|
||||
|
@ -37,10 +37,9 @@ def build(bld):
|
||||
if bld.env.DEST_OS == 'psvita':
|
||||
libs += [ 'sdk_includes', 'vgl_shim' ]
|
||||
else:
|
||||
libs += [ 'gl2_shim' ]
|
||||
libs += [ 'public', 'M' ]
|
||||
|
||||
source = bld.path.ant_glob(['*.c'])
|
||||
source = bld.path.ant_glob(['*.c', 'gl2_shim/*.c'])
|
||||
includes = '.'
|
||||
|
||||
targets = {
|
||||
@ -64,6 +63,11 @@ def build(bld):
|
||||
'libs': ['DL', 'gl4es', 'LOG'],
|
||||
'defines': ['XASH_GL_STATIC', 'XASH_GL4ES'],
|
||||
},
|
||||
'ref_gles3compat': {
|
||||
'enable': bld.env.GLES3COMPAT,
|
||||
'libs': ['DL', 'gl4es', 'LOG'],
|
||||
'defines': ['XASH_GLES3COMPAT'],
|
||||
},
|
||||
}
|
||||
|
||||
for k,v in targets.items():
|
||||
|
2
wscript
2
wscript
@ -90,7 +90,6 @@ SUBDIRS = [
|
||||
|
||||
# enabled on PSVita only
|
||||
Subproject('ref/gl/vgl_shim', lambda x: x.env.DEST_OS == 'psvita'),
|
||||
Subproject('ref/gl/gl2_shim', lambda x: not x.env.DEDICATED and x.env.GL),
|
||||
|
||||
]
|
||||
|
||||
@ -100,6 +99,7 @@ REFDLLS = [
|
||||
RefDll('gles1', False, 'NANOGL'),
|
||||
RefDll('gles2', False, 'GLWES'),
|
||||
RefDll('gl4es', False),
|
||||
RefDll('gles3compat', False),
|
||||
]
|
||||
|
||||
def options(opt):
|
||||
|
Loading…
x
Reference in New Issue
Block a user