From 245e8532cb194aedce21eacdce1db6f9531d1797 Mon Sep 17 00:00:00 2001 From: James Canete Date: Wed, 21 Mar 2012 10:29:55 +0000 Subject: [PATCH] Renderer, v29. --- reaction/code/renderergl2/qgl.h | 1375 ++++++++++---------- reaction/code/renderergl2/tr_backend.c | 101 +- reaction/code/renderergl2/tr_bsp.c | 10 +- reaction/code/renderergl2/tr_cmds.c | 73 +- reaction/code/renderergl2/tr_extensions.c | 170 +-- reaction/code/renderergl2/tr_extramath.h | 198 +-- reaction/code/renderergl2/tr_extratypes.h | 78 +- reaction/code/renderergl2/tr_fbo.c | 13 +- reaction/code/renderergl2/tr_glsl.c | 399 +++--- reaction/code/renderergl2/tr_image.c | 978 ++++++++++---- reaction/code/renderergl2/tr_init.c | 19 + reaction/code/renderergl2/tr_light.c | 2 +- reaction/code/renderergl2/tr_local.h | 16 +- reaction/code/renderergl2/tr_main.c | 14 +- reaction/code/renderergl2/tr_postprocess.c | 2 +- reaction/code/renderergl2/tr_shade.c | 12 +- reaction/code/renderergl2/tr_shader.c | 136 +- reaction/code/renderergl2/tr_surface.c | 8 +- 18 files changed, 2166 insertions(+), 1438 deletions(-) diff --git a/reaction/code/renderergl2/qgl.h b/reaction/code/renderergl2/qgl.h index 060964f6..79c60393 100644 --- a/reaction/code/renderergl2/qgl.h +++ b/reaction/code/renderergl2/qgl.h @@ -1,677 +1,702 @@ -/* -=========================================================================== -Copyright (C) 1999-2005 Id Software, Inc. - -This file is part of Quake III Arena source code. - -Quake III Arena source code is free software; you can redistribute it -and/or modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code is distributed in the hope that it will be -useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ -/* -** QGL.H -*/ - -#ifndef __QGL_H__ -#define __QGL_H__ - -#ifdef USE_LOCAL_HEADERS -# include "SDL_opengl.h" -#else -# include -#endif - -extern void (APIENTRYP qglActiveTextureARB) (GLenum texture); -extern void (APIENTRYP qglClientActiveTextureARB) (GLenum texture); -extern void (APIENTRYP qglMultiTexCoord2fARB) (GLenum target, GLfloat s, GLfloat t); - -extern void (APIENTRYP qglLockArraysEXT) (GLint first, GLsizei count); -extern void (APIENTRYP qglUnlockArraysEXT) (void); - -// GL_EXT_multi_draw_arrays -extern void (APIENTRY * qglMultiDrawArraysEXT) (GLenum, GLint *, GLsizei *, GLsizei); -extern void (APIENTRY * qglMultiDrawElementsEXT) (GLenum, const GLsizei *, GLenum, const GLvoid **, GLsizei); - -// GL_ARB_vertex_program -extern void (APIENTRY * qglVertexAttrib4fARB) (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); -extern void (APIENTRY * qglVertexAttrib4fvARB) (GLuint, const GLfloat *); -extern void (APIENTRY * qglVertexAttribPointerARB) (GLuint index, GLint size, GLenum type, GLboolean normalized, - GLsizei stride, const GLvoid * pointer); -extern void (APIENTRY * qglEnableVertexAttribArrayARB) (GLuint index); -extern void (APIENTRY * qglDisableVertexAttribArrayARB) (GLuint index); - -// GL_ARB_vertex_buffer_object -extern void (APIENTRY * qglBindBufferARB) (GLenum target, GLuint buffer); -extern void (APIENTRY * qglDeleteBuffersARB) (GLsizei n, const GLuint * buffers); -extern void (APIENTRY * qglGenBuffersARB) (GLsizei n, GLuint * buffers); -extern GLboolean(APIENTRY * qglIsBufferARB) (GLuint buffer); -extern void (APIENTRY * qglBufferDataARB) (GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage); -extern void (APIENTRY * qglBufferSubDataARB) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid * data); -extern void (APIENTRY * qglGetBufferSubDataARB) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid * data); -extern void (APIENTRY * qglGetBufferParameterivARB) (GLenum target, GLenum pname, GLint * params); -extern void (APIENTRY * qglGetBufferPointervARB) (GLenum target, GLenum pname, GLvoid * *params); - -// GL_ARB_shader_objects -extern void (APIENTRY * qglDeleteObjectARB) (GLhandleARB obj); -extern GLhandleARB(APIENTRY * qglGetHandleARB) (GLenum pname); -extern void (APIENTRY * qglDetachObjectARB) (GLhandleARB containerObj, GLhandleARB attachedObj); -extern GLhandleARB(APIENTRY * qglCreateShaderObjectARB) (GLenum shaderType); -extern void (APIENTRY * qglShaderSourceARB) (GLhandleARB shaderObj, GLsizei count, const GLcharARB * *string, - const GLint * length); -extern void (APIENTRY * qglCompileShaderARB) (GLhandleARB shaderObj); -extern GLhandleARB(APIENTRY * qglCreateProgramObjectARB) (void); -extern void (APIENTRY * qglAttachObjectARB) (GLhandleARB containerObj, GLhandleARB obj); -extern void (APIENTRY * qglLinkProgramARB) (GLhandleARB programObj); -extern void (APIENTRY * qglUseProgramObjectARB) (GLhandleARB programObj); -extern void (APIENTRY * qglValidateProgramARB) (GLhandleARB programObj); -extern void (APIENTRY * qglUniform1fARB) (GLint location, GLfloat v0); -extern void (APIENTRY * qglUniform2fARB) (GLint location, GLfloat v0, GLfloat v1); -extern void (APIENTRY * qglUniform3fARB) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -extern void (APIENTRY * qglUniform4fARB) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -extern void (APIENTRY * qglUniform1iARB) (GLint location, GLint v0); -extern void (APIENTRY * qglUniform2iARB) (GLint location, GLint v0, GLint v1); -extern void (APIENTRY * qglUniform3iARB) (GLint location, GLint v0, GLint v1, GLint v2); -extern void (APIENTRY * qglUniform4iARB) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -extern void (APIENTRY * qglUniform1fvARB) (GLint location, GLsizei count, const GLfloat * value); -extern void (APIENTRY * qglUniform2fvARB) (GLint location, GLsizei count, const GLfloat * value); -extern void (APIENTRY * qglUniform3fvARB) (GLint location, GLsizei count, const GLfloat * value); -extern void (APIENTRY * qglUniform4fvARB) (GLint location, GLsizei count, const GLfloat * value); -extern void (APIENTRY * qglUniform2ivARB) (GLint location, GLsizei count, const GLint * value); -extern void (APIENTRY * qglUniform3ivARB) (GLint location, GLsizei count, const GLint * value); -extern void (APIENTRY * qglUniform4ivARB) (GLint location, GLsizei count, const GLint * value); -extern void (APIENTRY * qglUniformMatrix2fvARB) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); -extern void (APIENTRY * qglUniformMatrix3fvARB) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); -extern void (APIENTRY * qglUniformMatrix4fvARB) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); -extern void (APIENTRY * qglGetObjectParameterfvARB) (GLhandleARB obj, GLenum pname, GLfloat * params); -extern void (APIENTRY * qglGetObjectParameterivARB) (GLhandleARB obj, GLenum pname, GLint * params); -extern void (APIENTRY * qglGetInfoLogARB) (GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog); -extern void (APIENTRY * qglGetAttachedObjectsARB) (GLhandleARB containerObj, GLsizei maxCount, GLsizei * count, - GLhandleARB * obj); -extern GLint(APIENTRY * qglGetUniformLocationARB) (GLhandleARB programObj, const GLcharARB * name); -extern void (APIENTRY * qglGetActiveUniformARB) (GLhandleARB programObj, GLuint index, GLsizei maxIndex, GLsizei * length, - GLint * size, GLenum * type, GLcharARB * name); -extern void (APIENTRY * qglGetUniformfvARB) (GLhandleARB programObj, GLint location, GLfloat * params); -extern void (APIENTRY * qglGetUniformivARB) (GLhandleARB programObj, GLint location, GLint * params); -extern void (APIENTRY * qglGetShaderSourceARB) (GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * source); - -// GL_ARB_vertex_shader -extern void (APIENTRY * qglBindAttribLocationARB) (GLhandleARB programObj, GLuint index, const GLcharARB * name); -extern void (APIENTRY * qglGetActiveAttribARB) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei * length, - GLint * size, GLenum * type, GLcharARB * name); -extern GLint(APIENTRY * qglGetAttribLocationARB) (GLhandleARB programObj, const GLcharARB * name); - -// GL_ARB_texture_compression -extern void (APIENTRY * qglCompressedTexImage3DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, - GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -extern void (APIENTRY * qglCompressedTexImage2DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, - GLint border, GLsizei imageSize, const GLvoid *data); -extern void (APIENTRY * qglCompressedTexImage1DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, - GLsizei imageSize, const GLvoid *data); -extern void (APIENTRY * qglCompressedTexSubImage3DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, - GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -extern void (APIENTRY * qglCompressedTexSubImage2DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, - GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -extern void (APIENTRY * qglCompressedTexSubImage1DARB)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, - GLsizei imageSize, const GLvoid *data); -extern void (APIENTRY * qglGetCompressedTexImageARB)(GLenum target, GLint lod, - GLvoid *img); - -// GL_NVX_gpu_memory_info -#ifndef GL_NVX_gpu_memory_info -#define GL_NVX_gpu_memory_info -#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047 -#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048 -#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049 -#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A -#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B -#endif - -// GL_ATI_meminfo -#ifndef GL_ATI_meminfo -#define GL_ATI_meminfo -#define GL_VBO_FREE_MEMORY_ATI 0x87FB -#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC -#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD -#endif - -// GL_ARB_texture_float -#ifndef GL_ARB_texture_float -#define GL_ARB_texture_float -#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 -#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 -#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 -#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 -#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 -#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 -#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 -#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 -#define GL_RGBA32F_ARB 0x8814 -#define GL_RGB32F_ARB 0x8815 -#define GL_ALPHA32F_ARB 0x8816 -#define GL_INTENSITY32F_ARB 0x8817 -#define GL_LUMINANCE32F_ARB 0x8818 -#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 -#define GL_RGBA16F_ARB 0x881A -#define GL_RGB16F_ARB 0x881B -#define GL_ALPHA16F_ARB 0x881C -#define GL_INTENSITY16F_ARB 0x881D -#define GL_LUMINANCE16F_ARB 0x881E -#define GL_LUMINANCE_ALPHA16F_ARB 0x881F -#endif - -#ifndef GL_ARB_half_float_pixel -#define GL_ARB_half_float_pixel -#define GL_HALF_FLOAT_ARB 0x140B -#endif - -// GL_EXT_framebuffer_object -extern GLboolean (APIENTRY * qglIsRenderbufferEXT)(GLuint renderbuffer); -extern void (APIENTRY * qglBindRenderbufferEXT)(GLenum target, GLuint renderbuffer); -extern void (APIENTRY * qglDeleteRenderbuffersEXT)(GLsizei n, const GLuint *renderbuffers); -extern void (APIENTRY * qglGenRenderbuffersEXT)(GLsizei n, GLuint *renderbuffers); -extern void (APIENTRY * qglRenderbufferStorageEXT)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -extern void (APIENTRY * qglGetRenderbufferParameterivEXT)(GLenum target, GLenum pname, GLint *params); -extern GLboolean (APIENTRY * qglIsFramebufferEXT)(GLuint framebuffer); -extern void (APIENTRY * qglBindFramebufferEXT)(GLenum target, GLuint framebuffer); -extern void (APIENTRY * qglDeleteFramebuffersEXT)(GLsizei n, const GLuint *framebuffers); -extern void (APIENTRY * qglGenFramebuffersEXT)(GLsizei n, GLuint *framebuffers); -extern GLenum (APIENTRY * qglCheckFramebufferStatusEXT)(GLenum target); -extern void (APIENTRY * qglFramebufferTexture1DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, - GLint level); -extern void (APIENTRY * qglFramebufferTexture2DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, - GLint level); -extern void (APIENTRY * qglFramebufferTexture3DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, - GLint level, GLint zoffset); -extern void (APIENTRY * qglFramebufferRenderbufferEXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, - GLuint renderbuffer); -extern void (APIENTRY * qglGetFramebufferAttachmentParameterivEXT)(GLenum target, GLenum attachment, GLenum pname, GLint *params); -extern void (APIENTRY * qglGenerateMipmapEXT)(GLenum target); - -#ifndef GL_EXT_framebuffer_object -#define GL_EXT_framebuffer_object -#define GL_FRAMEBUFFER_EXT 0x8D40 -#define GL_RENDERBUFFER_EXT 0x8D41 -#define GL_STENCIL_INDEX1_EXT 0x8D46 -#define GL_STENCIL_INDEX4_EXT 0x8D47 -#define GL_STENCIL_INDEX8_EXT 0x8D48 -#define GL_STENCIL_INDEX16_EXT 0x8D49 -#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 -#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 -#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 -#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 -#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 -#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 -#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 -#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 -#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 -#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 -#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 -#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 -#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 -#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 -#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 -#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 -#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 -#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 -#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA -#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB -#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC -#define GL_COLOR_ATTACHMENT13_EXT 0x8CED -#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE -#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF -#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 -#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 -#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 -#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 -#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC -#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD -#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 -#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 -#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF -#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 -#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 -#endif - -// GL_EXT_packed_depth_stencil -#ifndef GL_EXT_packed_depth_stencil -#define GL_EXT_packed_depth_stencil -#define GL_DEPTH_STENCIL_EXT 0x84F9 -#define GL_UNSIGNED_INT_24_8_EXT 0x84FA -#define GL_DEPTH24_STENCIL8_EXT 0x88F0 -#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 -#endif - -// GL_ARB_occlusion_query -extern void (APIENTRY * qglGenQueriesARB)(GLsizei n, GLuint *ids); -extern void (APIENTRY * qglDeleteQueriesARB)(GLsizei n, const GLuint *ids); -extern GLboolean (APIENTRY * qglIsQueryARB)(GLuint id); -extern void (APIENTRY * qglBeginQueryARB)(GLenum target, GLuint id); -extern void (APIENTRY * qglEndQueryARB)(GLenum target); -extern void (APIENTRY * qglGetQueryivARB)(GLenum target, GLenum pname, GLint *params); -extern void (APIENTRY * qglGetQueryObjectivARB)(GLuint id, GLenum pname, GLint *params); -extern void (APIENTRY * qglGetQueryObjectuivARB)(GLuint id, GLenum pname, GLuint *params); - -#ifndef GL_ARB_occlusion_query -#define GL_ARB_occlusion_query -#define GL_SAMPLES_PASSED_ARB 0x8914 -#define GL_QUERY_COUNTER_BITS_ARB 0x8864 -#define GL_CURRENT_QUERY_ARB 0x8865 -#define GL_QUERY_RESULT_ARB 0x8866 -#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 -#endif - -// GL_EXT_framebuffer_blit -void (APIENTRY * qglBlitFramebufferEXT)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, - GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, - GLbitfield mask, GLenum filter); - -#ifndef GL_EXT_framebuffer_blit -#define GL_EXT_framebuffer_blit -#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 -#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 -#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6 -#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA +/* +=========================================================================== +Copyright (C) 1999-2005 Id Software, Inc. + +This file is part of Quake III Arena source code. + +Quake III Arena source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +Quake III Arena source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Quake III Arena source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ +/* +** QGL.H +*/ + +#ifndef __QGL_H__ +#define __QGL_H__ + +#ifdef USE_LOCAL_HEADERS +# include "SDL_opengl.h" +#else +# include #endif - + +extern void (APIENTRYP qglActiveTextureARB) (GLenum texture); +extern void (APIENTRYP qglClientActiveTextureARB) (GLenum texture); +extern void (APIENTRYP qglMultiTexCoord2fARB) (GLenum target, GLfloat s, GLfloat t); + +extern void (APIENTRYP qglLockArraysEXT) (GLint first, GLsizei count); +extern void (APIENTRYP qglUnlockArraysEXT) (void); + +// GL_EXT_multi_draw_arrays +extern void (APIENTRY * qglMultiDrawArraysEXT) (GLenum, GLint *, GLsizei *, GLsizei); +extern void (APIENTRY * qglMultiDrawElementsEXT) (GLenum, const GLsizei *, GLenum, const GLvoid **, GLsizei); + +// GL_ARB_vertex_program +extern void (APIENTRY * qglVertexAttrib4fARB) (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +extern void (APIENTRY * qglVertexAttrib4fvARB) (GLuint, const GLfloat *); +extern void (APIENTRY * qglVertexAttribPointerARB) (GLuint index, GLint size, GLenum type, GLboolean normalized, + GLsizei stride, const GLvoid * pointer); +extern void (APIENTRY * qglEnableVertexAttribArrayARB) (GLuint index); +extern void (APIENTRY * qglDisableVertexAttribArrayARB) (GLuint index); + +// GL_ARB_vertex_buffer_object +extern void (APIENTRY * qglBindBufferARB) (GLenum target, GLuint buffer); +extern void (APIENTRY * qglDeleteBuffersARB) (GLsizei n, const GLuint * buffers); +extern void (APIENTRY * qglGenBuffersARB) (GLsizei n, GLuint * buffers); +extern GLboolean(APIENTRY * qglIsBufferARB) (GLuint buffer); +extern void (APIENTRY * qglBufferDataARB) (GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage); +extern void (APIENTRY * qglBufferSubDataARB) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid * data); +extern void (APIENTRY * qglGetBufferSubDataARB) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid * data); +extern void (APIENTRY * qglGetBufferParameterivARB) (GLenum target, GLenum pname, GLint * params); +extern void (APIENTRY * qglGetBufferPointervARB) (GLenum target, GLenum pname, GLvoid * *params); + +// GL_ARB_shader_objects +extern void (APIENTRY * qglDeleteObjectARB) (GLhandleARB obj); +extern GLhandleARB(APIENTRY * qglGetHandleARB) (GLenum pname); +extern void (APIENTRY * qglDetachObjectARB) (GLhandleARB containerObj, GLhandleARB attachedObj); +extern GLhandleARB(APIENTRY * qglCreateShaderObjectARB) (GLenum shaderType); +extern void (APIENTRY * qglShaderSourceARB) (GLhandleARB shaderObj, GLsizei count, const GLcharARB * *string, + const GLint * length); +extern void (APIENTRY * qglCompileShaderARB) (GLhandleARB shaderObj); +extern GLhandleARB(APIENTRY * qglCreateProgramObjectARB) (void); +extern void (APIENTRY * qglAttachObjectARB) (GLhandleARB containerObj, GLhandleARB obj); +extern void (APIENTRY * qglLinkProgramARB) (GLhandleARB programObj); +extern void (APIENTRY * qglUseProgramObjectARB) (GLhandleARB programObj); +extern void (APIENTRY * qglValidateProgramARB) (GLhandleARB programObj); +extern void (APIENTRY * qglUniform1fARB) (GLint location, GLfloat v0); +extern void (APIENTRY * qglUniform2fARB) (GLint location, GLfloat v0, GLfloat v1); +extern void (APIENTRY * qglUniform3fARB) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +extern void (APIENTRY * qglUniform4fARB) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +extern void (APIENTRY * qglUniform1iARB) (GLint location, GLint v0); +extern void (APIENTRY * qglUniform2iARB) (GLint location, GLint v0, GLint v1); +extern void (APIENTRY * qglUniform3iARB) (GLint location, GLint v0, GLint v1, GLint v2); +extern void (APIENTRY * qglUniform4iARB) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +extern void (APIENTRY * qglUniform1fvARB) (GLint location, GLsizei count, const GLfloat * value); +extern void (APIENTRY * qglUniform2fvARB) (GLint location, GLsizei count, const GLfloat * value); +extern void (APIENTRY * qglUniform3fvARB) (GLint location, GLsizei count, const GLfloat * value); +extern void (APIENTRY * qglUniform4fvARB) (GLint location, GLsizei count, const GLfloat * value); +extern void (APIENTRY * qglUniform2ivARB) (GLint location, GLsizei count, const GLint * value); +extern void (APIENTRY * qglUniform3ivARB) (GLint location, GLsizei count, const GLint * value); +extern void (APIENTRY * qglUniform4ivARB) (GLint location, GLsizei count, const GLint * value); +extern void (APIENTRY * qglUniformMatrix2fvARB) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); +extern void (APIENTRY * qglUniformMatrix3fvARB) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); +extern void (APIENTRY * qglUniformMatrix4fvARB) (GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); +extern void (APIENTRY * qglGetObjectParameterfvARB) (GLhandleARB obj, GLenum pname, GLfloat * params); +extern void (APIENTRY * qglGetObjectParameterivARB) (GLhandleARB obj, GLenum pname, GLint * params); +extern void (APIENTRY * qglGetInfoLogARB) (GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog); +extern void (APIENTRY * qglGetAttachedObjectsARB) (GLhandleARB containerObj, GLsizei maxCount, GLsizei * count, + GLhandleARB * obj); +extern GLint(APIENTRY * qglGetUniformLocationARB) (GLhandleARB programObj, const GLcharARB * name); +extern void (APIENTRY * qglGetActiveUniformARB) (GLhandleARB programObj, GLuint index, GLsizei maxIndex, GLsizei * length, + GLint * size, GLenum * type, GLcharARB * name); +extern void (APIENTRY * qglGetUniformfvARB) (GLhandleARB programObj, GLint location, GLfloat * params); +extern void (APIENTRY * qglGetUniformivARB) (GLhandleARB programObj, GLint location, GLint * params); +extern void (APIENTRY * qglGetShaderSourceARB) (GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * source); + +// GL_ARB_vertex_shader +extern void (APIENTRY * qglBindAttribLocationARB) (GLhandleARB programObj, GLuint index, const GLcharARB * name); +extern void (APIENTRY * qglGetActiveAttribARB) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei * length, + GLint * size, GLenum * type, GLcharARB * name); +extern GLint(APIENTRY * qglGetAttribLocationARB) (GLhandleARB programObj, const GLcharARB * name); + +// GL_ARB_texture_compression +extern void (APIENTRY * qglCompressedTexImage3DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, + GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +extern void (APIENTRY * qglCompressedTexImage2DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, + GLint border, GLsizei imageSize, const GLvoid *data); +extern void (APIENTRY * qglCompressedTexImage1DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, + GLsizei imageSize, const GLvoid *data); +extern void (APIENTRY * qglCompressedTexSubImage3DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +extern void (APIENTRY * qglCompressedTexSubImage2DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, + GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +extern void (APIENTRY * qglCompressedTexSubImage1DARB)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, + GLsizei imageSize, const GLvoid *data); +extern void (APIENTRY * qglGetCompressedTexImageARB)(GLenum target, GLint lod, + GLvoid *img); + +// GL_NVX_gpu_memory_info +#ifndef GL_NVX_gpu_memory_info +#define GL_NVX_gpu_memory_info +#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047 +#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048 +#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049 +#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A +#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B +#endif + +// GL_ATI_meminfo +#ifndef GL_ATI_meminfo +#define GL_ATI_meminfo +#define GL_VBO_FREE_MEMORY_ATI 0x87FB +#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC +#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD +#endif + +// GL_ARB_texture_float +#ifndef GL_ARB_texture_float +#define GL_ARB_texture_float +#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 +#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 +#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 +#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 +#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 +#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 +#define GL_RGBA32F_ARB 0x8814 +#define GL_RGB32F_ARB 0x8815 +#define GL_ALPHA32F_ARB 0x8816 +#define GL_INTENSITY32F_ARB 0x8817 +#define GL_LUMINANCE32F_ARB 0x8818 +#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 +#define GL_RGBA16F_ARB 0x881A +#define GL_RGB16F_ARB 0x881B +#define GL_ALPHA16F_ARB 0x881C +#define GL_INTENSITY16F_ARB 0x881D +#define GL_LUMINANCE16F_ARB 0x881E +#define GL_LUMINANCE_ALPHA16F_ARB 0x881F +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_ARB_half_float_pixel +#define GL_HALF_FLOAT_ARB 0x140B +#endif + +// GL_EXT_framebuffer_object +extern GLboolean (APIENTRY * qglIsRenderbufferEXT)(GLuint renderbuffer); +extern void (APIENTRY * qglBindRenderbufferEXT)(GLenum target, GLuint renderbuffer); +extern void (APIENTRY * qglDeleteRenderbuffersEXT)(GLsizei n, const GLuint *renderbuffers); +extern void (APIENTRY * qglGenRenderbuffersEXT)(GLsizei n, GLuint *renderbuffers); +extern void (APIENTRY * qglRenderbufferStorageEXT)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +extern void (APIENTRY * qglGetRenderbufferParameterivEXT)(GLenum target, GLenum pname, GLint *params); +extern GLboolean (APIENTRY * qglIsFramebufferEXT)(GLuint framebuffer); +extern void (APIENTRY * qglBindFramebufferEXT)(GLenum target, GLuint framebuffer); +extern void (APIENTRY * qglDeleteFramebuffersEXT)(GLsizei n, const GLuint *framebuffers); +extern void (APIENTRY * qglGenFramebuffersEXT)(GLsizei n, GLuint *framebuffers); +extern GLenum (APIENTRY * qglCheckFramebufferStatusEXT)(GLenum target); +extern void (APIENTRY * qglFramebufferTexture1DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, + GLint level); +extern void (APIENTRY * qglFramebufferTexture2DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, + GLint level); +extern void (APIENTRY * qglFramebufferTexture3DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, + GLint level, GLint zoffset); +extern void (APIENTRY * qglFramebufferRenderbufferEXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, + GLuint renderbuffer); +extern void (APIENTRY * qglGetFramebufferAttachmentParameterivEXT)(GLenum target, GLenum attachment, GLenum pname, GLint *params); +extern void (APIENTRY * qglGenerateMipmapEXT)(GLenum target); + +#ifndef GL_EXT_framebuffer_object +#define GL_EXT_framebuffer_object +#define GL_FRAMEBUFFER_EXT 0x8D40 +#define GL_RENDERBUFFER_EXT 0x8D41 +#define GL_STENCIL_INDEX1_EXT 0x8D46 +#define GL_STENCIL_INDEX4_EXT 0x8D47 +#define GL_STENCIL_INDEX8_EXT 0x8D48 +#define GL_STENCIL_INDEX16_EXT 0x8D49 +#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 +#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 +#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 +#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 +#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 +#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 +#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 +#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 +#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 +#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 +#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 +#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA +#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB +#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC +#define GL_COLOR_ATTACHMENT13_EXT 0x8CED +#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE +#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF +#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 +#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 +#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD +#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 +#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF +#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 +#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 +#endif + +// GL_EXT_packed_depth_stencil +#ifndef GL_EXT_packed_depth_stencil +#define GL_EXT_packed_depth_stencil +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#define GL_UNSIGNED_INT_24_8_EXT 0x84FA +#define GL_DEPTH24_STENCIL8_EXT 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 +#endif + +// GL_ARB_occlusion_query +extern void (APIENTRY * qglGenQueriesARB)(GLsizei n, GLuint *ids); +extern void (APIENTRY * qglDeleteQueriesARB)(GLsizei n, const GLuint *ids); +extern GLboolean (APIENTRY * qglIsQueryARB)(GLuint id); +extern void (APIENTRY * qglBeginQueryARB)(GLenum target, GLuint id); +extern void (APIENTRY * qglEndQueryARB)(GLenum target); +extern void (APIENTRY * qglGetQueryivARB)(GLenum target, GLenum pname, GLint *params); +extern void (APIENTRY * qglGetQueryObjectivARB)(GLuint id, GLenum pname, GLint *params); +extern void (APIENTRY * qglGetQueryObjectuivARB)(GLuint id, GLenum pname, GLuint *params); + +#ifndef GL_ARB_occlusion_query +#define GL_ARB_occlusion_query +#define GL_SAMPLES_PASSED_ARB 0x8914 +#define GL_QUERY_COUNTER_BITS_ARB 0x8864 +#define GL_CURRENT_QUERY_ARB 0x8865 +#define GL_QUERY_RESULT_ARB 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 +#endif + +// GL_EXT_framebuffer_blit +void (APIENTRY * qglBlitFramebufferEXT)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, + GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, + GLbitfield mask, GLenum filter); + +#ifndef GL_EXT_framebuffer_blit +#define GL_EXT_framebuffer_blit +#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA +#endif + // GL_EXT_framebuffer_multisample -void (APIENTRY * qglRenderbufferStorageMultisampleEXT)(GLenum target, GLsizei samples, - GLenum internalformat, GLsizei width, GLsizei height); - -#ifndef GL_EXT_framebuffer_multisample -#define GL_EXT_framebuffer_multisample -#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 -#define GL_MAX_SAMPLES_EXT 0x8D57 -#endif - -#if defined(WIN32) -// WGL_ARB_create_context -#ifndef WGL_ARB_create_context -#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 -#define WGL_CONTEXT_FLAGS_ARB 0x2094 -#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 -#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 -#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 -#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 -#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 -#define ERROR_INVALID_VERSION_ARB 0x2095 -#define ERROR_INVALID_PROFILE_ARB 0x2096 -#endif - -extern HGLRC(APIENTRY * qwglCreateContextAttribsARB) (HDC hdC, HGLRC hShareContext, const int *attribList); -#endif - -#if 0 //defined(__linux__) -// GLX_ARB_create_context -#ifndef GLX_ARB_create_context -#define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 -#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 -#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define GLX_CONTEXT_FLAGS_ARB 0x2094 -#endif - -extern GLXContext (APIENTRY * qglXCreateContextAttribsARB) (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); -#endif - -//=========================================================================== - -#define qglAccum glAccum -#define qglAlphaFunc glAlphaFunc -#define qglAreTexturesResident glAreTexturesResident -#define qglArrayElement glArrayElement -#define qglBegin glBegin -#define qglBindTexture glBindTexture -#define qglBitmap glBitmap -#define qglBlendFunc glBlendFunc -#define qglCallList glCallList -#define qglCallLists glCallLists -#define qglClear glClear -#define qglClearAccum glClearAccum -#define qglClearColor glClearColor -#define qglClearDepth glClearDepth -#define qglClearIndex glClearIndex -#define qglClearStencil glClearStencil -#define qglClipPlane glClipPlane -#define qglColor3b glColor3b -#define qglColor3bv glColor3bv -#define qglColor3d glColor3d -#define qglColor3dv glColor3dv -#define qglColor3f glColor3f -#define qglColor3fv glColor3fv -#define qglColor3i glColor3i -#define qglColor3iv glColor3iv -#define qglColor3s glColor3s -#define qglColor3sv glColor3sv -#define qglColor3ub glColor3ub -#define qglColor3ubv glColor3ubv -#define qglColor3ui glColor3ui -#define qglColor3uiv glColor3uiv -#define qglColor3us glColor3us -#define qglColor3usv glColor3usv -#define qglColor4b glColor4b -#define qglColor4bv glColor4bv -#define qglColor4d glColor4d -#define qglColor4dv glColor4dv -#define qglColor4f glColor4f -#define qglColor4fv glColor4fv -#define qglColor4i glColor4i -#define qglColor4iv glColor4iv -#define qglColor4s glColor4s -#define qglColor4sv glColor4sv -#define qglColor4ub glColor4ub -#define qglColor4ubv glColor4ubv -#define qglColor4ui glColor4ui -#define qglColor4uiv glColor4uiv -#define qglColor4us glColor4us -#define qglColor4usv glColor4usv -#define qglColorMask glColorMask -#define qglColorMaterial glColorMaterial -#define qglColorPointer glColorPointer -#define qglCopyPixels glCopyPixels -#define qglCopyTexImage1D glCopyTexImage1D -#define qglCopyTexImage2D glCopyTexImage2D -#define qglCopyTexSubImage1D glCopyTexSubImage1D -#define qglCopyTexSubImage2D glCopyTexSubImage2D -#define qglCullFace glCullFace -#define qglDeleteLists glDeleteLists -#define qglDeleteTextures glDeleteTextures -#define qglDepthFunc glDepthFunc -#define qglDepthMask glDepthMask -#define qglDepthRange glDepthRange -#define qglDisable glDisable -#define qglDisableClientState glDisableClientState -#define qglDrawArrays glDrawArrays -#define qglDrawBuffer glDrawBuffer -#define qglDrawElements glDrawElements -#define qglDrawPixels glDrawPixels -#define qglEdgeFlag glEdgeFlag -#define qglEdgeFlagPointer glEdgeFlagPointer -#define qglEdgeFlagv glEdgeFlagv -#define qglEnable glEnable -#define qglEnableClientState glEnableClientState -#define qglEnd glEnd -#define qglEndList glEndList -#define qglEvalCoord1d glEvalCoord1d -#define qglEvalCoord1dv glEvalCoord1dv -#define qglEvalCoord1f glEvalCoord1f -#define qglEvalCoord1fv glEvalCoord1fv -#define qglEvalCoord2d glEvalCoord2d -#define qglEvalCoord2dv glEvalCoord2dv -#define qglEvalCoord2f glEvalCoord2f -#define qglEvalCoord2fv glEvalCoord2fv -#define qglEvalMesh1 glEvalMesh1 -#define qglEvalMesh2 glEvalMesh2 -#define qglEvalPoint1 glEvalPoint1 -#define qglEvalPoint2 glEvalPoint2 -#define qglFeedbackBuffer glFeedbackBuffer -#define qglFinish glFinish -#define qglFlush glFlush -#define qglFogf glFogf -#define qglFogfv glFogfv -#define qglFogi glFogi -#define qglFogiv glFogiv -#define qglFrontFace glFrontFace -#define qglFrustum glFrustum -#define qglGenLists glGenLists -#define qglGenTextures glGenTextures -#define qglGetBooleanv glGetBooleanv -#define qglGetClipPlane glGetClipPlane -#define qglGetDoublev glGetDoublev -#define qglGetError glGetError -#define qglGetFloatv glGetFloatv -#define qglGetIntegerv glGetIntegerv -#define qglGetLightfv glGetLightfv -#define qglGetLightiv glGetLightiv -#define qglGetMapdv glGetMapdv -#define qglGetMapfv glGetMapfv -#define qglGetMapiv glGetMapiv -#define qglGetMaterialfv glGetMaterialfv -#define qglGetMaterialiv glGetMaterialiv -#define qglGetPixelMapfv glGetPixelMapfv -#define qglGetPixelMapuiv glGetPixelMapuiv -#define qglGetPixelMapusv glGetPixelMapusv -#define qglGetPointerv glGetPointerv -#define qglGetPolygonStipple glGetPolygonStipple -#define qglGetString glGetString -#define qglGetTexGendv glGetTexGendv -#define qglGetTexGenfv glGetTexGenfv -#define qglGetTexGeniv glGetTexGeniv -#define qglGetTexImage glGetTexImage -#define qglGetTexLevelParameterfv glGetTexLevelParameterfv -#define qglGetTexLevelParameteriv glGetTexLevelParameteriv -#define qglGetTexParameterfv glGetTexParameterfv -#define qglGetTexParameteriv glGetTexParameteriv -#define qglHint glHint -#define qglIndexMask glIndexMask -#define qglIndexPointer glIndexPointer -#define qglIndexd glIndexd -#define qglIndexdv glIndexdv -#define qglIndexf glIndexf -#define qglIndexfv glIndexfv -#define qglIndexi glIndexi -#define qglIndexiv glIndexiv -#define qglIndexs glIndexs -#define qglIndexsv glIndexsv -#define qglIndexub glIndexub -#define qglIndexubv glIndexubv -#define qglInitNames glInitNames -#define qglInterleavedArrays glInterleavedArrays -#define qglIsEnabled glIsEnabled -#define qglIsList glIsList -#define qglIsTexture glIsTexture -#define qglLightModelf glLightModelf -#define qglLightModelfv glLightModelfv -#define qglLightModeli glLightModeli -#define qglLightModeliv glLightModeliv -#define qglLightf glLightf -#define qglLightfv glLightfv -#define qglLighti glLighti -#define qglLightiv glLightiv -#define qglLineStipple glLineStipple -#define qglLineWidth glLineWidth -#define qglListBase glListBase -#define qglLoadIdentity glLoadIdentity -#define qglLoadMatrixd glLoadMatrixd -#define qglLoadMatrixf glLoadMatrixf -#define qglLoadName glLoadName -#define qglLogicOp glLogicOp -#define qglMap1d glMap1d -#define qglMap1f glMap1f -#define qglMap2d glMap2d -#define qglMap2f glMap2f -#define qglMapGrid1d glMapGrid1d -#define qglMapGrid1f glMapGrid1f -#define qglMapGrid2d glMapGrid2d -#define qglMapGrid2f glMapGrid2f -#define qglMaterialf glMaterialf -#define qglMaterialfv glMaterialfv -#define qglMateriali glMateriali -#define qglMaterialiv glMaterialiv -#define qglMatrixMode glMatrixMode -#define qglMultMatrixd glMultMatrixd -#define qglMultMatrixf glMultMatrixf -#define qglNewList glNewList -#define qglNormal3b glNormal3b -#define qglNormal3bv glNormal3bv -#define qglNormal3d glNormal3d -#define qglNormal3dv glNormal3dv -#define qglNormal3f glNormal3f -#define qglNormal3fv glNormal3fv -#define qglNormal3i glNormal3i -#define qglNormal3iv glNormal3iv -#define qglNormal3s glNormal3s -#define qglNormal3sv glNormal3sv -#define qglNormalPointer glNormalPointer -#define qglOrtho glOrtho -#define qglPassThrough glPassThrough -#define qglPixelMapfv glPixelMapfv -#define qglPixelMapuiv glPixelMapuiv -#define qglPixelMapusv glPixelMapusv -#define qglPixelStoref glPixelStoref -#define qglPixelStorei glPixelStorei -#define qglPixelTransferf glPixelTransferf -#define qglPixelTransferi glPixelTransferi -#define qglPixelZoom glPixelZoom -#define qglPointSize glPointSize -#define qglPolygonMode glPolygonMode -#define qglPolygonOffset glPolygonOffset -#define qglPolygonStipple glPolygonStipple -#define qglPopAttrib glPopAttrib -#define qglPopClientAttrib glPopClientAttrib -#define qglPopMatrix glPopMatrix -#define qglPopName glPopName -#define qglPrioritizeTextures glPrioritizeTextures -#define qglPushAttrib glPushAttrib -#define qglPushClientAttrib glPushClientAttrib -#define qglPushMatrix glPushMatrix -#define qglPushName glPushName -#define qglRasterPos2d glRasterPos2d -#define qglRasterPos2dv glRasterPos2dv -#define qglRasterPos2f glRasterPos2f -#define qglRasterPos2fv glRasterPos2fv -#define qglRasterPos2i glRasterPos2i -#define qglRasterPos2iv glRasterPos2iv -#define qglRasterPos2s glRasterPos2s -#define qglRasterPos2sv glRasterPos2sv -#define qglRasterPos3d glRasterPos3d -#define qglRasterPos3dv glRasterPos3dv -#define qglRasterPos3f glRasterPos3f -#define qglRasterPos3fv glRasterPos3fv -#define qglRasterPos3i glRasterPos3i -#define qglRasterPos3iv glRasterPos3iv -#define qglRasterPos3s glRasterPos3s -#define qglRasterPos3sv glRasterPos3sv -#define qglRasterPos4d glRasterPos4d -#define qglRasterPos4dv glRasterPos4dv -#define qglRasterPos4f glRasterPos4f -#define qglRasterPos4fv glRasterPos4fv -#define qglRasterPos4i glRasterPos4i -#define qglRasterPos4iv glRasterPos4iv -#define qglRasterPos4s glRasterPos4s -#define qglRasterPos4sv glRasterPos4sv -#define qglReadBuffer glReadBuffer -#define qglReadPixels glReadPixels -#define qglRectd glRectd -#define qglRectdv glRectdv -#define qglRectf glRectf -#define qglRectfv glRectfv -#define qglRecti glRecti -#define qglRectiv glRectiv -#define qglRects glRects -#define qglRectsv glRectsv -#define qglRenderMode glRenderMode -#define qglRotated glRotated -#define qglRotatef glRotatef -#define qglScaled glScaled -#define qglScalef glScalef -#define qglScissor glScissor -#define qglSelectBuffer glSelectBuffer -#define qglShadeModel glShadeModel -#define qglStencilFunc glStencilFunc -#define qglStencilMask glStencilMask -#define qglStencilOp glStencilOp -#define qglTexCoord1d glTexCoord1d -#define qglTexCoord1dv glTexCoord1dv -#define qglTexCoord1f glTexCoord1f -#define qglTexCoord1fv glTexCoord1fv -#define qglTexCoord1i glTexCoord1i -#define qglTexCoord1iv glTexCoord1iv -#define qglTexCoord1s glTexCoord1s -#define qglTexCoord1sv glTexCoord1sv -#define qglTexCoord2d glTexCoord2d -#define qglTexCoord2dv glTexCoord2dv -#define qglTexCoord2f glTexCoord2f -#define qglTexCoord2fv glTexCoord2fv -#define qglTexCoord2i glTexCoord2i -#define qglTexCoord2iv glTexCoord2iv -#define qglTexCoord2s glTexCoord2s -#define qglTexCoord2sv glTexCoord2sv -#define qglTexCoord3d glTexCoord3d -#define qglTexCoord3dv glTexCoord3dv -#define qglTexCoord3f glTexCoord3f -#define qglTexCoord3fv glTexCoord3fv -#define qglTexCoord3i glTexCoord3i -#define qglTexCoord3iv glTexCoord3iv -#define qglTexCoord3s glTexCoord3s -#define qglTexCoord3sv glTexCoord3sv -#define qglTexCoord4d glTexCoord4d -#define qglTexCoord4dv glTexCoord4dv -#define qglTexCoord4f glTexCoord4f -#define qglTexCoord4fv glTexCoord4fv -#define qglTexCoord4i glTexCoord4i -#define qglTexCoord4iv glTexCoord4iv -#define qglTexCoord4s glTexCoord4s -#define qglTexCoord4sv glTexCoord4sv -#define qglTexCoordPointer glTexCoordPointer -#define qglTexEnvf glTexEnvf -#define qglTexEnvfv glTexEnvfv -#define qglTexEnvi glTexEnvi -#define qglTexEnviv glTexEnviv -#define qglTexGend glTexGend -#define qglTexGendv glTexGendv -#define qglTexGenf glTexGenf -#define qglTexGenfv glTexGenfv -#define qglTexGeni glTexGeni -#define qglTexGeniv glTexGeniv -#define qglTexImage1D glTexImage1D -#define qglTexImage2D glTexImage2D -#define qglTexParameterf glTexParameterf -#define qglTexParameterfv glTexParameterfv -#define qglTexParameteri glTexParameteri -#define qglTexParameteriv glTexParameteriv -#define qglTexSubImage1D glTexSubImage1D -#define qglTexSubImage2D glTexSubImage2D -#define qglTranslated glTranslated -#define qglTranslatef glTranslatef -#define qglVertex2d glVertex2d -#define qglVertex2dv glVertex2dv -#define qglVertex2f glVertex2f -#define qglVertex2fv glVertex2fv -#define qglVertex2i glVertex2i -#define qglVertex2iv glVertex2iv -#define qglVertex2s glVertex2s -#define qglVertex2sv glVertex2sv -#define qglVertex3d glVertex3d -#define qglVertex3dv glVertex3dv -#define qglVertex3f glVertex3f -#define qglVertex3fv glVertex3fv -#define qglVertex3i glVertex3i -#define qglVertex3iv glVertex3iv -#define qglVertex3s glVertex3s -#define qglVertex3sv glVertex3sv -#define qglVertex4d glVertex4d -#define qglVertex4dv glVertex4dv -#define qglVertex4f glVertex4f -#define qglVertex4fv glVertex4fv -#define qglVertex4i glVertex4i -#define qglVertex4iv glVertex4iv -#define qglVertex4s glVertex4s -#define qglVertex4sv glVertex4sv -#define qglVertexPointer glVertexPointer -#define qglViewport glViewport - -#endif +void (APIENTRY * qglRenderbufferStorageMultisampleEXT)(GLenum target, GLsizei samples, + GLenum internalformat, GLsizei width, GLsizei height); + +#ifndef GL_EXT_framebuffer_multisample +#define GL_EXT_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +#ifndef GL_EXT_texture_sRGB +#define GL_EXT_texture_sRGB +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB8_EXT 0x8C41 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_SLUMINANCE_ALPHA_EXT 0x8C44 +#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45 +#define GL_SLUMINANCE_EXT 0x8C46 +#define GL_SLUMINANCE8_EXT 0x8C47 +#define GL_COMPRESSED_SRGB_EXT 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49 +#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B +#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F +#endif + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_EXT_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9 +#endif + +#if defined(WIN32) +// WGL_ARB_create_context +#ifndef WGL_ARB_create_context +#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 +#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 +#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 +#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 +#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 +#define ERROR_INVALID_VERSION_ARB 0x2095 +#define ERROR_INVALID_PROFILE_ARB 0x2096 +#endif + +extern HGLRC(APIENTRY * qwglCreateContextAttribsARB) (HDC hdC, HGLRC hShareContext, const int *attribList); +#endif + +#if 0 //defined(__linux__) +// GLX_ARB_create_context +#ifndef GLX_ARB_create_context +#define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 +#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 +#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define GLX_CONTEXT_FLAGS_ARB 0x2094 +#endif + +extern GLXContext (APIENTRY * qglXCreateContextAttribsARB) (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); +#endif + +//=========================================================================== + +#define qglAccum glAccum +#define qglAlphaFunc glAlphaFunc +#define qglAreTexturesResident glAreTexturesResident +#define qglArrayElement glArrayElement +#define qglBegin glBegin +#define qglBindTexture glBindTexture +#define qglBitmap glBitmap +#define qglBlendFunc glBlendFunc +#define qglCallList glCallList +#define qglCallLists glCallLists +#define qglClear glClear +#define qglClearAccum glClearAccum +#define qglClearColor glClearColor +#define qglClearDepth glClearDepth +#define qglClearIndex glClearIndex +#define qglClearStencil glClearStencil +#define qglClipPlane glClipPlane +#define qglColor3b glColor3b +#define qglColor3bv glColor3bv +#define qglColor3d glColor3d +#define qglColor3dv glColor3dv +#define qglColor3f glColor3f +#define qglColor3fv glColor3fv +#define qglColor3i glColor3i +#define qglColor3iv glColor3iv +#define qglColor3s glColor3s +#define qglColor3sv glColor3sv +#define qglColor3ub glColor3ub +#define qglColor3ubv glColor3ubv +#define qglColor3ui glColor3ui +#define qglColor3uiv glColor3uiv +#define qglColor3us glColor3us +#define qglColor3usv glColor3usv +#define qglColor4b glColor4b +#define qglColor4bv glColor4bv +#define qglColor4d glColor4d +#define qglColor4dv glColor4dv +#define qglColor4f glColor4f +#define qglColor4fv glColor4fv +#define qglColor4i glColor4i +#define qglColor4iv glColor4iv +#define qglColor4s glColor4s +#define qglColor4sv glColor4sv +#define qglColor4ub glColor4ub +#define qglColor4ubv glColor4ubv +#define qglColor4ui glColor4ui +#define qglColor4uiv glColor4uiv +#define qglColor4us glColor4us +#define qglColor4usv glColor4usv +#define qglColorMask glColorMask +#define qglColorMaterial glColorMaterial +#define qglColorPointer glColorPointer +#define qglCopyPixels glCopyPixels +#define qglCopyTexImage1D glCopyTexImage1D +#define qglCopyTexImage2D glCopyTexImage2D +#define qglCopyTexSubImage1D glCopyTexSubImage1D +#define qglCopyTexSubImage2D glCopyTexSubImage2D +#define qglCullFace glCullFace +#define qglDeleteLists glDeleteLists +#define qglDeleteTextures glDeleteTextures +#define qglDepthFunc glDepthFunc +#define qglDepthMask glDepthMask +#define qglDepthRange glDepthRange +#define qglDisable glDisable +#define qglDisableClientState glDisableClientState +#define qglDrawArrays glDrawArrays +#define qglDrawBuffer glDrawBuffer +#define qglDrawElements glDrawElements +#define qglDrawPixels glDrawPixels +#define qglEdgeFlag glEdgeFlag +#define qglEdgeFlagPointer glEdgeFlagPointer +#define qglEdgeFlagv glEdgeFlagv +#define qglEnable glEnable +#define qglEnableClientState glEnableClientState +#define qglEnd glEnd +#define qglEndList glEndList +#define qglEvalCoord1d glEvalCoord1d +#define qglEvalCoord1dv glEvalCoord1dv +#define qglEvalCoord1f glEvalCoord1f +#define qglEvalCoord1fv glEvalCoord1fv +#define qglEvalCoord2d glEvalCoord2d +#define qglEvalCoord2dv glEvalCoord2dv +#define qglEvalCoord2f glEvalCoord2f +#define qglEvalCoord2fv glEvalCoord2fv +#define qglEvalMesh1 glEvalMesh1 +#define qglEvalMesh2 glEvalMesh2 +#define qglEvalPoint1 glEvalPoint1 +#define qglEvalPoint2 glEvalPoint2 +#define qglFeedbackBuffer glFeedbackBuffer +#define qglFinish glFinish +#define qglFlush glFlush +#define qglFogf glFogf +#define qglFogfv glFogfv +#define qglFogi glFogi +#define qglFogiv glFogiv +#define qglFrontFace glFrontFace +#define qglFrustum glFrustum +#define qglGenLists glGenLists +#define qglGenTextures glGenTextures +#define qglGetBooleanv glGetBooleanv +#define qglGetClipPlane glGetClipPlane +#define qglGetDoublev glGetDoublev +#define qglGetError glGetError +#define qglGetFloatv glGetFloatv +#define qglGetIntegerv glGetIntegerv +#define qglGetLightfv glGetLightfv +#define qglGetLightiv glGetLightiv +#define qglGetMapdv glGetMapdv +#define qglGetMapfv glGetMapfv +#define qglGetMapiv glGetMapiv +#define qglGetMaterialfv glGetMaterialfv +#define qglGetMaterialiv glGetMaterialiv +#define qglGetPixelMapfv glGetPixelMapfv +#define qglGetPixelMapuiv glGetPixelMapuiv +#define qglGetPixelMapusv glGetPixelMapusv +#define qglGetPointerv glGetPointerv +#define qglGetPolygonStipple glGetPolygonStipple +#define qglGetString glGetString +#define qglGetTexGendv glGetTexGendv +#define qglGetTexGenfv glGetTexGenfv +#define qglGetTexGeniv glGetTexGeniv +#define qglGetTexImage glGetTexImage +#define qglGetTexLevelParameterfv glGetTexLevelParameterfv +#define qglGetTexLevelParameteriv glGetTexLevelParameteriv +#define qglGetTexParameterfv glGetTexParameterfv +#define qglGetTexParameteriv glGetTexParameteriv +#define qglHint glHint +#define qglIndexMask glIndexMask +#define qglIndexPointer glIndexPointer +#define qglIndexd glIndexd +#define qglIndexdv glIndexdv +#define qglIndexf glIndexf +#define qglIndexfv glIndexfv +#define qglIndexi glIndexi +#define qglIndexiv glIndexiv +#define qglIndexs glIndexs +#define qglIndexsv glIndexsv +#define qglIndexub glIndexub +#define qglIndexubv glIndexubv +#define qglInitNames glInitNames +#define qglInterleavedArrays glInterleavedArrays +#define qglIsEnabled glIsEnabled +#define qglIsList glIsList +#define qglIsTexture glIsTexture +#define qglLightModelf glLightModelf +#define qglLightModelfv glLightModelfv +#define qglLightModeli glLightModeli +#define qglLightModeliv glLightModeliv +#define qglLightf glLightf +#define qglLightfv glLightfv +#define qglLighti glLighti +#define qglLightiv glLightiv +#define qglLineStipple glLineStipple +#define qglLineWidth glLineWidth +#define qglListBase glListBase +#define qglLoadIdentity glLoadIdentity +#define qglLoadMatrixd glLoadMatrixd +#define qglLoadMatrixf glLoadMatrixf +#define qglLoadName glLoadName +#define qglLogicOp glLogicOp +#define qglMap1d glMap1d +#define qglMap1f glMap1f +#define qglMap2d glMap2d +#define qglMap2f glMap2f +#define qglMapGrid1d glMapGrid1d +#define qglMapGrid1f glMapGrid1f +#define qglMapGrid2d glMapGrid2d +#define qglMapGrid2f glMapGrid2f +#define qglMaterialf glMaterialf +#define qglMaterialfv glMaterialfv +#define qglMateriali glMateriali +#define qglMaterialiv glMaterialiv +#define qglMatrixMode glMatrixMode +#define qglMultMatrixd glMultMatrixd +#define qglMultMatrixf glMultMatrixf +#define qglNewList glNewList +#define qglNormal3b glNormal3b +#define qglNormal3bv glNormal3bv +#define qglNormal3d glNormal3d +#define qglNormal3dv glNormal3dv +#define qglNormal3f glNormal3f +#define qglNormal3fv glNormal3fv +#define qglNormal3i glNormal3i +#define qglNormal3iv glNormal3iv +#define qglNormal3s glNormal3s +#define qglNormal3sv glNormal3sv +#define qglNormalPointer glNormalPointer +#define qglOrtho glOrtho +#define qglPassThrough glPassThrough +#define qglPixelMapfv glPixelMapfv +#define qglPixelMapuiv glPixelMapuiv +#define qglPixelMapusv glPixelMapusv +#define qglPixelStoref glPixelStoref +#define qglPixelStorei glPixelStorei +#define qglPixelTransferf glPixelTransferf +#define qglPixelTransferi glPixelTransferi +#define qglPixelZoom glPixelZoom +#define qglPointSize glPointSize +#define qglPolygonMode glPolygonMode +#define qglPolygonOffset glPolygonOffset +#define qglPolygonStipple glPolygonStipple +#define qglPopAttrib glPopAttrib +#define qglPopClientAttrib glPopClientAttrib +#define qglPopMatrix glPopMatrix +#define qglPopName glPopName +#define qglPrioritizeTextures glPrioritizeTextures +#define qglPushAttrib glPushAttrib +#define qglPushClientAttrib glPushClientAttrib +#define qglPushMatrix glPushMatrix +#define qglPushName glPushName +#define qglRasterPos2d glRasterPos2d +#define qglRasterPos2dv glRasterPos2dv +#define qglRasterPos2f glRasterPos2f +#define qglRasterPos2fv glRasterPos2fv +#define qglRasterPos2i glRasterPos2i +#define qglRasterPos2iv glRasterPos2iv +#define qglRasterPos2s glRasterPos2s +#define qglRasterPos2sv glRasterPos2sv +#define qglRasterPos3d glRasterPos3d +#define qglRasterPos3dv glRasterPos3dv +#define qglRasterPos3f glRasterPos3f +#define qglRasterPos3fv glRasterPos3fv +#define qglRasterPos3i glRasterPos3i +#define qglRasterPos3iv glRasterPos3iv +#define qglRasterPos3s glRasterPos3s +#define qglRasterPos3sv glRasterPos3sv +#define qglRasterPos4d glRasterPos4d +#define qglRasterPos4dv glRasterPos4dv +#define qglRasterPos4f glRasterPos4f +#define qglRasterPos4fv glRasterPos4fv +#define qglRasterPos4i glRasterPos4i +#define qglRasterPos4iv glRasterPos4iv +#define qglRasterPos4s glRasterPos4s +#define qglRasterPos4sv glRasterPos4sv +#define qglReadBuffer glReadBuffer +#define qglReadPixels glReadPixels +#define qglRectd glRectd +#define qglRectdv glRectdv +#define qglRectf glRectf +#define qglRectfv glRectfv +#define qglRecti glRecti +#define qglRectiv glRectiv +#define qglRects glRects +#define qglRectsv glRectsv +#define qglRenderMode glRenderMode +#define qglRotated glRotated +#define qglRotatef glRotatef +#define qglScaled glScaled +#define qglScalef glScalef +#define qglScissor glScissor +#define qglSelectBuffer glSelectBuffer +#define qglShadeModel glShadeModel +#define qglStencilFunc glStencilFunc +#define qglStencilMask glStencilMask +#define qglStencilOp glStencilOp +#define qglTexCoord1d glTexCoord1d +#define qglTexCoord1dv glTexCoord1dv +#define qglTexCoord1f glTexCoord1f +#define qglTexCoord1fv glTexCoord1fv +#define qglTexCoord1i glTexCoord1i +#define qglTexCoord1iv glTexCoord1iv +#define qglTexCoord1s glTexCoord1s +#define qglTexCoord1sv glTexCoord1sv +#define qglTexCoord2d glTexCoord2d +#define qglTexCoord2dv glTexCoord2dv +#define qglTexCoord2f glTexCoord2f +#define qglTexCoord2fv glTexCoord2fv +#define qglTexCoord2i glTexCoord2i +#define qglTexCoord2iv glTexCoord2iv +#define qglTexCoord2s glTexCoord2s +#define qglTexCoord2sv glTexCoord2sv +#define qglTexCoord3d glTexCoord3d +#define qglTexCoord3dv glTexCoord3dv +#define qglTexCoord3f glTexCoord3f +#define qglTexCoord3fv glTexCoord3fv +#define qglTexCoord3i glTexCoord3i +#define qglTexCoord3iv glTexCoord3iv +#define qglTexCoord3s glTexCoord3s +#define qglTexCoord3sv glTexCoord3sv +#define qglTexCoord4d glTexCoord4d +#define qglTexCoord4dv glTexCoord4dv +#define qglTexCoord4f glTexCoord4f +#define qglTexCoord4fv glTexCoord4fv +#define qglTexCoord4i glTexCoord4i +#define qglTexCoord4iv glTexCoord4iv +#define qglTexCoord4s glTexCoord4s +#define qglTexCoord4sv glTexCoord4sv +#define qglTexCoordPointer glTexCoordPointer +#define qglTexEnvf glTexEnvf +#define qglTexEnvfv glTexEnvfv +#define qglTexEnvi glTexEnvi +#define qglTexEnviv glTexEnviv +#define qglTexGend glTexGend +#define qglTexGendv glTexGendv +#define qglTexGenf glTexGenf +#define qglTexGenfv glTexGenfv +#define qglTexGeni glTexGeni +#define qglTexGeniv glTexGeniv +#define qglTexImage1D glTexImage1D +#define qglTexImage2D glTexImage2D +#define qglTexParameterf glTexParameterf +#define qglTexParameterfv glTexParameterfv +#define qglTexParameteri glTexParameteri +#define qglTexParameteriv glTexParameteriv +#define qglTexSubImage1D glTexSubImage1D +#define qglTexSubImage2D glTexSubImage2D +#define qglTranslated glTranslated +#define qglTranslatef glTranslatef +#define qglVertex2d glVertex2d +#define qglVertex2dv glVertex2dv +#define qglVertex2f glVertex2f +#define qglVertex2fv glVertex2fv +#define qglVertex2i glVertex2i +#define qglVertex2iv glVertex2iv +#define qglVertex2s glVertex2s +#define qglVertex2sv glVertex2sv +#define qglVertex3d glVertex3d +#define qglVertex3dv glVertex3dv +#define qglVertex3f glVertex3f +#define qglVertex3fv glVertex3fv +#define qglVertex3i glVertex3i +#define qglVertex3iv glVertex3iv +#define qglVertex3s glVertex3s +#define qglVertex3sv glVertex3sv +#define qglVertex4d glVertex4d +#define qglVertex4dv glVertex4dv +#define qglVertex4f glVertex4f +#define qglVertex4fv glVertex4fv +#define qglVertex4i glVertex4i +#define qglVertex4iv glVertex4iv +#define qglVertex4s glVertex4s +#define qglVertex4sv glVertex4sv +#define qglVertexPointer glVertexPointer +#define qglViewport glViewport + +#endif diff --git a/reaction/code/renderergl2/tr_backend.c b/reaction/code/renderergl2/tr_backend.c index 760cb932..619df448 100644 --- a/reaction/code/renderergl2/tr_backend.c +++ b/reaction/code/renderergl2/tr_backend.c @@ -575,10 +575,14 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) { drawSurf_t *drawSurf; int oldSort; float originalTime; - float depth[2]; FBO_t* fbo = NULL; qboolean inQuery = qfalse; +#ifdef REACTION + float depth[2]; +#endif + + // save original time for entity shader offsets originalTime = backEnd.refdef.floatTime; @@ -598,8 +602,11 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) { oldPshadowed = qfalse; oldSort = -1; depthRange = qfalse; + +#ifdef REACTION depth[0] = 0.f; depth[1] = 1.f; +#endif backEnd.pc.c_surfaces += numDrawSurfs; @@ -759,8 +766,10 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) { if (!sunflare) qglDepthRange (0, 1); +#ifdef REACTION depth[0] = 0; depth[1] = 1; +#endif } oldDepthRange = depthRange; @@ -1265,7 +1274,16 @@ RB_ColorMask const void *RB_ColorMask(const void *data) { const colorMaskCommand_t *cmd = data; - + + if (glRefConfig.framebufferObject) + { + // reverse color mask, so 0 0 0 0 is the default + backEnd.colorMask[0] = !cmd->rgba[0]; + backEnd.colorMask[1] = !cmd->rgba[1]; + backEnd.colorMask[2] = !cmd->rgba[2]; + backEnd.colorMask[3] = !cmd->rgba[3]; + } + qglColorMask(cmd->rgba[0], cmd->rgba[1], cmd->rgba[2], cmd->rgba[3]); return (const void *)(cmd + 1); @@ -1337,42 +1355,66 @@ const void *RB_SwapBuffers( const void *data ) { // copy final image to screen vec2_t texScale; vec4_t srcBox, dstBox, white; + FBO_t *srcFbo, *dstFbo; texScale[0] = texScale[1] = 1.0f; white[0] = white[1] = - white[2] = pow(2, tr.overbrightBits); //exp2(tr.overbrightBits); + white[2] = white[3] = 1.0f; - VectorSet4(dstBox, 0, 0, glConfig.vidWidth, glConfig.vidHeight); - + VectorSet4(dstBox, 0, 0, tr.screenScratchFbo->width, tr.screenScratchFbo->height); + if (backEnd.framePostProcessed) { // frame was postprocessed into screen fbo, copy from there - VectorSet4(srcBox, 0, 0, tr.screenScratchFbo->width, tr.screenScratchFbo->height); + srcFbo = tr.screenScratchFbo; + } + else if (tr.msaaResolveFbo) + { + // Resolve the MSAA before copying + FBO_ResolveMSAA(tr.renderFbo, tr.msaaResolveFbo); - FBO_Blit(tr.screenScratchFbo, srcBox, texScale, NULL, dstBox, &tr.textureColorShader, white, 0); + // need to copy from resolve to screenscratch to fix gamma + srcFbo = tr.msaaResolveFbo; + dstFbo = tr.screenScratchFbo; + + VectorSet4(srcBox, 0, 0, srcFbo->width, srcFbo->height); + VectorSet4(dstBox, 0, 0, dstFbo->width, dstFbo->height); + + FBO_Blit(srcFbo, srcBox, texScale, dstFbo, dstBox, &tr.textureColorShader, white, 0); + + srcFbo = tr.screenScratchFbo; } else { - // frame still in render fbo, possibly resolve then copy from there - FBO_t *hdrFbo; + // need to copy from render to screenscratch to fix gamma + srcFbo = tr.renderFbo; + dstFbo = tr.screenScratchFbo; - if (tr.msaaResolveFbo) - { - // Resolve the MSAA before anything else - FBO_ResolveMSAA(tr.renderFbo, tr.msaaResolveFbo); - hdrFbo = tr.msaaResolveFbo; - } - else - hdrFbo = tr.renderFbo; + VectorSet4(srcBox, 0, 0, srcFbo->width, srcFbo->height); + VectorSet4(dstBox, 0, 0, dstFbo->width, dstFbo->height); - VectorSet4(srcBox, 0, 0, hdrFbo->width, hdrFbo->height); + FBO_Blit(srcFbo, srcBox, texScale, dstFbo, dstBox, &tr.textureColorShader, white, 0); - FBO_Blit(hdrFbo, srcBox, texScale, NULL, dstBox, &tr.textureColorShader, white, 0); + srcFbo = tr.screenScratchFbo; } + + VectorSet4(srcBox, 0, 0, srcFbo->width, srcFbo->height); + VectorSet4(dstBox, 0, 0, glConfig.vidWidth, glConfig.vidHeight); + + white[0] = + white[1] = + white[2] = pow(2, tr.overbrightBits); //exp2(tr.overbrightBits); + white[3] = 1.0f; + + // turn off colormask when copying final image + qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + FBO_Blit(srcFbo, srcBox, texScale, NULL, dstBox, &tr.textureColorShader, white, 0); + qglColorMask(!backEnd.colorMask[0], !backEnd.colorMask[1], !backEnd.colorMask[2], !backEnd.colorMask[3]); + } if ( !glState.finishCalled ) { @@ -1405,12 +1447,12 @@ const void *RB_CapShadowMap(const void *data) if (cmd->cubeSide != -1) { GL_BindCubemap(tr.shadowCubemaps[cmd->map]); - qglCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + cmd->cubeSide, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + 256 ), 256, 256, 0); + qglCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + cmd->cubeSide, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0); } else { GL_Bind(tr.pshadowMaps[cmd->map]); - qglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + 256 ), 256, 256, 0); + qglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0); } } @@ -1435,16 +1477,19 @@ const void *RB_PostProcess(const void *data) texScale[0] = texScale[1] = 1.0f; - if (tr.msaaResolveFbo) + if (glRefConfig.framebufferObject) { - // Resolve the MSAA before anything else - FBO_ResolveMSAA(tr.renderFbo, tr.msaaResolveFbo); - hdrFbo = tr.msaaResolveFbo; + if (tr.msaaResolveFbo) + { + // Resolve the MSAA before anything else + FBO_ResolveMSAA(tr.renderFbo, tr.msaaResolveFbo); + hdrFbo = tr.msaaResolveFbo; + } + else + hdrFbo = tr.renderFbo; } - else - hdrFbo = tr.renderFbo; - if (!r_postProcess->integer) + if (!r_postProcess->integer || !glRefConfig.framebufferObject) { // if we have an FBO, just copy it out, otherwise, do nothing. if (glRefConfig.framebufferObject) diff --git a/reaction/code/renderergl2/tr_bsp.c b/reaction/code/renderergl2/tr_bsp.c index 773cd108..d22cc567 100644 --- a/reaction/code/renderergl2/tr_bsp.c +++ b/reaction/code/renderergl2/tr_bsp.c @@ -408,7 +408,7 @@ static void R_LoadLightmaps( lump_t *l, lump_t *surfs ) { // if under an arbitrary value (say 12) grey it out // this prevents weird splotches in dimly lit areas - if (color[0] + color[1] + color[2] < 12) + if (color[0] + color[1] + color[2] < 12.0f) { float avg = (color[0] + color[1] + color[2]) * 0.3333f; color[0] = avg; @@ -626,11 +626,11 @@ static shader_t *ShaderForShaderNum( int shaderNum, int lightmapNum ) { shader_t *shader; dshader_t *dsh; - shaderNum = LittleLong( shaderNum ); - if ( shaderNum < 0 || shaderNum >= s_worldData.numShaders ) { - ri.Error( ERR_DROP, "ShaderForShaderNum: bad num %i", shaderNum ); + int _shaderNum = LittleLong( shaderNum ); + if ( _shaderNum < 0 || _shaderNum >= s_worldData.numShaders ) { + ri.Error( ERR_DROP, "ShaderForShaderNum: bad num %i", _shaderNum ); } - dsh = &s_worldData.shaders[ shaderNum ]; + dsh = &s_worldData.shaders[ _shaderNum ]; if ( r_vertexLight->integer || glConfig.hardwareType == GLHW_PERMEDIA2 ) { lightmapNum = LIGHTMAP_BY_VERTEX; diff --git a/reaction/code/renderergl2/tr_cmds.c b/reaction/code/renderergl2/tr_cmds.c index 16eee7dc..5d6f54f0 100644 --- a/reaction/code/renderergl2/tr_cmds.c +++ b/reaction/code/renderergl2/tr_cmds.c @@ -343,7 +343,8 @@ void RE_StretchPic ( float x, float y, float w, float h, #define MODE_RED_CYAN 1 #define MODE_RED_BLUE 2 #define MODE_RED_GREEN 3 -#define MODE_MAX MODE_RED_GREEN +#define MODE_GREEN_MAGENTA 4 +#define MODE_MAX MODE_GREEN_MAGENTA void R_SetColorMode(GLboolean *rgba, stereoFrame_t stereoFrame, int colormode) { @@ -359,16 +360,26 @@ void R_SetColorMode(GLboolean *rgba, stereoFrame_t stereoFrame, int colormode) colormode -= MODE_MAX; } - if(stereoFrame == STEREO_LEFT) - rgba[1] = rgba[2] = GL_FALSE; - else if(stereoFrame == STEREO_RIGHT) + if(colormode == MODE_GREEN_MAGENTA) { - rgba[0] = GL_FALSE; - - if(colormode == MODE_RED_BLUE) + if(stereoFrame == STEREO_LEFT) + rgba[0] = rgba[2] = GL_FALSE; + else if(stereoFrame == STEREO_RIGHT) rgba[1] = GL_FALSE; - else if(colormode == MODE_RED_GREEN) - rgba[2] = GL_FALSE; + } + else + { + if(stereoFrame == STEREO_LEFT) + rgba[1] = rgba[2] = GL_FALSE; + else if(stereoFrame == STEREO_RIGHT) + { + rgba[0] = GL_FALSE; + + if(colormode == MODE_RED_BLUE) + rgba[1] = GL_FALSE; + else if(colormode == MODE_RED_GREEN) + rgba[2] = GL_FALSE; + } } } @@ -482,6 +493,10 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) { { // clear both, front and backbuffer. qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + backEnd.colorMask[0] = GL_FALSE; + backEnd.colorMask[1] = GL_FALSE; + backEnd.colorMask[2] = GL_FALSE; + backEnd.colorMask[3] = GL_FALSE; qglClearColor(0.0f, 0.0f, 0.0f, 1.0f); qglDrawBuffer(GL_FRONT); @@ -489,6 +504,42 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) { qglDrawBuffer(GL_BACK); qglClear(GL_COLOR_BUFFER_BIT); + if (glRefConfig.framebufferObject) + { + // clear all framebuffers + // FIXME: must be a better way to do this + int i; + + for (i = 0; i < 3; i++) + { + if (i == 1 && !tr.msaaResolveFbo) + continue; + + switch(i) + { + case 0: + FBO_Bind(tr.renderFbo); + break; + + case 1: + FBO_Bind(tr.msaaResolveFbo); + break; + + case 2: + FBO_Bind(tr.screenScratchFbo); + break; + } + + qglDrawBuffer(GL_FRONT); + qglClear(GL_COLOR_BUFFER_BIT); + qglDrawBuffer(GL_BACK); + qglClear(GL_COLOR_BUFFER_BIT); + + } + + FBO_Bind(NULL); + } + r_anaglyphMode->modified = qfalse; } @@ -534,6 +585,10 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) { if(r_anaglyphMode->modified) { qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + backEnd.colorMask[0] = 0; + backEnd.colorMask[1] = 0; + backEnd.colorMask[2] = 0; + backEnd.colorMask[3] = 0; r_anaglyphMode->modified = qfalse; } diff --git a/reaction/code/renderergl2/tr_extensions.c b/reaction/code/renderergl2/tr_extensions.c index 629668f8..db32ded9 100644 --- a/reaction/code/renderergl2/tr_extensions.c +++ b/reaction/code/renderergl2/tr_extensions.c @@ -165,14 +165,14 @@ void (APIENTRY * qglGetQueryObjectivARB)(GLuint id, GLenum pname, GLint *params) void (APIENTRY * qglGetQueryObjectuivARB)(GLuint id, GLenum pname, GLuint *params); // GL_EXT_framebuffer_blit -void (APIENTRY * qglBlitFramebufferEXT)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, - GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, +void (APIENTRY * qglBlitFramebufferEXT)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, + GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); // GL_EXT_framebuffer_multisample -void (APIENTRY * qglRenderbufferStorageMultisampleEXT)(GLenum target, GLsizei samples, - GLenum internalformat, GLsizei width, GLsizei height); - +void (APIENTRY * qglRenderbufferStorageMultisampleEXT)(GLenum target, GLsizei samples, + GLenum internalformat, GLsizei width, GLsizei height); + static qboolean GLimp_HaveExtension(const char *ext) { const char *ptr = Q_stristr( glConfig.extensions_string, ext ); @@ -185,40 +185,37 @@ static qboolean GLimp_HaveExtension(const char *ext) void GLimp_InitExtraExtensions() { char *extension; - const char* action[2] = { "ignoring", "using" }; + const char* result[3] = { "...ignoring %s\n", "...using %s\n", "...%s not found\n" }; // GL_EXT_multi_draw_arrays + extension = "GL_EXT_multi_draw_arrays"; glRefConfig.multiDrawArrays = qfalse; qglMultiDrawArraysEXT = NULL; qglMultiDrawElementsEXT = NULL; - if( GLimp_HaveExtension( "GL_EXT_multi_draw_arrays")) + if( GLimp_HaveExtension( extension ) ) { qglMultiDrawArraysEXT = (PFNGLMULTIDRAWARRAYSEXTPROC) SDL_GL_GetProcAddress("glMultiDrawArraysEXT"); qglMultiDrawElementsEXT = (PFNGLMULTIDRAWELEMENTSEXTPROC) SDL_GL_GetProcAddress("glMultiDrawElementsEXT"); if ( r_ext_multi_draw_arrays->integer ) - { - ri.Printf(PRINT_ALL, "...using GL_EXT_multi_draw_arrays\n"); glRefConfig.multiDrawArrays = qtrue; - } - else - { - ri.Printf(PRINT_ALL, "...ignoring GL_EXT_multi_draw_arrays\n"); - } + + ri.Printf(PRINT_ALL, result[glRefConfig.multiDrawArrays], extension); } else { - ri.Printf(PRINT_ALL, "...GL_EXT_multi_draw_arrays not found\n"); + ri.Printf(PRINT_ALL, result[2], extension); } // GL_ARB_vertex_program //glRefConfig.vertexProgram = qfalse; + extension = "GL_ARB_vertex_program"; qglVertexAttrib4fARB = NULL; qglVertexAttrib4fvARB = NULL; qglVertexAttribPointerARB = NULL; qglEnableVertexAttribArrayARB = NULL; qglDisableVertexAttribArrayARB = NULL; - if( GLimp_HaveExtension( "GL_ARB_vertex_program")) + if( GLimp_HaveExtension( extension ) ) { qglVertexAttrib4fARB = (PFNGLVERTEXATTRIB4FARBPROC) SDL_GL_GetProcAddress("glVertexAttrib4fARB"); qglVertexAttrib4fvARB = (PFNGLVERTEXATTRIB4FVARBPROC) SDL_GL_GetProcAddress("glVertexAttrib4fvARB"); @@ -227,16 +224,18 @@ void GLimp_InitExtraExtensions() (PFNGLENABLEVERTEXATTRIBARRAYARBPROC) SDL_GL_GetProcAddress("glEnableVertexAttribArrayARB"); qglDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) SDL_GL_GetProcAddress("glDisableVertexAttribArrayARB"); - ri.Printf(PRINT_ALL, "...using GL_ARB_vertex_program\n"); + + ri.Printf(PRINT_ALL, result[1], extension); //glRefConfig.vertexProgram = qtrue; } else { - ri.Error(ERR_FATAL, "...GL_ARB_vertex_program not found\n"); + ri.Error(ERR_FATAL, result[2], extension); } // GL_ARB_vertex_buffer_object //glRefConfig.vertexBufferObject = qfalse; + extension = "GL_ARB_vertex_buffer_object"; qglBindBufferARB = NULL; qglDeleteBuffersARB = NULL; qglGenBuffersARB = NULL; @@ -246,7 +245,7 @@ void GLimp_InitExtraExtensions() qglGetBufferSubDataARB = NULL; qglGetBufferParameterivARB = NULL; qglGetBufferPointervARB = NULL; - if( GLimp_HaveExtension( "GL_ARB_vertex_buffer_object")) + if( GLimp_HaveExtension( extension ) ) { qglBindBufferARB = (PFNGLBINDBUFFERARBPROC) SDL_GL_GetProcAddress("glBindBufferARB"); qglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) SDL_GL_GetProcAddress("glDeleteBuffersARB"); @@ -257,15 +256,16 @@ void GLimp_InitExtraExtensions() qglGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC) SDL_GL_GetProcAddress("glGetBufferSubDataARB"); qglGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetBufferParameterivARB"); qglGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC) SDL_GL_GetProcAddress("glGetBufferPointervARB"); - ri.Printf(PRINT_ALL, "...using GL_ARB_vertex_buffer_object\n"); + ri.Printf(PRINT_ALL, result[1], extension); //glRefConfig.vertexBufferObject = qtrue; } else { - ri.Error(ERR_FATAL, "...GL_ARB_vertex_buffer_object not found\n"); + ri.Error(ERR_FATAL, result[2], extension); } // GL_ARB_shader_objects + extension = "GL_ARB_shader_objects"; //glRefConfig.shaderObjects = qfalse; qglDeleteObjectARB = NULL; qglGetHandleARB = NULL; @@ -305,7 +305,7 @@ void GLimp_InitExtraExtensions() qglGetUniformfvARB = NULL; qglGetUniformivARB = NULL; qglGetShaderSourceARB = NULL; - if( GLimp_HaveExtension( "GL_ARB_shader_objects")) + if( GLimp_HaveExtension( extension ) ) { qglDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB"); qglGetHandleARB = (PFNGLGETHANDLEARBPROC) SDL_GL_GetProcAddress("glGetHandleARB"); @@ -345,28 +345,29 @@ void GLimp_InitExtraExtensions() qglGetUniformfvARB = (PFNGLGETUNIFORMFVARBPROC) SDL_GL_GetProcAddress("glGetUniformfvARB"); qglGetUniformivARB = (PFNGLGETUNIFORMIVARBPROC) SDL_GL_GetProcAddress("glGetUniformivARB"); qglGetShaderSourceARB = (PFNGLGETSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glGetShaderSourceARB"); - ri.Printf(PRINT_ALL, "...using GL_ARB_shader_objects\n"); + ri.Printf(PRINT_ALL, result[1], extension); //glRefConfig.shaderObjects = qtrue; } else { - ri.Error(ERR_FATAL, "...GL_ARB_shader_objects not found\n"); + ri.Error(ERR_FATAL, result[2], extension); } // GL_ARB_vertex_shader //glRefConfig.vertexShader = qfalse; + extension = "GL_ARB_vertex_shader"; qglBindAttribLocationARB = NULL; qglGetActiveAttribARB = NULL; qglGetAttribLocationARB = NULL; - if( GLimp_HaveExtension( "GL_ARB_vertex_shader")) + if( GLimp_HaveExtension( extension ) ) { - int reservedComponents; + //int reservedComponents; //qglGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &glConfig.maxVertexUniforms); //qglGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &glConfig.maxVaryingFloats); //qglGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &glConfig.maxVertexAttribs); - reservedComponents = 16 * 10; // approximation how many uniforms we have besides the bone matrices + //reservedComponents = 16 * 10; // approximation how many uniforms we have besides the bone matrices #if 0 if(glConfig.driverType == GLDRV_MESA) @@ -385,84 +386,77 @@ void GLimp_InitExtraExtensions() qglBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) SDL_GL_GetProcAddress("glBindAttribLocationARB"); qglGetActiveAttribARB = (PFNGLGETACTIVEATTRIBARBPROC) SDL_GL_GetProcAddress("glGetActiveAttribARB"); qglGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetAttribLocationARB"); - ri.Printf(PRINT_ALL, "...using GL_ARB_vertex_shader\n"); + ri.Printf(PRINT_ALL, result[1], extension); //glRefConfig.vertexShader = qtrue; } else { - ri.Error(ERR_FATAL, "...GL_ARB_vertex_shader not found\n"); + ri.Error(ERR_FATAL, result[2], extension); } glRefConfig.memInfo = MI_NONE; - if( GLimp_HaveExtension( "GL_NVX_gpu_memory_info")) + if( GLimp_HaveExtension( "GL_NVX_gpu_memory_info" ) ) { glRefConfig.memInfo = MI_NVX; } - else if( GLimp_HaveExtension( "GL_ATI_meminfo")) + else if( GLimp_HaveExtension( "GL_ATI_meminfo" ) ) { glRefConfig.memInfo = MI_ATI; } + extension = "GL_ARB_texture_non_power_of_two"; glRefConfig.textureNonPowerOfTwo = qfalse; - if( GLimp_HaveExtension( "GL_ARB_texture_non_power_of_two" )) + if( GLimp_HaveExtension( extension ) ) { if(1) //(r_ext_texture_non_power_of_two->integer) { glRefConfig.textureNonPowerOfTwo = qtrue; - ri.Printf(PRINT_ALL, "...using GL_ARB_texture_non_power_of_two\n"); - } - else - { - ri.Printf(PRINT_ALL, "...ignoring GL_ARB_texture_non_power_of_two\n"); } + + ri.Printf(PRINT_ALL, result[glRefConfig.textureNonPowerOfTwo], extension); } else { - ri.Printf(PRINT_ALL, "...GL_ARB_texture_non_power_of_two not found\n"); + ri.Printf(PRINT_ALL, result[2], extension); } // GL_ARB_texture_float + extension = "GL_ARB_texture_float"; glRefConfig.textureFloat = qfalse; - if( GLimp_HaveExtension( "GL_ARB_texture_float" )) + if( GLimp_HaveExtension( extension ) ) { - if(r_ext_texture_float->integer) + if( r_ext_texture_float->integer ) { glRefConfig.textureFloat = qtrue; - ri.Printf(PRINT_ALL, "...using GL_ARB_texture_float\n"); - } - else - { - ri.Printf(PRINT_ALL, "...ignoring GL_ARB_texture_float\n"); } + + ri.Printf(PRINT_ALL, result[glRefConfig.textureFloat], extension); } else { - ri.Printf(PRINT_ALL, "...GL_ARB_texture_float not found\n"); + ri.Printf(PRINT_ALL, result[2], extension); } // GL_ARB_half_float_pixel + extension = "GL_ARB_texture_float"; glRefConfig.halfFloatPixel = qfalse; - if( GLimp_HaveExtension( "GL_ARB_half_float_pixel" )) + if( GLimp_HaveExtension( extension ) ) { - if(r_arb_half_float_pixel->integer) - { + if( r_arb_half_float_pixel->integer ) glRefConfig.halfFloatPixel = qtrue; - ri.Printf(PRINT_ALL, "...using GL_ARB_half_float_pixel\n"); - } - else - { - ri.Printf(PRINT_ALL, "...ignoring GL_ARB_half_float_pixel\n"); - } + + ri.Printf(PRINT_ALL, result[glRefConfig.halfFloatPixel], extension); } else { - ri.Printf(PRINT_ALL, "...GL_ARB_half_float_pixel not found\n"); + ri.Printf(PRINT_ALL, result[2], extension); } // GL_EXT_framebuffer_object + extension = "GL_EXT_framebuffer_object"; glRefConfig.framebufferObject = qfalse; - if( GLimp_HaveExtension( "GL_EXT_framebuffer_object" )) + if( GLimp_HaveExtension( extension ) ) { glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &glRefConfig.maxRenderbufferSize); glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &glRefConfig.maxColorAttachments); @@ -486,25 +480,26 @@ void GLimp_InitExtraExtensions() qglGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC) SDL_GL_GetProcAddress("glGenerateMipmapEXT"); if(r_ext_framebuffer_object->value) - { glRefConfig.framebufferObject = qtrue; - ri.Printf(PRINT_ALL, "...using GL_EXT_framebuffer_object\n"); - } - else - { - ri.Printf(PRINT_ALL, "...ignoring GL_EXT_framebuffer_object\n"); - } + + ri.Printf(PRINT_ALL, result[glRefConfig.framebufferObject], extension); } else { - ri.Printf(PRINT_ALL, "...GL_EXT_framebuffer_object not found\n"); + ri.Printf(PRINT_ALL, result[2], extension); } // GL_EXT_packed_depth_stencil + extension = "GL_EXT_packed_depth_stencil"; glRefConfig.packedDepthStencil = qfalse; - if( GLimp_HaveExtension( "GL_EXT_packed_depth_stencil" )) + if( GLimp_HaveExtension(extension)) { glRefConfig.packedDepthStencil = qtrue; + ri.Printf(PRINT_ALL, result[glRefConfig.packedDepthStencil], extension); + } + else + { + ri.Printf(PRINT_ALL, result[2], extension); } // GL_ARB_occlusion_query @@ -521,11 +516,11 @@ void GLimp_InitExtraExtensions() qglGetQueryObjectivARB = (PFNGLGETQUERYOBJECTIVARBPROC) SDL_GL_GetProcAddress("glGetQueryObjectivARB"); qglGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC) SDL_GL_GetProcAddress("glGetQueryObjectuivARB"); glRefConfig.occlusionQuery = qtrue; - ri.Printf(PRINT_ALL, "...%s %s\n", action[glRefConfig.occlusionQuery], extension); + ri.Printf(PRINT_ALL, result[glRefConfig.occlusionQuery], extension); } else { - ri.Printf(PRINT_ALL, "...%s not found\n", extension); + ri.Printf(PRINT_ALL, result[2], extension); } // GL_EXT_framebuffer_blit @@ -535,11 +530,11 @@ void GLimp_InitExtraExtensions() { qglBlitFramebufferEXT = (void *)SDL_GL_GetProcAddress("glBlitFramebufferEXT"); glRefConfig.framebufferBlit = qtrue; - ri.Printf(PRINT_ALL, "...%s %s\n", action[glRefConfig.framebufferBlit], extension); + ri.Printf(PRINT_ALL, result[glRefConfig.framebufferBlit], extension); } else { - ri.Printf(PRINT_ALL, "...%s not found\n", extension); + ri.Printf(PRINT_ALL, result[2], extension); } // GL_EXT_framebuffer_multisample @@ -549,11 +544,40 @@ void GLimp_InitExtraExtensions() { qglRenderbufferStorageMultisampleEXT = (void *)SDL_GL_GetProcAddress("glRenderbufferStorageMultisampleEXT"); glRefConfig.framebufferMultisample = qtrue; - ri.Printf(PRINT_ALL, "...%s %s\n", action[glRefConfig.framebufferMultisample], extension); + ri.Printf(PRINT_ALL, result[glRefConfig.framebufferMultisample], extension); } else { - ri.Printf(PRINT_ALL, "...%s not found\n", extension); + ri.Printf(PRINT_ALL, result[2], extension); + } + + // GL_EXT_texture_sRGB + extension = "GL_EXT_texture_sRGB"; + glRefConfig.texture_srgb = qfalse; + if (GLimp_HaveExtension(extension)) + { + if (r_srgb->integer) + glRefConfig.texture_srgb = qtrue; + + ri.Printf(PRINT_ALL, result[glRefConfig.texture_srgb], extension); + } + else + { + ri.Printf(PRINT_ALL, result[2], extension); + } + + // GL_EXT_framebuffer_sRGB + extension = "GL_EXT_framebuffer_sRGB"; + glRefConfig.framebuffer_srgb = qfalse; + if (GLimp_HaveExtension(extension)) + { + if (r_srgb->integer) + glRefConfig.framebuffer_srgb = qtrue; + + ri.Printf(PRINT_ALL, result[glRefConfig.framebuffer_srgb], extension); + } + else + { + ri.Printf(PRINT_ALL, result[2], extension); } - } diff --git a/reaction/code/renderergl2/tr_extramath.h b/reaction/code/renderergl2/tr_extramath.h index 442e46a4..e74b7a24 100644 --- a/reaction/code/renderergl2/tr_extramath.h +++ b/reaction/code/renderergl2/tr_extramath.h @@ -1,97 +1,101 @@ -/* -=========================================================================== -Copyright (C) 2010 James Canete (use.less01@gmail.com) - -This file is part of Quake III Arena source code. - -Quake III Arena source code is free software; you can redistribute it -and/or modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 of the License, -or (at your option) any later version. - -Quake III Arena source code is distributed in the hope that it will be -useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Quake III Arena source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ -// tr_extramath.h - -#ifndef __TR_EXTRAMATH_H__ -#define __TR_EXTRAMATH_H__ - -typedef vec_t matrix_t[16]; -typedef int vec2i_t[2]; -typedef int vec3i_t[2]; - -void Matrix16Zero( matrix_t out ); -void Matrix16Identity( matrix_t out ); -void Matrix16Copy( const matrix_t in, matrix_t out ); -void Matrix16Multiply( const matrix_t in1, const matrix_t in2, matrix_t out ); -void Matrix16Transform( const matrix_t in1, const vec4_t in2, vec4_t out ); -qboolean Matrix16Compare(const matrix_t a, const matrix_t b); -void Matrix16Dump( const matrix_t in ); -void Matrix16Translation( vec3_t vec, matrix_t out ); -void Matrix16Ortho( float left, float right, float bottom, float top, float znear, float zfar, matrix_t out ); - -#define VectorCopy2(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1]) - -#define VectorCopy4(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3]) -#define VectorSet4(v,x,y,z,w) ((v)[0]=(x),(v)[1]=(y),(v)[2]=(z),(v)[3]=(w)) -#define DotProduct4(a,b) ((a)[0]*(b)[0] + (a)[1]*(b)[1] + (a)[2]*(b)[2] + (a)[3]*(b)[3]) -#define VectorScale4(a,b,c) ((c)[0]=(a)[0]*(b),(c)[1]=(a)[1]*(b),(c)[2]=(a)[2]*(b),(c)[3]=(a)[3]*(b)) - -#define VectorCopy5(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3],(b)[4]=(a)[4]) - -#define OffsetByteToFloat(a) ((float)(a) * 1.0f/127.5f - 1.0f) -#define ByteToFloat(a) ((float)(a) * 1.0f/255.0f) -#define FloatToOffsetByte(a) (byte)(((a) + 1.0f) * 127.5f) - -static ID_INLINE int VectorCompare4(const vec4_t v1, const vec4_t v2) -{ - if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2] || v1[3] != v2[3]) - { - return 0; - } - return 1; -} - -static ID_INLINE int VectorCompare5(const vec5_t v1, const vec5_t v2) -{ - if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2] || v1[3] != v2[3] || v1[4] != v2[4]) - { - return 0; - } - return 1; -} - -void VectorLerp( vec3_t a, vec3_t b, float lerp, vec3_t c); - - -qboolean SpheresIntersect(vec3_t origin1, float radius1, vec3_t origin2, float radius2); -void BoundingSphereOfSpheres(vec3_t origin1, float radius1, vec3_t origin2, float radius2, vec3_t origin3, float *radius3); - -#ifndef SGN -#define SGN(x) (((x) >= 0) ? !!(x) : -1) -#endif - -#ifndef MAX -#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#endif - -#ifndef MIN -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif - -#ifndef CLAMP -#define CLAMP(a,b,c) MIN(MAX((a),(b)),(c)) -#endif - -int NextPowerOfTwo(int in); -unsigned short FloatToHalf(float in); - -#endif +/* +=========================================================================== +Copyright (C) 2010 James Canete (use.less01@gmail.com) + +This file is part of Quake III Arena source code. + +Quake III Arena source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +Quake III Arena source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Quake III Arena source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ +// tr_extramath.h + +#ifndef __TR_EXTRAMATH_H__ +#define __TR_EXTRAMATH_H__ + +typedef vec_t matrix_t[16]; +typedef int vec2i_t[2]; +typedef int vec3i_t[2]; + +void Matrix16Zero( matrix_t out ); +void Matrix16Identity( matrix_t out ); +void Matrix16Copy( const matrix_t in, matrix_t out ); +void Matrix16Multiply( const matrix_t in1, const matrix_t in2, matrix_t out ); +void Matrix16Transform( const matrix_t in1, const vec4_t in2, vec4_t out ); +qboolean Matrix16Compare(const matrix_t a, const matrix_t b); +void Matrix16Dump( const matrix_t in ); +void Matrix16Translation( vec3_t vec, matrix_t out ); +void Matrix16Ortho( float left, float right, float bottom, float top, float znear, float zfar, matrix_t out ); + +#define VectorCopy2(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1]) + +#define VectorCopy4(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3]) +#define VectorSet4(v,x,y,z,w) ((v)[0]=(x),(v)[1]=(y),(v)[2]=(z),(v)[3]=(w)) +#define DotProduct4(a,b) ((a)[0]*(b)[0] + (a)[1]*(b)[1] + (a)[2]*(b)[2] + (a)[3]*(b)[3]) +#define VectorScale4(a,b,c) ((c)[0]=(a)[0]*(b),(c)[1]=(a)[1]*(b),(c)[2]=(a)[2]*(b),(c)[3]=(a)[3]*(b)) + +#define VectorCopy5(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3],(b)[4]=(a)[4]) + +#define OffsetByteToFloat(a) ((float)(a) * 1.0f/127.5f - 1.0f) +#define FloatToOffsetByte(a) (byte)(((a) + 1.0f) * 127.5f) +#define ByteToFloat(a) ((float)(a) * 1.0f/255.0f) +#define FloatToByte(a) (byte)((a) * 255.0f) + +#define RGBtosRGB(a) (((a) < 0.0031308f) ? (12.92f * (a)) : (1.055f * pow((a), 0.41666f) - 0.055f)) +#define sRGBtoRGB(a) (((a) <= 0.04045f) ? ((a) / 12.92f) : (pow((((a) + 0.055f) / 1.055f), 2.4)) ) + +static ID_INLINE int VectorCompare4(const vec4_t v1, const vec4_t v2) +{ + if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2] || v1[3] != v2[3]) + { + return 0; + } + return 1; +} + +static ID_INLINE int VectorCompare5(const vec5_t v1, const vec5_t v2) +{ + if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2] || v1[3] != v2[3] || v1[4] != v2[4]) + { + return 0; + } + return 1; +} + +void VectorLerp( vec3_t a, vec3_t b, float lerp, vec3_t c); + + +qboolean SpheresIntersect(vec3_t origin1, float radius1, vec3_t origin2, float radius2); +void BoundingSphereOfSpheres(vec3_t origin1, float radius1, vec3_t origin2, float radius2, vec3_t origin3, float *radius3); + +#ifndef SGN +#define SGN(x) (((x) >= 0) ? !!(x) : -1) +#endif + +#ifndef MAX +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + +#ifndef MIN +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + +#ifndef CLAMP +#define CLAMP(a,b,c) MIN(MAX((a),(b)),(c)) +#endif + +int NextPowerOfTwo(int in); +unsigned short FloatToHalf(float in); + +#endif diff --git a/reaction/code/renderergl2/tr_extratypes.h b/reaction/code/renderergl2/tr_extratypes.h index 418667d1..896de75a 100644 --- a/reaction/code/renderergl2/tr_extratypes.h +++ b/reaction/code/renderergl2/tr_extratypes.h @@ -1,39 +1,39 @@ -/* -=========================================================================== -Copyright (C) 2009-2011 Andrei Drexler, Richard Allen, James Canete - -This file is part of Reaction source code. - -Reaction source code is free software; you can redistribute it -and/or modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 of the License, -or (at your option) any later version. - -Reaction source code is distributed in the hope that it will be -useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Reaction source code; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -=========================================================================== -*/ - -#ifndef __TR_EXTRATYPES_H__ -#define __TR_EXTRATYPES_H__ - -// tr_extratypes.h, for mods that want to extend tr_types.h without losing compatibility with original VMs - -// extra renderfx flags start at 0x0400 -#define RF_SUNFLARE 0x0400 - -// extra refdef flags start at 0x0008 -#define RDF_NOFOG 0x0008 // don't apply fog -#define RDF_EXTRA 0x0010 // Makro - refdefex_t to follow after refdef_t - -typedef struct { - float blurFactor; -} refdefex_t; - -#endif +/* +=========================================================================== +Copyright (C) 2009-2011 Andrei Drexler, Richard Allen, James Canete + +This file is part of Reaction source code. + +Reaction source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +Reaction source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Reaction source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +#ifndef __TR_EXTRATYPES_H__ +#define __TR_EXTRATYPES_H__ + +// tr_extratypes.h, for mods that want to extend tr_types.h without losing compatibility with original VMs + +// extra renderfx flags start at 0x0400 +#define RF_SUNFLARE 0x0400 + +// extra refdef flags start at 0x0008 +#define RDF_NOFOG 0x0008 // don't apply fog +#define RDF_EXTRA 0x0010 // Makro - refdefex_t to follow after refdef_t + +typedef struct { + float blurFactor; +} refdefex_t; + +#endif \ No newline at end of file diff --git a/reaction/code/renderergl2/tr_fbo.c b/reaction/code/renderergl2/tr_fbo.c index 59171a90..8a9e3bdd 100644 --- a/reaction/code/renderergl2/tr_fbo.c +++ b/reaction/code/renderergl2/tr_fbo.c @@ -464,7 +464,7 @@ void FBO_Init(void) FBO_AttachTextureImage(tr.pshadowMaps[i], 0); FBO_CreateBuffer(tr.pshadowFbos[i], GL_DEPTH_COMPONENT24_ARB, 0, 0); - R_AttachFBOTextureDepth(tr.textureDepthImage->texnum); + //R_AttachFBOTextureDepth(tr.textureDepthImage->texnum); R_CheckFBO(tr.pshadowFbos[i]); } @@ -491,11 +491,18 @@ void FBO_Init(void) } { + int format; + + if (glRefConfig.texture_srgb && glRefConfig.framebuffer_srgb) + format = GL_SRGB8_ALPHA8_EXT; + else + format = GL_RGBA8; + //tr.screenScratchFbo = FBO_Create("_screenscratch", width, height); tr.screenScratchFbo = FBO_Create("_screenscratch", tr.screenScratchImage->width, tr.screenScratchImage->height); FBO_Bind(tr.screenScratchFbo); - - FBO_CreateBuffer(tr.screenScratchFbo, GL_RGBA8, 0, 0); + + FBO_CreateBuffer(tr.screenScratchFbo, format, 0, 0); FBO_AttachTextureImage(tr.screenScratchImage, 0); // FIXME: hack: share zbuffer between render fbo and pre-screen fbo diff --git a/reaction/code/renderergl2/tr_glsl.c b/reaction/code/renderergl2/tr_glsl.c index 8c0d2328..79275211 100644 --- a/reaction/code/renderergl2/tr_glsl.c +++ b/reaction/code/renderergl2/tr_glsl.c @@ -115,15 +115,14 @@ static const char *fallbackGenericShader_fp = "\n\r\nvarying vec2 var_DiffuseTex;\r\n\r\n#if defined(USE_LIGHTMAP)\r" "\nvarying vec2 var_LightTex;\r\n#endif\r\n\r\nvarying vec4 var_Co" "lor;\r\n\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = texture2D(u_DiffuseMap," -" var_DiffuseTex);\r\n\r\n#if defined(USE_LIGHTMAP)\r\n #if defined(RGBE_LI" -"GHTMAP)\r\n\tvec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;\r" -"\n\tvec3 directedLight = lightSample.rgb * (exp2(lightSample.a * 255.0 - 12" -"8.0));\r\n\tvec4 color2 = vec4(directedLight, 1.0);\r\n #else\r\n\tvec4 co" -"lor2 = texture2D(u_LightMap, var_LightTex);\r\n #endif\r\n\r\n\tif (u_Text" -"ure1Env == TEXENV_MODULATE)\r\n\t{\r\n\t\tcolor *= color2;\r\n\t}\r\n\telse" -" if (u_Texture1Env == TEXENV_ADD)\r\n\t{\r\n\t\tcolor += color2;\r\n\t}\r\n" -"\telse if (u_Texture1Env == TEXENV_REPLACE)\r\n\t{\r\n\t\tcolor = color2;\r" -"\n\t}\r\n#endif\r\n\r\n\tgl_FragColor = color * var_Color;\r\n}\r\n"; +" var_DiffuseTex);\r\n#if defined(USE_LIGHTMAP)\r\n\tvec4 color2 = texture2D" +"(u_LightMap, var_LightTex);\r\n #if defined(RGBE_LIGHTMAP)\r\n\tcolor2.rgb" +" *= exp2(color2.a * 255.0 - 128.0);\r\n\tcolor2.a = 1.0;\r\n #endif\r\n\r" +"\n\tif (u_Texture1Env == TEXENV_MODULATE)\r\n\t{\r\n\t\tcolor *= color2;\r" +"\n\t}\r\n\telse if (u_Texture1Env == TEXENV_ADD)\r\n\t{\r\n\t\tcolor += col" +"or2;\r\n\t}\r\n\telse if (u_Texture1Env == TEXENV_REPLACE)\r\n\t{\r\n\t\tco" +"lor = color2;\r\n\t}\r\n#endif\r\n\r\n\tgl_FragColor = color * var_Color;\r" +"\n}\r\n"; static const char *fallbackTextureColorShader_vp = "#version 120\r\n\r\nattribute vec4 attr_Position;\r\nattribute vec4 attr_Te" @@ -291,118 +290,116 @@ static const char *fallbackLightallShader_fp = "ition;\r\n\r\n#if defined(USE_NORMALMAP)\r\nvarying vec3 var_Tangent;" "\r\nvarying vec3 var_Bitangent;\r\n#endif\r\n\r\nvarying vec3 var" "_Normal;\r\n\r\n#if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)\r\nv" -"arying vec3 var_LightDirection;\r\n#endif\r\n\r\n#if defined(USE_PARAL" -"LAXMAP)\r\nfloat SampleHeight(sampler2D normalMap, vec2 t)\r\n{\r\n #if de" -"fined(SWIZZLE_NORMALMAP)\r\n\treturn texture2D(normalMap, t).r;\r\n #else" -"\r\n\treturn texture2D(normalMap, t).a;\r\n #endif\r\n}\r\n\r\nfloat RayIn" -"tersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)\r\n{\r\n\tconst i" -"nt linearSearchSteps = 16;\r\n\tconst int binarySearchSteps = 6;\r\n\r\n\tf" -"loat depthStep = 1.0 / float(linearSearchSteps);\r\n\r\n\t// current size o" -"f search window\r\n\tfloat size = depthStep;\r\n\r\n\t// current depth posi" -"tion\r\n\tfloat depth = 0.0;\r\n\r\n\t// best match found (starts with last" -" position 1.0)\r\n\tfloat bestDepth = 1.0;\r\n\r\n\t// search front to back" -" for first point inside object\r\n\tfor(int i = 0; i < linearSearchSteps - " -"1; ++i)\r\n\t{\r\n\t\tdepth += size;\r\n\t\t\r\n\t\tfloat t = SampleHeight(" -"normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(bestDepth > 0.996)\t\t// if " -"no depth found yet\r\n\t\t\tif(depth >= t)\r\n\t\t\t\tbestDepth = depth;\t/" -"/ store best depth\r\n\t}\r\n\r\n\tdepth = bestDepth;\r\n\t\r\n\t// recurse" -" around first point (depth) for closest match\r\n\tfor(int i = 0; i < binar" -"ySearchSteps; ++i)\r\n\t{\r\n\t\tsize *= 0.5;\r\n\r\n\t\tfloat t = SampleHe" -"ight(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(depth >= t)\r\n\t\t{\r" -"\n\t\t\tbestDepth = depth;\r\n\t\t\tdepth -= 2.0 * size;\r\n\t\t}\r\n\r\n\t" -"\tdepth += size;\r\n\t}\r\n\r\n\treturn bestDepth;\r\n}\r\n#endif\r\n\r\n#i" -"f defined(USE_OREN_NAYAR)\r\nfloat OrenNayar(vec3 N, vec3 L, vec3 E, float " -"NE, float NL, float roughness)\r\n{\r\n\tfloat gamma = dot(E - N * NE, L - " -"N * NL);\r\n\tfloat r_sq = roughness * roughness;\r\n\r\n\tfloat A = 1.0 - " -"0.5 * (r_sq / (r_sq + 0.57));\r\n\tfloat B = 0.45 * (r_sq / (r_sq + 0.09));" -"\r\n\r\n\tfloat alpha = max(acos(NE), acos(NL));\r\n\tfloat beta = min(aco" -"s(NE), acos(NL));\r\n\r\n\tfloat C = sin(alpha) * tan(beta);\r\n\r\n\tretur" -"n (A + B * max(0.0, gamma) * C) * max(0.0, NL);\r\n}\r\n#endif\r\n\r\n#if d" -"efined(USE_COOK_TORRANCE)\r\nfloat CookTorrance(float NH, float NL, float N" -"E, float EH, float fzero, float roughness)\r\n{\r\n\tfloat geo = 2.0 * NH /" -" EH;\r\n\tgeo *= min(NE, NL);\r\n\tgeo = min(1, geo);\r\n\r\n\tfloat r_sq =" -" roughness * roughness;\r\n\tfloat NH_sq = NH * NH;\r\n\tfloat rough = exp(" -"(NH_sq - 1.0) / (r_sq * NH_sq)) / (4.0 * r_sq * pow(NH, 4));\r\n\r\n\tfloat" -" fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r\n\r\n\treturn fresne" -"l * geo * rough / NE;\r\n}\r\n#endif\r\n\r\n#if defined(USE_TRIACE)\r\nfloa" -"t TriAce(float NH, float NL, float NE, float EH, float fzero, float shinine" -"ss)\r\n{\t\r\n\tfloat factor = 0.1248582 * shininess + 0.2691817;\r\n\tfloa" -"t fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r\n\r\n\treturn facto" -"r * fresnel * pow(NH, shininess) / max(NL, NE);\r\n}\r\n#endif\r\n\r\nvoid " -"main()\r\n{\r\n#if defined(USE_LIGHTMAP)\r\n #if defined(RGBE_LIGHTMAP)\r" -"\n\tvec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;\r\n\tvec3 " -"directedLight = lightSample.rgb * (exp2(lightSample.a * 255.0 - 128.0));\r" -"\n #else\r\n\tvec3 directedLight = texture2D(u_LightMap, var_LightTex).rgb" -";\r\n #endif\r\n #if defined(USE_DELUXEMAP)\r\n\tvec3 worldLight = 2.0 * " -"texture2D(u_DeluxeMap, var_LightTex).xyz - vec3(1.0);\r\n #else\r\n\tvec3 " -"worldLight = var_LightDirection;\r\n #endif\r\n#endif\r\n#if defined(USE_L" -"IGHT_VECTOR)\r\n\tvec3 worldLight = u_LightOrigin.xyz - (var_Position * u_L" -"ightOrigin.w);\t\r\n #if defined(USE_INVSQRLIGHT)\r\n\tfloat intensity = 1" -".0 / dot(worldLight, worldLight);\r\n #else\r\n\tfloat intensity = clamp((" -"1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07" -", 0.0, 1.0);\r\n #endif\r\n #if defined(USE_SHADOWMAP)\r\n \tvec3 dist3 " -"= textureCube(u_ShadowMap, worldLight).rgb;\r\n\tfloat dist = dot(dist3, ve" -"c3(1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0)) * u_LightRadius;\r\n\r\n\tinte" -"nsity *= max(sign(dist - length(worldLight)), 0.0);\r\n #endif\r\n\tvec3 d" -"irectedLight = u_DirectedLight * intensity;\r\n\tvec3 ambientLight = u_Amb" -"ientLight;\r\n#endif\r\n#if defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLig" -"ht = var_Color.rgb;\r\n\tvec3 worldLight = var_LightDirection;\r\n#endif\r" -"\n\r\n#if !(defined(USE_LIGHTMAP) || defined(USE_LIGHT_VECTOR) || defined(U" -"SE_LIGHT_VERTEX))\r\n\tvec3 worldLight = var_Normal;\r\n#endif\r\n\r\n#if d" -"efined(USE_DELUXEMAP) \r\n\tworldLight += var_LightDirection * 0.01;\r\n#en" -"dif\r\n\r\n\tvec3 SampleToView = normalize(u_ViewOrigin - var_Position);\r" -"\n\tvec2 tex = var_DiffuseTex;\r\n\t\r\n\tfloat ambientDiff = 1.0;\r\n\r\n#" -"if defined(USE_NORMALMAP)\r\n\tmat3 tangentToWorld = mat3(var_Tangent.xyz, " -"var_Bitangent.xyz, var_Normal.xyz);\r\n\r\n #if defined(USE_PARALLAXMAP)\r" -"\n\tvec3 offsetDir = normalize(SampleToView * tangentToWorld);\r\n #if 0" -"\r\n float height = SampleHeight(u_NormalMap, tex);\r\n\tfloat dist " -"= 0.05 * height - (0.05 / 2.0);\r\n #else\r\n\toffsetDir.xy *= 0.02 / of" -"fsetDir.z;\r\n\tfloat dist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_N" -"ormalMap);\r\n #endif\t\r\n\ttex += offsetDir.xy * dist;\r\n #endif\r\n" -" #if defined(SWIZZLE_NORMALMAP)\r\n\tvec3 normal;\r\n\tnormal.xy = 2.0 * t" -"exture2D(u_NormalMap, tex).ag - 1.0;\r\n\tnormal.z = sqrt(1.0 - dot(normal." -"xy, normal.xy));\r\n #else\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap," -" tex).rgb - 1.0;\r\n #endif\r\n\tvec3 worldNormal = tangentToWorld * norma" -"l;\r\n #if defined(r_normalAmbient)\r\n\tambientDiff = 0.781341 * normal.z" -" + 0.218659;\r\n #endif\r\n#else\r\n\tvec3 worldNormal = var_Normal;\r\n#e" -"ndif\r\n\r\n\tvec4 diffuse = texture2D(u_DiffuseMap, tex);\r\n\t\r\n\tworld" -"Normal = normalize(worldNormal);\r\n\tworldLight = normalize(worldLight);\r" -"\n\r\n#if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)\r\n\tdirectedL" -"ight /= max(dot(normalize(var_Normal), worldLight), 0.004);\r\n\r\n #if de" -"fined(r_normalAmbient)\r\n\tvec3 ambientLight = directedLight * r_normalAmb" -"ient;\r\n\tdirectedLight -= ambientLight;\r\n #else\r\n\tvec3 ambientLight" -" = vec3(0);\r\n #endif\r\n#endif\r\n\r\n#if (defined(USE_LIGHTMAP) || defi" -"ned(USE_LIGHT_VECTOR) || defined(USE_LIGHT_VERTEX))\r\n\tfloat NL = max(dot" -"(worldNormal, worldLight), 0.0);\r\n\tfloat NE = max(dot(worldNormal, S" -"ampleToView), 0.00001);\r\n #if defined(USE_OREN_NAYAR)\r\n\tfloat directe" -"dDiff = OrenNayar(worldNormal, worldLight, SampleToView, NE, NL, u_DiffuseR" -"oughness);\r\n #else\r\n\tfloat directedDiff = NL;\r\n #endif\r\n\tdiffus" -"e.rgb *= directedLight * directedDiff + ambientDiff * ambientLight;\r\n#end" -"if\r\n \r\n#if defined(USE_SPECULARMAP) && (defined(USE_LIGHTMAP) || defin" -"ed(USE_LIGHT_VECTOR) || defined(USE_LIGHT_VERTEX))\r\n\tvec4 specular = tex" -"ture2D(u_SpecularMap, tex);\r\n\tfloat shininess = specular.a * 255 + 1.0;" -"\r\n\tfloat fzero = u_SpecularReflectance;\r\n\r\n\tvec3 halfAngle = normal" -"ize(worldLight + SampleToView);\r\n\r\n\tfloat EH = max(dot(SampleToView, h" -"alfAngle), 0.0);\r\n\tfloat NH = max(dot(worldNormal, halfAngle), 0.00001)" -";\r\n\t\r\n #if defined(USE_COOK_TORRANCE)\r\n\tfloat roughness = specular" -".a * -0.99 + 1.0;\r\n\tfloat directedSpec = CookTorrance(NH, NL, NE, EH, fz" -"ero, roughness);\r\n #endif\r\n \r\n #if defined(USE_TRIACE)\r\n\tfloat " -"directedSpec = TriAce(NH, NL, NE, EH, fzero, shininess);\r\n #endif\r\n " -"\r\n #if defined(USE_BLINN)\t\r\n\tfloat directedSpec = pow(NH, shininess)" -";\r\n #endif\r\n \r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientHalf" -" = normalize(var_Normal + SampleToView);\r\n\tfloat ambientSpec = max(dot(a" -"mbientHalf, worldNormal) + 0.5, 0.0);\r\n\tambientSpec *= ambientSpec * 0.4" -"4;\r\n\tambientSpec = pow(ambientSpec, shininess) * fzero;\r\n #if defin" -"ed(USE_TRIACE)\r\n\tambientSpec *= 0.1248582 * shininess + 0.2691817;\r\n " -" #endif \r\n\tspecular.rgb *= min(directedSpec * directedLight + ambien" -"tSpec * ambientLight, 1.0);\r\n #else\r\n\tspecular.rgb *= min(directedSpe" -"c * directedLight, 1.0);\r\n #endif\r\n#endif\r\n\r\n\tgl_FragColor = diff" -"use;\r\n\r\n#if defined(USE_SPECULARMAP) && (defined(USE_LIGHTMAP) || defin" -"ed(USE_LIGHT_VECTOR) || defined(USE_LIGHT_VERTEX))\r\n\tgl_FragColor.rgb +=" -" specular.rgb;\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\tgl_Frag" -"Color *= var_Color;\r\n#endif\r\n\r\n#if (defined(USE_LIGHTMAP) || defined(" -"USE_LIGHT_VECTOR) || defined(USE_LIGHT_VERTEX))\r\n\t//gl_FragColor.rgb = w" -"orldLight * 0.5 + 0.5;\r\n#endif\r\n}\r\n"; +"arying vec3 var_LightDirection;\r\n#endif\r\n\r\n#define EPSILON 0.000" +"00001\r\n\r\n#if defined(USE_PARALLAXMAP)\r\nfloat SampleHeight(sampler2D n" +"ormalMap, vec2 t)\r\n{\r\n #if defined(SWIZZLE_NORMALMAP)\r\n\treturn text" +"ure2D(normalMap, t).r;\r\n #else\r\n\treturn texture2D(normalMap, t).a;\r" +"\n #endif\r\n}\r\n\r\nfloat RayIntersectDisplaceMap(vec2 dp, vec2 ds, samp" +"ler2D normalMap)\r\n{\r\n\tconst int linearSearchSteps = 16;\r\n\tconst int" +" binarySearchSteps = 6;\r\n\r\n\tfloat depthStep = 1.0 / float(linearSearch" +"Steps);\r\n\r\n\t// current size of search window\r\n\tfloat size = depthSt" +"ep;\r\n\r\n\t// current depth position\r\n\tfloat depth = 0.0;\r\n\r\n\t// " +"best match found (starts with last position 1.0)\r\n\tfloat bestDepth = 1.0" +";\r\n\r\n\t// search front to back for first point inside object\r\n\tfor(i" +"nt i = 0; i < linearSearchSteps - 1; ++i)\r\n\t{\r\n\t\tdepth += size;\r\n" +"\t\t\r\n\t\tfloat t = SampleHeight(normalMap, dp + ds * depth);\r\n\t\t\r\n" +"\t\tif(bestDepth > 0.996)\t\t// if no depth found yet\r\n\t\t\tif(depth >= " +"t)\r\n\t\t\t\tbestDepth = depth;\t// store best depth\r\n\t}\r\n\r\n\tdepth" +" = bestDepth;\r\n\t\r\n\t// recurse around first point (depth) for closest " +"match\r\n\tfor(int i = 0; i < binarySearchSteps; ++i)\r\n\t{\r\n\t\tsize *=" +" 0.5;\r\n\r\n\t\tfloat t = SampleHeight(normalMap, dp + ds * depth);\r\n\t" +"\t\r\n\t\tif(depth >= t)\r\n\t\t{\r\n\t\t\tbestDepth = depth;\r\n\t\t\tdept" +"h -= 2.0 * size;\r\n\t\t}\r\n\r\n\t\tdepth += size;\r\n\t}\r\n\r\n\treturn " +"bestDepth;\r\n}\r\n#endif\r\n\r\n#if defined(USE_OREN_NAYAR)\r\nfloat OrenN" +"ayar(vec3 N, vec3 L, vec3 E, float NE, float NL, float roughness)\r\n{\r\n" +"\tfloat gamma = dot(E - N * NE, L - N * NL);\r\n\tfloat r_sq = roughness * " +"roughness;\r\n\r\n\tfloat A = 1.0 - 0.5 * (r_sq / (r_sq + 0.57));\r\n\tfloa" +"t B = 0.45 * (r_sq / (r_sq + 0.09));\r\n\r\n\tfloat alpha = max(acos(NE), a" +"cos(NL));\r\n\tfloat beta = min(acos(NE), acos(NL));\r\n\r\n\tfloat C = si" +"n(alpha) * tan(beta);\r\n\r\n\treturn (A + B * max(0.0, gamma) * C) * max(0" +".0, NL);\r\n}\r\n#endif\r\n\r\n#if defined(USE_SPECULARMAP)\r\nfloat CalcSp" +"ecular(float NH, float NL, float NE, float EH, float fzero, float shininess" +")\r\n{\r\n #if defined(USE_BLINN) || defined(USE_TRIACE) || defined(USE_TO" +"RRANCE_SPARROW)\r\n\tfloat blinn = pow(NH, shininess);\r\n #endif\r\n\r\n " +" #if defined(USE_BLINN)\r\n\treturn blinn;\r\n #endif\r\n\r\n #if defined" +"(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE_SPARRO" +"W)\r\n\tfloat fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r\n #end" +"if\r\n\r\n #if defined(USE_COOK_TORRANCE)\r\n\tfloat roughness = shininess" +" * -0.99 + 1.0;\r\n\r\n\tfloat geo = 2.0 * NH / EH;\r\n\tgeo *= min(NE, NL)" +";\r\n\tgeo = min(1, geo);\r\n\r\n\tfloat r_sq = roughness * roughness;\r\n" +"\tfloat NH_sq = NH * NH;\r\n\tfloat rough = exp((NH_sq - 1.0) / (r_sq * NH_" +"sq)) / (4.0 * r_sq * pow(NH, 4));\r\n\r\n\treturn min(fresnel * geo * rough" +" / NE, 1.0);\r\n #endif\r\n\r\n #if defined(USE_TRIACE) || defined(USE_TO" +"RRANCE_SPARROW)\r\n #if defined(USE_TRIACE)\r\n\tfloat scale = 0.1248582" +" * shininess + 0.2691817;\r\n #else // elif defined(USE_TORRANCE_SPARROW" +")\r\n\tfloat scale = (0.5 * shininess + 1.0) * NH / max(EH, EPSILON);\r\n " +" #endif\r\n\r\n\treturn min(scale * fresnel * blinn / max(max(NL, NE), EPS" +"ILON), 1.0);\r\n #endif\r\n}\r\n#endif\r\n\r\nvoid main()\r\n{\r\n#if defi" +"ned(USE_LIGHTMAP)\r\n #if defined(RGBE_LIGHTMAP)\r\n\tvec4 lightSample = t" +"exture2D(u_LightMap, var_LightTex).rgba;\r\n\tvec3 directedLight = lightSam" +"ple.rgb * exp2(lightSample.a * 255.0 - 128.0);\r\n #else\r\n\tvec3 directe" +"dLight = texture2D(u_LightMap, var_LightTex).rgb;\r\n #endif\r\n #if defi" +"ned(USE_DELUXEMAP)\r\n\tvec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_" +"LightTex).xyz - vec3(1.0);\r\n #else\r\n\tvec3 worldLight = var_LightDirec" +"tion;\r\n #endif\r\n#endif\r\n#if defined(USE_LIGHT_VECTOR)\r\n\tvec3 worl" +"dLight = u_LightOrigin.xyz - (var_Position * u_LightOrigin.w);\t\r\n #if d" +"efined(USE_INVSQRLIGHT)\r\n\tfloat intensity = 1.0 / dot(worldLight, worldL" +"ight);\r\n #else\r\n\tfloat intensity = clamp((1.0 - dot(worldLight, world" +"Light) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #endif\r" +"\n #if defined(USE_SHADOWMAP)\r\n \tvec3 dist3 = textureCube(u_ShadowMap," +" worldLight).rgb;\r\n\tfloat dist = dot(dist3, vec3(1.0 / (256.0 * 256.0), " +"1.0 / 256.0, 1.0)) * u_LightRadius;\r\n\r\n\tintensity *= max(sign(dist - l" +"ength(worldLight)), 0.0);\r\n #endif\r\n\tvec3 directedLight = u_DirectedL" +"ight * intensity;\r\n\tvec3 ambientLight = u_AmbientLight;\r\n#endif\r\n#i" +"f defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLight = var_Color.rgb;\r\n\tv" +"ec3 worldLight = var_LightDirection;\r\n#endif\r\n\r\n#if !(defined(USE_LIG" +"HT))\r\n\tvec3 worldLight = var_Normal;\r\n#endif\r\n\r\n#if defined(USE_DE" +"LUXEMAP) \r\n\tworldLight += var_LightDirection * 0.01;\r\n#endif\r\n\r\n\t" +"vec3 SampleToView = normalize(u_ViewOrigin - var_Position);\r\n\tvec2 tex =" +" var_DiffuseTex;\r\n\t\r\n\tfloat ambientDiff = 1.0;\r\n\r\n#if defined(USE" +"_NORMALMAP)\r\n\tmat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent." +"xyz, var_Normal.xyz);\r\n\r\n #if defined(USE_PARALLAXMAP)\r\n\tvec3 offse" +"tDir = normalize(SampleToView * tangentToWorld);\r\n #if 0\r\n float " +"height = SampleHeight(u_NormalMap, tex);\r\n\tfloat pdist = 0.05 * height -" +" (0.05 / 2.0);\r\n #else\r\n\toffsetDir.xy *= 0.02 / offsetDir.z;\r\n\tf" +"loat pdist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap);\r\n " +" #endif\t\r\n\ttex += offsetDir.xy * pdist;\r\n #endif\r\n #if defined(S" +"WIZZLE_NORMALMAP)\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb " +"- 1.0;\r\n #else\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb " +"- 1.0;\r\n #endif\r\n\t//normal.z = sqrt(max(1.0 - dot(normal.xy, normal.x" +"y), 0.0));\r\n\tvec3 worldNormal = tangentToWorld * normal;\r\n #if define" +"d(r_normalAmbient)\r\n\tambientDiff = 0.781341 * normal.z + 0.218659;\r\n " +"#endif\r\n#else\r\n\tvec3 worldNormal = var_Normal;\r\n#endif\r\n\r\n\tvec4" +" diffuse = texture2D(u_DiffuseMap, tex);\r\n\t\r\n\tworldNormal = normalize" +"(worldNormal);\r\n\tworldLight = normalize(worldLight);\r\n\r\n#if defined(" +"USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)\r\n\tdirectedLight /= max(dot(no" +"rmalize(var_Normal), worldLight), 0.004);\r\n\r\n #if defined(r_normalAmbi" +"ent)\r\n\tvec3 ambientLight = directedLight * r_normalAmbient;\r\n\tdirecte" +"dLight -= ambientLight;\r\n #else\r\n\tvec3 ambientLight = vec3(0);\r\n #" +"endif\r\n#endif\r\n\r\n#if defined(USE_LIGHT)\r\n\tfloat NL = max(dot(world" +"Normal, worldLight), 0.0);\r\n\tfloat NE = max(dot(worldNormal, SampleT" +"oView), 0.0);\r\n #if defined(USE_OREN_NAYAR)\r\n\tfloat directedDiff = Or" +"enNayar(worldNormal, worldLight, SampleToView, NE, NL, u_DiffuseRoughness);" +"\r\n #else\r\n\tfloat directedDiff = NL;\r\n #endif\r\n\tdiffuse.rgb *= d" +"irectedLight * directedDiff + ambientDiff * ambientLight;\r\n#endif\r\n \r" +"\n#if defined(USE_SPECULARMAP) && defined(USE_LIGHT)\r\n\tvec4 specular = t" +"exture2D(u_SpecularMap, tex);\r\n\tspecular.rgb = min(specular.rgb, 1.0 - d" +"iffuse.rgb);\r\n\tfloat shininess = specular.a * 255 + 1.0;\r\n\tfloat fzer" +"o = u_SpecularReflectance;\r\n\r\n\tvec3 halfAngle = normalize(worldLight +" +" SampleToView);\r\n\r\n\tfloat EH = max(dot(SampleToView, halfAngle), 0.0);" +"\r\n\tfloat NH = max(dot(worldNormal, halfAngle), 0.0);\r\n\t\r\n\tfloat d" +"irectedSpec = CalcSpecular(NH, NL, NE, EH, fzero, shininess);\r\n \r\n #i" +"f defined(r_normalAmbient)\r\n\tvec3 ambientHalf = normalize(var_Normal + S" +"ampleToView);\r\n\tfloat ambientSpec = max(dot(ambientHalf, worldNormal) + " +"0.5, 0.0);\r\n\tambientSpec *= ambientSpec * 0.44;\r\n\tambientSpec = pow(a" +"mbientSpec, shininess) * fzero;\r\n #if defined(USE_TRIACE)\r\n\tambient" +"Spec *= 0.1248582 * shininess + 0.2691817;\r\n #endif \r\n\tspecular." +"rgb *= min(directedSpec * directedLight + ambientSpec * ambientLight, 1.0);" +"\r\n #else\r\n\tspecular.rgb *= min(directedSpec * directedLight, 1.0);\r" +"\n #endif\r\n#endif\r\n\r\n\tgl_FragColor = diffuse;\r\n\r\n#if defined(US" +"E_SPECULARMAP) && defined(USE_LIGHT)\r\n\tgl_FragColor.rgb += specular.rgb;" +"\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\tgl_FragColor *= var_C" +"olor;\r\n#endif\r\n}\r\n"; static const char *fallbackShadowfillShader_vp = "attribute vec4 attr_Position;\r\nattribute vec3 attr_Normal;\r\nattribute" @@ -441,19 +438,20 @@ static const char *fallbackShadowfillShader_vp = static const char *fallbackShadowfillShader_fp = "uniform vec4 u_LightOrigin;\r\nuniform float u_LightRadius;\r\n\r\nvarying" -" vec3 var_Position;\r\n\r\nvoid main()\r\n{\r\n\tfloat depth = length(u_Li" -"ghtOrigin.xyz - var_Position) / u_LightRadius;\r\n#if 0\r\n\t// 32 bit prec" -"ision\r\n\tconst vec4 bitSh = vec4( 256 * 256 * 256, 256 * 256, 2" -"56, 1);\r\n\tconst vec4 bitMsk = vec4( 0, 1.0 / 256." -"0, 1.0 / 256.0, 1.0 / 256.0);\r\n\t\r\n\tvec4 comp;\r\n\tcomp = depth * bit" -"Sh;\r\n\tcomp.xyz = fract(comp.xyz);\r\n\tcomp -= comp.xxyz * bitMsk;\r\n\t" -"gl_FragColor = comp;\r\n#endif\r\n\r\n#if 1\r\n\t// 24 bit precision\r\n\tc" -"onst vec3 bitSh = vec3( 256 * 256, 256, 1);\r\n\tconst ve" -"c3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 / 256.0);\r\n\t\r\n\tvec3 comp" -";\r\n\tcomp = depth * bitSh;\r\n\tcomp.xy = fract(comp.xy);\r\n\tcomp -= co" -"mp.xxy * bitMsk;\r\n\tgl_FragColor = vec4(comp, 1.0);\r\n#endif\r\n\r\n#if " -"0\r\n\t// 8 bit precision\r\n\tgl_FragColor = vec4(depth, depth, depth, 1);" -"\r\n#endif\r\n}\r\n"; +" vec3 var_Position;\r\n\r\nvoid main()\r\n{\r\n#if defined(USE_DEPTH)\r\n" +"\tfloat depth = length(u_LightOrigin.xyz - var_Position) / u_LightRadius;\r" +"\n #if 0\r\n\t// 32 bit precision\r\n\tconst vec4 bitSh = vec4( 256 * 256 *" +" 256, 256 * 256, 256, 1);\r\n\tconst vec4 bitMsk = vec4" +"( 0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\r\n\t\r\n\tvec4 c" +"omp;\r\n\tcomp = depth * bitSh;\r\n\tcomp.xyz = fract(comp.xyz);\r\n\tcomp " +"-= comp.xxyz * bitMsk;\r\n\tgl_FragColor = comp;\r\n #endif\r\n\r\n #if 1\r" +"\n\t// 24 bit precision\r\n\tconst vec3 bitSh = vec3( 256 * 256, 25" +"6, 1);\r\n\tconst vec3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 " +"/ 256.0);\r\n\t\r\n\tvec3 comp;\r\n\tcomp = depth * bitSh;\r\n\tcomp.xy = f" +"ract(comp.xy);\r\n\tcomp -= comp.xxy * bitMsk;\r\n\tgl_FragColor = vec4(com" +"p, 1.0);\r\n #endif\r\n\r\n #if 0\r\n\t// 8 bit precision\r\n\tgl_FragColor" +" = vec4(depth, depth, depth, 1);\r\n #endif\r\n#else\r\n\tgl_FragColor = ve" +"c4(0, 0, 0, 1);\r\n#endif\r\n}\r\n"; static const char *fallbackPshadowShader_vp = "attribute vec4 attr_Position;\r\nattribute vec3 attr_Normal;\r\n\r\nuniform" @@ -484,23 +482,22 @@ static const char *fallbackPshadowShader_fp = "discard;\r\n\t}\r\n\r\n\tif (dot(var_Normal, lightToPos) > 0.0)\r\n\t{\r\n" "\t\tdiscard;\r\n\t}\r\n#else\r\n\tintensity *= max(sign(dot(u_LightForward," " lightToPos)), 0.0);\r\n\tintensity *= max(sign(-dot(var_Normal, lightToPos" -")), 0.0);\r\n#endif\r\n\r\n\tintensity *= fade;\r\n\t\r\n#if defined(USE_PC" -"F)\r\n\tfloat part;\r\n\t\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2(" -"-1.0/256.0, -1.0/256.0), u_LightRadius);\r\n\tpart = max(sign(lightDist - " -"dist), 0.0);\r\n\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/256." -"0, -1.0/256.0), u_LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0." -"0);\r\n\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/256.0, 1.0/2" -"56.0), u_LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r\n\r" -"\n\tdist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/256.0, 1.0/256.0), u_" -"LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r\n\r\n #if de" -"fined(USE_DISCARD)\r\n\tif (part <= 0.0)\r\n\t{\r\n\t\tdiscard;\r\n\t}\r\n " -"#endif\r\n\r\n\tintensity *= part * 0.25;\r\n#else\r\n\tdist = sampleDistMa" -"p(u_ShadowMap, st, u_LightRadius);\r\n\r\n #if defined(USE_DISCARD)\r\n\tif" -" (lightDist - dist <= 0.0)\r\n\t{\r\n\t\tdiscard;\r\n\t}\r\n #endif\r\n\t\t" -"\t\r\n\t//intensity *= max(sign(254.0 / 255.0 - dist / u_LightRadius), 0.0)" -";\r\n\tintensity *= max(sign(lightDist - dist), 0.0);\r\n#endif\r\n\t\t\r\n" -"\tgl_FragColor.rgb = vec3(0);\r\n\tgl_FragColor.a = clamp(intensity, 0.0, 0" -".75);\r\n}\r\n"; +")), 0.0);\r\n#endif\r\n\r\n\tintensity *= fade;\r\n#if defined(USE_PCF)\r\n" +"\tfloat part;\r\n\t\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/5" +"12.0, -1.0/512.0), u_LightRadius);\r\n\tpart = max(sign(lightDist - dist)," +" 0.0);\r\n\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, -1." +"0/512.0), u_LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r" +"\n\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, 1.0/512.0)" +", u_LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r\n\r\n\td" +"ist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, 1.0/512.0), u_Light" +"Radius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r\n\r\n #if define" +"d(USE_DISCARD)\r\n\tif (part <= 0.0)\r\n\t{\r\n\t\tdiscard;\r\n\t}\r\n #en" +"dif\r\n\r\n\tintensity *= part * 0.25;\r\n#else\r\n\tdist = sampleDistMap(u" +"_ShadowMap, st, u_LightRadius);\r\n\r\n #if defined(USE_DISCARD)\r\n\tif (" +"lightDist - dist <= 0.0)\r\n\t{\r\n\t\tdiscard;\r\n\t}\r\n #endif\r\n\t\t" +"\t\r\n\tintensity *= max(sign(lightDist - dist), 0.0);\r\n#endif\r\n\t\t\r" +"\n\tgl_FragColor.rgb = vec3(0);\r\n\tgl_FragColor.a = clamp(intensity, 0.0," +" 0.75);\r\n}\r\n"; static const char *fallbackDown4xShader_vp = "attribute vec4 attr_Position;\r\nattribute vec4 attr_TexCoord0;\r\n\r\nunif" @@ -614,30 +611,23 @@ static const char *fallbackToneMapShader_fp = "iform vec4 u_Color;\r\n\r\nuniform vec2 u_InvTexRes;\r\nuniform v" "ec2 u_AutoExposureMinMax;\r\n\r\nvarying vec2 var_TexCoords;\r\n" "\r\nconst vec3 LUMINANCE_VECTOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0" -".299, 0.587, 0.114);\r\n\r\n#if 1\r\nvec3 RGB2Yxy(vec3 RGB)\r\n{\r\n\tconst" -" mat3 RGB2XYZ = mat3(\r\n\t\t0.4124564, 0.3575761, 0.1804375, \r\n\t\t0.2" -"126729, 0.7151522, 0.0721750, \r\n\t\t0.0193339, 0.1191920, 0.9503041);" -"\r\n\r\n\tvec3 XYZ = RGB2XYZ * RGB;\r\n\r\n\tfloat scale = 1.0f / (XYZ.r + " -"XYZ.g + XYZ.b);\r\n\r\n\treturn XYZ.grg * vec3(1.0, scale, scale);\r\n}\r\n" -"\r\nvec3 Yxy2RGB(vec3 Yxy)\r\n{\r\n\tconst mat3 XYZ2RGB = mat3(\r\n\t\t 3." -"2404542, -1.5371385, -0.4985314,\r\n\t\t-0.9692660, 1.8760108, 0.0415560," -"\r\n\t\t 0.0556434, -0.2040259, 1.0572252);\r\n\r\n\tvec3 XYZ = Yxy.rrr;\r" -"\n\tfloat invy = 1.0 / Yxy.b;\r\n\tfloat xdivy = Yxy.g * invy;\r\n\t\r\n\tX" -"YZ *= vec3(xdivy, 1.0, invy - xdivy - 1.0);\r\n\t\t\r\n\treturn clamp(XYZ2R" -"GB * XYZ, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 color" -" = texture2D(u_TextureMap, var_TexCoords) * u_Color;\r\n\tvec3 minAvgMax = " -"texture2D(u_LevelsMap, var_TexCoords).rgb;\r\n\tvec3 logMinAvgMaxLum = clam" -"p(minAvgMax * 20.0 - 10.0, -u_AutoExposureMinMax.y, -u_AutoExposureMinMax.x" -");\r\n\t\t\r\n\tfloat avgLum = exp2(logMinAvgMaxLum.y) ;\r\n\tfloat maxLum " -"= exp2(logMinAvgMaxLum.z);\r\n\t\t\r\n\tvec3 Yxy = RGB2Yxy(color.rgb);\r\n" -"\tfloat lscale = 1000000000.0;\r\n\tfloat lkey = 1.03 - (2.0 / (2.0 + log(a" -"vgLum * lscale + 1.0) / log(10.0)));\r\n\tfloat lmax = 2.0;\r\n\t//float lu" -"mi = max(dot(LUMINANCE_VECTOR, color.rgb), 0.000001);\r\n\tfloat lumi = Yxy" -".r;\r\n\tfloat newLumi = lumi * lkey / avgLum;\r\n\tnewLumi = newLumi * (1." -"0 + newLumi / (lmax * lmax)) / (1.0 + newLumi);\r\n\t\r\n#if defined(r_obbc" -"orrect)\r\n\tnewLumi /= r_obbcorrect;\r\n#endif\r\n\r\n\tYxy.r = newLumi;\r" -"\n\tgl_FragColor.rgb = Yxy2RGB(Yxy);\r\n\t//gl_FragColor.rgb = color.rgb / " -"lumi * newLumi;\r\n\tgl_FragColor.a = color.a;\r\n}\r\n"; +".299, 0.587, 0.114);\r\n\r\nfloat FilmicTonemap(float x)\r\n{\r\n\tfloat sh" +"oulderStrength = 0.22;\r\n\tfloat linearStrength = 0.30;\r\n\tfloat linearA" +"ngle = 0.10;\r\n\tfloat toeStrength = 0.20;\r\n\tfloat toeAngleNumerator = " +"0.01;\r\n\tfloat toeAngleDenominator = 0.30;\r\n float toeAngle = toeAng" +"leNumerator / toeAngleDenominator;\r\n\t\r\n\treturn ((x*(shoulderStrength*" +"x+linearAngle*linearStrength)+toeStrength*toeAngleNumerator)/\r\n\t(x*(shou" +"lderStrength*x+linearStrength)+toeStrength*toeAngleDenominator)) - toeAngle" +";\r\n}\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = texture2D(u_TextureMap, va" +"r_TexCoords) * u_Color;\r\n\tvec3 minAvgMax = texture2D(u_LevelsMap, var_Te" +"xCoords).rgb;\r\n\tvec3 logMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, -u" +"_AutoExposureMinMax.y, -u_AutoExposureMinMax.x);\r\n\t\t\r\n\tfloat avgLum " +"= exp2(logMinAvgMaxLum.y) ;\r\n\tfloat maxLum = exp2(logMinAvgMaxLum.z);\r" +"\n\r\n\tfloat fWhite = 1.0 / FilmicTonemap(avgLum * 2);\r\n\tcolor.r = Film" +"icTonemap(color.r) * fWhite;\r\n\tcolor.g = FilmicTonemap(color.g) * fWhite" +";\r\n\tcolor.b = FilmicTonemap(color.b) * fWhite;\r\n\t\r\n#if defined(r_ob" +"bcorrect)\r\n\tcolor.rgb /= r_obbcorrect;\r\n#endif\r\n\t\r\n\tgl_FragColor" +" = color;\r\n}\r\n"; static const char *fallbackCalcLevels4xShader_vp = "attribute vec4 attr_Position;\r\nattribute vec4 attr_TexCoord0;\r\n\r\nunif" @@ -1732,24 +1722,29 @@ void GLSL_InitGPUShaders(void) if (r_hdr->integer && !(glRefConfig.textureFloat && glRefConfig.halfFloatPixel)) Q_strcat(extradefines, 1024, "#define RGBE_LIGHTMAP\n"); - switch (i & LIGHTDEF_LIGHTTYPE_MASK) + if (i & LIGHTDEF_LIGHTTYPE_MASK) { - case LIGHTDEF_USE_LIGHTMAP: - Q_strcat(extradefines, 1024, "#define USE_LIGHTMAP\n"); - attribs |= ATTR_LIGHTCOORD | ATTR_LIGHTDIRECTION; - break; - case LIGHTDEF_USE_LIGHT_VECTOR: - Q_strcat(extradefines, 1024, "#define USE_LIGHT_VECTOR\n"); - break; - case LIGHTDEF_USE_LIGHT_VERTEX: - Q_strcat(extradefines, 1024, "#define USE_LIGHT_VERTEX\n"); - attribs |= ATTR_LIGHTDIRECTION; - break; - default: - break; + Q_strcat(extradefines, 1024, "#define USE_LIGHT\n"); + + switch (i & LIGHTDEF_LIGHTTYPE_MASK) + { + case LIGHTDEF_USE_LIGHTMAP: + Q_strcat(extradefines, 1024, "#define USE_LIGHTMAP\n"); + attribs |= ATTR_LIGHTCOORD | ATTR_LIGHTDIRECTION; + break; + case LIGHTDEF_USE_LIGHT_VECTOR: + Q_strcat(extradefines, 1024, "#define USE_LIGHT_VECTOR\n"); + break; + case LIGHTDEF_USE_LIGHT_VERTEX: + Q_strcat(extradefines, 1024, "#define USE_LIGHT_VERTEX\n"); + attribs |= ATTR_LIGHTDIRECTION; + break; + default: + break; + } } - if (i & LIGHTDEF_USE_NORMALMAP && r_normalMapping->integer) + if ((i & LIGHTDEF_USE_NORMALMAP) && r_normalMapping->integer) { Q_strcat(extradefines, 1024, "#define USE_NORMALMAP\n"); @@ -1759,7 +1754,7 @@ void GLSL_InitGPUShaders(void) attribs |= ATTR_TANGENT | ATTR_BITANGENT; } - if (i & LIGHTDEF_USE_SPECULARMAP && r_specularMapping->integer) + if ((i & LIGHTDEF_USE_SPECULARMAP) && r_specularMapping->integer) { Q_strcat(extradefines, 1024, "#define USE_SPECULARMAP\n"); @@ -1777,13 +1772,17 @@ void GLSL_InitGPUShaders(void) case 3: Q_strcat(extradefines, 1024, "#define USE_COOK_TORRANCE\n"); break; + + case 4: + Q_strcat(extradefines, 1024, "#define USE_TORRANCE_SPARROW\n"); + break; } } - if (i & LIGHTDEF_USE_DELUXEMAP && r_deluxeMapping->integer) + if ((i & LIGHTDEF_USE_DELUXEMAP) && r_deluxeMapping->integer) Q_strcat(extradefines, 1024, "#define USE_DELUXEMAP\n"); - if (i & LIGHTDEF_USE_PARALLAXMAP && !(i & LIGHTDEF_ENTITY) && r_parallaxMapping->integer) + if ((i & LIGHTDEF_USE_PARALLAXMAP) && !(i & LIGHTDEF_ENTITY) && r_parallaxMapping->integer) Q_strcat(extradefines, 1024, "#define USE_PARALLAXMAP\n"); if (i & LIGHTDEF_TCGEN_ENVIRONMENT) @@ -1847,12 +1846,13 @@ void GLSL_InitGPUShaders(void) numLightShaders++; } - attribs = ATTR_POSITION | ATTR_POSITION2 | ATTR_NORMAL | ATTR_NORMAL2 | ATTR_TEXCOORD; - if (!GLSL_InitGPUShader(&tr.shadowmapShader, "shadowfill", attribs, qtrue, NULL, qtrue, fallbackShadowfillShader_vp, fallbackShadowfillShader_fp, GENERIC_UNIFORM_COUNT)) + extradefines[0] = '\0'; + + if (!GLSL_InitGPUShader(&tr.shadowmapShader, "shadowfill", attribs, qtrue, extradefines, qtrue, fallbackShadowfillShader_vp, fallbackShadowfillShader_fp, GENERIC_UNIFORM_COUNT)) { - ri.Error(ERR_FATAL, "Could not load depth shader!\n"); + ri.Error(ERR_FATAL, "Could not load shadowfill shader!\n"); } GLSL_AddUniform(&tr.shadowmapShader, GENERIC_UNIFORM_DEFORMGEN, "u_DeformGen", GLSL_INT); @@ -1870,7 +1870,6 @@ void GLSL_InitGPUShaders(void) numEtcShaders++; - attribs = ATTR_POSITION | ATTR_NORMAL; extradefines[0] = '\0'; @@ -2071,27 +2070,21 @@ void GLSL_ShutdownGPUShaders(void) GLSL_BindNullProgram(); for ( i = 0; i < GENERICDEF_COUNT; i++) - { GLSL_DeleteGPUShader(&tr.genericShader[i]); - } GLSL_DeleteGPUShader(&tr.textureColorShader); GLSL_DeleteGPUShader(&tr.fogShader); GLSL_DeleteGPUShader(&tr.dlightallShader); for ( i = 0; i < LIGHTDEF_COUNT; i++) - { GLSL_DeleteGPUShader(&tr.lightallShader[i]); - } GLSL_DeleteGPUShader(&tr.shadowmapShader); GLSL_DeleteGPUShader(&tr.pshadowShader); GLSL_DeleteGPUShader(&tr.down4xShader); for ( i = 0; i < 2; i++) - { GLSL_DeleteGPUShader(&tr.calclevels4xShader[i]); - } glState.currentProgram = 0; qglUseProgramObjectARB(0); diff --git a/reaction/code/renderergl2/tr_image.c b/reaction/code/renderergl2/tr_image.c index 01f7331a..b800c815 100644 --- a/reaction/code/renderergl2/tr_image.c +++ b/reaction/code/renderergl2/tr_image.c @@ -271,33 +271,196 @@ static void ResampleTexture( byte *in, int inwidth, int inheight, byte *out, } } +static void RGBAtoYCoCgA(const byte *in, byte *out, int width, int height) +{ + int x, y; + + for (y = 0; y < height; y++) + { + const byte *inbyte = in + y * width * 4; + byte *outbyte = out + y * width * 4; + + for (x = 0; x < width; x++) + { + byte r, g, b, a, rb2; + + r = *inbyte++; + g = *inbyte++; + b = *inbyte++; + a = *inbyte++; + rb2 = (r + b) >> 1; + + *outbyte++ = (g + rb2) >> 1; // Y = R/4 + G/2 + B/4 + *outbyte++ = (r - b + 256) >> 1; // Co = R/2 - B/2 + *outbyte++ = (g - rb2 + 256) >> 1; // Cg = -R/4 + G/2 - B/4 + *outbyte++ = a; + } + } +} + +static void YCoCgAtoRGBA(const byte *in, byte *out, int width, int height) +{ + int x, y; + + for (y = 0; y < height; y++) + { + const byte *inbyte = in + y * width * 4; + byte *outbyte = out + y * width * 4; + + for (x = 0; x < width; x++) + { + byte _Y, Co, Cg, a; + + _Y = *inbyte++; + Co = *inbyte++; + Cg = *inbyte++; + a = *inbyte++; + + *outbyte++ = CLAMP(_Y + Co - Cg, 0, 255); // R = Y + Co - Cg + *outbyte++ = CLAMP(_Y + Cg - 128, 0, 255); // G = Y + Cg + *outbyte++ = CLAMP(_Y - Co - Cg + 256, 0, 255); // B = Y - Co - Cg + *outbyte++ = a; + } + } +} + + +// uses a sobel filter to change a texture to a normal map +static void RGBAtoNormal(const byte *in, byte *out, int width, int height, qboolean clampToEdge) +{ + int x, y, max; + + // convert to heightmap, storing in alpha + // same as converting to Y in YCoCg + max = 1; + for (y = 0; y < height; y++) + { + const byte *inbyte = in + y * width * 4; + byte *outbyte = out + y * width * 4 + 3; + + for (x = 0; x < width; x++) + { + *outbyte = (inbyte[0] >> 2) + (inbyte[1] >> 1) + (inbyte[2] >> 2); + max = MAX(max, *outbyte); + outbyte += 4; + inbyte += 4; + } + } + + // level out heights + if (max < 255) + { + for (y = 0; y < height; y++) + { + byte *outbyte = out + y * width * 4 + 3; + + for (x = 0; x < width; x++) + { + *outbyte = *outbyte + (255 - max); + outbyte += 4; + } + } + } + + + // now run sobel filter over height values to generate X and Y + // then normalize + for (y = 0; y < height; y++) + { + byte *outbyte = out + y * width * 4; + + for (x = 0; x < width; x++) + { + // 0 1 2 + // 3 4 5 + // 6 7 8 + + byte s[9]; + int x2, y2, i; + vec3_t normal; + + i = 0; + for (y2 = -1; y2 <= 1; y2++) + { + int src_y = y + y2; + + if (clampToEdge) + { + src_y = CLAMP(src_y, 0, height - 1); + } + else + { + src_y = (src_y + height) % height; + } + + + for (x2 = -1; x2 <= 1; x2++) + { + int src_x = x + x2; + + if (clampToEdge) + { + src_x = CLAMP(src_x, 0, height - 1); + } + else + { + src_x = (src_x + height) % height; + } + + s[i++] = *(out + (src_y * width + src_x) * 4 + 3); + } + } + + normal[0] = s[0] - s[2] + + 2 * s[3] - 2 * s[5] + + s[6] - s[8]; + + normal[1] = s[0] + 2 * s[1] + s[2] + + - s[6] - 2 * s[7] - s[8]; + + normal[2] = s[4] * 4; + + if (!VectorNormalize2(normal, normal)) + { + VectorSet(normal, 0, 0, 1); + } + + *outbyte++ = FloatToOffsetByte(normal[0]); + *outbyte++ = FloatToOffsetByte(normal[1]); + *outbyte++ = FloatToOffsetByte(normal[2]); + outbyte++; + } + } +} + #define COPYSAMPLE(a,b) *(unsigned int *)(a) = *(unsigned int *)(b) // based on Fast Curve Based Interpolation // from Fast Artifacts-Free Image Interpolation (http://www.andreagiachetti.it/icbi/) // assumes data has a 2 pixel thick border of clamped or wrapped data // expects data to be a grid with even (0, 0), (2, 0), (0, 2), (2, 2) etc pixels filled -static void DoFCBI(byte *in, byte *out, int width, int height) +// only performs FCBI on specified component +static void DoFCBI(byte *in, byte *out, int width, int height, int component) { - int x, y, i; + int x, y; byte *outbyte, *inbyte; - //copy in to out - for (y = 0; y < height; y+=2) + // copy in to out + for (y = 2; y < height - 2; y += 2) { - inbyte = in + y * width * 4; - outbyte = out + y * width * 4; + inbyte = in + (y * width + 2) * 4 + component; + outbyte = out + (y * width + 2) * 4 + component; - for (x = width / 2; x > 0; x--) + for (x = 2; x < width - 2; x += 2) { - COPYSAMPLE(outbyte, inbyte); + *outbyte = *inbyte; outbyte += 8; inbyte += 8; } } - - //for (y = 1; y < height; y += 2) - for (y = 3; y < height - 4; y += 2) + + for (y = 3; y < height - 3; y += 2) { // diagonals // @@ -336,10 +499,9 @@ static void DoFCBI(byte *in, byte *out, int width, int height) // // only b, f, j, and l need to be sampled on next iteration - byte sa[4], sb[4], sc[4], sd[4], se[4], sf[4], sg[4], sh[4], si[4], sj[4], sk[4], sl[4]; + byte sa, sb, sc, sd, se, sf, sg, sh, si, sj, sk, sl; byte *line1, *line2, *line3, *line4; - //x = 1; x = 3; // optimization one @@ -349,21 +511,27 @@ static void DoFCBI(byte *in, byte *out, int width, int height) // SAMPLE2(sk, x-1, y+3); // optimization two - line1 = in + ((y - 3) * width + (x - 1)) * 4; - line2 = in + ((y - 1) * width + (x - 3)) * 4; - line3 = in + ((y + 1) * width + (x - 3)) * 4; - line4 = in + ((y + 3) * width + (x - 1)) * 4; + line1 = in + ((y - 3) * width + (x - 1)) * 4 + component; + line2 = in + ((y - 1) * width + (x - 3)) * 4 + component; + line3 = in + ((y + 1) * width + (x - 3)) * 4 + component; + line4 = in + ((y + 3) * width + (x - 1)) * 4 + component; - COPYSAMPLE(sa, line1); line1 += 8; - COPYSAMPLE(sc, line2); line2 += 8; COPYSAMPLE(sd, line2); line2 += 8; COPYSAMPLE(se, line2); line2 += 8; - COPYSAMPLE(sg, line3); line3 += 8; COPYSAMPLE(sh, line3); line3 += 8; COPYSAMPLE(si, line3); line3 += 8; - COPYSAMPLE(sk, line4); line4 += 8; + // COPYSAMPLE(sa, line1); line1 += 8; + //COPYSAMPLE(sc, line2); line2 += 8; COPYSAMPLE(sd, line2); line2 += 8; COPYSAMPLE(se, line2); line2 += 8; + //COPYSAMPLE(sg, line3); line3 += 8; COPYSAMPLE(sh, line3); line3 += 8; COPYSAMPLE(si, line3); line3 += 8; + // COPYSAMPLE(sk, line4); line4 += 8; - outbyte = &out[(y * width + x) << 2]; + sa = *line1; line1 += 8; + sc = *line2; line2 += 8; sd = *line2; line2 += 8; se = *line2; line2 += 8; + sg = *line3; line3 += 8; sh = *line3; line3 += 8; si = *line3; line3 += 8; + sk = *line4; line4 += 8; - //for ( ; x < width; x += 2) - for ( ; x < width - 4; x += 2) + outbyte = out + (y * width + x) * 4 + component; + + for ( ; x < width - 3; x += 2) { + int NWd, NEd, NWp, NEp; + // original // SAMPLE2(sa, x-1, y-3); SAMPLE2(sb, x+1, y-3); //SAMPLE2(sc, x-3, y-1); SAMPLE2(sd, x-1, y-1); SAMPLE2(se, x+1, y-1); SAMPLE2(sf, x+3, y-1); @@ -377,69 +545,71 @@ static void DoFCBI(byte *in, byte *out, int width, int height) //SAMPLE2(sl, x+1, y+3); // optimization two - COPYSAMPLE(sb, line1); line1 += 8; - COPYSAMPLE(sf, line2); line2 += 8; - COPYSAMPLE(sj, line3); line3 += 8; - COPYSAMPLE(sl, line4); line4 += 8; + //COPYSAMPLE(sb, line1); line1 += 8; + //COPYSAMPLE(sf, line2); line2 += 8; + //COPYSAMPLE(sj, line3); line3 += 8; + //COPYSAMPLE(sl, line4); line4 += 8; - for (i = 0; i < 4; i++) - { - int NWd, NEd, NWp, NEp; + sb = *line1; line1 += 8; + sf = *line2; line2 += 8; + sj = *line3; line3 += 8; + sl = *line4; line4 += 8; - NWp = sd[i] + si[i]; - NEp = se[i] + sh[i]; - NWd = abs(sd[i] - si[i]); - NEd = abs(se[i] - sh[i]); + NWp = sd + si; + NEp = se + sh; + NWd = abs(sd - si); + NEd = abs(se - sh); - if (NWd > 100 || NEd > 100 || abs(NWp-NEp) > 200) - { - if (NWd < NEd) - *outbyte = NWp >> 1; - else - *outbyte = NEp >> 1; - } + if (NWd > 100 || NEd > 100 || abs(NWp-NEp) > 200) + { + if (NWd < NEd) + *outbyte = NWp >> 1; else - { - int NWdd, NEdd; + *outbyte = NEp >> 1; + } + else + { + int NWdd, NEdd; - //NEdd = abs(sg + sd + sb - 3 * (se + sh) + sk + si + sf); - //NWdd = abs(sa + se + sj - 3 * (sd + si) + sc + sh + sl); - NEdd = abs(sg[i] + sb[i] - 3 * NEp + sk[i] + sf[i] + NWp); - NWdd = abs(sa[i] + sj[i] - 3 * NWp + sc[i] + sl[i] + NEp); + //NEdd = abs(sg + sd + sb - 3 * (se + sh) + sk + si + sf); + //NWdd = abs(sa + se + sj - 3 * (sd + si) + sc + sh + sl); + NEdd = abs(sg + sb - 3 * NEp + sk + sf + NWp); + NWdd = abs(sa + sj - 3 * NWp + sc + sl + NEp); - if (NWdd > NEdd) - *outbyte = NWp >> 1; - else - *outbyte = NEp >> 1; - } - - outbyte++; + if (NWdd > NEdd) + *outbyte = NWp >> 1; + else + *outbyte = NEp >> 1; } - outbyte += 4; + outbyte += 8; - COPYSAMPLE(sa, sb); - COPYSAMPLE(sc, sd); COPYSAMPLE(sd, se); COPYSAMPLE(se, sf); - COPYSAMPLE(sg, sh); COPYSAMPLE(sh, si); COPYSAMPLE(si, sj); - COPYSAMPLE(sk, sl); + // COPYSAMPLE(sa, sb); + //COPYSAMPLE(sc, sd); COPYSAMPLE(sd, se); COPYSAMPLE(se, sf); + //COPYSAMPLE(sg, sh); COPYSAMPLE(sh, si); COPYSAMPLE(si, sj); + // COPYSAMPLE(sk, sl); + + sa = sb; + sc = sd; sd = se; se = sf; + sg = sh; sh = si; si = sj; + sk = sl; } } // hack: copy out to in again - for (y = 1; y < height; y+=2) + for (y = 3; y < height - 3; y += 2) { - inbyte = out + y * width * 4 + 4; - outbyte = in + y * width * 4 + 4; + inbyte = out + (y * width + 3) * 4 + component; + outbyte = in + (y * width + 3) * 4 + component; - for (x = width / 2; x > 0; x--) + for (x = 3; x < width - 3; x += 2) { - COPYSAMPLE(outbyte, inbyte); + *outbyte = *inbyte; outbyte += 8; inbyte += 8; } } - //for (y = 0; y < height; y++) for (y = 2; y < height - 3; y++) { // horizontal & vertical @@ -474,7 +644,7 @@ static void DoFCBI(byte *in, byte *out, int width, int height) // // only b, e, g, j, and l need to be sampled on next iteration - byte sa[4], sb[4], sc[4], sd[4], se[4], sf[4], sg[4], sh[4], si[4], sj[4], sk[4], sl[4]; + byte sa, sb, sc, sd, se, sf, sg, sh, si, sj, sk, sl; byte *line1, *line2, *line3, *line4, *line5; //x = (y + 1) % 2; @@ -487,23 +657,30 @@ static void DoFCBI(byte *in, byte *out, int width, int height) //SAMPLE2(sh, x-2, y+1); SAMPLE2(si, x, y+1); // SAMPLE2(sk, x-1, y+2); - line1 = in + ((y - 2) * width + (x - 1)) * 4; - line2 = in + ((y - 1) * width + (x - 2)) * 4; - line3 = in + ((y ) * width + (x - 1)) * 4; - line4 = in + ((y + 1) * width + (x - 2)) * 4; - line5 = in + ((y + 2) * width + (x - 1)) * 4; + line1 = in + ((y - 2) * width + (x - 1)) * 4 + component; + line2 = in + ((y - 1) * width + (x - 2)) * 4 + component; + line3 = in + ((y ) * width + (x - 1)) * 4 + component; + line4 = in + ((y + 1) * width + (x - 2)) * 4 + component; + line5 = in + ((y + 2) * width + (x - 1)) * 4 + component; - COPYSAMPLE(sa, line1); line1 += 8; - COPYSAMPLE(sc, line2); line2 += 8; COPYSAMPLE(sd, line2); line2 += 8; - COPYSAMPLE(sf, line3); line3 += 8; - COPYSAMPLE(sh, line4); line4 += 8; COPYSAMPLE(si, line4); line4 += 8; - COPYSAMPLE(sk, line5); line5 += 8; + // COPYSAMPLE(sa, line1); line1 += 8; + //COPYSAMPLE(sc, line2); line2 += 8; COPYSAMPLE(sd, line2); line2 += 8; + // COPYSAMPLE(sf, line3); line3 += 8; + //COPYSAMPLE(sh, line4); line4 += 8; COPYSAMPLE(si, line4); line4 += 8; + // COPYSAMPLE(sk, line5); line5 += 8; - outbyte = &out[(y * width + x) << 2]; + sa = *line1; line1 += 8; + sc = *line2; line2 += 8; sd = *line2; line2 += 8; + sf = *line3; line3 += 8; + sh = *line4; line4 += 8; si = *line4; line4 += 8; + sk = *line5; line5 += 8; + + outbyte = out + (y * width + x) * 4 + component; - //for ( ; x < width; x+=2) for ( ; x < width - 3; x+=2) { + int hd, vd, hp, vp; + // SAMPLE2(sa, x-1, y-2); SAMPLE2(sb, x+1, y-2); //SAMPLE2(sc, x-2, y-1); SAMPLE2(sd, x, y-1); SAMPLE2(se, x+2, y-1); // SAMPLE2(sf, x-1, y ); SAMPLE2(sg, x+1, y ); @@ -517,73 +694,77 @@ static void DoFCBI(byte *in, byte *out, int width, int height) //SAMPLE2(sj, x+2, y+1); //SAMPLE2(sl, x+1, y+2); - COPYSAMPLE(sb, line1); line1 += 8; - COPYSAMPLE(se, line2); line2 += 8; - COPYSAMPLE(sg, line3); line3 += 8; - COPYSAMPLE(sj, line4); line4 += 8; - COPYSAMPLE(sl, line5); line5 += 8; + //COPYSAMPLE(sb, line1); line1 += 8; + //COPYSAMPLE(se, line2); line2 += 8; + //COPYSAMPLE(sg, line3); line3 += 8; + //COPYSAMPLE(sj, line4); line4 += 8; + //COPYSAMPLE(sl, line5); line5 += 8; - for (i = 0; i < 4; i++) + sb = *line1; line1 += 8; + se = *line2; line2 += 8; + sg = *line3; line3 += 8; + sj = *line4; line4 += 8; + sl = *line5; line5 += 8; + + hp = sf + sg; + vp = sd + si; + hd = abs(sf - sg); + vd = abs(sd - si); + + if (hd > 100 || vd > 100 || abs(hp-vp) > 200) { - int hd, vd, hp, vp; - - hp = sf[i] + sg[i]; - vp = sd[i] + si[i]; - hd = abs(sf[i] - sg[i]); - vd = abs(sd[i] - si[i]); - - if (hd > 100 || vd > 100 || abs(hp-vp) > 200) - { - if (hd < vd) - *outbyte = hp >> 1; - else - *outbyte = vp >> 1; - } + if (hd < vd) + *outbyte = hp >> 1; else - { - int hdd, vdd; + *outbyte = vp >> 1; + } + else + { + int hdd, vdd; - //hdd = abs(sc[i] + sd[i] + se[i] - 3 * (sf[i] + sg[i]) + sh[i] + si[i] + sj[i]); - //vdd = abs(sa[i] + sf[i] + sk[i] - 3 * (sd[i] + si[i]) + sb[i] + sg[i] + sl[i]); + //hdd = abs(sc[i] + sd[i] + se[i] - 3 * (sf[i] + sg[i]) + sh[i] + si[i] + sj[i]); + //vdd = abs(sa[i] + sf[i] + sk[i] - 3 * (sd[i] + si[i]) + sb[i] + sg[i] + sl[i]); - hdd = abs(sc[i] + se[i] - 3 * hp + sh[i] + sj[i] + vp); - vdd = abs(sa[i] + sk[i] - 3 * vp + sb[i] + sl[i] + hp); + hdd = abs(sc + se - 3 * hp + sh + sj + vp); + vdd = abs(sa + sk - 3 * vp + sb + sl + hp); - if (hdd > vdd) - *outbyte = hp >> 1; - else - *outbyte = vp >> 1; - } - - outbyte++; + if (hdd > vdd) + *outbyte = hp >> 1; + else + *outbyte = vp >> 1; } - outbyte += 4; + outbyte += 8; - COPYSAMPLE(sa, sb); - COPYSAMPLE(sc, sd); COPYSAMPLE(sd, se); - COPYSAMPLE(sf, sg); - COPYSAMPLE(sh, si); COPYSAMPLE(si, sj); - COPYSAMPLE(sk, sl); + // COPYSAMPLE(sa, sb); + //COPYSAMPLE(sc, sd); COPYSAMPLE(sd, se); + // COPYSAMPLE(sf, sg); + //COPYSAMPLE(sh, si); COPYSAMPLE(si, sj); + // COPYSAMPLE(sk, sl); + sa = sb; + sc = sd; sd = se; + sf = sg; + sh = si; si = sj; + sk = sl; } } } // Similar to FCBI, but throws out the second order derivatives for speed -static void DoFCBIQuick(byte *in, byte *out, int width, int height) +static void DoFCBIQuick(byte *in, byte *out, int width, int height, int component) { - int x, y, i; + int x, y; byte *outbyte, *inbyte; - //copy in to out - for (y = 0; y < height; y+=2) + // copy in to out + for (y = 2; y < height - 2; y += 2) { - inbyte = in + y * width * 4; - outbyte = out + y * width * 4; + inbyte = in + (y * width + 2) * 4 + component; + outbyte = out + (y * width + 2) * 4 + component; - for (x = width / 2; x > 0; x--) + for (x = 2; x < width - 2; x += 2) { - COPYSAMPLE(outbyte, inbyte); + *outbyte = *inbyte; outbyte += 8; inbyte += 8; } @@ -591,40 +772,143 @@ static void DoFCBIQuick(byte *in, byte *out, int width, int height) for (y = 3; y < height - 4; y += 2) { - byte sd[4], se[4], sh[4], si[4]; + byte sd, se, sh, si; byte *line2, *line3; x = 3; + line2 = in + ((y - 1) * width + (x - 1)) * 4 + component; + line3 = in + ((y + 1) * width + (x - 1)) * 4 + component; + + sd = *line2; line2 += 8; + sh = *line3; line3 += 8; + + outbyte = out + (y * width + x) * 4 + component; + + for ( ; x < width - 4; x += 2) + { + int NWd, NEd, NWp, NEp; + + se = *line2; line2 += 8; + si = *line3; line3 += 8; + + NWp = sd + si; + NEp = se + sh; + NWd = abs(sd - si); + NEd = abs(se - sh); + + if (NWd < NEd) + *outbyte = NWp >> 1; + else + *outbyte = NEp >> 1; + + outbyte += 8; + + sd = se; + sh = si; + } + } + + // hack: copy out to in again + for (y = 3; y < height - 3; y += 2) + { + inbyte = out + (y * width + 3) * 4 + component; + outbyte = in + (y * width + 3) * 4 + component; + + for (x = 3; x < width - 3; x += 2) + { + *outbyte = *inbyte; + outbyte += 8; + inbyte += 8; + } + } + + for (y = 2; y < height - 3; y++) + { + byte sd, sf, sg, si; + byte *line2, *line3, *line4; + + x = (y + 1) % 2 + 2; + + line2 = in + ((y - 1) * width + (x )) * 4 + component; + line3 = in + ((y ) * width + (x - 1)) * 4 + component; + line4 = in + ((y + 1) * width + (x )) * 4 + component; + + outbyte = out + (y * width + x) * 4 + component; + + sf = *line3; line3 += 8; + + for ( ; x < width - 3; x+=2) + { + int hd, vd, hp, vp; + + sd = *line2; line2 += 8; + sg = *line3; line3 += 8; + si = *line4; line4 += 8; + + hp = sf + sg; + vp = sd + si; + hd = abs(sf - sg); + vd = abs(sd - si); + + if (hd < vd) + *outbyte = hp >> 1; + else + *outbyte = vp >> 1; + + outbyte += 8; + + sf = sg; + } + } +} + +// Similar to DoFCBIQuick, but just takes the average instead of checking derivatives +// as well, this operates on all four components +static void DoLinear(byte *in, byte *out, int width, int height) +{ + int x, y, i; + byte *outbyte, *inbyte; + + // copy in to out + for (y = 2; y < height - 2; y += 2) + { + x = 2; + + inbyte = in + (y * width + x) * 4; + outbyte = out + (y * width + x) * 4; + + for ( ; x < width - 2; x += 2) + { + COPYSAMPLE(outbyte, inbyte); + outbyte += 8; + inbyte += 8; + } + } + + for (y = 1; y < height - 1; y += 2) + { + byte sd[4], se[4], sh[4], si[4]; + byte *line2, *line3; + + x = 1; + line2 = in + ((y - 1) * width + (x - 1)) * 4; line3 = in + ((y + 1) * width + (x - 1)) * 4; COPYSAMPLE(sd, line2); line2 += 8; COPYSAMPLE(sh, line3); line3 += 8; - outbyte = &out[(y * width + x) << 2]; + outbyte = out + (y * width + x) * 4; - //for ( ; x < width; x += 2) - for ( ; x < width - 4; x += 2) + for ( ; x < width - 1; x += 2) { COPYSAMPLE(se, line2); line2 += 8; COPYSAMPLE(si, line3); line3 += 8; for (i = 0; i < 4; i++) { - int NWd, NEd, NWp, NEp; - - NWp = sd[i] + si[i]; - NEp = se[i] + sh[i]; - NWd = abs(sd[i] - si[i]); - NEd = abs(se[i] - sh[i]); - - if (NWd < NEd) - *outbyte = NWp >> 1; - else - *outbyte = NEp >> 1; - - outbyte++; + *outbyte++ = (sd[i] + si[i] + se[i] + sh[i]) >> 2; } outbyte += 4; @@ -635,12 +919,14 @@ static void DoFCBIQuick(byte *in, byte *out, int width, int height) } // hack: copy out to in again - for (y = 1; y < height; y+=2) + for (y = 1; y < height - 1; y += 2) { - inbyte = out + y * width * 4 + 4; - outbyte = in + y * width * 4 + 4; + x = 1; - for (x = width / 2; x > 0; x--) + inbyte = out + (y * width + x) * 4; + outbyte = in + (y * width + x) * 4; + + for ( ; x < width - 1; x += 2) { COPYSAMPLE(outbyte, inbyte); outbyte += 8; @@ -648,23 +934,22 @@ static void DoFCBIQuick(byte *in, byte *out, int width, int height) } } - for (y = 2; y < height - 3; y++) + for (y = 1; y < height - 1; y++) { - byte sd[4], sf[4], sg[4], si[4]; byte *line2, *line3, *line4; - x = (y + 1) % 2 + 2; + x = y % 2 + 1; line2 = in + ((y - 1) * width + (x )) * 4; line3 = in + ((y ) * width + (x - 1)) * 4; line4 = in + ((y + 1) * width + (x )) * 4; - outbyte = &out[(y * width + x) << 2]; - COPYSAMPLE(sf, line3); line3 += 8; - for ( ; x < width - 3; x+=2) + outbyte = out + (y * width + x) * 4; + + for ( ; x < width - 1; x += 2) { COPYSAMPLE(sd, line2); line2 += 8; COPYSAMPLE(sg, line3); line3 += 8; @@ -672,19 +957,7 @@ static void DoFCBIQuick(byte *in, byte *out, int width, int height) for (i = 0; i < 4; i++) { - int hd, vd, hp, vp; - - hp = sf[i] + sg[i]; - vp = sd[i] + si[i]; - hd = abs(sf[i] - sg[i]); - vd = abs(sd[i] - si[i]); - - if (hd < vd) - *outbyte = hp >> 1; - else - *outbyte = vp >> 1; - - outbyte++; + *outbyte++ = (sf[i] + sg[i] + sd[i] + si[i]) >> 2; } outbyte += 4; @@ -701,15 +974,12 @@ static void ExpandHalfTextureToGrid( byte *data, int width, int height) for (y = height / 2; y > 0; y--) { - byte *outbyte = &data[((y * 2 - 1) * (width) - 2) * 4]; - byte *inbyte = &data[(y * (width / 2) - 1) * 4]; + byte *outbyte = data + ((y * 2 - 1) * (width) - 2) * 4; + byte *inbyte = data + (y * (width / 2) - 1) * 4; for (x = width / 2; x > 0; x--) { - outbyte[0] = inbyte[0]; - outbyte[1] = inbyte[1]; - outbyte[2] = inbyte[2]; - outbyte[3] = inbyte[3]; + COPYSAMPLE(outbyte, inbyte); outbyte -= 8; inbyte -= 4; @@ -717,19 +987,59 @@ static void ExpandHalfTextureToGrid( byte *data, int width, int height) } } +static void FillInNormalizedZ(const byte *in, byte *out, int width, int height) +{ + int x, y; + + for (y = 0; y < height; y++) + { + const byte *inbyte = in + y * width * 4; + byte *outbyte = out + y * width * 4; + + for (x = 0; x < width; x++) + { + byte nx, ny, nz, h; + float fnx, fny, fll, fnz; + + nx = *inbyte++; + ny = *inbyte++; + inbyte++; + h = *inbyte++; + + fnx = OffsetByteToFloat(nx); + fny = OffsetByteToFloat(ny); + fll = 1.0f - fnx * fnx - fny * fny; + if (fll >= 0.0f) + fnz = (float)sqrt(fll); + else + fnz = 0.0f; + + nz = FloatToOffsetByte(fnz); + + *outbyte++ = nx; + *outbyte++ = ny; + *outbyte++ = nz; + *outbyte++ = h; + } + } +} + + // size must be even #define WORKBLOCK_SIZE 128 #define WORKBLOCK_BORDER 4 #define WORKBLOCK_REALSIZE (WORKBLOCK_SIZE + WORKBLOCK_BORDER * 2) // assumes that data has already been expanded into a 2x2 grid -static void FCBIByBlock(byte *data, int width, int height, qboolean clampToEdge) +static void FCBIByBlock(byte *data, int width, int height, qboolean clampToEdge, qboolean normalized) { byte workdata[WORKBLOCK_REALSIZE * WORKBLOCK_REALSIZE * 4]; byte outdata[WORKBLOCK_REALSIZE * WORKBLOCK_REALSIZE * 4]; byte *inbyte, *outbyte; - int x, y, i; - int srcx, srcy, dstx, dsty; + int x, y; + int srcx, srcy; + + ExpandHalfTextureToGrid(data, width, height); for (y = 0; y < height; y += WORKBLOCK_SIZE) { @@ -749,42 +1059,79 @@ static void FCBIByBlock(byte *data, int width, int height, qboolean clampToEdge) // fill in work block for (y2 = 0; y2 < fullworkheight; y2 += 2) { + srcy = y + y2 - WORKBLOCK_BORDER; + + if (clampToEdge) + { + srcy = CLAMP(srcy, 0, height - 2); + } + else + { + srcy = (srcy + height) % height; + } + + outbyte = workdata + y2 * fullworkwidth * 4; + inbyte = data + srcy * width * 4; + for (x2 = 0; x2 < fullworkwidth; x2 += 2) { srcx = x + x2 - WORKBLOCK_BORDER; - srcy = y + y2 - WORKBLOCK_BORDER; - dstx = x2; - dsty = y2; if (clampToEdge) { srcx = CLAMP(srcx, 0, width - 2); - srcy = CLAMP(srcy, 0, height - 2); } else { - srcx = srcx % width; - srcy = srcy % height; + srcx = (srcx + width) % width; } - for (i = 0; i < 4; i++) - { - workdata[(dsty * fullworkwidth + dstx) * 4 + i] = data[(srcy * width + srcx) * 4 + i]; - } + COPYSAMPLE(outbyte, inbyte + srcx * 4); + outbyte += 8; } } // submit work block - if (r_imageUpsampleType->integer == 1) - DoFCBIQuick(workdata, outdata, fullworkwidth, fullworkheight); + DoLinear(workdata, outdata, fullworkwidth, fullworkheight); + + if (!normalized) + { + switch (r_imageUpsampleType->integer) + { + case 0: + break; + case 1: + DoFCBIQuick(workdata, outdata, fullworkwidth, fullworkheight, 0); + break; + case 2: + default: + DoFCBI(workdata, outdata, fullworkwidth, fullworkheight, 0); + break; + } + } else - DoFCBI(workdata, outdata, fullworkwidth, fullworkheight); + { + switch (r_imageUpsampleType->integer) + { + case 0: + break; + case 1: + DoFCBIQuick(workdata, outdata, fullworkwidth, fullworkheight, 0); + DoFCBIQuick(workdata, outdata, fullworkwidth, fullworkheight, 1); + break; + case 2: + default: + DoFCBI(workdata, outdata, fullworkwidth, fullworkheight, 0); + DoFCBI(workdata, outdata, fullworkwidth, fullworkheight, 1); + break; + } + } // copy back work block for (y2 = 0; y2 < workheight; y2++) { - inbyte = &outdata[((y2 + WORKBLOCK_BORDER) * fullworkwidth + WORKBLOCK_BORDER) * 4]; - outbyte = &data[((y + y2) * width + x) * 4]; + inbyte = outdata + ((y2 + WORKBLOCK_BORDER) * fullworkwidth + WORKBLOCK_BORDER) * 4; + outbyte = data + ((y + y2) * width + x) * 4; for (x2 = 0; x2 < workwidth; x2++) { COPYSAMPLE(outbyte, inbyte); @@ -912,6 +1259,48 @@ static void R_MipMap2( byte *in, int inWidth, int inHeight ) { ri.Hunk_FreeTempMemory( temp ); } + +static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) +{ + int i, j, k; + int outWidth, outHeight; + byte *temp; + + outWidth = inWidth >> 1; + outHeight = inHeight >> 1; + temp = ri.Hunk_AllocateTempMemory( outWidth * outHeight * 4 ); + + for ( i = 0 ; i < outHeight ; i++ ) { + byte *outbyte = temp + ( i * outWidth ) * 4; + byte *inbyte1 = in + ( i * 2 * inWidth ) * 4; + byte *inbyte2 = in + ( (i * 2 + 1) * inWidth ) * 4; + for ( j = 0 ; j < outWidth ; j++ ) { + for ( k = 0 ; k < 3 ; k++ ) { + float total, current; + + current = ByteToFloat(inbyte1[0]); total = sRGBtoRGB(current); + current = ByteToFloat(inbyte1[4]); total += sRGBtoRGB(current); + current = ByteToFloat(inbyte2[0]); total += sRGBtoRGB(current); + current = ByteToFloat(inbyte2[4]); total += sRGBtoRGB(current); + + total *= 0.25f; + + inbyte1++; + inbyte2++; + + current = RGBtosRGB(total); + *outbyte++ = FloatToByte(current); + } + *outbyte++ = (inbyte1[0] + inbyte1[4] + inbyte2[0] + inbyte2[4]) >> 2; + inbyte1 += 5; + inbyte2 += 5; + } + } + + Com_Memcpy( in, temp, outWidth * outHeight * 4 ); + ri.Hunk_FreeTempMemory( temp ); +} + /* ================ R_MipMap @@ -991,6 +1380,11 @@ static void R_MipMapNormalHeight (byte *in, int width, int height, qboolean swiz VectorNormalizeFast(v); + //v[0] *= 0.5f; + //v[1] *= 0.5f; + //v[2] = 1.0f - v[0] * v[0] - v[1] * v[1]; + //v[2] = sqrt(MAX(v[2], 0.0f)); + out[sx] = FloatToOffsetByte(v[0]); out[1 ] = FloatToOffsetByte(v[1]); out[2 ] = FloatToOffsetByte(v[2]); @@ -1021,6 +1415,11 @@ static void R_MipMapNormalHeight (byte *in, int width, int height, qboolean swiz VectorNormalizeFast(v); + //v[0] *= 0.25f; + //v[1] *= 0.25f; + //v[2] = 1.0f - v[0] * v[0] - v[1] * v[1]; + //v[2] = sqrt(MAX(v[2], 0.0f)); + out[sx] = FloatToOffsetByte(v[0]); out[1 ] = FloatToOffsetByte(v[1]); out[2 ] = FloatToOffsetByte(v[2]); @@ -1087,29 +1486,6 @@ static void RawImage_SwizzleRA( byte *data, int width, int height ) } } -#if 0 -static void RawImage_Normalize( byte *data, int width, int height, qboolean swizzle ) -{ - int i; - byte *ptr = data; - int s = swizzle ? 3 : 0; - - for (i=0; i scaled_width || height > scaled_height ) { - R_MipMap( (byte *)data, width, height ); + + if (flags & IMGFLAG_SRGB) + { + R_MipMapsRGB( (byte *)data, width, height ); + } + else + { + R_MipMap( (byte *)data, width, height ); + } + width >>= 1; height >>= 1; if ( width < 1 ) { @@ -1785,7 +2236,16 @@ void R_UpdateSubImage( image_t *image, byte *pic, int x, int y, int width, int h { // use the normal mip-mapping function to go down from here while ( width > scaled_width || height > scaled_height ) { - R_MipMap( (byte *)data, width, height ); + + if (image->flags & IMGFLAG_SRGB) + { + R_MipMapsRGB( (byte *)data, width, height ); + } + else + { + R_MipMap( (byte *)data, width, height ); + } + width >>= 1; height >>= 1; x >>= 1; @@ -1932,7 +2392,7 @@ Finds or loads the given image. Returns NULL if it fails, not a default image. ============== */ -image_t *R_FindImageFile2( const char *name, imgFlags_t flags ) +image_t *R_FindImageFile( const char *name, imgFlags_t flags ) { image_t *image; int width, height; @@ -1968,30 +2428,59 @@ image_t *R_FindImageFile2( const char *name, imgFlags_t flags ) return NULL; } + if (r_normalMapping->integer && !(flags & IMGFLAG_NORMALIZED) && (flags & IMGFLAG_PICMIP) && (flags & IMGFLAG_MIPMAP) && (flags & IMGFLAG_GENNORMALMAP)) + { + char normalName[MAX_QPATH]; + image_t *normalImage; + int normalWidth, normalHeight; + imgFlags_t normalFlags; + + normalFlags = (flags & ~(IMGFLAG_GENNORMALMAP | IMGFLAG_SRGB)) | IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE; + + COM_StripExtension(name, normalName, MAX_QPATH); + Q_strcat(normalName, MAX_QPATH, "_n"); + + // find normalmap in case it's there + normalImage = R_FindImageFile(normalName, normalFlags); + + // if not, generate it + if (normalImage == NULL) + { + byte *normalPic; + int x, y; + + normalWidth = width; + normalHeight = height; + normalPic = ri.Malloc(width * height * 4); + RGBAtoNormal(pic, normalPic, width, height, flags & IMGFLAG_CLAMPTOEDGE); + + // Brighten up the original image to work with the normal map + RGBAtoYCoCgA(pic, pic, width, height); + for (y = 0; y < height; y++) + { + byte *picbyte = pic + y * width * 4; + byte *normbyte = normalPic + y * width * 4; + for (x = 0; x < width; x++) + { + int div = MAX(normbyte[2] - 127, 16); + picbyte[0] = CLAMP(picbyte[0] * 128 / div, 0, 255); + picbyte += 4; + normbyte += 4; + } + } + YCoCgAtoRGBA(pic, pic, width, height); + + R_CreateImage2( normalName, normalPic, normalWidth, normalHeight, normalFlags, 0 ); + ri.Free( normalPic ); + } + } + image = R_CreateImage2( ( char * ) name, pic, width, height, flags, 0 ); ri.Free( pic ); return image; } -image_t *R_FindImageFile( const char *name, qboolean mipmap, qboolean allowPicmip, int glWrapClampMode ) { - imgFlags_t flags = IMGFLAG_NONE; - - flags = IMGFLAG_NONE; - - if (mipmap) - flags |= IMGFLAG_MIPMAP; - - if (allowPicmip) - flags |= IMGFLAG_PICMIP; - - if (glWrapClampMode == GL_CLAMP_TO_EDGE) - flags |= IMGFLAG_CLAMPTOEDGE; - - return R_FindImageFile2( name, flags ); -} - - /* ================ R_CreateDlightImage @@ -2224,12 +2713,21 @@ void R_CreateBuiltinImages( void ) { tr.godRaysImage = R_CreateImage2("*godRays", NULL, width, height, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8); #endif - tr.screenScratchImage = R_CreateImage2("*screenScratch", NULL, width, height, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8); + { + int format; + + if (glRefConfig.texture_srgb && glRefConfig.framebuffer_srgb) + format = GL_SRGB8_ALPHA8_EXT; + else + format = GL_RGBA8; + + tr.screenScratchImage = R_CreateImage2("*screenScratch", NULL, width, height, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, format); + } if (glRefConfig.framebufferObject) { tr.renderDepthImage = R_CreateImage2("*renderdepth", NULL, width, height, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24_ARB); - tr.textureDepthImage = R_CreateImage2("*texturedepth", NULL, 256, 256, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24_ARB); + tr.textureDepthImage = R_CreateImage2("*texturedepth", NULL, PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24_ARB); } { @@ -2269,7 +2767,7 @@ void R_CreateBuiltinImages( void ) { for( x = 0; x < MAX_DRAWN_PSHADOWS; x++) { - tr.pshadowMaps[x] = R_CreateImage2(va("*shadowmap%i", x), NULL, 256, 256, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8); + tr.pshadowMaps[x] = R_CreateImage2(va("*shadowmap%i", x), NULL, PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8); } } diff --git a/reaction/code/renderergl2/tr_init.c b/reaction/code/renderergl2/tr_init.c index b5696087..b11c9a15 100644 --- a/reaction/code/renderergl2/tr_init.c +++ b/reaction/code/renderergl2/tr_init.c @@ -34,6 +34,10 @@ glstate_t glState; static void GfxInfo_f( void ); static void GfxMemInfo_f( void ); +#ifdef USE_RENDERER_DLOPEN +cvar_t *com_altivec; +#endif + cvar_t *r_flareSize; cvar_t *r_flareFade; cvar_t *r_flareCoeff; @@ -107,6 +111,8 @@ cvar_t *r_postProcess; cvar_t *r_toneMap; cvar_t *r_autoExposure; +cvar_t *r_srgb; + cvar_t *r_normalMapping; cvar_t *r_specularMapping; cvar_t *r_deluxeMapping; @@ -119,6 +125,7 @@ cvar_t *r_pshadowDist; cvar_t *r_imageUpsample; cvar_t *r_imageUpsampleMaxSize; cvar_t *r_imageUpsampleType; +cvar_t *r_genNormalMaps; cvar_t *r_ignoreGLErrors; cvar_t *r_logFile; @@ -908,6 +915,11 @@ void GL_SetDefaultState( void ) glState.currentVBO = NULL; glState.currentIBO = NULL; + if (glRefConfig.framebuffer_srgb) + { + qglEnable(GL_FRAMEBUFFER_SRGB_EXT); + } + qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL); qglDepthMask( GL_TRUE ); qglDisable( GL_DEPTH_TEST ); @@ -1067,6 +1079,10 @@ R_Register */ void R_Register( void ) { + #ifdef USE_RENDERER_DLOPEN + com_altivec = ri.Cvar_Get("com_altivec", "1", CVAR_ARCHIVE); + #endif + // // latched and archived variables // @@ -1120,6 +1136,8 @@ void R_Register( void ) r_autoExposure = ri.Cvar_Get( "r_autoExposure", "1", CVAR_ARCHIVE ); r_cameraExposure = ri.Cvar_Get( "r_cameraExposure", "0", CVAR_CHEAT ); + r_srgb = ri.Cvar_Get( "r_srgb", "0", CVAR_ARCHIVE | CVAR_LATCH ); + r_normalMapping = ri.Cvar_Get( "r_normalMapping", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_specularMapping = ri.Cvar_Get( "r_specularMapping", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_deluxeMapping = ri.Cvar_Get( "r_deluxeMapping", "1", CVAR_ARCHIVE | CVAR_LATCH ); @@ -1132,6 +1150,7 @@ void R_Register( void ) r_imageUpsample = ri.Cvar_Get( "r_imageUpsample", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_imageUpsampleMaxSize = ri.Cvar_Get( "r_imageUpsampleMaxSize", "1024", CVAR_ARCHIVE | CVAR_LATCH ); r_imageUpsampleType = ri.Cvar_Get( "r_imageUpsampleType", "1", CVAR_ARCHIVE | CVAR_LATCH ); + r_genNormalMaps = ri.Cvar_Get( "r_genNormalMaps", "0", CVAR_ARCHIVE | CVAR_LATCH ); // // temporary latched variables that can only change over a restart diff --git a/reaction/code/renderergl2/tr_light.c b/reaction/code/renderergl2/tr_light.c index c77c84a7..cec6b295 100644 --- a/reaction/code/renderergl2/tr_light.c +++ b/reaction/code/renderergl2/tr_light.c @@ -442,7 +442,7 @@ int R_LightDirForPoint( vec3_t point, vec3_t lightDir, vec3_t normal, world_t *w VectorCopy( point, ent.e.origin ); R_SetupEntityLightingGrid( &ent, world ); - if ((DotProduct(ent.lightDir, ent.lightDir) < 0.9f) || (DotProduct(ent.lightDir, normal) < 0.3f)) + if ((DotProduct(ent.lightDir, ent.lightDir) < 0.9f) || (DotProduct(ent.lightDir, normal) < 0.1f)) { VectorCopy(normal, lightDir); } diff --git a/reaction/code/renderergl2/tr_local.h b/reaction/code/renderergl2/tr_local.h index 8a5ecbc8..ce9da5c7 100644 --- a/reaction/code/renderergl2/tr_local.h +++ b/reaction/code/renderergl2/tr_local.h @@ -66,6 +66,7 @@ typedef unsigned int glIndex_t; #define MAX_CALC_PSHADOWS 64 #define MAX_DRAWN_PSHADOWS 16 // do not increase past 32, because bit flags are used on surfaces +#define PSHADOW_MAP_SIZE 512 typedef struct dlight_s { vec3_t origin; @@ -116,6 +117,8 @@ typedef enum IMGFLAG_NORMALIZED = 0x0020, IMGFLAG_NOLIGHTSCALE = 0x0040, IMGFLAG_CLAMPTOEDGE = 0x0080, + IMGFLAG_SRGB = 0x0100, + IMGFLAG_GENNORMALMAP = 0x0200, } imgFlags_t; typedef struct image_s { @@ -940,6 +943,7 @@ typedef struct { qboolean isPortal; // true if this view is through a portal qboolean isMirror; // the portal is a mirror, invert the face culling qboolean isShadowmap; + qboolean isDepthShadow; int frameSceneNum; // copied from tr.frameSceneNum int frameCount; // copied from tr.frameCount cplane_t portalPlane; // clip anything behind this if mirroring @@ -1527,7 +1531,7 @@ the bits are allocated as follows: */ #define QSORT_FOGNUM_SHIFT 2 #define QSORT_ENTITYNUM_SHIFT 7 -#define QSORT_SHADERNUM_SHIFT (QSORT_ENTITYNUM_SHIFT+GENTITYNUM_BITS) +#define QSORT_SHADERNUM_SHIFT (QSORT_ENTITYNUM_SHIFT+ENTITYNUM_BITS) #if (QSORT_SHADERNUM_SHIFT+SHADERNUM_BITS) > 32 #error "Need to update sorting, too many bits." #endif @@ -1602,6 +1606,9 @@ typedef struct { qboolean framebufferMultisample; qboolean framebufferBlit; + + qboolean texture_srgb; + qboolean framebuffer_srgb; } glRefConfig_t; @@ -1660,6 +1667,7 @@ typedef struct { trRefEntity_t entity2D; // currentEntity will point at this when doing 2D rendering FBO_t *last2DFBO; + qboolean colorMask[4]; qboolean framePostProcessed; } backEndState_t; @@ -1965,6 +1973,8 @@ extern cvar_t *r_toneMap; extern cvar_t *r_autoExposure; extern cvar_t *r_cameraExposure; +extern cvar_t *r_srgb; + extern cvar_t *r_normalMapping; extern cvar_t *r_specularMapping; extern cvar_t *r_deluxeMapping; @@ -1977,6 +1987,7 @@ extern cvar_t *r_mergeLightmaps; extern cvar_t *r_imageUpsample; extern cvar_t *r_imageUpsampleMaxSize; extern cvar_t *r_imageUpsampleType; +extern cvar_t *r_genNormalMaps; extern cvar_t *r_greyscale; @@ -2109,8 +2120,7 @@ qboolean R_GetEntityToken( char *buffer, int size ); model_t *R_AllocModel( void ); void R_Init( void ); -image_t *R_FindImageFile( const char *name, qboolean mipmap, qboolean allowPicmip, int glWrapClampMode ); -image_t *R_FindImageFile2( const char *name, imgFlags_t flags ); +image_t *R_FindImageFile( const char *name, imgFlags_t flags ); image_t *R_CreateImage( const char *name, byte *pic, int width, int height, qboolean mipmap , qboolean allowPicmip, int wrapClampMode ); image_t *R_CreateImage2( const char *name, byte *pic, int width, int height, imgFlags_t flags, int internalFormat ); diff --git a/reaction/code/renderergl2/tr_main.c b/reaction/code/renderergl2/tr_main.c index ca1ee37d..db3d70d6 100644 --- a/reaction/code/renderergl2/tr_main.c +++ b/reaction/code/renderergl2/tr_main.c @@ -2100,9 +2100,9 @@ void R_RenderDlightCubemaps(const refdef_t *fd) Com_Memset( &shadowParms, 0, sizeof( shadowParms ) ); shadowParms.viewportX = tr.refdef.x; - shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + 256 ); - shadowParms.viewportWidth = 256; - shadowParms.viewportHeight = 256; + shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + PSHADOW_MAP_SIZE ); + shadowParms.viewportWidth = PSHADOW_MAP_SIZE; + shadowParms.viewportHeight = PSHADOW_MAP_SIZE; shadowParms.isPortal = qfalse; shadowParms.isMirror = qtrue; // because it is @@ -2110,6 +2110,7 @@ void R_RenderDlightCubemaps(const refdef_t *fd) shadowParms.fovY = 90; shadowParms.isShadowmap = qtrue; + shadowParms.isDepthShadow = qtrue; shadowParms.zFar = tr.refdef.dlights[i].radius; VectorCopy( tr.refdef.dlights[i].origin, shadowParms.or.origin ); @@ -2402,10 +2403,10 @@ void R_RenderPshadowMaps(const refdef_t *fd) else { shadowParms.viewportX = tr.refdef.x; - shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + 256 ); + shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + PSHADOW_MAP_SIZE ); } - shadowParms.viewportWidth = 256; - shadowParms.viewportHeight = 256; + shadowParms.viewportWidth = PSHADOW_MAP_SIZE; + shadowParms.viewportHeight = PSHADOW_MAP_SIZE; shadowParms.isPortal = qfalse; shadowParms.isMirror = qfalse; @@ -2416,6 +2417,7 @@ void R_RenderPshadowMaps(const refdef_t *fd) shadowParms.targetFbo = tr.pshadowFbos[i]; shadowParms.isShadowmap = qtrue; + shadowParms.isDepthShadow = qtrue; shadowParms.zFar = shadow->lightRadius; diff --git a/reaction/code/renderergl2/tr_postprocess.c b/reaction/code/renderergl2/tr_postprocess.c index 328a14d8..e3eb5f07 100644 --- a/reaction/code/renderergl2/tr_postprocess.c +++ b/reaction/code/renderergl2/tr_postprocess.c @@ -484,7 +484,7 @@ static void RB_VBlur(FBO_t *srcFbo, FBO_t *dstFbo, float strength) void RB_GaussianBlur(float blur) { - float mul = 1.f; + //float mul = 1.f; float factor = Com_Clamp(0.f, 1.f, blur); if (factor <= 0.f) diff --git a/reaction/code/renderergl2/tr_shade.c b/reaction/code/renderergl2/tr_shade.c index ccdf40f7..ef339d20 100644 --- a/reaction/code/renderergl2/tr_shade.c +++ b/reaction/code/renderergl2/tr_shade.c @@ -689,8 +689,8 @@ static void ComputeFogColorMask( shaderStage_t *pStage, vec4_t fogColorMask ) static void ForwardDlight( void ) { int l; - vec3_t origin; - float scale; + //vec3_t origin; + //float scale; float radius; int deformGen; @@ -721,15 +721,15 @@ static void ForwardDlight( void ) { } dl = &backEnd.refdef.dlights[l]; - VectorCopy( dl->transformed, origin ); + //VectorCopy( dl->transformed, origin ); radius = dl->radius; - scale = 1.0f / radius; + //scale = 1.0f / radius; //if (pStage->glslShaderGroup == tr.lightallShader) { int index = pStage->glslShaderIndex; - index &= ~(LIGHTDEF_USE_LIGHTMAP | LIGHTDEF_USE_DELUXEMAP); + index &= ~(LIGHTDEF_LIGHTTYPE_MASK | LIGHTDEF_USE_DELUXEMAP); index |= LIGHTDEF_USE_LIGHT_VECTOR; sp = &tr.lightallShader[index]; @@ -1399,7 +1399,7 @@ void RB_StageIteratorGeneric( void ) if ( tess.dlightBits && tess.shader->sort <= SS_OPAQUE && !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY) ) ) { if (tess.shader->numUnfoggedPasses == 1 && tess.xstages[0]->glslShaderGroup == tr.lightallShader - && r_dlightMode->integer) + && (tess.xstages[0]->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK) && r_dlightMode->integer) { ForwardDlight(); } diff --git a/reaction/code/renderergl2/tr_shader.c b/reaction/code/renderergl2/tr_shader.c index 9eda15ed..04651494 100644 --- a/reaction/code/renderergl2/tr_shader.c +++ b/reaction/code/renderergl2/tr_shader.c @@ -661,38 +661,25 @@ static qboolean ParseStage( shaderStage_t *stage, char **text ) flags |= IMGFLAG_PICMIP; if (stage->type == ST_NORMALMAP || stage->type == ST_NORMALPARALLAXMAP) + { flags |= IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE; + } + else + { + if (r_genNormalMaps->integer) + flags |= IMGFLAG_GENNORMALMAP; - stage->bundle[0].image[0] = R_FindImageFile2( token, flags ); + if (r_srgb->integer) + flags |= IMGFLAG_SRGB; + } + + stage->bundle[0].image[0] = R_FindImageFile( token, flags ); if ( !stage->bundle[0].image[0] ) { ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name ); return qfalse; } - - if (stage->type == ST_DIFFUSEMAP) - { - char filename[MAX_QPATH]; - //if ( r_autoFindNormalMap->integer ) - if ( r_normalMapping->integer ) - { - COM_StripExtension(token, filename, sizeof(filename)); - Q_strcat(filename, sizeof(filename), "_normal"); - - stage->bundle[TB_NORMALMAP].image[0] = R_FindImageFile2( filename, flags | IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE); - } - - //if ( r_autoFindSpecularMap->integer ) - if ( r_specularMapping->integer ) - { - COM_StripExtension(token, filename, sizeof(filename)); - Q_strcat(filename, sizeof(filename), "_specular"); - - stage->bundle[TB_SPECULARMAP].image[0] = R_FindImageFile2( filename, flags ); - stage->specularReflectance = 0.04f; - } - } } } // @@ -700,6 +687,8 @@ static qboolean ParseStage( shaderStage_t *stage, char **text ) // else if ( !Q_stricmp( token, "clampmap" ) ) { + imgFlags_t flags = IMGFLAG_CLAMPTOEDGE | IMGFLAG_SRGB; + token = COM_ParseExt( text, qfalse ); if ( !token[0] ) { @@ -707,7 +696,27 @@ static qboolean ParseStage( shaderStage_t *stage, char **text ) return qfalse; } - stage->bundle[0].image[0] = R_FindImageFile( token, !shader.noMipMaps, !shader.noPicMip, GL_CLAMP_TO_EDGE ); + if (!shader.noMipMaps) + flags |= IMGFLAG_MIPMAP; + + if (!shader.noPicMip) + flags |= IMGFLAG_PICMIP; + + if (stage->type == ST_NORMALMAP || stage->type == ST_NORMALPARALLAXMAP) + { + flags |= IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE; + } + else + { + if (r_genNormalMaps->integer) + flags |= IMGFLAG_GENNORMALMAP; + + if (r_srgb->integer) + flags |= IMGFLAG_SRGB; + } + + + stage->bundle[0].image[0] = R_FindImageFile( token, flags ); if ( !stage->bundle[0].image[0] ) { ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name ); @@ -737,7 +746,15 @@ static qboolean ParseStage( shaderStage_t *stage, char **text ) } num = stage->bundle[0].numImageAnimations; if ( num < MAX_IMAGE_ANIMATIONS ) { - stage->bundle[0].image[num] = R_FindImageFile( token, !shader.noMipMaps, !shader.noPicMip, GL_REPEAT ); + imgFlags_t flags = IMGFLAG_SRGB; + + if (!shader.noMipMaps) + flags |= IMGFLAG_MIPMAP; + + if (!shader.noPicMip) + flags |= IMGFLAG_PICMIP; + + stage->bundle[0].image[num] = R_FindImageFile( token, flags ); if ( !stage->bundle[0].image[num] ) { ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name ); @@ -1356,7 +1373,7 @@ static void ParseSkyParms( char **text ) { for (i=0 ; i<6 ; i++) { Com_sprintf( pathname, sizeof(pathname), "%s_%s.tga" , token, suf[i] ); - shader.sky.outerbox[i] = R_FindImageFile( ( char * ) pathname, qtrue, qtrue, GL_CLAMP_TO_EDGE ); + shader.sky.outerbox[i] = R_FindImageFile( ( char * ) pathname, IMGFLAG_SRGB | IMGFLAG_MIPMAP | IMGFLAG_PICMIP | IMGFLAG_CLAMPTOEDGE ); if ( !shader.sky.outerbox[i] ) { shader.sky.outerbox[i] = tr.defaultImage; @@ -1387,7 +1404,7 @@ static void ParseSkyParms( char **text ) { for (i=0 ; i<6 ; i++) { Com_sprintf( pathname, sizeof(pathname), "%s_%s.tga" , token, suf[i] ); - shader.sky.innerbox[i] = R_FindImageFile( ( char * ) pathname, qtrue, qtrue, GL_REPEAT ); + shader.sky.innerbox[i] = R_FindImageFile( ( char * ) pathname, IMGFLAG_SRGB | IMGFLAG_MIPMAP | IMGFLAG_PICMIP ); if ( !shader.sky.innerbox[i] ) { shader.sky.innerbox[i] = tr.defaultImage; } @@ -2119,6 +2136,7 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse, if (r_normalMapping->integer) { + image_t *diffuseImg; if (normal) { //ri.Printf(PRINT_ALL, ", normalmap %s", normal->bundle[0].image[0]->imgName); @@ -2127,12 +2145,26 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse, if (parallax && r_parallaxMapping->integer) defs |= LIGHTDEF_USE_PARALLAXMAP; } - else if (diffuse->bundle[TB_NORMALMAP].image[0]) + else if ((lightmap || useLightVector || useLightVertex) && (diffuseImg = diffuse->bundle[TB_DIFFUSEMAP].image[0])) { - image_t *tmpImg = diffuse->bundle[TB_NORMALMAP].image[0]; - diffuse->bundle[TB_NORMALMAP] = diffuse->bundle[TB_DIFFUSEMAP]; - diffuse->bundle[TB_NORMALMAP].image[0] = tmpImg; - defs |= LIGHTDEF_USE_NORMALMAP; + char normalName[MAX_QPATH]; + image_t *normalImg; + imgFlags_t normalFlags = (diffuseImg->flags & ~(IMGFLAG_GENNORMALMAP | IMGFLAG_SRGB)) | IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE; + + COM_StripExtension(diffuseImg->imgName, normalName, MAX_QPATH); + Q_strcat(normalName, MAX_QPATH, "_n"); + + normalImg = R_FindImageFile(normalName, normalFlags); + + if (normalImg) + { + diffuse->bundle[TB_NORMALMAP] = diffuse->bundle[0]; + diffuse->bundle[TB_NORMALMAP].image[0] = normalImg; + + defs |= LIGHTDEF_USE_NORMALMAP; + if (parallax && r_parallaxMapping->integer) + defs |= LIGHTDEF_USE_PARALLAXMAP; + } } } @@ -2145,13 +2177,6 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse, diffuse->specularReflectance = specular->specularReflectance; defs |= LIGHTDEF_USE_SPECULARMAP; } - else if (diffuse->bundle[TB_SPECULARMAP].image[0]) - { - image_t *tmpImg = diffuse->bundle[TB_SPECULARMAP].image[0]; - diffuse->bundle[TB_SPECULARMAP] = diffuse->bundle[TB_DIFFUSEMAP]; - diffuse->bundle[TB_SPECULARMAP].image[0] = tmpImg; - defs |= LIGHTDEF_USE_SPECULARMAP; - } } if (environment) @@ -3062,11 +3087,32 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag // if not defined in the in-memory shader descriptions, // look for a single supported image file // - image = R_FindImageFile( name, mipRawImage, mipRawImage, mipRawImage ? GL_REPEAT : GL_CLAMP_TO_EDGE ); - if ( !image ) { - ri.Printf( PRINT_DEVELOPER, "Couldn't find image file for shader %s\n", name ); - shader.defaultShader = qtrue; - return FinishShader(); + { + imgFlags_t flags; + + flags = IMGFLAG_NONE; + + if (r_srgb->integer) + flags |= IMGFLAG_SRGB; + + if (mipRawImage) + { + flags |= IMGFLAG_MIPMAP | IMGFLAG_PICMIP; + + if (r_genNormalMaps->integer) + flags |= IMGFLAG_GENNORMALMAP; + } + else + { + flags |= IMGFLAG_CLAMPTOEDGE; + } + + image = R_FindImageFile( name, flags ); + if ( !image ) { + ri.Printf( PRINT_DEVELOPER, "Couldn't find image file for shader %s\n", name ); + shader.defaultShader = qtrue; + return FinishShader(); + } } // diff --git a/reaction/code/renderergl2/tr_surface.c b/reaction/code/renderergl2/tr_surface.c index bd9c9fd3..c9cc7b09 100644 --- a/reaction/code/renderergl2/tr_surface.c +++ b/reaction/code/renderergl2/tr_surface.c @@ -1599,8 +1599,8 @@ static void RB_SurfaceVBOMesh(srfVBOMesh_t * srf) void RB_SurfaceVBOMDVMesh(srfVBOMDVMesh_t * surface) { - mdvModel_t *mdvModel; - mdvSurface_t *mdvSurface; + //mdvModel_t *mdvModel; + //mdvSurface_t *mdvSurface; refEntity_t *refEnt; GLimp_LogComment("--- RB_SurfaceVBOMDVMesh ---\n"); @@ -1620,8 +1620,8 @@ void RB_SurfaceVBOMDVMesh(srfVBOMDVMesh_t * surface) tess.numIndexes += surface->numIndexes; tess.numVertexes += surface->numVerts; - mdvModel = surface->mdvModel; - mdvSurface = surface->mdvSurface; + //mdvModel = surface->mdvModel; + //mdvSurface = surface->mdvSurface; refEnt = &backEnd.currentEntity->e;