Finish OpenGL shader bindings
This commit is contained in:
parent
99f788ead5
commit
436fedccea
@ -9,6 +9,7 @@
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#define UNUSED __attribute__ ((unused))
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
|
||||
54
kitty/gl.h
54
kitty/gl.h
@ -383,6 +383,56 @@ BindTexture(PyObject UNUSED *self, PyObject *args) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
TexStorage3D(PyObject UNUSED *self, PyObject *args) {
|
||||
int target, fmt;
|
||||
unsigned int levels, width, height, depth;
|
||||
if (!PyArg_ParseTuple(args, "iIiIII", &target, &levels, &fmt, &width, &height, &depth)) return NULL;
|
||||
glTexStorage3D(target, levels, fmt, width, height, depth);
|
||||
CHECK_ERROR;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
CopyImageSubData(PyObject UNUSED *self, PyObject *args) {
|
||||
int src_target, src_level, srcX, srcY, srcZ, dest_target, dest_level, destX, destY, destZ;
|
||||
unsigned int src, dest, width, height, depth;
|
||||
if (!PyArg_ParseTuple(args, "IiiiiiIiiiiiIII",
|
||||
&src, &src_target, &src_level, &srcX, &srcY, &srcZ,
|
||||
&dest, &dest_target, &dest_level, &destX, &destY, &destZ,
|
||||
&width, &height, &depth
|
||||
)) return NULL;
|
||||
glCopyImageSubData(src, src_target, src_level, srcX, srcY, srcZ, dest, dest_target, dest_level, destX, destY, destZ, width, height, depth);
|
||||
CHECK_ERROR;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
TexSubImage3D(PyObject UNUSED *self, PyObject *args) {
|
||||
int target, level, x, y, z, fmt, type;
|
||||
unsigned int width, height, depth;
|
||||
PyObject *pixels;
|
||||
if (!PyArg_ParseTuple(args, "iiiiiIIIiiO!", &target, &level, &x, &y, &z, &width, &height, &depth, &fmt, &type, &PyLong_Type, &pixels)) return NULL;
|
||||
void *data = PyLong_AsVoidPtr(pixels);
|
||||
if (data == NULL) { PyErr_SetString(PyExc_TypeError, "Not a valid data pointer"); return NULL; }
|
||||
glTexSubImage3D(target, level, x, y, z, width, height, depth, fmt, type, data);
|
||||
CHECK_ERROR;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
BufferData(PyObject UNUSED *self, PyObject *args) {
|
||||
int target, usage;
|
||||
unsigned long size;
|
||||
PyObject *address;
|
||||
if (!PyArg_ParseTuple(args, "ikO!i", &target, &size, &PyLong_Type, &address, &usage)) return NULL;
|
||||
void *data = PyLong_AsVoidPtr(address);
|
||||
if (data == NULL) { PyErr_SetString(PyExc_TypeError, "Not a valid data pointer"); return NULL; }
|
||||
glBufferData(target, size, data, usage);
|
||||
CHECK_ERROR;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
TexParameteri(PyObject UNUSED *self, PyObject *args) {
|
||||
int target, name, param;
|
||||
@ -495,4 +545,8 @@ int add_module_gl_constants(PyObject *module) {
|
||||
METH(PixelStorei, METH_VARARGS) \
|
||||
METH(BindBuffer, METH_VARARGS) \
|
||||
METH(TexBuffer, METH_VARARGS) \
|
||||
METH(TexStorage3D, METH_VARARGS) \
|
||||
METH(CopyImageSubData, METH_VARARGS) \
|
||||
METH(TexSubImage3D, METH_VARARGS) \
|
||||
METH(BufferData, METH_VARARGS) \
|
||||
|
||||
|
||||
@ -2,13 +2,9 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from ctypes import addressof, sizeof
|
||||
from functools import lru_cache
|
||||
|
||||
import OpenGL.GL as gl
|
||||
from OpenGL.arrays import ArrayDatatype
|
||||
from OpenGL.GL.ARB.copy_image import glCopyImageSubData # only present in opengl core >= 4.3
|
||||
from OpenGL.GL.ARB.texture_storage import glTexStorage3D # only present in opengl core >= 4.2
|
||||
|
||||
from .fonts import render_cell
|
||||
from .data_types import ITALIC_MASK, BOLD_MASK
|
||||
from .fast_data_types import (
|
||||
@ -18,13 +14,13 @@ from .fast_data_types import (
|
||||
glCreateShader, glShaderSource, glCompileShader, glGetShaderiv,
|
||||
GL_COMPILE_STATUS, glGetShaderInfoLog, glGetUniformLocation,
|
||||
glGetAttribLocation, glUseProgram, glBindVertexArray, GL_TEXTURE0,
|
||||
GL_TEXTURE1, glGetIntegerv, GL_MAX_ARRAY_TEXTURE_LAYERS,
|
||||
GL_TEXTURE1, glGetIntegerv, GL_MAX_ARRAY_TEXTURE_LAYERS, glBufferData,
|
||||
GL_MAX_TEXTURE_SIZE, glDeleteTexture, GL_TEXTURE_2D_ARRAY, glGenTextures,
|
||||
glBindTexture, glTexParameteri, GL_LINEAR, GL_CLAMP_TO_EDGE,
|
||||
GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_WRAP_S,
|
||||
GL_TEXTURE_WRAP_T, glGenBuffers, GL_R8, GL_RED, GL_UNPACK_ALIGNMENT, GL_UNSIGNED_BYTE,
|
||||
GL_STATIC_DRAW, GL_TEXTURE_BUFFER, GL_RGB32UI, glBindBuffer, glPixelStorei,
|
||||
glTexBuffer, glActiveTexture
|
||||
glTexBuffer, glActiveTexture, glTexStorage3D, glCopyImageSubData, glTexSubImage3D
|
||||
)
|
||||
|
||||
GL_VERSION = (3, 3)
|
||||
@ -105,7 +101,7 @@ class Sprites:
|
||||
glBindTexture(tgt, self.texture_id)
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
|
||||
x, y = self.x * self.cell_width, self.y * self.cell_height
|
||||
gl.glTexSubImage3D(tgt, 0, x, y, self.z, self.cell_width, self.cell_height, 1, GL_RED, GL_UNSIGNED_BYTE, buf)
|
||||
glTexSubImage3D(tgt, 0, x, y, self.z, self.cell_width, self.cell_height, 1, GL_RED, GL_UNSIGNED_BYTE, addressof(buf))
|
||||
glBindTexture(tgt, 0)
|
||||
|
||||
# co-ordinates for this sprite in the sprite sheet
|
||||
@ -126,7 +122,7 @@ class Sprites:
|
||||
def set_sprite_map(self, data):
|
||||
tgt = GL_TEXTURE_BUFFER
|
||||
glBindBuffer(tgt, self.buffer_id)
|
||||
gl.glBufferData(tgt, ArrayDatatype.arrayByteCount(data), data, GL_STATIC_DRAW)
|
||||
glBufferData(tgt, sizeof(data), addressof(data), GL_STATIC_DRAW)
|
||||
glBindBuffer(tgt, 0)
|
||||
|
||||
def primary_sprite_position(self, key):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user