Skip to content

Commit

Permalink
Split out the GL backend (#392)
Browse files Browse the repository at this point in the history
This splits the kiva OpenGL backend out into its own independent C-extension.
Until now, it was part of the Agg backend which forced users to have OpenGL
installed even if they only wanted to use the software renderer.
  • Loading branch information
jwiggins authored Jan 28, 2021
1 parent b424c29 commit af58c7c
Show file tree
Hide file tree
Showing 70 changed files with 12,194 additions and 1,741 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ dist/
kiva/agg/agg.py
kiva/agg/agg_wrap.cpp
kiva/agg/plat_support.py
kiva/agg/src/gl/plat_support_wrap.cpp
kiva/agg/src/gtk1/plat_support_wrap.cpp
kiva/agg/src/osx/plat_support_wrap.cpp
kiva/agg/src/win32/plat_support_wrap.cpp
kiva/agg/src/x11/plat_support_wrap.cpp
kiva/gl/gl.py
kiva/gl/gl_wrap.cpp
kiva/quartz/ABCGI.c
kiva/quartz/CTFont.c

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ include docs/kiva/agg/notes
recursive-include docs *.py *.rst *.txt *.css *.png *.ico *.doc
recursive-include enable/examples *.py *.svg *.jpg *.enaml
recursive-include kiva/examples *.py *.txt *.gif *.jpg
recursive-include kiva/gl *.h *.cpp *.i LICENSE_*
recursive-include kiva/quartz *.pyx *.pxi *.pxd mac_context*.*
recursive-include kiva/fonttools/tests/data *.ttc *.ttf
1 change: 1 addition & 0 deletions enable/qt4/base_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def closeEvent(self, event):
def paintEvent(self, event):
super(_QtGLWindow, self).paintEvent(event)
self.handler.paintEvent(event)
self.swapBuffers()

def resizeEvent(self, event):
super(_QtGLWindow, self).resizeEvent(event)
Expand Down
28 changes: 12 additions & 16 deletions enable/qt4/gl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Copyright (c) 2011, Enthought, Inc.
# All rights reserved.
#
Expand All @@ -7,35 +7,30 @@
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
from enable.qt4.base_window import BaseGLWindow
from enable.qt4.scrollbar import NativeScrollBar
from kiva.gl import CompiledPath, FakePygletContext, GraphicsContext

import pyglet
pyglet.options['shadow_window'] = False

from traits.api import Bool, Instance
from kiva.gl import CompiledPath, GraphicsContext

from .base_window import BaseGLWindow
from .scrollbar import NativeScrollBar

class Window(BaseGLWindow):
def _create_gc(self, size, pix_format=None):
""" Create a GraphicsContext instance.
"""
from pyglet.gl import Context

gc = GraphicsContext((size[0]+1, size[1]+1))
self._pyglet_gl_context = Context()
self._fake_pyglet_context = FakePygletContext()
gc.gl_init()
gc.translate_ctm(0.5, 0.5)
return gc

def _init_gc(self):
""" Gives the GC a chance to initialize itself before components perform layout
and draw. This is called every time through the paint loop.
""" Gives the GC a chance to initialize itself before components
perform layout and draw.
This is called every time through the paint loop.
"""
self._pyglet_gl_context.set_current()
self.control.makeCurrent()
self._fake_pyglet_context.set_current()
super(Window, self)._init_gc()

def _paint(self, event=None):
Expand All @@ -54,6 +49,7 @@ def _paint(self, event=None):
self.component.draw(self._gc, view_bounds=(0, 0, size[0], size[1]))
self._update_region = []


def font_metrics_provider():
from kiva.fonttools import Font
gc = GraphicsContext((1, 1))
Expand Down
5 changes: 2 additions & 3 deletions enable/wx/gl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from wx.glcanvas import GLCanvas

from traits.api import Instance
from kiva.gl import CompiledPath, GraphicsContext
from kiva.gl import CompiledPath, FakePygletContext, GraphicsContext

from .base_window import BaseWindow
from .scrollbar import NativeScrollBar
Expand Down Expand Up @@ -33,8 +33,7 @@ def _create_gc(self, size, pix_format=None):
"""
gc = GraphicsContext((size[0]+1,size[1]+1))
if self._pyglet_gl_context is None:
from pyglet.gl import Context
self._pyglet_gl_context = Context()
self._pyglet_gl_context = FakePygletContext()
gc.gl_init()
gc.translate_ctm(0.5, 0.5)
return gc
Expand Down
25 changes: 8 additions & 17 deletions kiva/agg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def configuration(parent_package='', top_path=None):
if sys.platform=='win32':
plat = 'win32'
elif sys.platform == 'darwin':
plat = 'gl'
plat = 'osx'
else:
#plat = 'gtk1' # use with gtk1, it's fast
plat = 'x11' # use with gtk2, it's slow but reliable
Expand Down Expand Up @@ -144,8 +144,7 @@ def get_ft2_sources(name_info, build_dir):
macros = []

kiva_include_dirs = ['src'] + agg_include_dirs
config.add_library('kiva_src',
['src/kiva_*.cpp', 'src/gl_graphics_context.cpp'],
config.add_library('kiva_src', ['src/kiva_*.cpp'],
include_dirs = kiva_include_dirs,
# Use "macros" instead of "define_macros" because the
# latter is only used for extensions, and not clibs
Expand Down Expand Up @@ -177,11 +176,11 @@ def get_ft2_sources(name_info, build_dir):
if use_32bit_workaround:
define_macros.append(("ALWAYS_32BIT_WORKAROUND", 1))

# Options to make OS X link OpenGL
# Options to make OS X link
if '64bit' not in platform.architecture():
darwin_frameworks = ['Carbon', 'ApplicationServices', 'OpenGL']
darwin_frameworks = ['Carbon', 'ApplicationServices']
else:
darwin_frameworks = ['ApplicationServices', 'OpenGL']
darwin_frameworks = ['ApplicationServices']

darwin_extra_link_args = []
for framework in darwin_frameworks:
Expand All @@ -198,13 +197,8 @@ def get_ft2_sources(name_info, build_dir):
build_info = {}
kiva_lib = 'kiva_src'
build_libraries = [kiva_lib, agg_lib, freetype_lib]
if sys.platform == "win32":
build_libraries += ["opengl32", "glu32"]
elif sys.platform == "darwin":
if sys.platform == "darwin":
dict_append(build_info, **darwin_opengl_opts)
else:
# This should work for most linuxes (linuces?)
build_libraries += ["GL", "GLU"]
dict_append(build_info,
sources = ['agg.i'],
include_dirs = kiva_include_dirs,
Expand All @@ -220,7 +214,7 @@ def get_ft2_sources(name_info, build_dir):
sources = [os.path.join('src',plat,'plat_support.i'),
os.path.join('src',plat,'agg_bmp.cpp'),
]
if plat != 'gl':
if plat != 'osx':
sources.append(os.path.join('src',plat,'agg_platform_specific.cpp'))

plat_info = {}
Expand Down Expand Up @@ -249,12 +243,9 @@ def get_ft2_sources(name_info, build_dir):
#x11_info = get_info('x11',notfound_action=1)
#dict_append(plat_info,**x11_info)

elif plat == 'gl':
elif plat == 'osx':
if sys.platform == 'darwin':
dict_append(plat_info, **darwin_opengl_opts)
else:
msg = "OpenGL build support only on MacOSX right now."
raise NotImplementedError(msg)


config.add_extension('_plat_support',
Expand Down
159 changes: 0 additions & 159 deletions kiva/agg/src/gl_graphics_context.h

This file was deleted.

Loading

0 comments on commit af58c7c

Please sign in to comment.