Start work on moving shaders.py to C

This commit is contained in:
Kovid Goyal 2017-09-10 14:43:51 +05:30
parent 83f4b6e391
commit a1c9c90fc8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 46 additions and 22 deletions

View File

@ -98,7 +98,8 @@ extern int init_Window(PyObject *);
extern bool init_freetype_library(PyObject*);
extern bool init_fontconfig_library(PyObject*);
extern bool init_glfw(PyObject *m);
bool init_sprites(PyObject *module);
extern bool init_sprites(PyObject *module);
extern bool init_shaders(PyObject *module);
#ifdef __APPLE__
extern int init_CoreText(PyObject *);
extern bool init_cocoa(PyObject *module);
@ -124,6 +125,7 @@ PyInit_fast_data_types(void) {
if (!add_module_gl_constants(m)) return NULL;
if (!init_glfw(m)) return NULL;
if (!init_sprites(m)) return NULL;
if (!init_shaders(m)) return NULL;
if (!init_Window(m)) return NULL;
#ifdef __APPLE__
if (!init_CoreText(m)) return NULL;

View File

@ -17,7 +17,7 @@ from .constants import (
appname, config_dir, isosx, logo_data_file, str_version, viewport_size
)
from .fast_data_types import (
GL_COLOR_BUFFER_BIT, GLFW_CONTEXT_VERSION_MAJOR,
GL_COLOR_BUFFER_BIT, GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION_REQUIRED,
GLFW_CONTEXT_VERSION_MINOR, GLFW_DECORATED, GLFW_OPENGL_CORE_PROFILE,
GLFW_OPENGL_FORWARD_COMPAT, GLFW_OPENGL_PROFILE, GLFW_SAMPLES,
GLFW_STENCIL_BITS, Window, change_wcwidth, check_for_extensions,
@ -26,7 +26,6 @@ from .fast_data_types import (
glfw_swap_interval, glfw_terminate, glfw_window_hint
)
from .layout import all_layouts
from .shaders import GL_VERSION
from .utils import detach, safe_print
try:
@ -144,8 +143,8 @@ def option_parser():
def setup_opengl(opts):
if opts.macos_hide_titlebar:
glfw_window_hint(GLFW_DECORATED, False)
glfw_window_hint(GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION[0])
glfw_window_hint(GLFW_CONTEXT_VERSION_MINOR, GL_VERSION[1])
glfw_window_hint(GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION_REQUIRED[0])
glfw_window_hint(GLFW_CONTEXT_VERSION_MINOR, GL_VERSION_REQUIRED[1])
glfw_window_hint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE)
glfw_window_hint(GLFW_OPENGL_FORWARD_COMPAT, True)
glfw_window_hint(GLFW_SAMPLES, 0)

24
kitty/shaders.c Normal file
View File

@ -0,0 +1,24 @@
/*
* shaders.c
* Copyright (C) 2017 Kovid Goyal <kovid at kovidgoyal.net>
*
* Distributed under terms of the GPL3 license.
*/
#include "data-types.h"
#define GL_VERSION_MAJOR 3
#define GL_VERSION_MINOR 3
#define GLSL_VERSION (GL_VERSION_MAJOR * 100 + GL_VERSION_MINOR * 10)
enum Program { CELL_PROGRAM, CURSOR_PROGRAM, BORDERS_PROGRAM};
bool
init_shaders(PyObject *module) {
#define C(x) if (PyModule_AddIntConstant(module, #x, x) != 0) { PyErr_NoMemory(); return false; }
C(CELL_PROGRAM); C(CURSOR_PROGRAM); C(BORDERS_PROGRAM);
C(GLSL_VERSION);
#undef C
PyModule_AddObject(module, "GL_VERSION_REQUIRED", Py_BuildValue("II", GL_VERSION_MAJOR, GL_VERSION_MINOR));
return true;
}

View File

@ -16,26 +16,25 @@ from .fast_data_types import (
GL_TEXTURE0, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,
GL_TEXTURE_MIN_FILTER, GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_TRUE,
GL_UNIFORM_BUFFER, GL_UNPACK_ALIGNMENT, GL_UNSIGNED_BYTE, GL_VERTEX_SHADER,
GL_WRITE_ONLY, copy_image_sub_data, get_uniform_block_offsets,
get_uniform_block_size, glActiveTexture, glAttachShader, glBindBuffer,
glBindBufferBase, glBindTexture, glBindVertexArray, glCompileShader,
glCopyImageSubData, glCreateProgram, glCreateShader, glDeleteBuffer,
glDeleteProgram, glDeleteShader, glDeleteTexture, glDeleteVertexArray,
glEnableVertexAttribArray, glGenBuffers, glGenTextures, glGenVertexArrays,
glGetAttribLocation, glGetBufferSubData, glGetIntegerv,
glGetProgramInfoLog, glGetProgramiv, glGetShaderInfoLog, glGetShaderiv,
glGetUniformBlockIndex, glGetUniformLocation, glLinkProgram, glMapBuffer,
glPixelStorei, glShaderSource, glTexParameteri, glTexStorage3D,
glTexSubImage3D, glUnmapBuffer, glUseProgram, glVertexAttribDivisor,
glVertexAttribPointer, render_dirty_sprites, replace_or_create_buffer,
sprite_map_current_layout, sprite_map_free, sprite_map_increment,
sprite_map_set_layout, sprite_map_set_limits
GL_WRITE_ONLY, GLSL_VERSION, copy_image_sub_data,
get_uniform_block_offsets, get_uniform_block_size, glActiveTexture,
glAttachShader, glBindBuffer, glBindBufferBase, glBindTexture,
glBindVertexArray, glCompileShader, glCopyImageSubData, glCreateProgram,
glCreateShader, glDeleteBuffer, glDeleteProgram, glDeleteShader,
glDeleteTexture, glDeleteVertexArray, glEnableVertexAttribArray,
glGenBuffers, glGenTextures, glGenVertexArrays, glGetAttribLocation,
glGetBufferSubData, glGetIntegerv, glGetProgramInfoLog, glGetProgramiv,
glGetShaderInfoLog, glGetShaderiv, glGetUniformBlockIndex,
glGetUniformLocation, glLinkProgram, glMapBuffer, glPixelStorei,
glShaderSource, glTexParameteri, glTexStorage3D, glTexSubImage3D,
glUnmapBuffer, glUseProgram, glVertexAttribDivisor, glVertexAttribPointer,
render_dirty_sprites, replace_or_create_buffer, sprite_map_current_layout,
sprite_map_free, sprite_map_increment, sprite_map_set_layout,
sprite_map_set_limits
)
from .fonts.render import render_cell
from .utils import safe_print
GL_VERSION = (3, 3)
VERSION = GL_VERSION[0] * 100 + GL_VERSION[1] * 10
UBO = namedtuple('UBO', 'size index offsets buf_id')
BASE = os.path.dirname(os.path.abspath(__file__))
@ -333,7 +332,7 @@ class ShaderProgram: # {{{
def add_shader(self, source: str, shader_type: int) -> int:
' Compile a shader and return its id, or raise an exception if compilation fails '
shader_id = glCreateShader(shader_type)
source = source.replace('GLSL_VERSION', str(VERSION), 1)
source = source.replace('GLSL_VERSION', str(GLSL_VERSION), 1)
try:
glShaderSource(shader_id, source)
glCompileShader(shader_id)