Ensure ctypes data type sizes match GL sizes
This commit is contained in:
parent
b3550391e9
commit
cfca4cd0bf
@ -2,9 +2,9 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import ctypes
|
||||
from ctypes import addressof
|
||||
|
||||
from .constants import viewport_size
|
||||
from .constants import viewport_size, GLfloat, GLint, GLuint
|
||||
from .fast_data_types import glUniform3fv, GL_TRIANGLE_FAN, glMultiDrawArrays
|
||||
from .layout import available_height
|
||||
from .utils import get_dpi
|
||||
@ -53,7 +53,7 @@ void main() {
|
||||
self.send_vertex_data('rect', data)
|
||||
|
||||
def set_colors(self, color_buf):
|
||||
glUniform3fv(self.uniform_location('colors'), 3, ctypes.addressof(color_buf))
|
||||
glUniform3fv(self.uniform_location('colors'), 3, addressof(color_buf))
|
||||
|
||||
|
||||
class Borders:
|
||||
@ -64,7 +64,7 @@ class Borders:
|
||||
dpix, dpiy = get_dpi()['logical']
|
||||
dpi = (dpix + dpiy) / 2
|
||||
self.border_width = round(opts.window_border_width * dpi / 72)
|
||||
self.color_buf = (ctypes.c_float * 9)(
|
||||
self.color_buf = (GLfloat * 9)(
|
||||
*as_color(opts.background),
|
||||
*as_color(opts.active_border_color),
|
||||
*as_color(opts.inactive_border_color)
|
||||
@ -102,9 +102,9 @@ class Borders:
|
||||
rects.extend(as_rect(g.right, g.top - bw, g.right + bw, g.bottom + bw, color))
|
||||
rects.extend(as_rect(g.left - bw, g.bottom, g.right + bw, g.bottom + bw, color))
|
||||
self.num_of_rects = len(rects) // 12
|
||||
self.rects = (ctypes.c_float * len(rects))()
|
||||
self.starts = (ctypes.c_int * self.num_of_rects)()
|
||||
self.counts = (ctypes.c_uint * self.num_of_rects)()
|
||||
self.rects = (GLfloat * len(rects))()
|
||||
self.starts = (GLint * self.num_of_rects)()
|
||||
self.counts = (GLuint * self.num_of_rects)()
|
||||
for i, x in enumerate(rects):
|
||||
self.rects[i] = x
|
||||
if i % 12 == 0:
|
||||
@ -120,4 +120,4 @@ class Borders:
|
||||
program.send_data(self.rects)
|
||||
program.set_colors(self.color_buf)
|
||||
self.is_dirty = False
|
||||
glMultiDrawArrays(GL_TRIANGLE_FAN, ctypes.addressof(self.starts), ctypes.addressof(self.counts), self.num_of_rects)
|
||||
glMultiDrawArrays(GL_TRIANGLE_FAN, addressof(self.starts), addressof(self.counts), self.num_of_rects)
|
||||
|
||||
@ -3,11 +3,11 @@
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from collections import namedtuple
|
||||
from ctypes import c_uint, addressof, memmove, sizeof
|
||||
from ctypes import addressof, memmove, sizeof
|
||||
from threading import Lock
|
||||
|
||||
from .config import build_ansi_color_table
|
||||
from .constants import tab_manager, viewport_size, cell_size, ScreenGeometry
|
||||
from .constants import tab_manager, viewport_size, cell_size, ScreenGeometry, GLuint
|
||||
from .utils import get_logical_dpi, to_color
|
||||
from .fast_data_types import (
|
||||
glUniform2ui, glUniform4f, glUniform1i, glUniform2f, glDrawArraysInstanced,
|
||||
@ -182,7 +182,7 @@ class CharGrid:
|
||||
|
||||
def resize(self, window_geometry):
|
||||
self.update_position(window_geometry)
|
||||
self.sprite_map_type = (c_uint * (self.screen_geometry.ynum * self.screen_geometry.xnum * DATA_CELL_SIZE))
|
||||
self.sprite_map_type = (GLuint * (self.screen_geometry.ynum * self.screen_geometry.xnum * DATA_CELL_SIZE))
|
||||
self.main_sprite_map = self.sprite_map_type()
|
||||
self.scroll_sprite_map = self.sprite_map_type()
|
||||
with self.buffer_lock:
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
import os
|
||||
import threading
|
||||
import pwd
|
||||
import ctypes
|
||||
from collections import namedtuple
|
||||
|
||||
appname = 'kitty'
|
||||
@ -61,3 +62,11 @@ cell_size = ViewportSize()
|
||||
terminfo_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'terminfo')
|
||||
main_thread = threading.current_thread()
|
||||
shell_path = pwd.getpwuid(os.geteuid()).pw_shell or '/bin/sh'
|
||||
|
||||
GLint = ctypes.c_int if ctypes.sizeof(ctypes.c_int) == 4 else ctypes.c_long
|
||||
GLuint = ctypes.c_uint if ctypes.sizeof(ctypes.c_uint) == 4 else ctypes.c_ulong
|
||||
GLfloat = ctypes.c_float
|
||||
if ctypes.sizeof(GLfloat) != 4:
|
||||
raise RuntimeError('float size is not 4')
|
||||
if ctypes.sizeof(GLint) != 4:
|
||||
raise RuntimeError('int size is not 4')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user