diff --git a/phy/cluster/views/trace.py b/phy/cluster/views/trace.py index 07f4e6cc8..bf6754f78 100644 --- a/phy/cluster/views/trace.py +++ b/phy/cluster/views/trace.py @@ -207,7 +207,7 @@ def _create_visuals(self): # Gradient of color for the traces. if self.trace_color_0 and self.trace_color_1: self.trace_visual.inserter.insert_frag( - 'gl_FragColor.rgb = mix(vec3%s, vec3%s, (v_signal_index / %d));' % ( + 'fragColor.rgb = mix(vec3%s, vec3%s, (v_signal_index / %d));' % ( self.trace_color_0, self.trace_color_1, self.n_channels), 'end') self.canvas.add_visual(self.trace_visual) diff --git a/phy/plot/base.py b/phy/plot/base.py index e82f42002..486ff17c6 100644 --- a/phy/plot/base.py +++ b/phy/plot/base.py @@ -238,8 +238,8 @@ def __init__(self): def _init_insert(self): self.insert_vert('vec2 {{varout}} = {{varin}};', 'before_transforms', index=0) self.insert_vert('gl_Position = vec4({{varout}}, 0., 1.);', 'after_transforms', index=0) - self.insert_vert('varying vec2 v_{{varout}};\n', 'header', index=0) - self.insert_frag('varying vec2 v_{{varout}};\n', 'header', index=0) + self.insert_vert('out vec2 v_{{varout}};\n', 'header', index=0) + self.insert_frag('in vec2 v_{{varout}};\n', 'header', index=0) def _insert(self, shader_type, glsl, location, origin=None, index=None): assert location in ( @@ -289,8 +289,8 @@ def insert_frag(self, glsl, location=None, origin=None, index=None): def add_varying(self, vtype, name, value): """Add a varying variable.""" - self.insert_vert('varying %s %s;' % (vtype, name), 'header') - self.insert_frag('varying %s %s;' % (vtype, name), 'header') + self.insert_vert('out %s %s;' % (vtype, name), 'header') + self.insert_frag('in %s %s;' % (vtype, name), 'header') self.insert_vert('%s = %s;' % (name, value), 'end') def add_gpu_transforms(self, tc): diff --git a/phy/plot/gloo/gl.py b/phy/plot/gloo/gl.py index 48c440fe0..d54a3e1c0 100644 --- a/phy/plot/gloo/gl.py +++ b/phy/plot/gloo/gl.py @@ -48,14 +48,10 @@ def enable_depth_mask(): glClearColor(0, 0, 0, 0) # noqa glClearDepth(1.) # noqa - glEnable(GL_BLEND) # noqa glDepthRange(0., 1.) # noqa glDepthFunc(GL_EQUAL) # noqa glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # noqa - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) # noqa - glEnable(GL_POINT_SPRITE) # noqa - # Patch: pythonize the glGetActiveAttrib _glGetActiveAttrib = glGetActiveAttrib # noqa diff --git a/phy/plot/gloo/program.py b/phy/plot/gloo/program.py index 242cab289..b26499c33 100644 --- a/phy/plot/gloo/program.py +++ b/phy/plot/gloo/program.py @@ -50,7 +50,7 @@ class Program(GLObject): # --------------------------------- def __init__(self, vertex=None, fragment=None, geometry=None, - count=0, version="120"): + count=0, version="410"): """ Initialize the program and optionnaly buffer. """ @@ -141,7 +141,7 @@ def hooks(self): .. code:: C - attribute vec3 position; + in vec3 position; void main () { gl_Position = (position); # "transform" is a hook } @@ -506,8 +506,8 @@ def active_attributes(self): .. code:: - attribute vec3 normal; # Inactive - attribute vec3 position; # Active + in vec3 normal; # Inactive + in vec3 position; # Active void main() { gl_Position = vec4(position, 1.0); } @@ -552,8 +552,8 @@ def inactive_attributes(self): .. code:: - attribute vec3 normal; # Inactive - attribute vec3 position; # Active + in vec3 normal; # Inactive + in vec3 position; # Active void main() { gl_Position = vec4(position, 1.0); } diff --git a/phy/plot/gloo/shader.py b/phy/plot/gloo/shader.py index 4849cd7cd..76ae7a96c 100644 --- a/phy/plot/gloo/shader.py +++ b/phy/plot/gloo/shader.py @@ -15,15 +15,16 @@ .. code:: python vertex = ''' - attribute vec2 position; + in vec2 position; void main (void) { gl_Position = vec4(0.85*position, 0.0, 1.0); } ''' fragment = ''' + out vec4 fragColor; void main(void) { - gl_FragColor = vec4(1.0,1.0,0.0,1.0); + fragColor = vec4(1.0,1.0,0.0,1.0); } ''' quad = gloo.Program(vertex, fragment, count=4) @@ -85,7 +86,7 @@ class Shader(GLObject): 'samplerCube': gl.GL_SAMPLER_CUBE, } - def __init__(self, target, code, version="120"): + def __init__(self, target, code, version="410"): """ Initialize the shader. """ @@ -338,7 +339,7 @@ def attributes(self): class VertexShader(Shader): """ Vertex shader class """ - def __init__(self, code=None, version="120"): + def __init__(self, code=None, version="410"): Shader.__init__(self, gl.GL_VERTEX_SHADER, code, version) @property @@ -354,7 +355,7 @@ def __repr__(self): class FragmentShader(Shader): """ Fragment shader class """ - def __init__(self, code=None, version="120"): + def __init__(self, code=None, version="410"): Shader.__init__(self, gl.GL_FRAGMENT_SHADER, code, version) @property @@ -387,7 +388,7 @@ class GeometryShader(Shader): """ def __init__(self, code=None, - vertices_out=None, input_type=None, output_type=None, version="120"): + vertices_out=None, input_type=None, output_type=None, version="410"): Shader.__init__(self, gl.GL_GEOMETRY_SHADER_EXT, code, version) self._vertices_out = vertices_out diff --git a/phy/plot/gloo/texture.py b/phy/plot/gloo/texture.py index 1d9964e0f..c205484cf 100644 --- a/phy/plot/gloo/texture.py +++ b/phy/plot/gloo/texture.py @@ -15,11 +15,11 @@ ... fragment = ''' - uniform sampler2D texture; + uniform sampler2D tex; varying vec2 v_texcoord; void main() { - gl_FragColor = texture2D(texture, v_texcoord); + gl_FragColor = texture(texture, v_texcoord); } ''' ... @@ -394,7 +394,6 @@ def _setup(self): """ Setup texture on GPU """ Texture._setup(self) - gl.glEnable(gl.GL_TEXTURE_CUBE_MAP) gl.glBindTexture(self.target, self._handle) targets = [gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X, gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, @@ -411,7 +410,6 @@ def _update(self): log.log(5, "GPU: Updating texture cube") if self.need_update: - gl.glEnable(gl.GL_TEXTURE_CUBE_MAP) gl.glBindTexture(self.target, self.handle) targets = [gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X, @@ -455,7 +453,6 @@ def _activate(self): """ Activate texture on GPU """ log.log(5, "GPU: Activate texture cube") - gl.glEnable(gl.GL_TEXTURE_CUBE_MAP) gl.glBindTexture(self.target, self._handle) if self._need_setup: self._setup() diff --git a/phy/plot/gloo/uniforms.py b/phy/plot/gloo/uniforms.py index 53d2ff8e0..473911a30 100644 --- a/phy/plot/gloo/uniforms.py +++ b/phy/plot/gloo/uniforms.py @@ -226,7 +226,7 @@ def code(self, prefix="u_"): count, shift = _dtype[name], 0 while count: if store == 0: - body += "\n _uniform = texture2D(u_uniforms, vec2(float(i++)/size_x,ty));\n" + body += "\n _uniform = texture(u_uniforms, vec2(float(i++)/size_x,ty));\n" store = 4 if store == 4: a = "xyzw" diff --git a/phy/plot/gloo/variable.py b/phy/plot/gloo/variable.py index c3f4b6b8a..99c1616d5 100644 --- a/phy/plot/gloo/variable.py +++ b/phy/plot/gloo/variable.py @@ -41,16 +41,17 @@ .. code:: vertex = ''' - attribute vec3 position; + in vec3 position; void main (void) { gl_Position = vec4(position, 1.0); } ''' fragment = ''' uniform vec4 color; + out vec4 fragColor; void main(void) { - gl_FragColor = color; + fragColor = color; } ''' program = gloo.Program(vertex, fragment, count=4) # program["position"] type is Attribute @@ -363,14 +364,35 @@ def set_data(self, data): self._generic = False def _activate(self): + """Activate the attribute ensuring proper GL state.""" + if not self._active: + return + if isinstance(self.data, (VertexBuffer, VertexArray)): - self.data.activate() - size, gtype, dtype = gl_typeinfo[self._gtype] - stride = self.data.stride - offset = ctypes.c_void_p(self.data.offset) - gl.glEnableVertexAttribArray(self.handle) - gl.glVertexAttribPointer( - self.handle, size, gtype, gl.GL_FALSE, stride, offset) + # Early validation + if self.handle < 0: + log.debug("Skipping activation of attribute %s (invalid handle)", self.name) + return + + try: + # 1. First bind the buffer + self.data.activate() + + # 2. Get the attribute information + size, gtype, dtype = gl_typeinfo[self._gtype] + stride = self.data.stride + offset = ctypes.c_void_p(self.data.offset) + + # 3. Set pointer before enabling + gl.glVertexAttribPointer( + self.handle, size, gtype, gl.GL_FALSE, stride, offset) + + # 4. Enable the attribute array + gl.glEnableVertexAttribArray(self.handle) + + except Exception as e: + log.error("Error activating attribute %s: %s", self.name, str(e)) + raise def _deactivate(self): if isinstance(self.data, VertexBuffer): diff --git a/phy/plot/glsl/histogram.frag b/phy/plot/glsl/histogram.frag index 7c31f83aa..eb82f98f7 100644 --- a/phy/plot/glsl/histogram.frag +++ b/phy/plot/glsl/histogram.frag @@ -1,5 +1,7 @@ -varying vec4 v_color; +out vec4 FragColor; + +in vec4 v_color; void main() { - gl_FragColor = v_color; + FragColor = v_color; } diff --git a/phy/plot/glsl/histogram.vert b/phy/plot/glsl/histogram.vert index 1889ca2f4..555cd5ab7 100644 --- a/phy/plot/glsl/histogram.vert +++ b/phy/plot/glsl/histogram.vert @@ -1,17 +1,17 @@ #include "utils.glsl" -attribute vec2 a_position; -attribute float a_hist_index; // 0..n_hists-1 +in vec2 a_position; +in float a_hist_index; // 0..n_hists-1 uniform sampler2D u_color; uniform float n_hists; -varying vec4 v_color; -varying float v_hist_index; +out vec4 v_color; +out float v_hist_index; void main() { gl_Position = transform(a_position); - v_color = fetch_texture(a_hist_index, u_color, n_hists); + v_color = texture(u_color, vec2(a_hist_index / n_hists, 0.0)); v_hist_index = a_hist_index; } diff --git a/phy/plot/glsl/image.frag b/phy/plot/glsl/image.frag index d0bfdbe7e..658dd00b3 100644 --- a/phy/plot/glsl/image.frag +++ b/phy/plot/glsl/image.frag @@ -1,6 +1,8 @@ uniform sampler2D u_tex; -varying vec2 v_tex_coords; +in vec2 v_tex_coords; + +out vec4 FragColor; void main() { - gl_FragColor = texture2D(u_tex, v_tex_coords); + FragColor = texture(u_tex, v_tex_coords); } diff --git a/phy/plot/glsl/image.vert b/phy/plot/glsl/image.vert index a378a1981..6aacb6ed8 100644 --- a/phy/plot/glsl/image.vert +++ b/phy/plot/glsl/image.vert @@ -1,7 +1,7 @@ -attribute vec2 a_position; -attribute vec2 a_tex_coords; +in vec2 a_position; +in vec2 a_tex_coords; -varying vec2 v_tex_coords; +out vec2 v_tex_coords; void main() { gl_Position = transform(a_position); diff --git a/phy/plot/glsl/line.frag b/phy/plot/glsl/line.frag index 7c31f83aa..eb82f98f7 100644 --- a/phy/plot/glsl/line.frag +++ b/phy/plot/glsl/line.frag @@ -1,5 +1,7 @@ -varying vec4 v_color; +out vec4 FragColor; + +in vec4 v_color; void main() { - gl_FragColor = v_color; + FragColor = v_color; } diff --git a/phy/plot/glsl/line.vert b/phy/plot/glsl/line.vert index a5c0c5474..336fadbf3 100644 --- a/phy/plot/glsl/line.vert +++ b/phy/plot/glsl/line.vert @@ -1,6 +1,7 @@ -attribute vec2 a_position; -attribute vec4 a_color; -varying vec4 v_color; +in vec2 a_position; +in vec4 a_color; + +out vec4 v_color; void main() { gl_Position = transform(a_position); diff --git a/phy/plot/glsl/line_agg_geom.frag b/phy/plot/glsl/line_agg_geom.frag index c4664b2e9..b1b3b3f9a 100644 --- a/phy/plot/glsl/line_agg_geom.frag +++ b/phy/plot/glsl/line_agg_geom.frag @@ -1,3 +1,15 @@ +in vec2 v_texcoord; +in float v_length; +in vec2 v_caps; +in vec2 v_bevel_distance; + +out vec4 FragColor; + +uniform vec4 color; +uniform float antialias; +uniform float linewidth; +uniform float miter_limit; + vec4 stroke(float distance, float linewidth, float antialias, vec4 color) { vec4 frag_color; @@ -41,17 +53,6 @@ vec4 cap(int type, float dx, float dy, float linewidth, float antialias, vec4 co return stroke(d, linewidth, antialias, color); } - -uniform vec4 color; -uniform float antialias; -uniform float linewidth; -uniform float miter_limit; - -varying float v_length; -varying vec2 v_caps; -varying vec2 v_texcoord; -varying vec2 v_bevel_distance; - void main() { @@ -59,12 +60,12 @@ void main() if (v_caps.x < 0.0) { - gl_FragColor = cap(1, v_texcoord.x, v_texcoord.y, linewidth, antialias, color); + FragColor = cap(1, v_texcoord.x, v_texcoord.y, linewidth, antialias, color); return; } if (v_caps.y > v_length) { - gl_FragColor = cap(1, v_texcoord.x-v_length, v_texcoord.y, linewidth, antialias, color); + FragColor = cap(1, v_texcoord.x - v_length, v_texcoord.y, linewidth, antialias, color); return; } @@ -73,16 +74,16 @@ void main() // else if(v_texcoord.x > v_length) { distance = length(v_texcoord - vec2(v_length, 0.0)); } // Miter limit - float t = (miter_limit-1.0)*(linewidth/2.0) + antialias; + float t = (miter_limit - 1.0) * (linewidth / 2.0) + antialias; - if( (v_texcoord.x < 0.0) && (v_bevel_distance.x > (abs(distance) + t)) ) + if ((v_texcoord.x < 0.0) && (v_bevel_distance.x > (abs(distance) + t))) { distance = v_bevel_distance.x - t; } - else if( (v_texcoord.x > v_length) && (v_bevel_distance.y > (abs(distance) + t)) ) + else if ((v_texcoord.x > v_length) && (v_bevel_distance.y > (abs(distance) + t))) { distance = v_bevel_distance.y - t; } - gl_FragColor = stroke(distance, linewidth, antialias, color); + FragColor = stroke(distance, linewidth, antialias, color); } diff --git a/phy/plot/glsl/line_agg_geom.geom b/phy/plot/glsl/line_agg_geom.geom index c779e2bcd..e36b6403f 100644 --- a/phy/plot/glsl/line_agg_geom.geom +++ b/phy/plot/glsl/line_agg_geom.geom @@ -1,4 +1,4 @@ -#version 120 +#version 410 #extension GL_EXT_gpu_shader4 : enable #extension GL_EXT_geometry_shader4 : enable @@ -7,14 +7,14 @@ uniform mat4 projection; // uniform float linewidth; // uniform float miter_limit; -varying in float v_antialias[4][1]; -varying in float v_linewidth[4][1]; -varying in float v_miter_limit[4][1]; +in in float v_antialias[4][1]; +in in float v_linewidth[4][1]; +in in float v_miter_limit[4][1]; -varying out vec2 v_caps; -varying out float v_length; -varying out vec2 v_texcoord; -varying out vec2 v_bevel_distance; +out out vec2 v_caps; +out out float v_length; +out out vec2 v_texcoord; +out out vec2 v_bevel_distance; float compute_u(vec2 p0, vec2 p1, vec2 p) { diff --git a/phy/plot/glsl/line_agg_geom.vert b/phy/plot/glsl/line_agg_geom.vert index 5c0f9c26e..cced1391e 100644 --- a/phy/plot/glsl/line_agg_geom.vert +++ b/phy/plot/glsl/line_agg_geom.vert @@ -2,11 +2,11 @@ uniform float antialias; uniform float linewidth; uniform float miter_limit; -attribute vec2 position; +in vec2 position; -varying float v_antialias[1]; -varying float v_linewidth[1]; -varying float v_miter_limit[1]; +out float v_antialias[1]; +out float v_linewidth[1]; +out float v_miter_limit[1]; void main() { diff --git a/phy/plot/glsl/msdf.frag b/phy/plot/glsl/msdf.frag index 7dd70f719..15e3655ad 100644 --- a/phy/plot/glsl/msdf.frag +++ b/phy/plot/glsl/msdf.frag @@ -8,9 +8,10 @@ uniform vec4 u_color; uniform vec2 u_tex_size; uniform vec2 u_zoom; -varying vec2 v_tex_coords; -varying vec4 v_color; +in vec2 v_tex_coords; +in vec4 v_color; +out vec4 fragColor; float median(float r, float g, float b) { return max(min(r, g), min(max(r, g), b)); @@ -24,8 +25,8 @@ float contour(float d, float w) { float get_alpha(vec2 uv) { vec2 msdfUnit = 4.0 / u_tex_size; - vec3 sample = texture2D(u_tex, uv).rgb; - float sigDist = median(sample.r, sample.g, sample.b) - 0.5; + vec3 _sample = texture(u_tex, uv).rgb; + float sigDist = median(_sample.r, _sample.g, _sample.b) - 0.5; sigDist *= dot(msdfUnit, 0.5 / fwidth(uv)); sigDist += 0.5; return clamp(sigDist, 0.0, 1.0); @@ -60,10 +61,10 @@ void main() { alpha = supersample(alpha); // CONTOUR -- does not work well with small font sizes - // vec3 sample = texture2D(u_tex, v_tex_coords).rgb; + // vec3 sample = texture(u_tex, v_tex_coords).rgb; // float sigDist = median(sample.r, sample.g, sample.b); // sigDist = exp(-20 * pow(sigDist - 1, 2)); // color = mix(vec3(1, 1, 1), u_color.rgb, sigDist); - gl_FragColor = vec4(v_color.rgb * alpha, v_color.a); + fragColor = vec4(v_color.rgb * alpha, v_color.a); } diff --git a/phy/plot/glsl/msdf.vert b/phy/plot/glsl/msdf.vert index d4510262a..a8448db05 100644 --- a/phy/plot/glsl/msdf.vert +++ b/phy/plot/glsl/msdf.vert @@ -1,20 +1,20 @@ -attribute vec2 a_position; // text position -attribute vec4 a_color; -attribute float a_glyph_index; // glyph index in the text -attribute float a_quad_index; // quad index in the glyph -attribute float a_char_index; // index of the glyph in the texture -attribute float a_lengths; -attribute float a_string_index; // index of the string +in vec2 a_position; // text position +in vec4 a_color; +in float a_glyph_index; // glyph index in the text +in float a_quad_index; // quad index in the glyph +in float a_char_index; // index of the glyph in the texture +in float a_lengths; +in float a_string_index; // index of the string // (1, 1) for lower left, (-1, 1) for lower right, // (1, -1) for upper left, (-1, -1) for upper right -attribute vec2 a_anchor; +in vec2 a_anchor; uniform vec2 u_glyph_size; // (w, h) -varying vec4 v_color; -varying vec2 v_tex_coords; +out vec4 v_color; +out vec2 v_tex_coords; const float rows = 6; const float cols = 16; diff --git a/phy/plot/glsl/patch.frag b/phy/plot/glsl/patch.frag index 3649a0883..de6a5377e 100644 --- a/phy/plot/glsl/patch.frag +++ b/phy/plot/glsl/patch.frag @@ -1,6 +1,8 @@ -varying vec4 v_color; +in vec4 v_color; + +out vec4 fragColor; void main() { - gl_FragColor = v_color; + fragColor = v_color; } diff --git a/phy/plot/glsl/patch.vert b/phy/plot/glsl/patch.vert index f03afe4f4..57c2c324c 100644 --- a/phy/plot/glsl/patch.vert +++ b/phy/plot/glsl/patch.vert @@ -1,7 +1,7 @@ -attribute vec3 a_position; -attribute vec4 a_color; +in vec3 a_position; +in vec4 a_color; -varying vec4 v_color; +out vec4 v_color; void main() { vec2 xy = a_position.xy; diff --git a/phy/plot/glsl/plot.frag b/phy/plot/glsl/plot.frag index c5547f7e8..9b08ae2c5 100644 --- a/phy/plot/glsl/plot.frag +++ b/phy/plot/glsl/plot.frag @@ -1,8 +1,10 @@ #include "utils.glsl" -varying vec4 v_color; -varying float v_signal_index; -varying float v_mask; +in vec4 v_color; +in float v_signal_index; +in float v_mask; + +out vec4 fragColor; void main() { @@ -10,5 +12,5 @@ void main() { if (fract(v_signal_index) > 0.) discard; - gl_FragColor = apply_mask(v_color, v_mask); + fragColor = apply_mask(v_color, v_mask); } diff --git a/phy/plot/glsl/plot.vert b/phy/plot/glsl/plot.vert index bf7c34a1d..f5367b479 100644 --- a/phy/plot/glsl/plot.vert +++ b/phy/plot/glsl/plot.vert @@ -1,15 +1,15 @@ #include "utils.glsl" -attribute vec3 a_position; -attribute vec4 a_color; -attribute float a_signal_index; // 0..n_signals-1 -attribute float a_mask; +in vec3 a_position; +in vec4 a_color; +in float a_signal_index; // 0..n_signals-1 +in float a_mask; uniform float u_mask_max; -varying vec4 v_color; -varying float v_signal_index; -varying float v_mask; +out vec4 v_color; +out float v_signal_index; +out float v_mask; void main() { vec2 xy = a_position.xy; diff --git a/phy/plot/glsl/plot_agg.frag b/phy/plot/glsl/plot_agg.frag index 42a2da705..bac09bd72 100644 --- a/phy/plot/glsl/plot_agg.frag +++ b/phy/plot/glsl/plot_agg.frag @@ -7,17 +7,19 @@ // Varyings // ------------------------------------ -varying vec4 v_color; -varying float v_distance; -varying float v_linewidth; -varying float v_antialias; -varying float v_mask; +in vec4 v_color; +in float v_distance; +in float v_linewidth; +in float v_antialias; +in float v_mask; + +out vec4 fragColor; // Main // ------------------------------------ void main() { if (v_color.a == 0) { discard; } - gl_FragColor = stroke(v_distance, v_linewidth, v_antialias, v_color); - gl_FragColor = apply_mask(gl_FragColor, v_mask); + vec4 strokeColor = stroke(v_distance, v_linewidth, v_antialias, v_color); + fragColor = apply_mask(gl_FragColor, v_mask); } diff --git a/phy/plot/glsl/plot_agg.vert b/phy/plot/glsl/plot_agg.vert index 592ca4328..8e06e84e0 100644 --- a/phy/plot/glsl/plot_agg.vert +++ b/phy/plot/glsl/plot_agg.vert @@ -6,26 +6,26 @@ // Externs // ------------------------------------ -attribute vec3 a_prev; -attribute vec3 a_curr; -attribute vec3 a_next; -attribute float a_id; -attribute vec4 a_color; -attribute float a_mask; -attribute float a_depth; +in vec3 a_prev; +in vec3 a_curr; +in vec3 a_next; +in float a_id; +in vec4 a_color; +in float a_mask; +in float a_depth; uniform float u_antialias; uniform float u_linewidth; uniform float u_mask_max; -// Varyings +// outs // ------------------------------------ -varying float v_antialias; -varying float v_linewidth; -varying float v_distance; -varying vec4 v_color; +out float v_antialias; +out float v_linewidth; +out float v_distance; +out vec4 v_color; -varying float v_mask; +out float v_mask; vec2 NDC_to_viewport(vec4 position, vec2 viewport) { diff --git a/phy/plot/glsl/polygon.frag b/phy/plot/glsl/polygon.frag index 8df552c17..ec82f252f 100644 --- a/phy/plot/glsl/polygon.frag +++ b/phy/plot/glsl/polygon.frag @@ -1,5 +1,7 @@ uniform vec4 u_color; +out vec4 fragColor; + void main() { - gl_FragColor = u_color; + fragColor = u_color; } diff --git a/phy/plot/glsl/polygon.vert b/phy/plot/glsl/polygon.vert index a82e7671b..0e21ad701 100644 --- a/phy/plot/glsl/polygon.vert +++ b/phy/plot/glsl/polygon.vert @@ -1,4 +1,4 @@ -attribute vec2 a_position; +in vec2 a_position; uniform vec4 u_color; void main() { diff --git a/phy/plot/glsl/scatter.frag b/phy/plot/glsl/scatter.frag index a17f606ff..148e08285 100644 --- a/phy/plot/glsl/scatter.frag +++ b/phy/plot/glsl/scatter.frag @@ -1,15 +1,19 @@ #include "markers/%MARKER.glsl" #include "utils.glsl" -varying vec4 v_color; -varying float v_size; +in vec4 v_color; +in float v_size; + uniform vec2 u_zoom; + +out vec4 fragColor; + void main() { vec2 P = gl_PointCoord.xy - vec2(0.5, 0.5); float point_size = v_size + 5.; %MARKER_SCALING float distance = marker_%MARKER(P * point_size, marker_size); - gl_FragColor = filled(distance, 1.0, 1.0, v_color); + fragColor = filled(distance, 1.0, 1.0, v_color); } diff --git a/phy/plot/glsl/scatter.vert b/phy/plot/glsl/scatter.vert index c241fca42..ea1e2029a 100644 --- a/phy/plot/glsl/scatter.vert +++ b/phy/plot/glsl/scatter.vert @@ -1,9 +1,9 @@ -attribute vec3 a_position; -attribute vec4 a_color; -attribute float a_size; +in vec3 a_position; +in vec4 a_color; +in float a_size; -varying vec4 v_color; -varying float v_size; +out vec4 v_color; +out float v_size; void main() { vec2 xy = a_position.xy; diff --git a/phy/plot/glsl/simple.frag b/phy/plot/glsl/simple.frag index 8df552c17..ec82f252f 100644 --- a/phy/plot/glsl/simple.frag +++ b/phy/plot/glsl/simple.frag @@ -1,5 +1,7 @@ uniform vec4 u_color; +out vec4 fragColor; + void main() { - gl_FragColor = u_color; + fragColor = u_color; } diff --git a/phy/plot/glsl/simple.vert b/phy/plot/glsl/simple.vert index 2a59757e8..60eeb92f8 100644 --- a/phy/plot/glsl/simple.vert +++ b/phy/plot/glsl/simple.vert @@ -1,4 +1,4 @@ -attribute vec2 a_position; +in vec2 a_position; uniform vec4 u_color; void main() { diff --git a/phy/plot/glsl/text.frag b/phy/plot/glsl/text.frag index 6e4ba84ef..7883df42b 100644 --- a/phy/plot/glsl/text.frag +++ b/phy/plot/glsl/text.frag @@ -5,10 +5,12 @@ uniform sampler2D u_tex; uniform vec4 u_color; uniform vec2 u_zoom; -varying vec2 v_tex_coords; +in vec2 v_tex_coords; + +out vec4 fragColor; void main() { // Texture scalar. - float c = texture2D(u_tex, v_tex_coords).x; - gl_FragColor = vec4(u_color.rgb * c, u_color.a); + float c = texture(u_tex, v_tex_coords).x; + fragColor = vec4(u_color.rgb * c, u_color.a); } diff --git a/phy/plot/glsl/text.vert b/phy/plot/glsl/text.vert index e54731b2f..653972555 100644 --- a/phy/plot/glsl/text.vert +++ b/phy/plot/glsl/text.vert @@ -1,19 +1,19 @@ // NOTE: NOT USED ANYMORE (see msdf.vert instead) -attribute vec2 a_position; // text position -attribute float a_glyph_index; // glyph index in the text -attribute float a_quad_index; // quad index in the glyph -attribute float a_char_index; // index of the glyph in the texture -attribute float a_lengths; +in vec2 a_position; // text position +in float a_glyph_index; // glyph index in the text +in float a_quad_index; // quad index in the glyph +in float a_char_index; // index of the glyph in the texture +in float a_lengths; // (1, 1) for lower left, (-1, 1) for lower right, // (1, -1) for upper left, (-1, -1) for upper right -attribute vec2 a_anchor; +in vec2 a_anchor; uniform vec2 u_glyph_size; // (w, h) -varying vec2 v_tex_coords; +out vec2 v_tex_coords; const float rows = 6; const float cols = 16; diff --git a/phy/plot/glsl/uni_plot.frag b/phy/plot/glsl/uni_plot.frag index 4ebbe9701..f77f7e254 100644 --- a/phy/plot/glsl/uni_plot.frag +++ b/phy/plot/glsl/uni_plot.frag @@ -1,14 +1,15 @@ #include "utils.glsl" uniform vec4 u_color; -varying float v_signal_index; -varying float v_mask; +in float v_signal_index; +in float v_mask; + +out vec4 fragColor; void main() { // Discard pixels between signals. if (fract(v_signal_index) > 0.) discard; - - gl_FragColor = apply_mask(u_color, v_mask); + fragColor = apply_mask(u_color, v_mask); } diff --git a/phy/plot/glsl/uni_plot.vert b/phy/plot/glsl/uni_plot.vert index 3bac16626..9ef3e968b 100644 --- a/phy/plot/glsl/uni_plot.vert +++ b/phy/plot/glsl/uni_plot.vert @@ -1,14 +1,14 @@ #include "utils.glsl" -attribute vec2 a_position; -attribute float a_signal_index; // 0..n_signals-1 -attribute float a_mask; +in vec2 a_position; +in float a_signal_index; // 0..n_signals-1 +in float a_mask; uniform vec4 u_color; uniform float u_mask_max; -varying float v_signal_index; -varying float v_mask; +out float v_signal_index; +out float v_mask; void main() { gl_Position = transform(a_position); @@ -16,4 +16,4 @@ void main() { v_signal_index = a_signal_index; v_mask = a_mask; -} +} \ No newline at end of file diff --git a/phy/plot/glsl/uni_scatter.frag b/phy/plot/glsl/uni_scatter.frag index c9aa6c45b..855999f3e 100644 --- a/phy/plot/glsl/uni_scatter.frag +++ b/phy/plot/glsl/uni_scatter.frag @@ -4,7 +4,9 @@ uniform vec4 u_color; uniform float u_size; -varying float v_mask; +in float v_mask; + +out vec4 fragColor; vec4 filled2(float distance, float linewidth, float antialias, vec4 bg_color) { @@ -36,5 +38,5 @@ void main() float point_size = u_size + 5.; float distance = marker_%MARKER(P * point_size, u_size); vec4 color = apply_mask(u_color, v_mask); - gl_FragColor = filled2(distance, 1.0, 1.0, color); + fragColor = filled2(distance, 1.0, 1.0, color); } diff --git a/phy/plot/glsl/uni_scatter.vert b/phy/plot/glsl/uni_scatter.vert index d7f263cc7..24ccc0817 100644 --- a/phy/plot/glsl/uni_scatter.vert +++ b/phy/plot/glsl/uni_scatter.vert @@ -1,13 +1,13 @@ #include "utils.glsl" -attribute vec2 a_position; -attribute float a_mask; +in vec2 a_position; +in float a_mask; uniform vec4 u_color; uniform float u_size; uniform float u_mask_max; -varying float v_mask; +out float v_mask; void main() { gl_Position = transform(a_position); diff --git a/phy/plot/glsl/utils.glsl b/phy/plot/glsl/utils.glsl index 3b2875911..c2e3a77d6 100644 --- a/phy/plot/glsl/utils.glsl +++ b/phy/plot/glsl/utils.glsl @@ -18,8 +18,8 @@ vec3 rgb_to_hsv(vec3 c) } -vec4 fetch_texture(float index, sampler2D texture, float size) { - return texture2D(texture, vec2(index / (size - 1.), .5)); +vec4 fetch_texture(float index, sampler2D tex, float size) { + return texture(tex, vec2(index / (size - 1.), .5)); } diff --git a/phy/plot/interact.py b/phy/plot/interact.py index c44957a97..2c2ad1b8a 100644 --- a/phy/plot/interact.py +++ b/phy/plot/interact.py @@ -80,7 +80,7 @@ def attach(self, canvas): canvas.gpu_transforms += self.gpu_transforms canvas.inserter.insert_vert( """ - attribute vec2 {}; + in vec2 {}; uniform vec2 {}; uniform vec2 u_grid_scaling; """.format(self.box_var, self.shape_var), @@ -204,7 +204,7 @@ def attach(self, canvas): canvas.gpu_transforms += self.gpu_transforms canvas.inserter.insert_vert(""" #include "utils.glsl" - attribute float {}; + in float {}; uniform sampler2D u_box_pos; uniform float n_boxes; uniform vec2 u_box_size; @@ -385,7 +385,7 @@ def attach(self, canvas): canvas.gpu_transforms += self.gpu_transforms canvas.inserter.insert_vert(""" #include "utils.glsl" - attribute float {}; + in float {}; uniform float n_boxes; uniform bool u_top_origin; uniform vec2 u_box_size; diff --git a/phy/plot/tests/test_base.py b/phy/plot/tests/test_base.py index 5382aa38b..a2b9a062a 100644 --- a/phy/plot/tests/test_base.py +++ b/phy/plot/tests/test_base.py @@ -28,7 +28,7 @@ @fixture def vertex_shader_nohook(): yield """ - attribute vec2 a_position; + in vec2 a_position; void main() { gl_Position = vec4(a_position.xy, 0, 1); } @@ -38,7 +38,7 @@ def vertex_shader_nohook(): @fixture def vertex_shader(): yield """ - attribute vec2 a_position; + in vec2 a_position; void main() { gl_Position = transform(a_position.xy); gl_PointSize = 2.0; @@ -49,8 +49,9 @@ def vertex_shader(): @fixture def fragment_shader(): yield """ + out vec4 fragColor; void main() { - gl_FragColor = vec4(1, 1, 1, 1); + fragColor = vec4(1, 1, 1, 1); } """ diff --git a/phy/plot/tests/test_interact.py b/phy/plot/tests/test_interact.py index 2c6d97799..4050d4c52 100644 --- a/phy/plot/tests/test_interact.py +++ b/phy/plot/tests/test_interact.py @@ -32,7 +32,7 @@ class MyTestVisual(BaseVisual): def __init__(self): super(MyTestVisual, self).__init__() self.vertex_shader = """ - attribute vec2 a_position; + in vec2 a_position; void main() { vec2 xy = a_position.xy; gl_Position = transform(xy); @@ -40,8 +40,9 @@ def __init__(self): } """ self.fragment_shader = """ + out vec4 fragColor; void main() { - gl_FragColor = vec4(1, 1, 1, 1); + fragColor = vec4(1, 1, 1, 1); } """ self.set_primitive_type('points')