Skip to content

Commit

Permalink
Starting to break up opengl/CyOpenGL.pyx into smaller pieces.
Browse files Browse the repository at this point in the history
  • Loading branch information
unhyperbolic committed Jan 25, 2024
1 parent cb85f9e commit 01383f4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
48 changes: 0 additions & 48 deletions opengl/CyOpenGL.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
48 changes: 48 additions & 0 deletions opengl/modern/triangle.pyx
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 01383f4

Please sign in to comment.