Finally, found a fix for the GL API errors on Linux

Bugs that have been resolved.

Moderator: Graf Zahl

User avatar
Saya-chan
Posts: 10
Joined: Mon Dec 26, 2011 16:48
Location: Vigo, Galicia
Contact:

Finally, found a fix for the GL API errors on Linux

Post by Saya-chan »

(Sorry in advance for any bad English)

The problem is actually that glBlendEquation, glActiveTexture, glMultiTexCoord2f and glMultiTexCoord2v are not "extensions" anymore in the latest versions of Mesa, so basically removing all the code involved in "loading" them is the actual fix to this issue (then again, this might be system-specific, so I think it'd be best kept as an optional patch).

Here's the patch (it's just commenting out a lot of lines):

Code: Select all

diff --git a/src/gl/api/gl_api.h b/src/gl/api/gl_api.h
index bcb03c4..992c768 100644
--- a/src/gl/api/gl_api.h
+++ b/src/gl/api/gl_api.h
@@ -7,7 +7,7 @@
 #define __EXTERN extern
 #endif
 
-__EXTERN PFNGLBLENDEQUATIONPROC glBlendEquation;
+//__EXTERN PFNGLBLENDEQUATIONPROC glBlendEquation;
 
 // ARB_SHADER_OBJECTS
 __EXTERN PFNGLDELETESHADERPROC glDeleteShader;
@@ -67,9 +67,9 @@ __EXTERN PFNGLBEGINQUERYARBPROC glBeginQuery;
 __EXTERN PFNGLENDQUERYARBPROC glEndQuery;
 __EXTERN PFNGLGETQUERYOBJECTUIVARBPROC glGetQueryObjectuiv;
 
-__EXTERN PFNGLACTIVETEXTUREPROC glActiveTexture;
-__EXTERN PFNGLMULTITEXCOORD2FPROC glMultiTexCoord2f;
-__EXTERN PFNGLMULTITEXCOORD2FVPROC glMultiTexCoord2fv;
+//__EXTERN PFNGLACTIVETEXTUREPROC glActiveTexture;
+//__EXTERN PFNGLMULTITEXCOORD2FPROC glMultiTexCoord2f;
+//__EXTERN PFNGLMULTITEXCOORD2FVPROC glMultiTexCoord2fv;
 
 __EXTERN PFNGLBINDBUFFERPROC glBindBuffer;
 __EXTERN PFNGLDELETEBUFFERSPROC glDeleteBuffers;
diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp
index cadab5a..54bc5bb 100644
--- a/src/gl/system/gl_interface.cpp
+++ b/src/gl/system/gl_interface.cpp
@@ -117,7 +117,7 @@ static bool CheckExtension(const char *ext)
 static void InitContext()
 {
 	gl.flags=0;
-	glBlendEquation = glBlendEquationDummy;
+	//glBlendEquation = glBlendEquationDummy;
 }
 
 //==========================================================================
@@ -152,11 +152,11 @@ void gl_LoadExtensions()
 	gl.vendorstring=(char*)glGetString(GL_VENDOR);
 
 	// First try the regular function
-	glBlendEquation = (PFNGLBLENDEQUATIONPROC)wglGetProcAddress("glBlendEquation");
+	//glBlendEquation = (PFNGLBLENDEQUATIONPROC)wglGetProcAddress("glBlendEquation");
 	// If that fails try the EXT version
-	if (!glBlendEquation) glBlendEquation = (PFNGLBLENDEQUATIONPROC)wglGetProcAddress("glBlendEquationEXT");
+	//if (!glBlendEquation) glBlendEquation = (PFNGLBLENDEQUATIONPROC)wglGetProcAddress("glBlendEquationEXT");
 	// If that fails use a no-op dummy
-	if (!glBlendEquation) glBlendEquation = glBlendEquationDummy;
+	//if (!glBlendEquation) glBlendEquation = glBlendEquationDummy;
 
 	if (CheckExtension("GL_ARB_texture_non_power_of_two")) gl.flags|=RFL_NPOT_TEXTURE;
 	if (CheckExtension("GL_ARB_texture_compression")) gl.flags|=RFL_TEXTURE_COMPRESSION;
@@ -318,9 +318,9 @@ void gl_LoadExtensions()
 
 
 
-	glActiveTexture = (PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTextureARB");
-	glMultiTexCoord2f = (PFNGLMULTITEXCOORD2FPROC) wglGetProcAddress("glMultiTexCoord2fARB");
-	glMultiTexCoord2fv = (PFNGLMULTITEXCOORD2FVPROC) wglGetProcAddress("glMultiTexCoord2fvARB");
+	//glActiveTexture = (PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTextureARB");
+	//glMultiTexCoord2f = (PFNGLMULTITEXCOORD2FPROC) wglGetProcAddress("glMultiTexCoord2fARB");
+	//glMultiTexCoord2fv = (PFNGLMULTITEXCOORD2FVPROC) wglGetProcAddress("glMultiTexCoord2fvARB");
 }
 
 //==========================================================================
PS: src/gl/system/gl_framebuffer.cpp was saved in UTF-16 and makes GCC freak out unless I convert the file to UTF-8.
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Finally, found a fix for the GL API errors on Linux

Post by Graf Zahl »

So you 'fixed' it by commenting out some stuff that's actually needed. Yes, right. That compiles on Linux but not on Windows!
Sorry, can't use.
User avatar
Gez
Developer
Developer
Posts: 1399
Joined: Mon Oct 22, 2007 16:47

Re: Finally, found a fix for the GL API errors on Linux

Post by Gez »

It can be #ifdefed I suppose. Is there a define set allowing to know if Mesa is used and which version of it?
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Finally, found a fix for the GL API errors on Linux

Post by Graf Zahl »

I won't act on this unless I get a patch that was APPROVED by multiple Linux users and still works on Windows. Don't forget that I cannot test this!
Edward-san
Developer
Developer
Posts: 197
Joined: Sun Nov 29, 2009 16:36

Re: Finally, found a fix for the GL API errors on Linux

Post by Edward-san »

The latest commit by alexey did not fix at all the problem.

So, I did something else:

Code: Select all

diff --git a/src/gl/system/gl_system.h b/src/gl/system/gl_system.h
index 8a0c307..7ba7878 100644
--- a/src/gl/system/gl_system.h
+++ b/src/gl/system/gl_system.h
@@ -66,8 +66,9 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__unix__)
 #include <GL/glew.h>
+#elif defined(__APPLE__)
 #include <OpenGL/OpenGL.h>
 #else // !__APPLE__
 #include <GL/gl.h>
and this shut up the error, but then I get this error in src/gl/system/gl_interface.cpp:

gcc:

Code: Select all

/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:56:22: error: expected initializer before ‘glBlendEquationDummy’
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp: In function ‘void InitContext()’:
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:129:20: error: ‘glBlendEquationDummy’ was not declared in this scope
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp: In function ‘void gl_LoadExtensions()’:
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:168:42: error: ‘glBlendEquationDummy’ was not declared in this scope
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp: At global scope:
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:372:22: error: expected initializer before ‘glBlendEquationDummy’
clang:

Code: Select all

/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:56:13: error: 
      variable has incomplete type 'void'
static void APIENTRY glBlendEquationDummy (GLenum mode);
            ^
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:56:21: error: 
      expected ';' after top level declarator
static void APIENTRY glBlendEquationDummy (GLenum mode);
                    ^
                    ;
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:129:20: error: 
      use of undeclared identifier 'glBlendEquationDummy'
        glBlendEquation = glBlendEquationDummy;
                          ^
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:168:42: error: 
      use of undeclared identifier 'glBlendEquationDummy'
        if (!glBlendEquation) glBlendEquation = glBlendEquationDummy;
                                                ^
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:372:13: error: 
      variable has incomplete type 'void'
static void APIENTRY glBlendEquationDummy (GLenum mode)
            ^
/home/edward-san/zdoom/gzdoom/trunk/src/gl/system/gl_interface.cpp:372:21: error: 
      expected ';' after top level declarator
static void APIENTRY glBlendEquationDummy (GLenum mode)
                    ^
                    ;
6 errors generated.
so APIENTRY is defined to something I have no idea ...
Edward-san
Developer
Developer
Posts: 197
Joined: Sun Nov 29, 2009 16:36

Re: Finally, found a fix for the GL API errors on Linux

Post by Edward-san »

I did more experiments:

Code: Select all

diff --git a/src/gl/api/gl_api.h b/src/gl/api/gl_api.h
index bcb03c4..8cfbdc5 100644
--- a/src/gl/api/gl_api.h
+++ b/src/gl/api/gl_api.h
@@ -1,4 +1,4 @@
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__unix__)
 #define APIENTRY
 #define APIENTRYP *
 #endif // __APPLE__
diff --git a/src/gl/system/gl_system.h b/src/gl/system/gl_system.h
index 8a0c307..7ba7878 100644
--- a/src/gl/system/gl_system.h
+++ b/src/gl/system/gl_system.h
@@ -66,8 +66,9 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__unix__)
 #include <GL/glew.h>
+#elif defined(__APPLE__)
 #include <OpenGL/OpenGL.h>
 #else // !__APPLE__
 #include <GL/gl.h>
With this I managed to compile, but when I run gzdoom, I get this:

Code: Select all

Init Shader 'Default::colormapDefault::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Warp 1::colormapWarp 1::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Warp 2::colormapWarp 2::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Brightmap::colormapBrightmap::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'No Texture::colormapNo Texture::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Basic Fuzz::colormapBasic Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Smooth Fuzz::colormapSmooth Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Swirly Fuzz::colormapSwirly Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Translucent Fuzz::colormapTranslucent Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Jagged Fuzz::colormapJagged Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Noise Fuzz::colormapNoise Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Smooth Noise Fuzz::colormapSmooth Noise Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Resolution: 800 x 500
Init Shader 'Default::colormapDefault::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Warp 1::colormapWarp 1::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Playing /tmp/zmidd1VcJB
MIDI file: /tmp/zmidd1VcJB
Format: 0  Tracks: 1  Divisions: 140
Init Shader 'Warp 2::colormapWarp 2::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Brightmap::colormapBrightmap::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'No Texture::colormapNo Texture::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Basic Fuzz::colormapBasic Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Smooth Fuzz::colormapSmooth Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Swirly Fuzz::colormapSwirly Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Translucent Fuzz::colormapTranslucent Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Jagged Fuzz::colormapJagged Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Noise Fuzz::colormapNoise Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader

Init Shader 'Smooth Noise Fuzz::colormapSmooth Noise Fuzz::foglayer':
Fragment shader:
0:58(79): error: `glColor' undeclared
0:58(81): error: type mismatch
0:58(81): error: Operands to arithmetic operators must be numeric
0:58(17): error: cannot construct `vec4' from a non-numeric data type

Linking:
error: linking with uncompiled shader
*scratching his head*
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Finally, found a fix for the GL API errors on Linux

Post by Graf Zahl »

Hm...

I wonder why it compiled properly on my system with that typo in the shader... :?
User avatar
Gez
Developer
Developer
Posts: 1399
Joined: Mon Oct 22, 2007 16:47

Re: Finally, found a fix for the GL API errors on Linux

Post by Gez »

Edward-san wrote:

Code: Select all

-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__unix__)
 #include <GL/glew.h>
+#elif defined(__APPLE__)
 #include <OpenGL/OpenGL.h>
 #else // !__APPLE__
 #include <GL/gl.h>
This seems faulty.

if (apple or unix)
else if (apple)

If apple needs to include <OpenGL/OpenGL.h>, then this part should not be behind an else if, but a normal if.
Edward-san
Developer
Developer
Posts: 197
Joined: Sun Nov 29, 2009 16:36

Re: Finally, found a fix for the GL API errors on Linux

Post by Edward-san »

Now the last commit works fine (though strangely cmake doesn't update the pk3 after recompiling ... had to remove the pk3 and redo it).

Anyways, does windows part compile with the attached patch?
Attachments
linux_compile_fix.txt
(723 Bytes) Downloaded 92 times
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Finally, found a fix for the GL API errors on Linux

Post by Graf Zahl »

No, it doesn't compile because you #include glew.h for all platforms.
Does it even make sense to include glew, and then the complete gl headers again?
Edward-san
Developer
Developer
Posts: 197
Joined: Sun Nov 29, 2009 16:36

Re: Finally, found a fix for the GL API errors on Linux

Post by Edward-san »

.. at this point: is glew.h bad in Windows, or is it okay to download glew.h instead of gl(u).h? From what I read, glew is supposed to be supported in windows.
Edward-san
Developer
Developer
Posts: 197
Joined: Sun Nov 29, 2009 16:36

Re: Finally, found a fix for the GL API errors on Linux

Post by Edward-san »

Attaching the patch with just glew.h ...
Attachments
linux_compile_fix.txt
(859 Bytes) Downloaded 97 times
User avatar
skyrimguy
Posts: 2
Joined: Mon Dec 09, 2013 3:32

Re: Finally, found a fix for the GL API errors on Linux

Post by skyrimguy »

The latest patch works, I successfully compiled GZDoom g1.8.1-385-gfd76723 on Debian Wheezy x86_64 (Mesa 8.0.5) and Debian Sid x86_64 (Mesa 9.2.2). With Edward-san's patch, the use of "gl/api/glext.h" (the local copy) is no longer necessary and you can now use <GL/glext.h>; it shouldn't cause any problems. Linux users will need to install libglew or glew development files.

@Edward-san
From "src/gl/system/gl_system.h" patched

I think you should change:

Code: Select all

//GL headers
#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/OpenGL.h>
#else // !__APPLE__
#include "gl/api/glext.h"	//  use the local copy
#endif // __APPLE__
#include "gl/api/gl_api.h"
to:

Code: Select all

#if defined(__APPLE__)
#include <GL/glew.h>
#include <OpenGL/OpenGL.h>
#elif defined(__unix__)
#include <GL/glew.h>
#include <GL/glext.h>
#else // !__APPLE__ !__unix__
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#endif // __APPLE__
#include "gl/api/gl_api.h"
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Finally, found a fix for the GL API errors on Linux

Post by Graf Zahl »

Edward-san wrote:.. at this point: is glew.h bad in Windows, or is it okay to download glew.h instead of gl(u).h? From what I read, glew is supposed to be supported in windows.

Glew exists on Windows but it's another external dependency and a DLL that needs to be included. Not really necessary for the ~50 functions I need to get the address for.
Edward-san
Developer
Developer
Posts: 197
Joined: Sun Nov 29, 2009 16:36

Re: Finally, found a fix for the GL API errors on Linux

Post by Edward-san »

Ok, attaching the proper fix.
Attachments
linux_compile_fix.txt
(995 Bytes) Downloaded 118 times
Locked

Return to “Closed Bugs”