From 8c4def54af32a2290993030d3ca2ed8fc0acd2cb Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Thu, 12 Feb 2026 21:08:00 -0500 Subject: [PATCH] Cache shader attribute locations in TileRenderable --- playscii/renderable.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/playscii/renderable.py b/playscii/renderable.py index 4bdb09b..ea17f69 100644 --- a/playscii/renderable.py +++ b/playscii/renderable.py @@ -92,6 +92,11 @@ class TileRenderable: self.alpha_uniform = self.shader.get_uniform_location("alpha") self.brightness_uniform = self.shader.get_uniform_location("brightness") self.bg_alpha_uniform = self.shader.get_uniform_location("bgColorAlpha") + self.attrib_vert_position = self.shader.get_attrib_location("vertPosition") + self.attrib_char_index = self.shader.get_attrib_location("charIndex") + self.attrib_uv_mod = self.shader.get_attrib_location("uvMod") + self.attrib_fg_color_index = self.shader.get_attrib_location("fgColorIndex") + self.attrib_bg_color_index = self.shader.get_attrib_location("bgColorIndex") self.create_buffers() # finish if self.app.use_vao: @@ -485,39 +490,38 @@ class TileRenderable: if self.app.use_vao: GL.glBindVertexArray(self.vao) else: - attrib = self.shader.get_attrib_location # for brevity vp = ctypes.c_void_p(0) # bind each buffer and set its attrib: # verts GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vert_buffer) GL.glVertexAttribPointer( - attrib("vertPosition"), VERT_LENGTH, GL.GL_FLOAT, GL.GL_FALSE, 0, vp + self.attrib_vert_position, VERT_LENGTH, GL.GL_FLOAT, GL.GL_FALSE, 0, vp ) - GL.glEnableVertexAttribArray(attrib("vertPosition")) + GL.glEnableVertexAttribArray(self.attrib_vert_position) # chars GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.char_buffer) GL.glVertexAttribPointer( - attrib("charIndex"), 1, GL.GL_FLOAT, GL.GL_FALSE, 0, vp + self.attrib_char_index, 1, GL.GL_FLOAT, GL.GL_FALSE, 0, vp ) - GL.glEnableVertexAttribArray(attrib("charIndex")) + GL.glEnableVertexAttribArray(self.attrib_char_index) # uvs GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.uv_buffer) GL.glVertexAttribPointer( - attrib("uvMod"), 2, GL.GL_FLOAT, GL.GL_FALSE, 0, vp + self.attrib_uv_mod, 2, GL.GL_FLOAT, GL.GL_FALSE, 0, vp ) - GL.glEnableVertexAttribArray(attrib("uvMod")) + GL.glEnableVertexAttribArray(self.attrib_uv_mod) # fg colors GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.fg_buffer) GL.glVertexAttribPointer( - attrib("fgColorIndex"), 1, GL.GL_FLOAT, GL.GL_FALSE, 0, vp + self.attrib_fg_color_index, 1, GL.GL_FLOAT, GL.GL_FALSE, 0, vp ) - GL.glEnableVertexAttribArray(attrib("fgColorIndex")) + GL.glEnableVertexAttribArray(self.attrib_fg_color_index) # bg colors GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.bg_buffer) GL.glVertexAttribPointer( - attrib("bgColorIndex"), 1, GL.GL_FLOAT, GL.GL_FALSE, 0, vp + self.attrib_bg_color_index, 1, GL.GL_FLOAT, GL.GL_FALSE, 0, vp ) - GL.glEnableVertexAttribArray(attrib("bgColorIndex")) + GL.glEnableVertexAttribArray(self.attrib_bg_color_index) # finally, bind element buffer GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, self.elem_buffer) GL.glEnable(GL.GL_BLEND)