Support vertex attrib divisors
This commit is contained in:
@@ -50,7 +50,7 @@ void main() {
|
|||||||
final_color = vec4(color, 1);
|
final_color = vec4(color, 1);
|
||||||
}
|
}
|
||||||
''')
|
''')
|
||||||
self.add_vertex_array('rect')
|
self.add_vertex_arrays(self.vertex_array('rect'))
|
||||||
|
|
||||||
def send_data(self, data):
|
def send_data(self, data):
|
||||||
self.send_vertex_data('rect', data)
|
self.send_vertex_data('rect', data)
|
||||||
|
|||||||
10
kitty/gl.h
10
kitty/gl.h
@@ -695,6 +695,15 @@ VertexAttribPointer(PyObject UNUSED *self, PyObject *args) {
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
VertexAttribDivisor(PyObject UNUSED *self, PyObject *args) {
|
||||||
|
unsigned int index, divisor;
|
||||||
|
if (!PyArg_ParseTuple(args, "II", &index, &divisor)) return NULL;
|
||||||
|
glVertexAttribDivisor(index, divisor);
|
||||||
|
CHECK_ERROR;
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
Flush(PyObject UNUSED *self) {
|
Flush(PyObject UNUSED *self) {
|
||||||
glFinish();
|
glFinish();
|
||||||
@@ -798,6 +807,7 @@ int add_module_gl_constants(PyObject *module) {
|
|||||||
METH(Disable, METH_O) \
|
METH(Disable, METH_O) \
|
||||||
METH(EnableVertexAttribArray, METH_O) \
|
METH(EnableVertexAttribArray, METH_O) \
|
||||||
METH(VertexAttribPointer, METH_VARARGS) \
|
METH(VertexAttribPointer, METH_VARARGS) \
|
||||||
|
METH(VertexAttribDivisor, METH_VARARGS) \
|
||||||
METH(GetProgramInfoLog, METH_O) \
|
METH(GetProgramInfoLog, METH_O) \
|
||||||
METH(GetShaderInfoLog, METH_O) \
|
METH(GetShaderInfoLog, METH_O) \
|
||||||
METH(ActiveTexture, METH_O) \
|
METH(ActiveTexture, METH_O) \
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from collections import namedtuple
|
||||||
from ctypes import addressof, sizeof
|
from ctypes import addressof, sizeof
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
@@ -24,8 +25,8 @@ from .fast_data_types import (
|
|||||||
glGetIntegerv, glGetProgramInfoLog, glGetProgramiv, glGetShaderInfoLog,
|
glGetIntegerv, glGetProgramInfoLog, glGetProgramiv, glGetShaderInfoLog,
|
||||||
glGetShaderiv, glGetUniformLocation, glLinkProgram, glNamedBufferData,
|
glGetShaderiv, glGetUniformLocation, glLinkProgram, glNamedBufferData,
|
||||||
glPixelStorei, glShaderSource, glTexBuffer, glTexParameteri,
|
glPixelStorei, glShaderSource, glTexBuffer, glTexParameteri,
|
||||||
glTexStorage3D, glTexSubImage3D, glUseProgram, glVertexAttribPointer,
|
glTexStorage3D, glTexSubImage3D, glUseProgram, glVertexAttribDivisor,
|
||||||
replace_or_create_buffer
|
glVertexAttribPointer, replace_or_create_buffer
|
||||||
)
|
)
|
||||||
from .fonts.render import render_cell
|
from .fonts.render import render_cell
|
||||||
from .utils import safe_print
|
from .utils import safe_print
|
||||||
@@ -35,6 +36,7 @@ VERSION = GL_VERSION[0] * 100 + GL_VERSION[1] * 10
|
|||||||
ITALIC_MASK = 1 << ITALIC
|
ITALIC_MASK = 1 << ITALIC
|
||||||
BOLD_MASK = 1 << BOLD
|
BOLD_MASK = 1 << BOLD
|
||||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
VertexArray = namedtuple('VertexArray', 'name size dtype normalized stride offset divisor')
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
@@ -267,13 +269,19 @@ class ShaderProgram:
|
|||||||
self.vao_id = glGenVertexArrays(1)
|
self.vao_id = glGenVertexArrays(1)
|
||||||
self.buffers = {}
|
self.buffers = {}
|
||||||
|
|
||||||
def add_vertex_array(self, name, size=3, dtype=GL_FLOAT, normalized=False, stride=0, offset=0):
|
def vertex_array(self, name, size=3, dtype=GL_FLOAT, normalized=False, stride=0, offset=0, divisor=0):
|
||||||
|
return VertexArray(name, size, dtype, normalized, stride, offset, divisor)
|
||||||
|
|
||||||
|
def add_vertex_arrays(self, *arrays):
|
||||||
glBindVertexArray(self.vao_id)
|
glBindVertexArray(self.vao_id)
|
||||||
self.buffers[name] = buf_id = buffer_manager.create(for_use=GL_ARRAY_BUFFER)
|
for x in arrays:
|
||||||
buffer_manager.bind(buf_id)
|
self.buffers[x.name] = buf_id = buffer_manager.create(for_use=GL_ARRAY_BUFFER)
|
||||||
aid = self.attribute_location(name)
|
buffer_manager.bind(buf_id)
|
||||||
glEnableVertexAttribArray(aid)
|
aid = self.attribute_location(x.name)
|
||||||
glVertexAttribPointer(aid, size, dtype, normalized, stride, offset)
|
glEnableVertexAttribArray(aid)
|
||||||
|
glVertexAttribPointer(aid, x.size, x.dtype, x.normalized, x.stride, x.offset)
|
||||||
|
if x.divisor > 0:
|
||||||
|
glVertexAttribDivisor(aid, x.divisor)
|
||||||
buffer_manager.unbind(buf_id)
|
buffer_manager.unbind(buf_id)
|
||||||
glBindVertexArray(0)
|
glBindVertexArray(0)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user