Support TextureInteger*
This PR adds TextureInteger* classes.
This modification alone would not let us use IntegerTexture with uniforms.
I will send another PR that allows us to do that. I split the PR because I felt that the changes are large.
This PR alone can let users use IntegerTexture with framebuffers.
Here is an example.
# -----------------------------------------------------------------------------
# Copyright (c) 2009-2016 Nicolas P. Rougier. All rights reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
import numpy as np
from glumpy import app, gl, gloo
vertex_1 = """
in vec2 position;
void main()
{
gl_Position = vec4(position,0.0,1.0);
}
"""
fragment_1 = """
layout(location = 0) out vec4 FragColor;
layout(location = 1) out int v_int;
void main()
{
FragColor = vec4(10.0, 10.0, 10.0, 1.0);
v_int = 10;
}
"""
app.use('glfw', api='GL', major=4, minor=3, profile='core')
window = app.Window(width=8, height=8)
vao = gl.glGenVertexArrays(1)
gl.glBindVertexArray(vao)
@window.event
def on_draw(dt):
window.clear()
framebuffer.activate()
quad_1.draw(gl.GL_TRIANGLE_STRIP)
out_texture = framebuffer.color[1].get()
print(out_texture[:, :, 0])
texture_0 = np.zeros((window.height,window.width,4), np.float32).view(gloo.TextureFloat2D)
texture_1 = np.zeros((window.height,window.width,1), np.int32).view(gloo.TextureInteger2D)
framebuffer = gloo.FrameBuffer(color=[texture_0, texture_1])
quad_1 = gloo.Program(vertex_1, fragment_1, count=4, version="330")
quad_1["position"] = (-1,-1), (-1,+1), (+1,-1), (+1,+1)
app.run(framecount=1)
This example prints the contents of register buffer, which is an integer texture. You can check that the contents are updated.
What is the underlying GL object? A regular texture?
Yes. It is just a texture. The class hierarchy is analogous to the float texture.
Ok. What is the relation with PR #140? Is it an extension to this PR?
Yes. #140 is an extension to this PR.
The extension is necessary to use TextureInteger* as uniforms.
Since the change in #140 is relatively big, I split the PRs to make review easier.
Ok. I'll need some time to test it. Don't hesitate to ping me here to ask for news.