def __init__(self, ctx): # TODO: Support querying a subset of these queries (faster) # TODO: Evalute of this query should be included # gl.GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN # gl.GL_ANY_SAMPLES_PASSED self._ctx = ctx self._glo_samples_passed = glo_samples_passed = gl.GLuint() gl.glGenQueries(1, self._glo_samples_passed) self._glo_time_elapsed = glo_time_elapsed = gl.GLuint() gl.glGenQueries(1, self._glo_time_elapsed) self._glo_primitives_generated = glo_time_elapsed = gl.GLuint() gl.glGenQueries(1, self._glo_primitives_generated) glos = [glo_samples_passed, glo_time_elapsed, glo_time_elapsed] weakref.finalize(self, Query.release, self._ctx, glos)
def __init__(self, world, chunk_position): self.world = world self.shader_chunk_offset_location = self.world.shader.find_uniform(b"u_ChunkPosition") self.modified = False self.chunk_position = chunk_position self.position = ( self.chunk_position[0] * CHUNK_WIDTH, self.chunk_position[1] * CHUNK_HEIGHT, self.chunk_position[2] * CHUNK_LENGTH) self.blocks = [[[0 for z in range(CHUNK_LENGTH)] for y in range(CHUNK_HEIGHT)] for x in range(CHUNK_WIDTH)] # Numpy is really slow there self.lightmap = [[[0 for z in range(CHUNK_LENGTH)] for y in range(CHUNK_HEIGHT)] for x in range(CHUNK_WIDTH)] self.subchunks = {} self.chunk_update_queue = deque() for x in range(int(CHUNK_WIDTH / subchunk.SUBCHUNK_WIDTH)): for y in range(int(CHUNK_HEIGHT / subchunk.SUBCHUNK_HEIGHT)): for z in range(int(CHUNK_LENGTH / subchunk.SUBCHUNK_LENGTH)): self.subchunks[(x, y, z)] = subchunk.Subchunk(self, (x, y, z)) # mesh variables self.mesh = [] self.translucent_mesh = [] self.mesh_quad_count = 0 self.translucent_quad_count = 0 # create VAO and VBO's self.vao = gl.GLuint(0) gl.glGenVertexArrays(1, self.vao) gl.glBindVertexArray(self.vao) self.vbo = gl.GLuint(0) gl.glGenBuffers(1, self.vbo) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vbo) gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(gl.GLfloat * CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_LENGTH * 7), None, gl.GL_DYNAMIC_DRAW) gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 7 * ctypes.sizeof(gl.GLfloat), 0) gl.glEnableVertexAttribArray(0) gl.glVertexAttribPointer(1, 1, gl.GL_FLOAT, gl.GL_FALSE, 7 * ctypes.sizeof(gl.GLfloat), 3 * ctypes.sizeof(gl.GLfloat)) gl.glEnableVertexAttribArray(1) gl.glVertexAttribPointer(2, 1, gl.GL_FLOAT, gl.GL_FALSE, 7 * ctypes.sizeof(gl.GLfloat), 4 * ctypes.sizeof(gl.GLfloat)) gl.glEnableVertexAttribArray(2) gl.glVertexAttribPointer(3, 1, gl.GL_FLOAT, gl.GL_FALSE, 7 * ctypes.sizeof(gl.GLfloat), 5 * ctypes.sizeof(gl.GLfloat)) gl.glEnableVertexAttribArray(3) gl.glVertexAttribPointer(4, 1, gl.GL_FLOAT, gl.GL_FALSE, 7 * ctypes.sizeof(gl.GLfloat), 6 * ctypes.sizeof(gl.GLfloat)) gl.glEnableVertexAttribArray(4) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, world.ibo) if self.world.options.INDIRECT_RENDERING: self.indirect_command_buffer = gl.GLuint(0) gl.glGenBuffers(1, self.indirect_command_buffer) gl.glBindBuffer(gl.GL_DRAW_INDIRECT_BUFFER, self.indirect_command_buffer) gl.glBufferData( gl.GL_DRAW_INDIRECT_BUFFER, ctypes.sizeof(gl.GLuint * 10), None, gl.GL_DYNAMIC_DRAW ) self.draw_commands = [] self.occlusion_query = gl.GLuint(0) gl.glGenQueries(1, self.occlusion_query)