Add a function to query supported glsl ver

This commit is contained in:
Vincent Lejeune 2014-03-21 21:49:40 +01:00
parent aa39246404
commit ae3cf30070
6 changed files with 79 additions and 30 deletions

View File

@ -1,4 +1,4 @@
#version 330
#version 140
uniform sampler2D tex;
in vec2 uv;

View File

@ -1,5 +1,5 @@
// Passthrough shader for drawQuad()
#version 330
#version 140
in vec3 Position;
in vec2 Texcoord;

View File

@ -368,6 +368,65 @@ void IrrPrintXGrabError(int grabResult, const c8 * grabCommand )
}
#endif
static GLXContext getMeAGLContext(Display *display, GLXFBConfig glxFBConfig)
{
GLXContext Context;
int compat33ctx[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
int core33ctx[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
int core31ctx[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
int legacyctx[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
None
};
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
// create compat 3.3 context (for proprietary drivers)
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, compat33ctx);
if (!XErrorSignaled)
return Context;
XErrorSignaled = false;
// create core 3.3 context (for mesa)
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, core33ctx);
if (!XErrorSignaled)
return Context;
XErrorSignaled = false;
// create core 3.1 context (for older mesa)
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, core31ctx);
if (!XErrorSignaled)
return Context;
XErrorSignaled = false;
// fall back to legacy context
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, legacyctx);
return Context;
}
bool CIrrDeviceLinux::createWindow()
{
@ -741,30 +800,7 @@ bool CIrrDeviceLinux::createWindow()
glxWin=glXCreateWindow(display,glxFBConfig,window,NULL);
if (glxWin)
{
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //GLX_CONTEXT_CORE_PROFILE_BIT_ARB
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
// create glx context
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, context_attribs);
if (XErrorSignaled)
{
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
None
};
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, context_attribs);
XErrorSignaled = false;
}
Context = getMeAGLContext(display, glxFBConfig);
if (Context)
{
if (!glXMakeContextCurrent(display, glxWin, glxWin, Context))

View File

@ -210,7 +210,9 @@ void initGL()
static GLuint LoadShader(const char * file, unsigned type)
{
GLuint Id = glCreateShader(type);
std::string Code = "#version 330\n";
char versionString[20];
sprintf(versionString, "#version %d\n", irr_driver->getGLSLVersion());
std::string Code = versionString;
std::ifstream Stream(file, std::ios::in);
if (Stream.is_open())
{

View File

@ -422,12 +422,12 @@ void IrrDriver::initDevice()
m_gui_env = m_device->getGUIEnvironment();
m_video_driver = m_device->getVideoDriver();
int GLMajorVersion = 0, GLMinorVersion = 0;
GLMajorVersion = 2;
GLMinorVersion = 1;
glGetIntegerv(GL_MAJOR_VERSION, &GLMajorVersion);
glGetIntegerv(GL_MINOR_VERSION, &GLMinorVersion);
Log::info("IrrDriver", "OPENGL VERSION IS %d.%d", GLMajorVersion, GLMinorVersion);
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion == 3)) && UserConfigParams::m_pixel_shaders;
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion >= 1)) && UserConfigParams::m_pixel_shaders;
// This remaps the window, so it has to be done before the clear to avoid flicker
m_device->setResizable(false);

View File

@ -82,6 +82,7 @@ enum STKRenderingPass
class IrrDriver : public IEventReceiver, public NoCopy
{
private:
int GLMajorVersion, GLMinorVersion;
/** The irrlicht device. */
IrrlichtDevice *m_device;
/** Irrlicht scene manager. */
@ -148,6 +149,16 @@ public:
float power;
};
unsigned getGLSLVersion() const
{
if (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion == 3))
return GLMajorVersion * 100 + GLMinorVersion * 10;
else if (GLMajorVersion == 3)
return 100 + (GLMinorVersion + 3) * 10;
else
return 120;
}
private:
std::vector<VideoMode> m_modes;