...
This commit is contained in:
parent
9c184c794a
commit
c1dc4d0575
@ -13,6 +13,7 @@
|
||||
#include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
static char glbuf[4096];
|
||||
|
||||
// GL setup and error handling {{{
|
||||
// Required minimum OpenGL version
|
||||
@ -20,6 +21,14 @@
|
||||
#define REQUIRED_VERSION_MINOR 3
|
||||
#define GLSL_VERSION (REQUIRED_VERSION_MAJOR * 100 + REQUIRED_VERSION_MINOR * 10)
|
||||
|
||||
#ifndef GL_STACK_UNDERFLOW
|
||||
#define GL_STACK_UNDERFLOW 0x0504
|
||||
#endif
|
||||
|
||||
#ifndef GL_STACK_OVERFLOW
|
||||
#define GL_STACK_OVERFLOW 0x0503
|
||||
#endif
|
||||
|
||||
static inline bool
|
||||
set_error_from_gl() {
|
||||
int code = glGetError();
|
||||
@ -69,10 +78,10 @@ glew_init(PyObject UNUSED *self) {
|
||||
}
|
||||
// }}}
|
||||
|
||||
// Programs {{{
|
||||
enum Program { CELL_PROGRAM, CURSOR_PROGRAM, BORDERS_PROGRAM, NUM_PROGRAMS };
|
||||
|
||||
static GLuint program_ids[NUM_PROGRAMS] = {0};
|
||||
static char glbuf[4096];
|
||||
|
||||
static inline GLuint
|
||||
compile_shader(GLenum shader_type, const char *source) {
|
||||
@ -94,6 +103,8 @@ compile_shader(GLenum shader_type, const char *source) {
|
||||
}
|
||||
return shader_id;
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
// Python API {{{
|
||||
static PyObject*
|
||||
@ -138,7 +149,7 @@ end:
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
#define M(name, arg_type) {#name, (PyCFunction)name, arg_type, ""}
|
||||
#define M(name, arg_type) {#name, (PyCFunction)name, arg_type, NULL}
|
||||
static PyMethodDef module_methods[] = {
|
||||
M(enable_automatic_opengl_error_checking, METH_O),
|
||||
{"glewInit", (PyCFunction)glew_init, METH_NOARGS, NULL},
|
||||
|
||||
@ -37,8 +37,8 @@ BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
@lru_cache()
|
||||
def load_shaders(name):
|
||||
vert = open(os.path.join(BASE, '{}_vertex.glsl'.format(name))).read()
|
||||
frag = open(os.path.join(BASE, '{}_fragment.glsl'.format(name))).read()
|
||||
vert = open(os.path.join(BASE, '{}_vertex.glsl'.format(name))).read().replace('GLSL_VERSION', str(GLSL_VERSION), 1)
|
||||
frag = open(os.path.join(BASE, '{}_fragment.glsl'.format(name))).read().replace('GLSL_VERSION', str(GLSL_VERSION), 1)
|
||||
return vert, frag
|
||||
|
||||
|
||||
@ -244,11 +244,7 @@ class ShaderProgram: # {{{
|
||||
Create a shader program.
|
||||
|
||||
"""
|
||||
self.program_id = compile_program(
|
||||
which,
|
||||
vertex.replace('GLSL_VERSION', str(GLSL_VERSION), 1),
|
||||
fragment.replace('GLSL_VERSION', str(GLSL_VERSION), 1)
|
||||
)
|
||||
self.program_id = compile_program(which, vertex, fragment)
|
||||
self.vertex_arrays = {}
|
||||
|
||||
@contextmanager
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user