From 4b60b739f7e0ea2b50a6a5281dae1cccaf869777 Mon Sep 17 00:00:00 2001 From: KrimZon Date: Tue, 4 Jan 2005 23:34:42 +0000 Subject: [PATCH] Added GL_ARB_shader_objects extension code in glsupp.h Added init of the used functions to GL_CheckExtensions and some functions for the simplifying api to gl_vidcommon.c Added the function declarations and other defines for that interface to glquake.h git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@723 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/gl/gl_vidcommon.c | 122 ++++++++++++++++++++++++++++++++++++++- engine/gl/glquake.h | 27 +++++++++ engine/gl/glsupp.h | 104 +++++++++++++++++++++++++++++++++ 3 files changed, 252 insertions(+), 1 deletion(-) diff --git a/engine/gl/gl_vidcommon.c b/engine/gl/gl_vidcommon.c index e8ba29cf6..394802add 100644 --- a/engine/gl/gl_vidcommon.c +++ b/engine/gl/gl_vidcommon.c @@ -92,7 +92,21 @@ PFNGLGENPROGRAMSARBPROC qglGenProgramsARB; PFNGLLOCKARRAYSEXTPROC qglLockArraysEXT; PFNGLUNLOCKARRAYSEXTPROC qglUnlockArraysEXT; - +//glslang - arb_shader_objects +PFNGLCREATEPROGRAMOBJECTARBPROC qglCreateProgramObjectARB; +PFNGLDELETEOBJECTARBPROC qglDeleteObjectARB; +PFNGLUSEPROGRAMOBJECTARBPROC qglUseProgramObjectARB; +PFNGLCREATESHADEROBJECTARBPROC qglCreateShaderObjectARB; +PFNGLSHADERSOURCEARBPROC qglShaderSourceARB; +PFNGLCOMPILESHADERARBPROC qglCompileShaderARB; +PFNGLGETOBJECTPARAMETERIVARBPROC qglGetObjectParameterivARB; +PFNGLATTACHOBJECTARBPROC qglAttachObjectARB; +PFNGLGETINFOLOGARBPROC qglGetInfoLogARB; +PFNGLLINKPROGRAMARBPROC qglLinkProgramARB; +PFNGLGETUNIFORMLOCATIONARBPROC qglGetUniformLocationARB; +PFNGLUNIFORM4FARBPROC qglUniform4fARB; +PFNGLUNIFORM1IARBPROC qglUniform1iARB; +PFNGLUNIFORM1FARBPROC qglUniform1fARB; //extensions //arb multitexture @@ -194,6 +208,8 @@ void GL_CheckExtensions (void *(*getglfunction) (char *name)) gl_config.arb_texture_env_dot3 = false; gl_config.arb_texture_cube_map = false; + gl_config.arb_fragment_program = false; + gl_config.arb_shader_objects = false; if (strstr(gl_extensions, "GL_ARB_texture_non_power_of_two")) gl_config.arb_texture_non_power_of_two = true; @@ -301,6 +317,110 @@ void GL_CheckExtensions (void *(*getglfunction) (char *name)) qglBindProgramARB = (void *)getglext("glBindProgramARB"); qglGenProgramsARB = (void *)getglext("glGenProgramsARB"); } + + // glslang + if (!!strstr(gl_extensions, "GL_ARB_shader_objects")) + { + gl_config.arb_shader_objects = true; + qglCreateProgramObjectARB = (void *)getglext("glCreateProgramObjectARB"); + qglDeleteObjectARB = (void *)getglext("glDeleteObjectARB"); + qglUseProgramObjectARB = (void *)getglext("glUseProgramObjectARB"); + qglCreateShaderObjectARB = (void *)getglext("glCreateShaderObjectARB"); + qglShaderSourceARB = (void *)getglext("glShaderSourceARB"); + qglCompileShaderARB = (void *)getglext("glCompileShaderARB"); + qglGetObjectParameterivARB = (void *)getglext("glGetObjectParameterivARB"); + qglAttachObjectARB = (void *)getglext("glAttachObjectARB"); + qglGetInfoLogARB = (void *)getglext("glGetInfoLogARB"); + qglLinkProgramARB = (void *)getglext("glLinkProgramARB"); + qglGetUniformLocationARB = (void *)getglext("glGetUniformLocationARB"); + qglUniform4fARB = (void *)getglext("glUniform4fARB"); + qglUniform1iARB = (void *)getglext("glUniform1iARB"); + qglUniform1fARB = (void *)getglext("glUniform1fARB"); + } +} + + +// glslang helper api function definitions +// type should be GL_FRAGMENT_SHADER_ARB or GL_VERTEX_SHADER_ARB +GLhandleARB GLSlang_CreateShader (char *shadersource, int shadertype) +{ + GLhandleARB shader; + GLenum type; + GLint compiled; + char str[1024]; + + switch (shadertype) + { + case 0: + type = GL_FRAGMENT_SHADER_ARB; + break; + case 1: + type = GL_VERTEX_SHADER_ARB; + break; + default: + return -1; + break; + } + + shader = qglCreateShaderObjectARB(type); + + qglShaderSourceARB(shader, 1, &shadersource, NULL); + qglCompileShaderARB(shader); + + qglGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &compiled); + if(!compiled) + { + qglGetInfoLogARB(shader, sizeof(str), NULL, str); + switch (shadertype) + { + case 0: + Con_Printf("Fragment shader compilation error:\n----------\n%s\n----------\n", str); + break; + case 1: + Con_Printf("Vertex shader compilation error:\n----------\n%s\n----------\n", str); + break; + default: + Con_Printf("Shader_CreateShader: This shouldn't happen ever\n"); + break; + } + return -1; + } + + return shader; +} + +GLhandleARB GLSlang_CreateProgram (GLhandleARB vert, GLhandleARB frag) +{ + GLhandleARB program; + GLint linked; + char str[1024]; + + program = qglCreateProgramObjectARB(); + qglAttachObjectARB(program, vert); + qglAttachObjectARB(program, frag); + + qglLinkProgramARB(program); + + qglGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &linked); + + if(!linked) + { + qglGetInfoLogARB(program, sizeof(str), NULL, str); + Con_Printf("Program link error: %s\n", str); + return (int)NULL; + } + + return program; +} + +GLint GLSlang_GetUniformLocation (int prog, char *name) +{ + int i = qglGetUniformLocationARB(prog, name); + if (i == -1) + { + Con_Printf("Failed to get location of uniform '%s'\n", name); + } + return i; } //the vid routines have initialised a window, and now they are giving us a reference to some of of GetProcAddress to get pointers to the funcs. diff --git a/engine/gl/glquake.h b/engine/gl/glquake.h index 03bc7766d..aa586bed8 100644 --- a/engine/gl/glquake.h +++ b/engine/gl/glquake.h @@ -100,6 +100,7 @@ typedef struct { qboolean arb_texture_compression; qboolean arb_fragment_program; + qboolean arb_shader_objects; qboolean ext_stencil_wrap; int maxtmus; //max texture units } gl_config_t; @@ -715,6 +716,32 @@ extern PFNGLGETPROGRAMIVARBPROC qglGetProgramivARB; extern PFNGLBINDPROGRAMARBPROC qglBindProgramARB; extern PFNGLGENPROGRAMSARBPROC qglGenProgramsARB; +//glslang - arb_shader_objects +extern PFNGLCREATEPROGRAMOBJECTARBPROC qglCreateProgramObjectARB; +extern PFNGLDELETEOBJECTARBPROC qglDeleteObjectARB; +extern PFNGLUSEPROGRAMOBJECTARBPROC qglUseProgramObjectARB; +extern PFNGLCREATESHADEROBJECTARBPROC qglCreateShaderObjectARB; +extern PFNGLSHADERSOURCEARBPROC qglShaderSourceARB; +extern PFNGLCOMPILESHADERARBPROC qglCompileShaderARB; +extern PFNGLGETOBJECTPARAMETERIVARBPROC qglGetObjectParameterivARB; +extern PFNGLATTACHOBJECTARBPROC qglAttachObjectARB; +extern PFNGLGETINFOLOGARBPROC qglGetInfoLogARB; +extern PFNGLLINKPROGRAMARBPROC qglLinkProgramARB; +extern PFNGLGETUNIFORMLOCATIONARBPROC qglGetUniformLocationARB; +extern PFNGLUNIFORM4FARBPROC qglUniform4fARB; +extern PFNGLUNIFORM1IARBPROC qglUniform1iARB; +extern PFNGLUNIFORM1FARBPROC qglUniform1fARB; + +//glslang helper api +GLhandleARB GLSlang_CreateShader (char *shadersource, int shadertype); +GLhandleARB GLSlang_CreateProgram (GLhandleARB vert, GLhandleARB frag); +GLint GLSlang_GetUniformLocation (int prog, char *name); +#define GLSlang_UseProgram(prog) qglUseProgramObjectARB(prog); +#define GLSlang_SetUniform1i(uni, parm0) qglUniform1iARB(uni, parm0); +#define GLSlang_SetUniform1f(uni, parm0) qglUniform1fARB(uni, parm0); +#define GLSlang_DeleteObject(object) qglDeleteObjectARB(object); + + extern PFNGLLOCKARRAYSEXTPROC qglLockArraysEXT; extern PFNGLUNLOCKARRAYSEXTPROC qglUnlockArraysEXT; diff --git a/engine/gl/glsupp.h b/engine/gl/glsupp.h index a4ecbcee6..2ffa432d4 100644 --- a/engine/gl/glsupp.h +++ b/engine/gl/glsupp.h @@ -417,6 +417,110 @@ typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); /* All ARB_fragment_program entry points are shared with ARB_vertex_program. */ #endif + + + +#ifndef GL_ARB_shader_objects +#define GL_ARB_shader_objects 1 +#define GL_PROGRAM_OBJECT_ARB 0x8B40 +#define GL_OBJECT_TYPE_ARB 0x8B4E +#define GL_OBJECT_SUBTYPE_ARB 0x8B4F +#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 +#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 +#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 +#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 +#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 +#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 +#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 +#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 +#define GL_SHADER_OBJECT_ARB 0x8B48 +#define GL_FLOAT 0x1406 +#define GL_FLOAT_VEC2_ARB 0x8B50 +#define GL_FLOAT_VEC3_ARB 0x8B51 +#define GL_FLOAT_VEC4_ARB 0x8B52 +//#define GL_INT 0x1404 +#define GL_INT_VEC2_ARB 0x8B53 +#define GL_INT_VEC3_ARB 0x8B54 +#define GL_INT_VEC4_ARB 0x8B55 +#define GL_BOOL_ARB 0x8B56 +#define GL_BOOL_VEC2_ARB 0x8B57 +#define GL_BOOL_VEC3_ARB 0x8B58 +#define GL_BOOL_VEC4_ARB 0x8B59 +#define GL_FLOAT_MAT2_ARB 0x8B5A +#define GL_FLOAT_MAT3_ARB 0x8B5B +#define GL_FLOAT_MAT4_ARB 0x8B5C +#define GL_SAMPLER_1D_ARB 0x8B5D +#define GL_SAMPLER_2D_ARB 0x8B5E +#define GL_SAMPLER_3D_ARB 0x8B5F +#define GL_SAMPLER_CUBE_ARB 0x8B60 +#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 +#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 +#define GL_SAMPLER_2D_RECT_ARB 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 +// dont know if these two should go somewhere better: +typedef unsigned int GLhandleARB; +typedef char GLcharARB; +typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); +typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARB) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLsizei *size, GLenum *type, GLcharARB *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *parms); +typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *parms); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif // GL_ARB_shader_objects + +#ifndef GL_ARB_vertex_shader +#define GL_VERTEX_SHADER_ARB 0x8B31 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A +#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D +#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 +#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_FRAGMENT_SHADER_ARB 0x8B30 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 +#endif + + + + + #ifndef GL_SGIS_generate_mipmap #define GL_SGIS_generate_mipmap 1