Do not use GL_ARB_texture_buffer_object_rgb32
This is not available on macOS using Intel graphics cards
This commit is contained in:
parent
a9f3a698d2
commit
101a50b0ff
@ -17,7 +17,7 @@ from .fast_data_types import (
|
||||
CURSOR_BEAM, CURSOR_BLOCK, CURSOR_UNDERLINE, DATA_CELL_SIZE, GL_BLEND,
|
||||
GL_LINE_LOOP, GL_TRIANGLE_FAN, ColorProfile, glDisable, glDrawArrays,
|
||||
glDrawArraysInstanced, glEnable, glUniform1i, glUniform2f, glUniform2ui,
|
||||
glUniform4f
|
||||
glUniform4f, glUniform2i
|
||||
)
|
||||
from .rgb import to_color
|
||||
from .utils import (
|
||||
@ -44,7 +44,7 @@ uniform uvec2 dimensions; // xnum, ynum
|
||||
uniform vec4 steps; // xstart, ystart, dx, dy
|
||||
uniform vec2 sprite_layout; // dx, dy
|
||||
uniform usamplerBuffer sprite_map; // gl_InstanceID -> x, y, z
|
||||
uniform uvec2 color_indices; // which color to use as fg and which as bg
|
||||
uniform ivec2 color_indices; // which color to use as fg and which as bg
|
||||
out vec3 sprite_pos;
|
||||
out vec3 underline_pos;
|
||||
out vec3 strike_pos;
|
||||
@ -89,17 +89,21 @@ void main() {
|
||||
gl_Position = vec4(xpos[pos[0]], ypos[pos[1]], 0, 1);
|
||||
|
||||
int sprite_id = gl_InstanceID * STRIDE;
|
||||
uvec4 spos = texelFetch(sprite_map, sprite_id);
|
||||
uvec4 colors = texelFetch(sprite_map, sprite_id + 1);
|
||||
sprite_pos = to_sprite_pos(pos, spos[0], spos[1], spos[2]);
|
||||
foreground = to_color(colors[color_indices[0]]);
|
||||
background = to_color(colors[color_indices[1]]);
|
||||
uint decoration = colors[2];
|
||||
uint x = texelFetch(sprite_map, sprite_id).r;
|
||||
uint y = texelFetch(sprite_map, sprite_id + 1).r;
|
||||
uint z = texelFetch(sprite_map, sprite_id + 2).r;
|
||||
sprite_pos = to_sprite_pos(pos, x, y, z);
|
||||
sprite_id += 3;
|
||||
uint fg = texelFetch(sprite_map, sprite_id + color_indices[0]).r;
|
||||
uint bg = texelFetch(sprite_map, sprite_id + color_indices[1]).r;
|
||||
uint decoration = texelFetch(sprite_map, sprite_id + 2).r;
|
||||
foreground = to_color(fg);
|
||||
background = to_color(bg);
|
||||
decoration_fg = to_color(decoration);
|
||||
underline_pos = to_sprite_pos(pos, (decoration >> 24) & SMASK, ZERO, ZERO);
|
||||
strike_pos = to_sprite_pos(pos, (decoration >> 26) & SMASK, ZERO, ZERO);
|
||||
}
|
||||
'''.replace('STRIDE', str(DATA_CELL_SIZE // 3)),
|
||||
'''.replace('STRIDE', str(DATA_CELL_SIZE)),
|
||||
|
||||
'''\
|
||||
uniform sampler2DArray sprites;
|
||||
@ -234,7 +238,7 @@ def render_cells(buffer_id, sg, cell_program, sprites, invert_colors=False):
|
||||
sprites.bind_sprite_map(buffer_id)
|
||||
ul = cell_program.uniform_location
|
||||
glUniform2ui(ul('dimensions'), sg.xnum, sg.ynum)
|
||||
glUniform2ui(ul('color_indices'), 1 if invert_colors else 0, 0 if invert_colors else 1)
|
||||
glUniform2i(ul('color_indices'), 1 if invert_colors else 0, 0 if invert_colors else 1)
|
||||
glUniform4f(ul('steps'), sg.xstart, sg.ystart, sg.dx, sg.dy)
|
||||
glUniform1i(ul('sprites'), sprites.sampler_num)
|
||||
glUniform1i(ul('sprite_map'), sprites.buffer_sampler_num)
|
||||
|
||||
@ -35,8 +35,7 @@ typedef unsigned int index_type;
|
||||
|
||||
#define CELL_FIELD_COUNT 5
|
||||
#define CELL_SIZE (CELL_FIELD_COUNT * 4)
|
||||
// The data cell size must be a multiple of 3
|
||||
#define DATA_CELL_SIZE 2 * 3
|
||||
#define DATA_CELL_SIZE 6
|
||||
|
||||
#define CHAR_MASK 0xFFFFFF
|
||||
#define ATTRS_SHIFT 24
|
||||
|
||||
20
kitty/gl.h
20
kitty/gl.h
@ -84,6 +84,16 @@ Uniform2ui(PyObject UNUSED *self, PyObject *args) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
Uniform2i(PyObject UNUSED *self, PyObject *args) {
|
||||
int location;
|
||||
int x, y;
|
||||
if (!PyArg_ParseTuple(args, "iii", &location, &x, &y)) return NULL;
|
||||
glUniform2i(location, x, y);
|
||||
CHECK_ERROR;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
Uniform1i(PyObject UNUSED *self, PyObject *args) {
|
||||
int location;
|
||||
@ -147,7 +157,6 @@ _glewInit(PyObject UNUSED *self) {
|
||||
return NULL; \
|
||||
}
|
||||
ARB_TEST(texture_storage);
|
||||
ARB_TEST(texture_buffer_object_rgb32);
|
||||
#undef ARB_TEST
|
||||
#endif
|
||||
Py_RETURN_NONE;
|
||||
@ -657,19 +666,19 @@ static PyObject*
|
||||
check_for_extensions(PyObject UNUSED *self) {
|
||||
GLint n = 0, i, left = 2;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
|
||||
bool texture_storage = false, texture_buffer_object_rgb32 = false;
|
||||
bool texture_storage = false;
|
||||
#define CHECK(name) if (!name) { \
|
||||
if (strstr((const char*)ext, "GL_ARB_" #name) == (const char *)ext) { left--; name = true; } \
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
const GLubyte *ext = glGetStringi(GL_EXTENSIONS, i);
|
||||
CHECK(texture_storage); CHECK(texture_buffer_object_rgb32);
|
||||
CHECK(texture_storage);
|
||||
if (left < 1) break;
|
||||
}
|
||||
#undef CHECK
|
||||
if (left > 0) {
|
||||
#define CHECK(name) if (!name) { PyErr_Format(PyExc_RuntimeError, "The OpenGL driver on this system is missing the required extension: GL_ARB_%s", #name); return NULL; }
|
||||
CHECK(texture_storage); CHECK(texture_buffer_object_rgb32);
|
||||
CHECK(texture_storage);
|
||||
#undef CHECK
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
@ -697,7 +706,7 @@ int add_module_gl_constants(PyObject *module) {
|
||||
GLC(GL_TEXTURE_MIN_FILTER); GLC(GL_TEXTURE_MAG_FILTER);
|
||||
GLC(GL_TEXTURE_WRAP_S); GLC(GL_TEXTURE_WRAP_T);
|
||||
GLC(GL_UNPACK_ALIGNMENT);
|
||||
GLC(GL_R8); GLC(GL_RED); GLC(GL_UNSIGNED_BYTE); GLC(GL_RGB32UI); GLC(GL_RGBA);
|
||||
GLC(GL_R8); GLC(GL_RED); GLC(GL_UNSIGNED_BYTE); GLC(GL_R32UI); GLC(GL_RGB32UI); GLC(GL_RGBA);
|
||||
GLC(GL_TEXTURE_BUFFER); GLC(GL_STATIC_DRAW); GLC(GL_STREAM_DRAW);
|
||||
GLC(GL_SRC_ALPHA); GLC(GL_ONE_MINUS_SRC_ALPHA);
|
||||
GLC(GL_BLEND); GLC(GL_FLOAT); GLC(GL_ARRAY_BUFFER);
|
||||
@ -716,6 +725,7 @@ int add_module_gl_constants(PyObject *module) {
|
||||
METH(GetProgramiv, METH_VARARGS) \
|
||||
METH(GetShaderiv, METH_VARARGS) \
|
||||
METH(Uniform2ui, METH_VARARGS) \
|
||||
METH(Uniform2i, METH_VARARGS) \
|
||||
METH(Uniform1i, METH_VARARGS) \
|
||||
METH(Uniform2f, METH_VARARGS) \
|
||||
METH(Uniform4f, METH_VARARGS) \
|
||||
|
||||
@ -209,6 +209,7 @@ def run_app(opts, args):
|
||||
window.set_title(appname)
|
||||
window.make_context_current()
|
||||
if isosx:
|
||||
check_for_extensions()
|
||||
if opts.macos_hide_titlebar:
|
||||
from .fast_data_types import cocoa_hide_titlebar
|
||||
cocoa_hide_titlebar(window.cocoa_window_id())
|
||||
@ -220,8 +221,6 @@ def run_app(opts, args):
|
||||
viewport_size.x_ratio = viewport_size.width / float(w)
|
||||
viewport_size.y_ratio = viewport_size.height / float(h)
|
||||
glewInit()
|
||||
if isosx:
|
||||
check_for_extensions()
|
||||
boss = Boss(window, opts, args)
|
||||
boss.start()
|
||||
clear_buffers(window, opts)
|
||||
|
||||
@ -21,7 +21,7 @@ from .fast_data_types import (
|
||||
GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_WRAP_S,
|
||||
GL_NEAREST, GL_TEXTURE_WRAP_T, glGenBuffers, GL_R8, GL_RED,
|
||||
GL_UNPACK_ALIGNMENT, GL_UNSIGNED_BYTE, GL_STATIC_DRAW, GL_STREAM_DRAW,
|
||||
GL_TEXTURE_BUFFER, GL_RGB32UI, GL_FLOAT, GL_ARRAY_BUFFER, glBindBuffer,
|
||||
GL_TEXTURE_BUFFER, GL_R32UI, GL_FLOAT, GL_ARRAY_BUFFER, glBindBuffer,
|
||||
glPixelStorei, glTexBuffer, glActiveTexture, glTexStorage3D,
|
||||
glCopyImageSubData, glTexSubImage3D, ITALIC, BOLD, SpriteMap,
|
||||
glEnableVertexAttribArray, glVertexAttribPointer, copy_image_sub_data
|
||||
@ -162,7 +162,7 @@ class Sprites:
|
||||
|
||||
def bind_sprite_map(self, buf_id):
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, buf_id)
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32UI, buf_id)
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, buf_id)
|
||||
|
||||
def destroy_sprite_map(self, buf_id):
|
||||
glDeleteBuffer(buf_id)
|
||||
@ -179,7 +179,7 @@ class Sprites:
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, 0)
|
||||
glBindTexture(GL_TEXTURE_BUFFER, 0)
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, 0)
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32UI, 0)
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, 0)
|
||||
|
||||
|
||||
class ShaderProgram:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user