Skip to content

Commit

Permalink
gloo.gl: add dummy backend (each function raises error)
Browse files Browse the repository at this point in the history
For when the rendering is done elsewhere.

Gloo initialize (for desktop/es2) compat implemented better
  • Loading branch information
almarklein committed Oct 19, 2014
1 parent 4d25ea1 commit fd29ab1
Show file tree
Hide file tree
Showing 14 changed files with 35,959 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ source = vispy
# Omit fonts/_quartz.py and _win32 for platform specificity
omit =
*/vispy/app/backends/_egl.py
*/vispy/gloo/gl/angle.py
*/vispy/gloo/gl/_angle.py
*/vispy/gloo/gl/es2.py
*/vispy/gloo/gl/_es2.py
*/vispy/testing/*
*/vispy/ext/*
*/vispy/geometry/_triangulation_debugger.py
Expand Down
3 changes: 3 additions & 0 deletions codegen/createglapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ def __call__(self, funcname, returns, *args):
def glShaderSource_compat(self, handle, code):
return self("glShaderSource_compat", True, handle, code)
def gl_initialize(self):
return self("gl_initialize", False)
'''

def _returns(self, des):
Expand Down
35,899 changes: 35,899 additions & 0 deletions codegen/headers/gl.spec

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions vispy/app/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
# todo: add focus events


def _gloo_initialize(event):
from ..gloo import gl_initialize
gl_initialize()


class Canvas(object):
"""Representation of a GUI element with an OpenGL context
Expand Down Expand Up @@ -52,8 +47,6 @@ class Canvas(object):
Note the canvas application can be accessed at ``canvas.app``.
create_native : bool
Whether to create the widget immediately. Default True.
init_gloo : bool
Initialize standard values in gloo (e.g., ``GL_POINT_SPRITE``).
vsync : bool
Enable vertical synchronization.
resizable : bool
Expand Down Expand Up @@ -82,8 +75,8 @@ class Canvas(object):

def __init__(self, title='Vispy canvas', size=(800, 600), position=None,
show=False, autoswap=True, app=None, create_native=True,
init_gloo=True, vsync=False, resizable=True, decorate=True,
fullscreen=False, context=None, keys=None, parent=None):
vsync=False, resizable=True, decorate=True, fullscreen=False,
context=None, keys=None, parent=None):

size = [int(s) for s in size]
if len(size) != 2:
Expand Down Expand Up @@ -125,11 +118,6 @@ def __init__(self, title='Vispy canvas', size=(800, 600), position=None,
event_class=DrawEvent)
self.events.add(paint=emitter)
self.events.draw.connect(self.events.paint)

# Initialize gloo settings
if init_gloo:
self.events.initialize.connect(_gloo_initialize,
ref='gloo_initialize')

# Get app instance
if app is None:
Expand Down
1 change: 0 additions & 1 deletion vispy/gloo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
get_current_context, get_a_context) # noqa
from .globject import GLObject # noqa
from .buffer import VertexBuffer, IndexBuffer # noqa
from .initialize import gl_initialize # noqa
from .texture import Texture2D, TextureAtlas, Texture3D # noqa
from .program import Program # noqa
from .framebuffer import FrameBuffer, RenderBuffer # noqa
Expand Down
1 change: 1 addition & 0 deletions vispy/gloo/gl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def use_gl(target='desktop'):
* desktop - Use desktop (i.e. normal) OpenGL.
* pyopengl - Use pyopengl (for fallback and testing).
* es2 - Use the ES2 library (Angle/DirectX on Windows)
* dummy - Prevent usage gloo.gl (for when rendering occrurs elsewhere)
"""
target = target or 'desktop'
Expand Down
9 changes: 9 additions & 0 deletions vispy/gloo/gl/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ def glShaderSource_compat(handle, code):
return []


def gl_initialize():
""" Initialize GL so it behaves more like ES 2.0.
"""
GL_VERTEX_PROGRAM_POINT_SIZE = 34370
GL_POINT_SPRITE = 34913
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)
glEnable(GL_POINT_SPRITE)


## Inject


Expand Down
25 changes: 25 additions & 0 deletions vispy/gloo/gl/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2014, Vispy Development Team.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.

""" A dummy backend.
"""

from . import BaseGLProxy, _copy_gl_functions
from ._constants import * # noqa


class DummyProxy(BaseGLProxy):
""" A dummy backend that can be activated when the GL is not
processed in this process. Each GL function call will raise an
error.
"""

def __call__(self, funcname, returns, *args):
raise RuntimeError('Cannot call %r (or any other GL function), '
'since GL is disabled.' % funcname)


# Instantiate proxy and inject functions
_proxy = DummyProxy()
_copy_gl_functions(_proxy, globals())
6 changes: 6 additions & 0 deletions vispy/gloo/gl/es2.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def glShaderSource_compat(handle, code):
return []


def gl_initialize():
""" Initialize GL so it behaves more like ES 2.0.
"""
pass


## Inject


Expand Down
9 changes: 9 additions & 0 deletions vispy/gloo/gl/pyopengl.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def glShaderSource_compat(handle, code):
return []


def gl_initialize():
""" Initialize GL so it behaves more like ES 2.0.
"""
GL_VERTEX_PROGRAM_POINT_SIZE = 34370
GL_POINT_SPRITE = 34913
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)
glEnable(GL_POINT_SPRITE)


def _patch():
""" Monkey-patch pyopengl to fix a bug in glBufferSubData. """
import sys
Expand Down
29 changes: 0 additions & 29 deletions vispy/gloo/gl/webgl.py

This file was deleted.

3 changes: 2 additions & 1 deletion vispy/gloo/glir.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def parse(self, commands):
if cmd == 'CURRENT':
# This context is made current
self.env.clear()
gl.gl_initialize() # For desktop/es2 compat
gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)
elif cmd == 'FUNC':
# GL function call
Expand Down Expand Up @@ -730,7 +731,7 @@ def set_size(self, shape, format):
self._shape_format = shape, format
self.activate()
gl.glTexImage2D(self._target, 0, format, format,
gl.GL_BYTE, shape[:2])
gl.GL_UNSIGNED_BYTE, shape[:2])

def set_data(self, offset, data):
self.activate()
Expand Down
18 changes: 0 additions & 18 deletions vispy/gloo/initialize.py

This file was deleted.

2 changes: 1 addition & 1 deletion vispy/testing/_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _flake():
sys.argv[1:] = ['vispy']
sys.argv.append('--ignore=E226,E241,E265,W291,W293')
sys.argv.append('--exclude=six.py,py24_ordereddict.py,glfw.py,'
'_proxy.py,_angle.py,_desktop.py,_pyopengl.py,'
'_proxy.py,_es2.py,_desktop.py,_pyopengl.py,'
'_constants.py,png.py,decorator.py')
try:
from flake8.main import main
Expand Down

0 comments on commit fd29ab1

Please sign in to comment.