Cache shader attribute locations in TileRenderable
This commit is contained in:
parent
4f8b009a71
commit
8c4def54af
1 changed files with 15 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue