← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/opengl3 into lp:widelands

 

SirVer has proposed merging lp:~widelands-dev/widelands/opengl3 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/opengl3/+merge/285967

DO NOT MERGE!!

This is a quick port from OpenGL 2.1 to OpenGL 3.2 core which is much clearer specification and maybe even better supported than OpenGL 2.1. I hope to get more information out of this for the various Windows errors that we see. This is only a merge request so that appveyor builds it.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/opengl3 into lp:widelands.
=== modified file 'data/shaders/blit.fp'
--- data/shaders/blit.fp	2016-02-01 10:24:34 +0000
+++ data/shaders/blit.fp	2016-02-13 14:17:23 +0000
@@ -1,27 +1,29 @@
-#version 120
+#version 150 core
 
 uniform sampler2D u_texture;
 uniform sampler2D u_mask;
 
-varying vec2 out_mask_texture_coordinate;
-varying vec2 out_texture_coordinate;
-varying vec4 out_blend;
-varying float out_program_flavor;
+in vec2 out_mask_texture_coordinate;
+in vec2 out_texture_coordinate;
+in vec4 out_blend;
+in float out_program_flavor;
+
+out vec4 out_color;
 
 void main() {
-	vec4 texture_color = texture2D(u_texture, out_texture_coordinate);
+	vec4 texture_color = texture(u_texture, out_texture_coordinate);
 
 	// See http://en.wikipedia.org/wiki/YUV.
 	float luminance = dot(vec3(0.299, 0.587, 0.114), texture_color.rgb);
 
 	if (out_program_flavor == 0.) {
-		gl_FragColor = vec4(texture_color.rgb, out_blend.a * texture_color.a);
+		out_color = vec4(texture_color.rgb, out_blend.a * texture_color.a);
 	} else if (out_program_flavor == 1.) {
-		gl_FragColor = vec4(vec3(luminance) * out_blend.rgb, out_blend.a * texture_color.a);
+		out_color = vec4(vec3(luminance) * out_blend.rgb, out_blend.a * texture_color.a);
 	} else {
-		vec4 mask_color = texture2D(u_mask, out_mask_texture_coordinate);
+		vec4 mask_color = texture(u_mask, out_mask_texture_coordinate);
 		float blend_influence = mask_color.r * mask_color.a;
-		gl_FragColor = vec4(
+		out_color = vec4(
 			mix(texture_color.rgb, out_blend.rgb * luminance, blend_influence),
 				out_blend.a * texture_color.a);
 	}

=== modified file 'data/shaders/blit.vp'
--- data/shaders/blit.vp	2016-02-01 10:24:34 +0000
+++ data/shaders/blit.vp	2016-02-13 14:17:23 +0000
@@ -1,16 +1,16 @@
-#version 120
+#version 150 core
 
 // Attributes.
-attribute vec2 attr_mask_texture_position;
-attribute vec2 attr_texture_position;
-attribute vec3 attr_position;
-attribute vec4 attr_blend;
-attribute float attr_program_flavor;
+in vec2 attr_mask_texture_position;
+in vec2 attr_texture_position;
+in vec3 attr_position;
+in vec4 attr_blend;
+in float attr_program_flavor;
 
-varying vec2 out_mask_texture_coordinate;
-varying vec2 out_texture_coordinate;
-varying vec4 out_blend;
-varying float out_program_flavor;
+out vec2 out_mask_texture_coordinate;
+out vec2 out_texture_coordinate;
+out vec4 out_blend;
+out float out_program_flavor;
 
 void main() {
 	out_mask_texture_coordinate = attr_mask_texture_position;

=== modified file 'data/shaders/dither.fp'
--- data/shaders/dither.fp	2016-02-01 10:24:34 +0000
+++ data/shaders/dither.fp	2016-02-13 14:17:23 +0000
@@ -1,13 +1,15 @@
-#version 120
+#version 150 core
 
 uniform sampler2D u_dither_texture;
 uniform sampler2D u_terrain_texture;
 uniform vec2 u_texture_dimensions;
 
-varying float var_brightness;
-varying vec2 var_dither_texture_position;
-varying vec2 var_texture_position;
-varying vec2 var_texture_offset;
+in float var_brightness;
+in vec2 var_dither_texture_position;
+in vec2 var_texture_position;
+in vec2 var_texture_offset;
+
+out vec4 out_color;
 
 // TODO(sirver): This is a hack to make sure we are sampling inside of the
 // terrain texture. This is a common problem with OpenGL and texture atlases.
@@ -18,7 +20,7 @@
 			fract(var_texture_position),
 			vec2(MARGIN, MARGIN),
 			vec2(1. - MARGIN, 1. - MARGIN));
-	vec4 clr = texture2D(u_terrain_texture, var_texture_offset + u_texture_dimensions * texture_fract);
-	gl_FragColor = vec4(clr.rgb * var_brightness,
-			1. - texture2D(u_dither_texture, var_dither_texture_position).a);
+	vec4 clr = texture(u_terrain_texture, var_texture_offset + u_texture_dimensions * texture_fract);
+	out_color = vec4(clr.rgb * var_brightness,
+			1. - texture(u_dither_texture, var_dither_texture_position).a);
 }

=== modified file 'data/shaders/dither.vp'
--- data/shaders/dither.vp	2016-02-01 10:24:34 +0000
+++ data/shaders/dither.vp	2016-02-13 14:17:23 +0000
@@ -1,19 +1,19 @@
-#version 120
+#version 150 core
 
 // Attributes.
-attribute float attr_brightness;
-attribute vec2 attr_dither_texture_position;
-attribute vec2 attr_position;
-attribute vec2 attr_texture_offset;
-attribute vec2 attr_texture_position;
+in float attr_brightness;
+in vec2 attr_dither_texture_position;
+in vec2 attr_position;
+in vec2 attr_texture_offset;
+in vec2 attr_texture_position;
 
 uniform float u_z_value;
 
 // Output of vertex shader.
-varying float var_brightness;
-varying vec2 var_dither_texture_position;
-varying vec2 var_texture_offset;
-varying vec2 var_texture_position;
+out float var_brightness;
+out vec2 var_dither_texture_position;
+out vec2 var_texture_offset;
+out vec2 var_texture_position;
 
 void main() {
 	var_brightness = attr_brightness;

=== modified file 'data/shaders/draw_line.fp'
--- data/shaders/draw_line.fp	2016-02-01 10:24:34 +0000
+++ data/shaders/draw_line.fp	2016-02-13 14:17:23 +0000
@@ -1,7 +1,8 @@
-#version 120
+#version 150 core
 
-varying vec3 var_color;
+in vec3 var_color;
+out vec4 out_color;
 
 void main() {
-	gl_FragColor = vec4(var_color.rgb, 1.);
+	out_color = vec4(var_color.rgb, 1.);
 }

=== modified file 'data/shaders/draw_line.vp'
--- data/shaders/draw_line.vp	2016-02-01 10:24:34 +0000
+++ data/shaders/draw_line.vp	2016-02-13 14:17:23 +0000
@@ -1,10 +1,10 @@
-#version 120
+#version 150 core
 
 // Attributes.
-attribute vec3 attr_position;
-attribute vec3 attr_color;
+in vec3 attr_position;
+in vec3 attr_color;
 
-varying vec3 var_color;
+out vec3 var_color;
 
 void main() {
 	var_color = attr_color;

=== modified file 'data/shaders/fill_rect.fp'
--- data/shaders/fill_rect.fp	2016-02-01 10:24:34 +0000
+++ data/shaders/fill_rect.fp	2016-02-13 14:17:23 +0000
@@ -1,7 +1,9 @@
-#version 120
-
-varying vec4 var_color;
+#version 150 core
+
+in vec4 var_color;
+
+out vec4 out_color;
 
 void main() {
-	gl_FragColor = var_color;
+	out_color = var_color;
 }

=== modified file 'data/shaders/fill_rect.vp'
--- data/shaders/fill_rect.vp	2016-02-01 10:24:34 +0000
+++ data/shaders/fill_rect.vp	2016-02-13 14:17:23 +0000
@@ -1,10 +1,10 @@
-#version 120
+#version 150 core
 
 // Attributes.
-attribute vec3 attr_position;
-attribute vec4 attr_color;
+in vec3 attr_position;
+in vec4 attr_color;
 
-varying vec4 var_color;
+out vec4 var_color;
 
 void main() {
 	var_color = attr_color;

=== modified file 'data/shaders/road.fp'
--- data/shaders/road.fp	2016-02-01 10:24:34 +0000
+++ data/shaders/road.fp	2016-02-13 14:17:23 +0000
@@ -1,13 +1,15 @@
-#version 120
+#version 150 core
 
 // Inputs.
-varying vec2 out_texture_position;
-varying float out_brightness;
+in vec2 out_texture_position;
+in float out_brightness;
+
+out vec4 out_color;
 
 uniform sampler2D u_texture;
 
 void main() {
-	vec4 color = texture2D(u_texture, out_texture_position);
+	vec4 color = texture(u_texture, out_texture_position);
 	color.rgb *= out_brightness;
-	gl_FragColor = color;
+	out_color = color;
 }

=== modified file 'data/shaders/road.vp'
--- data/shaders/road.vp	2016-02-01 10:24:34 +0000
+++ data/shaders/road.vp	2016-02-13 14:17:23 +0000
@@ -1,15 +1,15 @@
-#version 120
+#version 150 core
 
 // Attributes.
-attribute vec2 attr_position;
-attribute vec2 attr_texture_position;
-attribute float attr_brightness;
+in vec2 attr_position;
+in vec2 attr_texture_position;
+in float attr_brightness;
 
 uniform float u_z_value;
 
 // Outputs.
-varying vec2 out_texture_position;
-varying float out_brightness;
+out vec2 out_texture_position;
+out float out_brightness;
 
 void main() {
 	out_texture_position = attr_texture_position;

=== modified file 'data/shaders/terrain.fp'
--- data/shaders/terrain.fp	2016-02-01 10:24:34 +0000
+++ data/shaders/terrain.fp	2016-02-13 14:17:23 +0000
@@ -1,11 +1,13 @@
-#version 120
+#version 150 core
 
 uniform sampler2D u_terrain_texture;
 uniform vec2 u_texture_dimensions;
 
-varying float var_brightness;
-varying vec2 var_texture_position;
-varying vec2 var_texture_offset;
+in float var_brightness;
+in vec2 var_texture_position;
+in vec2 var_texture_offset;
+
+out vec4 out_color;
 
 // TODO(sirver): This is a hack to make sure we are sampling inside of the
 // terrain texture. This is a common problem with OpenGL and texture atlases.
@@ -20,7 +22,7 @@
 			fract(var_texture_position),
 			vec2(MARGIN, MARGIN),
 			vec2(1. - MARGIN, 1. - MARGIN));
-	vec4 clr = texture2D(u_terrain_texture, var_texture_offset + u_texture_dimensions * texture_fract);
+	vec4 clr = texture(u_terrain_texture, var_texture_offset + u_texture_dimensions * texture_fract);
 	clr.rgb *= var_brightness;
-	gl_FragColor = clr;
+	out_color = clr;
 }

=== modified file 'data/shaders/terrain.vp'
--- data/shaders/terrain.vp	2016-02-01 10:24:34 +0000
+++ data/shaders/terrain.vp	2016-02-13 14:17:23 +0000
@@ -1,17 +1,17 @@
-#version 120
+#version 150 core
 
 // Attributes.
-attribute float attr_brightness;
-attribute vec2 attr_position;
-attribute vec2 attr_texture_offset;
-attribute vec2 attr_texture_position;
+in float attr_brightness;
+in vec2 attr_position;
+in vec2 attr_texture_offset;
+in vec2 attr_texture_position;
 
 uniform float u_z_value;
 
 // Output of vertex shader.
-varying float var_brightness;
-varying vec2 var_texture_offset;
-varying vec2 var_texture_position;
+out float var_brightness;
+out vec2 var_texture_offset;
+out vec2 var_texture_position;
 
 void main() {
 	var_texture_position = attr_texture_position;

=== modified file 'src/graphic/gl/initialize.cc'
--- src/graphic/gl/initialize.cc	2016-01-25 06:02:27 +0000
+++ src/graphic/gl/initialize.cc	2016-02-13 14:17:23 +0000
@@ -38,9 +38,9 @@
    GLint* max_texture_size) {
 	// Request an OpenGL 2 context with double buffering.
 	SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
-	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
-	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
-	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
+	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
+	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
 	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
 	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
@@ -50,6 +50,11 @@
 #ifdef USE_GLBINDING
 	glbinding::Binding::initialize();
 
+	// NOCOM(#sirver): hack. we only ever bind one.
+	GLuint VaoID;
+	glGenVertexArrays(1, &VaoID);
+	glBindVertexArray(VaoID);
+
 	// The undocumented command line argument --debug_gl_trace will set
 	// Trace::kYes. This will log every OpenGL call that is made, together with
 	// arguments, return values and glError status. This requires that Widelands

=== modified file 'src/graphic/gl/system_headers.h'
--- src/graphic/gl/system_headers.h	2016-01-25 20:17:03 +0000
+++ src/graphic/gl/system_headers.h	2016-02-13 14:17:23 +0000
@@ -35,10 +35,11 @@
 // loading problem. Switch to it everywhere. (https://github.com/hpicgs/glbinding).
 
 #ifdef USE_GLBINDING
-#   include <glbinding/gl/gl.h>
+#   include <glbinding/gl/gl32core.h>
 #   include <glbinding/Binding.h>
 // This fakes that most other gl bindings define gl functions in the public namespace.
 CLANG_DIAG_OFF("-Wheader-hygiene")
+using namespace gl32core;
 using namespace gl;
 CLANG_DIAG_ON("-Wheader-hygiene")
 #else


Follow ups