Check for required extensions

This commit is contained in:
Kovid Goyal 2016-10-28 12:32:55 +05:30
parent d00e03ca03
commit fabdebfd89
3 changed files with 17 additions and 2 deletions

View File

@ -6,7 +6,7 @@ import glfw
import OpenGL.GL as gl
import sys
from kitty.shaders import ShaderProgram, GL_VERSION, Sprites
from kitty.shaders import ShaderProgram, GL_VERSION, Sprites, check_for_required_extensions
from kitty.fonts import set_font_family, cell_size
textured_shaders = (
@ -148,6 +148,7 @@ def _main():
raise SystemExit("glfwCreateWindow failed")
glfw.glfwMakeContextCurrent(window)
glfw.glfwSwapInterval(1)
check_for_required_extensions()
# If everything went well the following calls
# will display the version of opengl being used

View File

@ -13,7 +13,7 @@ from .config import load_config
from .constants import appname, str_version, config_dir
from .boss import Boss
from .utils import fork_child, hangup
from .shaders import GL_VERSION
from .shaders import GL_VERSION, check_for_required_extensions
import glfw
@ -52,6 +52,7 @@ def run_app(opts, args):
glfw.glfwSetWindowTitle(window, appname.encode('utf-8'))
try:
glfw.glfwMakeContextCurrent(window)
check_for_required_extensions()
glfw.glfwSwapInterval(1)
boss = Boss(window, window_width, window_height, opts, args)
glfw.glfwSetFramebufferSizeCallback(window, boss.on_window_resize)

View File

@ -13,12 +13,25 @@ from .fonts import render_cell, cell_size
GL_VERSION = (3, 3)
VERSION = GL_VERSION[0] * 100 + GL_VERSION[1] * 10
REQUIRED_EXTENSIONS = frozenset('GL_ARB_copy_image GL_ARB_texture_storage'.split())
def array(*args, dtype=gl.GLfloat):
return (dtype * len(args))(*args)
def check_for_required_extensions():
num = gl.glGetIntegerv(gl.GL_NUM_EXTENSIONS)
required = set(REQUIRED_EXTENSIONS)
for i in range(num):
ext = gl.glGetStringi(gl.GL_EXTENSIONS, i).decode('utf-8')
required.discard(ext)
if not required:
break
if required:
raise RuntimeError('Your OpenGL implementation is missing the following required extensions: %s' % ','.join(required))
class Sprites:
''' Maintain sprite sheets of all rendered characters on the GPU as a texture
array with each texture being a sprite sheet. '''