Mercurial > touhou
annotate pytouhou/ui/opengl/framebuffer.pyx @ 616:4ce3ef053a25
Remove every case where an exception could be silently eaten by a cdef function.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 28 Mar 2015 23:21:15 +0100 |
parents | 1b31169dc344 |
children | a6af3ff86612 |
rev | line source |
---|---|
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 ## |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 ## Copyright (C) 2014 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 ## |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 ## |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ## |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
610
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
15 from libc.stdlib cimport free |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
16 |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 from pytouhou.lib.opengl cimport \ |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 (glPushDebugGroup, glPopDebugGroup, GL_DEBUG_SOURCE_APPLICATION, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 glGenTextures, glDeleteTextures, glBindTexture, glTexParameteri, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 glTexImage2D, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 GL_TEXTURE_MAG_FILTER, GL_LINEAR, GL_RGBA, GL_UNSIGNED_BYTE, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 glGenRenderbuffers, glDeleteRenderbuffers, glBindRenderbuffer, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 glRenderbufferStorage, GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 glGenFramebuffers, glDeleteFramebuffers, glBindFramebuffer, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 glFramebufferTexture2D, glFramebufferRenderbuffer, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 glCheckFramebufferStatus, GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_COMPLETE, glGenBuffers, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 glDeleteBuffers, glBindBuffer, glBufferData, GL_ARRAY_BUFFER, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 GL_STATIC_DRAW, glGenVertexArrays, glDeleteVertexArrays, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 glBindVertexArray, glVertexAttribPointer, GL_SHORT, GL_FLOAT, |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
31 glEnableVertexAttribArray, glDrawArrays, GL_TRIANGLE_STRIP, |
609
23b9418e4b2f
Remove generic usage of GL_DRAW_FRAMEBUFFER which was introduced in GL 3.0 with framebuffer_blit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
32 glBlitFramebuffer, GL_READ_FRAMEBUFFER, glClear, GL_COLOR_BUFFER_BIT, |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
33 GL_DEPTH_BUFFER_BIT, glViewport, glBlendFunc, GL_ONE, GL_ZERO) |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 |
610
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
35 from pytouhou.utils.maths cimport ortho_2d |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
36 |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
37 from .shaders.eosd import PassthroughShader |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
38 from .backend cimport use_debug_group, use_vao, use_framebuffer_blit |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 cdef class Framebuffer: |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 def __init__(self, int x, int y, int width, int height): |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 if use_debug_group: |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer creation") |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 # This texture will receive the game area in native resolution. |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 glGenTextures(1, &self.texture) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 glBindTexture(GL_TEXTURE_2D, self.texture) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 glTexImage2D(GL_TEXTURE_2D, 0, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 GL_RGBA, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 width, height, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 0, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 GL_RGBA, GL_UNSIGNED_BYTE, |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 NULL) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 glBindTexture(GL_TEXTURE_2D, 0) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 # We need a depth buffer, but don’t care about retrieving it. |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 glGenRenderbuffers(1, &self.rbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 glBindRenderbuffer(GL_RENDERBUFFER, self.rbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 glBindRenderbuffer(GL_RENDERBUFFER, 0) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 # The framebuffer is there as a rendering target. |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 glGenFramebuffers(1, &self.fbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 glBindFramebuffer(GL_FRAMEBUFFER, self.fbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self.texture, 0) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, self.rbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 assert glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 glBindFramebuffer(GL_FRAMEBUFFER, 0) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
72 if not use_framebuffer_blit: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
73 # We’ll use only those vertices, everytime. |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
74 self.buf[0] = PassthroughVertex(x, y, 0, 1) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
75 self.buf[1] = PassthroughVertex(x + width, y, 1, 1) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
76 self.buf[2] = PassthroughVertex(x, y + height, 0, 0) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
77 self.buf[3] = PassthroughVertex(x + width, y + height, 1, 0) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
78 |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
79 # Now we upload those vertices into a static vbo. |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
80 glGenBuffers(1, &self.vbo) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
81 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
82 glBufferData(GL_ARRAY_BUFFER, sizeof(self.buf), self.buf, GL_STATIC_DRAW) |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
84 # As a performance optimisation, if supported, store the rendering state into a vao. |
610
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
85 if use_vao: |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
86 glGenVertexArrays(1, &self.vao) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
87 glBindVertexArray(self.vao) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
88 self.set_state() |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
89 glBindVertexArray(0) |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
91 glBindBuffer(GL_ARRAY_BUFFER, 0) |
610
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
92 |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
93 # And finally the shader we’ll use to display everything. |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
94 self.shader = PassthroughShader() |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
95 self.mvp = ortho_2d(0., float(width), float(height), 0.) |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
96 else: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
97 self.x = x |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
98 self.y = y |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
99 self.width = width |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
100 self.height = height |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 if use_debug_group: |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 glPopDebugGroup() |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 def __dealloc__(self): |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
106 if not use_framebuffer_blit: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
107 glDeleteBuffers(1, &self.vbo) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
108 if use_vao: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
109 glDeleteVertexArrays(1, &self.vao) |
610
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
110 if self.mvp != NULL: |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
111 free(self.mvp) |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 glDeleteTextures(1, &self.texture) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 glDeleteRenderbuffers(1, &self.rbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 glDeleteFramebuffers(1, &self.fbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 cpdef bind(self): |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 glBindFramebuffer(GL_FRAMEBUFFER, self.fbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 cdef void set_state(self) nogil: |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 #TODO: find a way to use offsetof() instead of those ugly hardcoded values. |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 glVertexAttribPointer(0, 2, GL_SHORT, False, sizeof(PassthroughVertex), <void*>0) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 glEnableVertexAttribArray(0) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(PassthroughVertex), <void*>4) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 glEnableVertexAttribArray(1) |
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 |
610
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
128 cdef void render(self, int x, int y, int width, int height) except *: |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
129 if use_debug_group: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
130 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer drawing") |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
131 |
609
23b9418e4b2f
Remove generic usage of GL_DRAW_FRAMEBUFFER which was introduced in GL 3.0 with framebuffer_blit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
132 glBindFramebuffer(GL_FRAMEBUFFER, 0) |
23b9418e4b2f
Remove generic usage of GL_DRAW_FRAMEBUFFER which was introduced in GL 3.0 with framebuffer_blit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
133 glClear(GL_COLOR_BUFFER_BIT) |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
134 |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
135 if use_framebuffer_blit: |
609
23b9418e4b2f
Remove generic usage of GL_DRAW_FRAMEBUFFER which was introduced in GL 3.0 with framebuffer_blit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
136 glBindFramebuffer(GL_READ_FRAMEBUFFER, self.fbo) |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
137 glBlitFramebuffer(self.x, self.y, self.width, self.height, |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
138 x, y, x + width, y + height, |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
139 GL_COLOR_BUFFER_BIT, GL_LINEAR) |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 else: |
610
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
141 self.shader.bind() |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
142 self.shader.uniform_matrix('mvp', self.mvp) |
1b31169dc344
Move the passthrough shader to the Framebuffer class, since it isn’t used in the use_framebuffer_blit path.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
609
diff
changeset
|
143 |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
144 glViewport(x, y, width, height) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
145 glBlendFunc(GL_ONE, GL_ZERO) |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
147 if use_vao: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
148 glBindVertexArray(self.vao) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
149 else: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
150 self.set_state() |
586
4b0593da29d5
Simplify framebuffer rendering with glDrawArrays, and move it all to its own file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
151 |
587
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
152 glBindTexture(GL_TEXTURE_2D, self.texture) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
153 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
154 glBindTexture(GL_TEXTURE_2D, 0) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
155 |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
156 if use_vao: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
157 glBindVertexArray(0) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
158 else: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
159 glBindBuffer(GL_ARRAY_BUFFER, 0) |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
160 |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
161 if use_debug_group: |
6c9d8a3d853f
Use ARB_framebuffer_blit instead of a second rendering pass for scaled rendering, if supported, and remove framebuffer stuff from the Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
162 glPopDebugGroup() |