diff --git a/data/shaders/pass.frag b/data/shaders/pass.frag index e5b1e7c69..d721a3d7c 100644 --- a/data/shaders/pass.frag +++ b/data/shaders/pass.frag @@ -1,4 +1,4 @@ -#version 330 +#version 140 uniform sampler2D tex; in vec2 uv; diff --git a/data/shaders/pass.vert b/data/shaders/pass.vert index 4c495e0a7..3f3a70263 100644 --- a/data/shaders/pass.vert +++ b/data/shaders/pass.vert @@ -1,5 +1,5 @@ // Passthrough shader for drawQuad() -#version 330 +#version 140 in vec3 Position; in vec2 Texcoord; diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 939d7fff1..dc2db7199 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -29,7 +29,7 @@ float getShadowFactor(vec3 pos, float bias, int index) { //float a[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1); - const vec2 shadowoffset[4] = vec2[]( + vec2 shadowoffset[4] = vec2[]( vec2(-1., -1.), vec2(-1., 1.), vec2(1., -1.), diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp index 4829cf72c..e9877a3e3 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp @@ -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)) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 0a36c5a1f..100dee0cf 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -210,7 +210,9 @@ void initGL() 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()) { diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 97c104339..60cf5e9fb 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -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); diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 9155451bf..08620da7f 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -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 m_modes; diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index d5927c483..c8ef946cd 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -137,6 +137,8 @@ RTT::RTT() drv->setRenderTarget(0, false, false); drv->endScene(); + if (irr_driver->getGLSLVersion() < 150) + return; glGenFramebuffers(1, &shadowFBO); glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO); glGenTextures(1, &shadowColorTex); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 08c45b14e..2e425c913 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1049,6 +1049,12 @@ namespace MeshShader void ShadowShader::init() { + // Geometry shader needed + if (irr_driver->getGLSLVersion() < 150) + { + attrib_position = -1; + return; + } Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(), GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(), @@ -1076,6 +1082,13 @@ namespace MeshShader void RefShadowShader::init() { + // Geometry shader needed + if (irr_driver->getGLSLVersion() < 150) + { + attrib_position = -1; + attrib_texcoord = -1; + return; + } Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(), GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(), diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 8acc40732..27a0119ff 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -55,6 +55,8 @@ TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE typ GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride) { + if (attrib_position == -1) + return 0; GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao);