Projection: Set the new window_block + initialize block on window creation
@@ -268,13 +268,7 @@ class Projection2D(Projection):
height = max(1, window_height)
gl.glViewport(0, 0, framebuffer_width, framebuffer_height)
-
- with pyglet.graphics.get_default_shader().uniform_buffers['WindowBlock'] as window_block:
- window_block.projection[:] = Mat4.orthogonal_projection(0, width, 0, height, -255, 255)
- if not self._view:
- # Set view to Identity Matrix
- self._view = Mat4()
- window_block.view[:] = self._view
+ gl.current_context.window_block.set_projection(Mat4.orthogonal_projection(0, width, 0, height, -255, 255))
class Projection3D(Projection):
@@ -302,13 +296,7 @@ class Projection3D(Projection):
height = max(1, window_height)
gl.glViewport(0, 0, framebuffer_width, framebuffer_height)
-
- with pyglet.graphics.get_default_shader().uniform_buffers['WindowBlock'] as window_block:
- window_block.projection[:] = Mat4.perspective_projection(0, width, 0, height, self.znear, self.zfar, self.fov)
- if not self._view:
- # Set view to Identity Matrix
- self._view = Mat4()
- window_block.view[:] = self._view
+ gl.current_context.window_block.set_projection(Mat4.perspective_projection(0, width, 0, height, self.znear, self.zfar, self.fov))
def _PlatformEventHandler(data):
@@ -643,6 +631,12 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)):
self.set_visible(True)
self.activate()
+ # Initialize context specific resources like default programs and UBOs
+ from pyglet.graphics.shader import WindowBlock
+ self.context.window_block = WindowBlock()
+
+ self._projection.set(self._width, self._height, *self.get_framebuffer_size())
+
def __del__(self):
# Always try to clean up the window when it is dereferenced.
# Makes sure there are no dangling pointers or memory leaks.
@@ -1060,7 +1054,7 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)):
Retina screens on OS X and Gnome on Linux are some examples.
On a Retina systems the returned ratio would usually be 2.0 as a
- window of size 500 x 500 would have a frambuffer of 1000 x 1000.
+ window of size 500 x 500 would have a framebuffer of 1000 x 1000.
Fractional values between 1.0 and 2.0, as well as values above
2.0 may also be encountered.
