From 01383f4b391c63643b0ea78557d8fa6ae53d652d Mon Sep 17 00:00:00 2001 From: Matthias Goerner <1239022+unhyperbolic@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:26:49 -0800 Subject: [PATCH] Starting to break up opengl/CyOpenGL.pyx into smaller pieces. --- opengl/CyOpenGL.pyx | 48 -------------------------------------- opengl/modern/triangle.pyx | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 48 deletions(-) create mode 100644 opengl/modern/triangle.pyx diff --git a/opengl/CyOpenGL.pyx b/opengl/CyOpenGL.pyx index 51305dd6..81576015 100644 --- a/opengl/CyOpenGL.pyx +++ b/opengl/CyOpenGL.pyx @@ -2718,51 +2718,3 @@ class GLSLPerspectiveWidget(RawOpenGLWidget, GLSLPerspectiveView): if not skip_swap_buffers: self.swap_buffers() -cdef class Triangle: - """ - A triangle with given vertices. - """ - - cdef _gl_widget - cdef _program - cdef _vertex_buffer - - def __init__(self, gl_widget, program, vertices): - """ - Constructed from GL widget, GLSLProgram and vertices - such as [[0,0,0],[1,1,0],[0,1,1]]. - """ - - self._gl_widget = gl_widget - self._program = program - self._vertex_buffer = VertexBuffer() - self._vertex_buffer.load(vertices) - - def draw(self, view_width, view_height): - """ - Draw the object (given size of viewport) by binding - the program and the uniforms and calling draw_impl() which - is implemented by some subclass. - """ - - self._program.use_program() - self._program.bind_uniforms( - self.get_uniform_bindings(view_width, view_height)) - - self._vertex_buffer.bind() - - # Draw the triangle - glDrawArrays(GL_TRIANGLES, 0, 3) - - def delete_resource(self): - self._vertex_buffer.delete_resource() - self._program.delete_resource() - - def get_uniform_bindings(self, view_width, view_height): - """ - Override to bind the uniforms you want. - - Arguments are size of viewport. - """ - - return self._gl_widget.get_uniform_bindings(view_width, view_height) diff --git a/opengl/modern/triangle.pyx b/opengl/modern/triangle.pyx new file mode 100644 index 00000000..c4e275d1 --- /dev/null +++ b/opengl/modern/triangle.pyx @@ -0,0 +1,48 @@ +cdef class Triangle: + """ + A triangle with given vertices. + """ + + cdef _gl_widget + cdef _program + cdef _vertex_buffer + + def __init__(self, gl_widget, program, vertices): + """ + Constructed from GL widget, GLSLProgram and vertices + such as [[0,0,0],[1,1,0],[0,1,1]]. + """ + + self._gl_widget = gl_widget + self._program = program + self._vertex_buffer = VertexBuffer() + self._vertex_buffer.load(vertices) + + def draw(self, view_width, view_height): + """ + Draw the object (given size of viewport) by binding + the program and the uniforms and calling draw_impl() which + is implemented by some subclass. + """ + + self._program.use_program() + self._program.bind_uniforms( + self.get_uniform_bindings(view_width, view_height)) + + self._vertex_buffer.bind() + + # Draw the triangle + glDrawArrays(GL_TRIANGLES, 0, 3) + + def delete_resource(self): + self._vertex_buffer.delete_resource() + self._program.delete_resource() + + def get_uniform_bindings(self, view_width, view_height): + """ + Override to bind the uniforms you want. + + Arguments are size of viewport. + """ + + return self._gl_widget.get_uniform_bindings(view_width, view_height)