mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 11:11:47 +02:00
Fix incorrect tracking of previous buffer sizes to avoid re-allocs
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from ctypes import addressof, sizeof
|
from ctypes import addressof, sizeof
|
||||||
|
from collections import defaultdict
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ class Sprites:
|
|||||||
# extensions one they become available.
|
# extensions one they become available.
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prev_sprite_map_sz = 0
|
self.prev_sprite_map_sizes = defaultdict(lambda: 0)
|
||||||
self.xnum = self.ynum = 1
|
self.xnum = self.ynum = 1
|
||||||
self.first_cell_cache = {}
|
self.first_cell_cache = {}
|
||||||
self.second_cell_cache = {}
|
self.second_cell_cache = {}
|
||||||
@@ -170,11 +171,12 @@ class Sprites:
|
|||||||
return glGenBuffers(1)
|
return glGenBuffers(1)
|
||||||
|
|
||||||
def set_sprite_map(self, buf_id, data, usage=GL_STREAM_DRAW):
|
def set_sprite_map(self, buf_id, data, usage=GL_STREAM_DRAW):
|
||||||
prev_sz, self.prev_sprite_map_sz = self.prev_sprite_map_sz, sizeof(data)
|
prev_sz = self.prev_sprite_map_sizes[buf_id]
|
||||||
replace_or_create_buffer(buf_id, self.prev_sprite_map_sz, prev_sz, addressof(data), usage)
|
self.prev_sprite_map_sizes[buf_id] = new_sz = sizeof(data)
|
||||||
|
replace_or_create_buffer(buf_id, new_sz, prev_sz, addressof(data), usage)
|
||||||
if False:
|
if False:
|
||||||
verify_data = type(data)()
|
verify_data = type(data)()
|
||||||
glGetBufferSubData(buf_id, self.prev_sprite_map_sz, 0, addressof(verify_data))
|
glGetBufferSubData(buf_id, new_sz, 0, addressof(verify_data))
|
||||||
if list(data) != list(verify_data):
|
if list(data) != list(verify_data):
|
||||||
raise RuntimeError('OpenGL failed to upload to buffer')
|
raise RuntimeError('OpenGL failed to upload to buffer')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user