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 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)
def __draw(self): gl.glClearColor(self.__bg_color[0], self.__bg_color[1], self.__bg_color[2], self.__bg_color[3]) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glUseProgram(self.__prog.value) # update data buffer if necessary with self.__data_lock: if self.__data_altered: self.__setup_data_buffer() self.__set_uniforms() self.__set_attributes() gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) gl.glEnable(gl.GL_BLEND) gl.glEnable(gl.GL_CULL_FACE) gl.glDrawArraysInstanced(gl.GL_TRIANGLES, 0, 36, self.__data.size / (self.__downsample**3))