]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_backend.c
Travis: Force XInput and XRandR support.
[xonotic/darkplaces.git] / gl_backend.c
index bc13cd7ab5c43ec7c123e59d132169ad13f8bbee..663c5f86fe951f11bd330836e659a0a3acb51cb8 100644 (file)
@@ -2,77 +2,6 @@
 #include "quakedef.h"
 #include "cl_collision.h"
 
-// on GLES we have to use some proper #define's
-#ifndef GL_FRAMEBUFFER
-#define GL_FRAMEBUFFER                                   0x8D40
-#define GL_DEPTH_ATTACHMENT                              0x8D00
-#define GL_COLOR_ATTACHMENT0                             0x8CE0
-#define GL_INVALID_FRAMEBUFFER_OPERATION                 0x0506
-#endif
-#ifndef GL_COLOR_ATTACHMENT1
-#define GL_COLOR_ATTACHMENT1                             0x8CE1
-#define GL_COLOR_ATTACHMENT2                             0x8CE2
-#define GL_COLOR_ATTACHMENT3                             0x8CE3
-#define GL_COLOR_ATTACHMENT4                             0x8CE4
-#define GL_COLOR_ATTACHMENT5                             0x8CE5
-#define GL_COLOR_ATTACHMENT6                             0x8CE6
-#define GL_COLOR_ATTACHMENT7                             0x8CE7
-#define GL_COLOR_ATTACHMENT8                             0x8CE8
-#define GL_COLOR_ATTACHMENT9                             0x8CE9
-#define GL_COLOR_ATTACHMENT10                            0x8CEA
-#define GL_COLOR_ATTACHMENT11                            0x8CEB
-#define GL_COLOR_ATTACHMENT12                            0x8CEC
-#define GL_COLOR_ATTACHMENT13                            0x8CED
-#define GL_COLOR_ATTACHMENT14                            0x8CEE
-#define GL_COLOR_ATTACHMENT15                            0x8CEF
-#endif
-#ifndef GL_ARRAY_BUFFER
-#define GL_ARRAY_BUFFER               0x8892
-#define GL_ELEMENT_ARRAY_BUFFER       0x8893
-#endif
-#ifndef GL_TEXTURE0
-#define GL_TEXTURE0                                    0x84C0
-#define GL_TEXTURE1                                    0x84C1
-#define GL_TEXTURE2                                    0x84C2
-#define GL_TEXTURE3                                    0x84C3
-#define GL_TEXTURE4                                    0x84C4
-#define GL_TEXTURE5                                    0x84C5
-#define GL_TEXTURE6                                    0x84C6
-#define GL_TEXTURE7                                    0x84C7
-#define GL_TEXTURE8                                    0x84C8
-#define GL_TEXTURE9                                    0x84C9
-#define GL_TEXTURE10                           0x84CA
-#define GL_TEXTURE11                           0x84CB
-#define GL_TEXTURE12                           0x84CC
-#define GL_TEXTURE13                           0x84CD
-#define GL_TEXTURE14                           0x84CE
-#define GL_TEXTURE15                           0x84CF
-#define GL_TEXTURE16                           0x84D0
-#define GL_TEXTURE17                           0x84D1
-#define GL_TEXTURE18                           0x84D2
-#define GL_TEXTURE19                           0x84D3
-#define GL_TEXTURE20                           0x84D4
-#define GL_TEXTURE21                           0x84D5
-#define GL_TEXTURE22                           0x84D6
-#define GL_TEXTURE23                           0x84D7
-#define GL_TEXTURE24                           0x84D8
-#define GL_TEXTURE25                           0x84D9
-#define GL_TEXTURE26                           0x84DA
-#define GL_TEXTURE27                           0x84DB
-#define GL_TEXTURE28                           0x84DC
-#define GL_TEXTURE29                           0x84DD
-#define GL_TEXTURE30                           0x84DE
-#define GL_TEXTURE31                           0x84DF
-#endif
-
-#ifndef GL_TEXTURE_3D
-#define GL_TEXTURE_3D                          0x806F
-#endif
-#ifndef GL_TEXTURE_CUBE_MAP
-#define GL_TEXTURE_CUBE_MAP                0x8513
-#endif
-
-
 #define MAX_RENDERTARGETS 4
 
 cvar_t gl_debug = {0, "gl_debug", "0", "enables OpenGL debug output, 0 = off, 1 = HIGH severity only, 2 = also MEDIUM severity, 3 = also LOW severity messages.  (note: enabling may not take effect until vid_restart on some drivers)"};
@@ -97,9 +26,6 @@ float gl_modelview16f[16];
 float gl_modelviewprojection16f[16];
 qboolean gl_modelmatrixchanged;
 
-int gl_maxdrawrangeelementsvertices;
-int gl_maxdrawrangeelementsindices;
-
 #ifdef DEBUGGL
 int gl_errornumber = 0;
 
@@ -230,6 +156,9 @@ typedef struct gl_state_s
        int defaultframebufferobject; // deal with platforms that use a non-zero default fbo
        qboolean pointer_color_enabled;
 
+       // GL3.2 Core requires that we have a GL_VERTEX_ARRAY_OBJECT, but... just one.
+       unsigned int defaultvao;
+
        int pointer_vertex_components;
        int pointer_vertex_gltype;
        size_t pointer_vertex_stride;
@@ -333,17 +262,21 @@ static void gl_backend_start(void)
 
        CHECKGLERROR
 
-       GL_Backend_ResetState();
-
        switch(vid.renderpath)
        {
        case RENDERPATH_GL32:
+               // GL3.2 Core requires that we have a VAO bound - but using more than one has no performance benefit so this is just placeholder
+               qglGenVertexArrays(1, &gl_state.defaultvao);
+               qglBindVertexArray(gl_state.defaultvao);
+               // fall through
        case RENDERPATH_GLES2:
                // fetch current fbo here (default fbo is not 0 on some GLES devices)
                CHECKGLERROR
                qglGetIntegerv(GL_FRAMEBUFFER_BINDING, &gl_state.defaultframebufferobject);CHECKGLERROR
                break;
        }
+
+       GL_Backend_ResetState();
 }
 
 static void gl_backend_shutdown(void)
@@ -1061,27 +994,27 @@ int R_Mesh_CreateFramebufferObject(rtexture_t *depthtexture, rtexture_t *colorte
                if (colortexture4 && colortexture4->renderbuffernum) qglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3 , GL_RENDERBUFFER, colortexture4->renderbuffernum);CHECKGLERROR
 
 #ifndef USE_GLES2
-               if (colortexture4 && qglDrawBuffersARB)
+               if (colortexture4)
                {
-                       qglDrawBuffersARB(4, drawbuffers);CHECKGLERROR
+                       qglDrawBuffers(4, drawbuffers);CHECKGLERROR
                        qglReadBuffer(GL_NONE);CHECKGLERROR
                }
-               else if (colortexture3 && qglDrawBuffersARB)
+               else if (colortexture3)
                {
-                       qglDrawBuffersARB(3, drawbuffers);CHECKGLERROR
+                       qglDrawBuffers(3, drawbuffers);CHECKGLERROR
                        qglReadBuffer(GL_NONE);CHECKGLERROR
                }
-               else if (colortexture2 && qglDrawBuffersARB)
+               else if (colortexture2)
                {
-                       qglDrawBuffersARB(2, drawbuffers);CHECKGLERROR
+                       qglDrawBuffers(2, drawbuffers);CHECKGLERROR
                        qglReadBuffer(GL_NONE);CHECKGLERROR
                }
-               else if (colortexture && qglDrawBuffer)
+               else if (colortexture)
                {
                        qglDrawBuffer(GL_COLOR_ATTACHMENT0);CHECKGLERROR
                        qglReadBuffer(GL_COLOR_ATTACHMENT0);CHECKGLERROR
                }
-               else if (qglDrawBuffer)
+               else
                {
                        qglDrawBuffer(GL_NONE);CHECKGLERROR
                        qglReadBuffer(GL_NONE);CHECKGLERROR
@@ -1452,18 +1385,18 @@ void GL_AlphaToCoverage(qboolean state)
                case RENDERPATH_GLES2:
                        break;
                case RENDERPATH_GL32:
-#ifdef GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
+#ifndef USE_GLES2
                        // alpha to coverage turns the alpha value of the pixel into 0%, 25%, 50%, 75% or 100% by masking the multisample fragments accordingly
                        CHECKGLERROR
                        if (gl_state.alphatocoverage)
                        {
-                               qglEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);CHECKGLERROR
-//                             qglEnable(GL_MULTISAMPLE_ARB);CHECKGLERROR
+                               qglEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);CHECKGLERROR
+//                             qglEnable(GL_MULTISAMPLE);CHECKGLERROR
                        }
                        else
                        {
-                               qglDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);CHECKGLERROR
-//                             qglDisable(GL_MULTISAMPLE_ARB);CHECKGLERROR
+                               qglDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);CHECKGLERROR
+//                             qglDisable(GL_MULTISAMPLE);CHECKGLERROR
                        }
 #endif
                        break;
@@ -2194,9 +2127,12 @@ void R_Mesh_PrepareVertices_Generic_Arrays(int numvertices, const float *vertex3
        int bufferoffset_vertex3f = 0;
        int bufferoffset_color4f = 0;
        int bufferoffset_texcoord2f = 0;
-       buffer_color4f    = R_BufferData_Store(numvertices * sizeof(float[4]), color4f   , R_BUFFERDATA_VERTEX, &bufferoffset_color4f   );
-       buffer_vertex3f   = R_BufferData_Store(numvertices * sizeof(float[3]), vertex3f  , R_BUFFERDATA_VERTEX, &bufferoffset_vertex3f  );
-       buffer_texcoord2f = R_BufferData_Store(numvertices * sizeof(float[2]), texcoord2f, R_BUFFERDATA_VERTEX, &bufferoffset_texcoord2f);
+       if (color4f)
+               buffer_color4f    = R_BufferData_Store(numvertices * sizeof(float[4]), color4f   , R_BUFFERDATA_VERTEX, &bufferoffset_color4f   );
+       if (vertex3f)
+               buffer_vertex3f   = R_BufferData_Store(numvertices * sizeof(float[3]), vertex3f  , R_BUFFERDATA_VERTEX, &bufferoffset_vertex3f  );
+       if (texcoord2f)
+               buffer_texcoord2f = R_BufferData_Store(numvertices * sizeof(float[2]), texcoord2f, R_BUFFERDATA_VERTEX, &bufferoffset_texcoord2f);
        R_Mesh_VertexPointer(     3, GL_FLOAT        , sizeof(float[3])        , vertex3f          , buffer_vertex3f          , bufferoffset_vertex3f          );
        R_Mesh_ColorPointer(      4, GL_FLOAT        , sizeof(float[4])        , color4f           , buffer_color4f           , bufferoffset_color4f           );
        R_Mesh_TexCoordPointer(0, 2, GL_FLOAT        , sizeof(float[2])        , texcoord2f        , buffer_texcoord2f        , bufferoffset_texcoord2f        );
@@ -2225,13 +2161,20 @@ void R_Mesh_PrepareVertices_Mesh_Arrays(int numvertices, const float *vertex3f,
        int bufferoffset_tvector3f = 0;
        int bufferoffset_normal3f = 0;
        int bufferoffset_texcoordlightmap2f = 0;
-       buffer_color4f            = R_BufferData_Store(numvertices * sizeof(float[4]), color4f           , R_BUFFERDATA_VERTEX, &bufferoffset_color4f           );
-       buffer_vertex3f           = R_BufferData_Store(numvertices * sizeof(float[3]), vertex3f          , R_BUFFERDATA_VERTEX, &bufferoffset_vertex3f          );
-       buffer_svector3f          = R_BufferData_Store(numvertices * sizeof(float[3]), svector3f         , R_BUFFERDATA_VERTEX, &bufferoffset_svector3f         );
-       buffer_tvector3f          = R_BufferData_Store(numvertices * sizeof(float[3]), tvector3f         , R_BUFFERDATA_VERTEX, &bufferoffset_tvector3f         );
-       buffer_normal3f           = R_BufferData_Store(numvertices * sizeof(float[3]), normal3f          , R_BUFFERDATA_VERTEX, &bufferoffset_normal3f          );
-       buffer_texcoordtexture2f  = R_BufferData_Store(numvertices * sizeof(float[2]), texcoordtexture2f , R_BUFFERDATA_VERTEX, &bufferoffset_texcoordtexture2f );
-       buffer_texcoordlightmap2f = R_BufferData_Store(numvertices * sizeof(float[2]), texcoordlightmap2f, R_BUFFERDATA_VERTEX, &bufferoffset_texcoordlightmap2f);
+       if (color4f)
+               buffer_color4f            = R_BufferData_Store(numvertices * sizeof(float[4]), color4f           , R_BUFFERDATA_VERTEX, &bufferoffset_color4f           );
+       if (vertex3f)
+               buffer_vertex3f           = R_BufferData_Store(numvertices * sizeof(float[3]), vertex3f          , R_BUFFERDATA_VERTEX, &bufferoffset_vertex3f          );
+       if (svector3f)
+               buffer_svector3f          = R_BufferData_Store(numvertices * sizeof(float[3]), svector3f         , R_BUFFERDATA_VERTEX, &bufferoffset_svector3f         );
+       if (tvector3f)
+               buffer_tvector3f          = R_BufferData_Store(numvertices * sizeof(float[3]), tvector3f         , R_BUFFERDATA_VERTEX, &bufferoffset_tvector3f         );
+       if (normal3f)
+               buffer_normal3f           = R_BufferData_Store(numvertices * sizeof(float[3]), normal3f          , R_BUFFERDATA_VERTEX, &bufferoffset_normal3f          );
+       if (texcoordtexture2f)
+               buffer_texcoordtexture2f  = R_BufferData_Store(numvertices * sizeof(float[2]), texcoordtexture2f , R_BUFFERDATA_VERTEX, &bufferoffset_texcoordtexture2f );
+       if (texcoordlightmap2f)
+               buffer_texcoordlightmap2f = R_BufferData_Store(numvertices * sizeof(float[2]), texcoordlightmap2f, R_BUFFERDATA_VERTEX, &bufferoffset_texcoordlightmap2f);
        R_Mesh_VertexPointer(     3, GL_FLOAT        , sizeof(float[3])        , vertex3f          , buffer_vertex3f          , bufferoffset_vertex3f          );
        R_Mesh_ColorPointer(      4, GL_FLOAT        , sizeof(float[4])        , color4f           , buffer_color4f           , bufferoffset_color4f           );
        R_Mesh_TexCoordPointer(0, 2, GL_FLOAT        , sizeof(float[2])        , texcoordtexture2f , buffer_texcoordtexture2f , bufferoffset_texcoordtexture2f );
@@ -2253,7 +2196,7 @@ void GL_BlendEquationSubtract(qboolean negated)
                {
                case RENDERPATH_GL32:
                case RENDERPATH_GLES2:
-                       qglBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT);CHECKGLERROR
+                       qglBlendEquation(GL_FUNC_REVERSE_SUBTRACT);CHECKGLERROR
                        break;
                }
        }
@@ -2263,7 +2206,7 @@ void GL_BlendEquationSubtract(qboolean negated)
                {
                case RENDERPATH_GL32:
                case RENDERPATH_GLES2:
-                       qglBlendEquationEXT(GL_FUNC_ADD);CHECKGLERROR
+                       qglBlendEquation(GL_FUNC_ADD);CHECKGLERROR
                        break;
                }
        }