Browse Source

Add support for GLSL 4.30 and GLSL ES 3.10, via #pragma language glsl4.

macOS and iOS won't support glsl4 until a Metal backend is implemented.

--HG--
branch : minor
Alex Szpakowski 5 years ago
parent
commit
37c579929b

+ 1 - 0
src/modules/graphics/Graphics.cpp

@@ -1939,6 +1939,7 @@ StringMap<Graphics::Feature, Graphics::FEATURE_MAX_ENUM>::Entry Graphics::featur
 	{ "pixelshaderhighp",   FEATURE_PIXEL_SHADER_HIGHP   },
 	{ "shaderderivatives",  FEATURE_SHADER_DERIVATIVES   },
 	{ "glsl3",              FEATURE_GLSL3                },
+	{ "glsl4",              FEATURE_GLSL4                },
 	{ "instancing",         FEATURE_INSTANCING           },
 };
 

+ 1 - 0
src/modules/graphics/Graphics.h

@@ -163,6 +163,7 @@ public:
 		FEATURE_PIXEL_SHADER_HIGHP,
 		FEATURE_SHADER_DERIVATIVES,
 		FEATURE_GLSL3,
+		FEATURE_GLSL4,
 		FEATURE_INSTANCING,
 		FEATURE_MAX_ENUM
 	};

+ 4 - 2
src/modules/graphics/opengl/Graphics.cpp

@@ -189,7 +189,8 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b
 
 	gl.setTextureUnit(0);
 
-	// Set pixel row alignment
+	// Set pixel row alignment - code that calls glTexSubImage and glReadPixels
+	// assumes there's no row alignment, but OpenGL defaults to 4 bytes.
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 	glPixelStorei(GL_PACK_ALIGNMENT, 1);
 
@@ -1384,8 +1385,9 @@ void Graphics::initCapabilities()
 	capabilities.features[FEATURE_PIXEL_SHADER_HIGHP] = gl.isPixelShaderHighpSupported();
 	capabilities.features[FEATURE_SHADER_DERIVATIVES] = GLAD_VERSION_2_0 || GLAD_ES_VERSION_3_0 || GLAD_OES_standard_derivatives;
 	capabilities.features[FEATURE_GLSL3] = GLAD_ES_VERSION_3_0 || gl.isCoreProfile();
+	capabilities.features[FEATURE_GLSL4] = GLAD_ES_VERSION_3_1 || (gl.isCoreProfile() && GLAD_VERSION_4_3);
 	capabilities.features[FEATURE_INSTANCING] = gl.isInstancingSupported();
-	static_assert(FEATURE_MAX_ENUM == 8, "Graphics::initCapabilities must be updated when adding a new graphics feature!");
+	static_assert(FEATURE_MAX_ENUM == 9, "Graphics::initCapabilities must be updated when adding a new graphics feature!");
 
 	capabilities.limits[LIMIT_POINT_SIZE] = gl.getMaxPointSize();
 	capabilities.limits[LIMIT_TEXTURE_SIZE] = gl.getMax2DTextureSize();

+ 9 - 2
src/modules/graphics/wrap_GraphicsShader.lua

@@ -30,6 +30,7 @@ local GLSL = {}
 GLSL.VERSION = { -- index using [target][gles]
 	glsl1 = {[false]="#version 120",      [true]="#version 100"},
 	glsl3 = {[false]="#version 330 core", [true]="#version 300 es"},
+	glsl4 = {[false]="#version 430 core", [true]="#version 310 es"},
 }
 
 GLSL.SYNTAX = [[
@@ -374,7 +375,9 @@ function love.graphics._shaderCodeToGLSL(gles, arg1, arg2)
 		end
 	end
 
-	local supportsGLSL3 = love.graphics.getSupported().glsl3
+	local graphicsfeatures = love.graphics.getSupported()
+	local supportsGLSL3 = graphicsfeatures.glsl3
+	local supportsGLSL4 = graphicsfeatures.glsl4
 	local gammacorrect = love.graphics.isGammaCorrect()
 
 	local targetlang = getLanguageTarget(pixelcode or vertexcode)
@@ -383,7 +386,11 @@ function love.graphics._shaderCodeToGLSL(gles, arg1, arg2)
 	end
 
 	if targetlang == "glsl3" and not supportsGLSL3 then
-		error("GLSL 3 shaders are not supported on this system!", 2)
+		error("GLSL 3 shaders are not supported on this system.", 2)
+	end
+
+	if targetlang == "glsl4" and not supportsGLSL4 then
+		error("GLSL 4 shaders are not supported on this system.", 2)
 	end
 
 	if targetlang ~= nil and not GLSL.VERSION[targetlang] then

+ 27 - 11
src/modules/window/sdl/Window.cpp

@@ -223,8 +223,8 @@ std::vector<Window::ContextAttribs> Window::getContextAttribsList() const
 
 			// Prior to SDL 2.0.4, backends that use OpenGL ES didn't properly
 			// ask for a sRGB framebuffer when requested by SDL_GL_SetAttribute.
-			// FIXME: This doesn't account for windowing backends that sometimes
-			// use EGL, e.g. the X11 and windows SDL backends.
+			// This doesn't account for windowing backends that sometimes use
+			// EGL, e.g. the X11 and windows SDL backends.
 			if (hasSDL203orEarlier)
 				graphics::setGammaCorrect(false);
 
@@ -244,17 +244,33 @@ std::vector<Window::ContextAttribs> Window::getContextAttribsList() const
 	const char *preferGL2hint = SDL_GetHint("LOVE_GRAPHICS_USE_GL2");
 	bool preferGL2 = (preferGL2hint != nullptr && preferGL2hint[0] != '0');
 
-	std::vector<ContextAttribs> glcontexts = {{2, 1, false, debug}};
-	glcontexts.insert(preferGL2 ? glcontexts.end() : glcontexts.begin(), {3, 3, false, debug});
+	const char *preferGL3hint = SDL_GetHint("LOVE_GRAPHICS_USE_GL3");
+	bool preferGL3 = (preferGL3hint != nullptr && preferGL3hint[0] != '0');
 
-	std::vector<ContextAttribs> glescontexts = {{2, 0, true, debug}};
+	std::vector<ContextAttribs> glcontexts =
+	{
+		{4, 3, false, debug},
+		{3, 3, false, debug},
+		{2, 1, false, debug},
+	};
 
-	// While UWP SDL is above 2.0.4, it still doesn't support OpenGL ES 3+
-#ifndef LOVE_WINDOWS_UWP
-	// OpenGL ES 3+ contexts are only properly supported in SDL 2.0.4+.
-	if (!hasSDL203orEarlier)
-		glescontexts.insert(preferGL2 ? glescontexts.end() : glescontexts.begin(), {3, 0, true, debug});
-#endif
+	std::vector<ContextAttribs> glescontexts =
+	{
+		{3, 1, true, debug},
+		{3, 0, true, debug},
+		{2, 0, true, debug}
+	};
+
+	if (preferGL2)
+	{
+		std::swap(glcontexts[0], glcontexts[2]);
+		std::swap(glescontexts[0], glescontexts[2]);
+	}
+	else if (preferGL3)
+	{
+		std::swap(glcontexts[0], glcontexts[1]);
+		std::swap(glescontexts[0], glescontexts[1]);
+	}
 
 	std::vector<ContextAttribs> attribslist;