def render(self, mode: gl.GLuint, instances: int = 1): if self.ibo is not None: count = self.ibo.size // 4 gl.glDrawElementsInstanced(mode, count, gl.GL_UNSIGNED_INT, None, instances) else: gl.glDrawArraysInstanced(mode, 0, self.num_vertices, instances)
def transform( self, buffer: Buffer, mode: gl.GLenum, output_mode: gl.GLenum, first: int = 0, vertices: int = 0, instances: int = 1, buffer_offset=0, ): """Run a transform feedback. :param Buffer buffer: The buffer to write the output :param gl.GLenum mode: The input primitive mode :param gl.GLenum output:mode: The output primitive mode :param int first: Offset start vertex :param int vertices: Number of vertices to render :param int instances: Number of instances to render :param int buffer_offset: Byte offset for the buffer (target) """ if vertices < 0: raise ValueError( f"Cannot determine the number of vertices: {vertices}") if buffer_offset >= buffer.size: raise ValueError("buffer_offset at end or past the buffer size") gl.glBindVertexArray(self.glo) gl.glEnable(gl.GL_RASTERIZER_DISCARD) if buffer_offset > 0: gl.glBindBufferRange( gl.GL_TRANSFORM_FEEDBACK_BUFFER, 0, buffer.glo, buffer_offset, buffer.size - buffer_offset, ) else: gl.glBindBufferBase(gl.GL_TRANSFORM_FEEDBACK_BUFFER, 0, buffer.glo) gl.glBeginTransformFeedback(output_mode) if self._ibo is not None: count = self._ibo.size // 4 # TODO: Support first argument by offsetting pointer (second last arg) gl.glDrawElementsInstanced(mode, count, gl.GL_UNSIGNED_INT, None, instances) else: # print(f"glDrawArraysInstanced({mode}, {first}, {vertices}, {instances})") gl.glDrawArraysInstanced(mode, first, vertices, instances) gl.glEndTransformFeedback() gl.glDisable(gl.GL_RASTERIZER_DISCARD)
def draw(self): previous_draw_mode = gl.GLint(0) gl.glGetIntegerv(gl.GL_POLYGON_MODE, byref(previous_draw_mode)) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) self.shader.use() gl.glBindVertexArray(self.array) # gl.glDrawElements(gl.GL_TRIANGLES, self.width * self.height * 6, gl.GL_UNSIGNED_INT, None) gl.glDrawElementsInstanced(gl.GL_TRIANGLES, Chunk.cells * 6, gl.GL_UNSIGNED_INT, None, self.instances) gl.glBindVertexArray(0) self.shader.clear() gl.glPolygonMode(gl.GL_FRONT_AND_BACK, previous_draw_mode.value)
def render( self, mode: gl.GLenum, first: int = 0, vertices: int = 0, instances: int = 1 ): """Render the VertexArray to the currently active framebuffer. :param GLuint mode: Primitive type to render. TRIANGLES, LINES etc. :param int first: The first vertex to render from :param int vertices: Number of vertices to render :param int instances: OpenGL instance, used in using vertices over and over """ gl.glBindVertexArray(self.glo) if self._ibo is not None: gl.glDrawElementsInstanced(mode, vertices, gl.GL_UNSIGNED_INT, first * 4, instances) else: gl.glDrawArraysInstanced(mode, first, vertices, instances)
def render( self, mode: gl.GLenum, first: int = 0, vertices: int = 0, instances: int = 1 ): """Render the VertexArray to the currently active framebuffer. :param GLuint mode: Primitive type to render. TRIANGLES, LINES etc. :param int first: The first vertex to render from :param int vertices: Number of vertices to render :param int instances: OpenGL instance, used in using vertices over and over """ gl.glBindVertexArray(self.glo) if self._ibo is not None: count = self._ibo.size // 4 # TODO: Support first argument by offsetting pointer (second last arg) gl.glDrawElementsInstanced(mode, count, gl.GL_UNSIGNED_INT, None, instances) else: # print(f"glDrawArraysInstanced({mode}, {first}, {vertices}, {instances})") gl.glDrawArraysInstanced(mode, first, vertices, instances)