コード例 #1
0
ファイル: test_functionality.py プロジェクト: alexflint/vispy
def _test_functonality(backend):
    """ Create app and canvas so we have a context. Then run tests.
    """
    # use the backend
    gl.use_gl(backend)
    
    with Canvas() as canvas:
        _clear_screen()
        
        # Prepare
        w, h = canvas.size
        gl.glViewport(0, 0, w, h)
        gl.glScissor(0, 0, w, h)  # touch
        gl.glClearColor(0.0, 0.0, 0.0, 1.0)
        
        # Setup visualization, ensure to do it in a draw event
        objects = _prepare_vis()
        _clear_screen()
        _draw1()
        _clear_screen()
        _draw2()
        _clear_screen()
        _draw3()

        # Clean up
        for delete_func, handle in objects:
            delete_func(handle)
        gl.glFinish()
コード例 #2
0
ファイル: test_functionality.py プロジェクト: djhoese/vispy
def _test_functionality(backend):
    """Create app and canvas so we have a context. Then run tests."""
    # use the backend
    gl.use_gl(backend)

    with Canvas() as canvas:
        _clear_screen()

        # Prepare
        w, h = canvas.size
        gl.glViewport(0, 0, w, h)
        gl.glScissor(0, 0, w, h)  # touch
        gl.glClearColor(0.0, 0.0, 0.0, 1.0)

        # Setup visualization, ensure to do it in a draw event
        objects = _prepare_vis()
        _clear_screen()
        _draw1()
        _clear_screen()
        _draw2()
        _clear_screen()
        _draw3()

        # Clean up
        for delete_func, handle in objects:
            delete_func(handle)
        gl.glFinish()
コード例 #3
0
ファイル: test_wrappers.py プロジェクト: kod3r/vispy
def test_wrappers():
    """Test gloo wrappers"""
    with Canvas():
        gl.use_gl('desktop debug')
        gloo.clear('#112233')  # make it so that there's something non-zero
        # check presets
        assert_raises(ValueError, gloo.set_state, preset='foo')
        for state in gloo.get_state_presets().keys():
            gloo.set_state(state)
        assert_raises(ValueError, gloo.set_blend_color, (0., 0.))  # bad color
        assert_raises(TypeError, gloo.set_hint, 1, 2)  # need strs
        assert_raises(TypeError, gloo.get_parameter, 1)  # need str
        # this doesn't exist in ES 2.0 namespace
        assert_raises(ValueError, gloo.set_hint, 'fog_hint', 'nicest')
        # test bad enum
        assert_raises(RuntimeError, gloo.set_line_width, -1)

        # check read_pixels
        x = gloo.read_pixels()
        assert_true(isinstance(x, np.ndarray))
        assert_true(isinstance(gloo.read_pixels((0, 0, 1, 1)), np.ndarray))
        assert_raises(ValueError, gloo.read_pixels, (0, 0, 1))  # bad port
        y = gloo.read_pixels(alpha=False, out_type=np.ubyte)
        assert_equal(y.shape, x.shape[:2] + (3, ))
        assert_array_equal(x[..., :3], y)
        y = gloo.read_pixels(out_type='float')
        assert_allclose(x / 255., y)

        # now let's (indirectly) check our set_* functions
        viewport = (0, 0, 1, 1)
        blend_color = (0., 0., 0.)
        _funs = dict(
            viewport=viewport,  # checked
            hint=('generate_mipmap_hint', 'nicest'),
            depth_range=(1., 2.),
            front_face='cw',  # checked
            cull_face='front',
            line_width=1.,
            polygon_offset=(1., 1.),
            blend_func=('zero', 'one'),
            blend_color=blend_color,
            blend_equation='func_add',
            scissor=(0, 0, 1, 1),
            stencil_func=('never', 1, 2, 'back'),
            stencil_mask=4,
            stencil_op=('zero', 'zero', 'zero', 'back'),
            depth_func='greater',
            depth_mask=True,
            color_mask=(True, True, True, True),
            sample_coverage=(0.5, True))
        gloo.set_state(**_funs)
        gloo.clear((1., 1., 1., 1.), 0.5, 1)
        gloo.flush()
        gloo.finish()
        # check some results
        assert_array_equal(gloo.get_parameter('viewport'), viewport)
        assert_equal(gloo.get_parameter('front_face'), gl.GL_CW)
        assert_equal(gloo.get_parameter('blend_color'), blend_color + (1, ))
コード例 #4
0
ファイル: test_wrappers.py プロジェクト: Zulko/vispy
def test_wrappers():
    """Test gloo wrappers"""
    with Canvas():
        gl.use_gl('desktop debug')
        gloo.clear('#112233')  # make it so that there's something non-zero
        # check presets
        assert_raises(ValueError, gloo.set_state, preset='foo')
        for state in gloo.get_state_presets().keys():
            gloo.set_state(state)
        assert_raises(ValueError, gloo.set_blend_color, (0., 0.))  # bad color
        assert_raises(TypeError, gloo.set_hint, 1, 2)  # need strs
        assert_raises(TypeError, gloo.get_parameter, 1)  # need str
        # this doesn't exist in ES 2.0 namespace
        assert_raises(ValueError, gloo.set_hint, 'fog_hint', 'nicest')
        # test bad enum
        assert_raises(RuntimeError, gloo.set_line_width, -1)

        # check read_pixels
        x = gloo.read_pixels()
        assert_true(isinstance(x, np.ndarray))
        assert_true(isinstance(gloo.read_pixels((0, 0, 1, 1)), np.ndarray))
        assert_raises(ValueError, gloo.read_pixels, (0, 0, 1))  # bad port
        y = gloo.read_pixels(alpha=False, out_type=np.ubyte)
        assert_equal(y.shape, x.shape[:2] + (3,))
        assert_array_equal(x[..., :3], y)
        y = gloo.read_pixels(out_type='float')
        assert_allclose(x/255., y)

        # now let's (indirectly) check our set_* functions
        viewport = (0, 0, 1, 1)
        blend_color = (0., 0., 0.)
        _funs = dict(viewport=viewport,  # checked
                     hint=('generate_mipmap_hint', 'nicest'),
                     depth_range=(1., 2.),
                     front_face='cw',  # checked
                     cull_face='front',
                     line_width=1.,
                     polygon_offset=(1., 1.),
                     blend_func=('zero', 'one'),
                     blend_color=blend_color,
                     blend_equation='func_add',
                     scissor=(0, 0, 1, 1),
                     stencil_func=('never', 1, 2, 'back'),
                     stencil_mask=4,
                     stencil_op=('zero', 'zero', 'zero', 'back'),
                     depth_func='greater',
                     depth_mask=True,
                     color_mask=(True, True, True, True),
                     sample_coverage=(0.5, True))
        gloo.set_state(**_funs)
        gloo.clear((1., 1., 1., 1.), 0.5, 1)
        gloo.flush()
        gloo.finish()
        # check some results
        assert_array_equal(gloo.get_parameter('viewport'), viewport)
        assert_equal(gloo.get_parameter('front_face'), gl.GL_CW)
        assert_equal(gloo.get_parameter('blend_color'), blend_color + (1,))
コード例 #5
0
def test_glplus():
    """Run glplus, check that mo names, set back, check exact set of names."""
    gl.use_gl('gl+')
    # Check that there are more names
    fnames = set([name for name in dir(gl) if name.startswith('gl')])
    assert len(fnames.difference(function_names).difference(['gl2'])) > 50
    cnames = set([name for name in dir(gl) if name.startswith('GL')])
    assert len(cnames.difference(constant_names)) > 50
    gl.use_gl('gl2')
    _test_function_names(gl)
    _test_constant_names(gl)
コード例 #6
0
ファイル: test_names.py プロジェクト: Calvarez20/vispy
def test_glplus():
    """ Run glplus, check that mo names, set back, check exact set of names.
    """
    gl.use_gl('gl+')
    # Check that there are more names
    fnames = set([name for name in dir(gl) if name.startswith('gl')])
    assert len(fnames.difference(function_names).difference(['gl2'])) > 50
    cnames = set([name for name in dir(gl) if name.startswith('GL')])
    assert len(cnames.difference(constant_names)) > 50
    gl.use_gl('gl2')
    _test_function_names(gl)
    _test_constant_names(gl)
コード例 #7
0
def _test_basics(backend):
    """Create app and canvas so we have a context. Then run tests."""
    # use the backend
    with use_log_level('error', print_msg=False):
        gl.use_gl(backend)  # pyopengl throws warning on injection

    with Canvas():
        _test_setting_parameters()
        _test_enabling_disabling()
        _test_setting_stuff()
        _test_object_creation_and_deletion()
        _test_fbo()
        gl.glFinish()
コード例 #8
0
ファイル: test_basics.py プロジェクト: shjoshi/vispy
def _test_basics(backend):
    """ Create app and canvas so we have a context. Then run tests.
    """

    # use the backend
    gl.use_gl(backend)

    with Canvas():
        _test_setting_parameters()
        _test_enabling_disabling()
        _test_setting_stuff()
        _test_object_creation_and_deletion()
        _test_fbo()
        gl.glFinish()
コード例 #9
0
ファイル: test_basics.py プロジェクト: almarklein/vispy
def _test_basics(backend):
    """ Create app and canvas so we have a context. Then run tests.
    """

    # use the backend
    with use_log_level('error', print_msg=False):
        gl.use_gl(backend)  # pyopengl throws warning on injection

    with Canvas():
        _test_setting_parameters()
        _test_enabling_disabling()
        _test_setting_stuff()
        _test_object_creation_and_deletion()
        _test_fbo()
        gl.glFinish()
コード例 #10
0
ファイル: test_use.py プロジェクト: alexflint/vispy
def test_use_desktop():
    """ Testing that gl.use injects all names in gl namespace """

    # Use desktop
    gl.use_gl('desktop')
    #
    for name in dir(gl.desktop):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.desktop, name)
            assert_is(val1, val2)

    # Use pyopengl
    gl.use_gl('pyopengl')
    #
    for name in dir(gl.desktop):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.pyopengl, name)
            assert_is(val1, val2)
    
    # Use webgl
    gl.use_gl('webgl')
    #
    for name in dir(gl.desktop):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.webgl, name)
            assert_is(val1, val2)
    
    # Touch debug wrapper stuff
    gl.use_gl('desktop debug')
    
    # Use desktop again
    gl.use_gl('desktop')
    #
    for name in dir(gl.desktop):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.desktop, name)
            assert_is(val1, val2)
コード例 #11
0
def test_use_desktop():
    """ Testing that gl.use injects all names in gl namespace """

    # Use desktop
    gl.use_gl('desktop')
    #
    for name in dir(gl.desktop):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.desktop, name)
            assert_is(val1, val2)

    # Use pyopengl
    gl.use_gl('pyopengl')
    #
    for name in dir(gl.desktop):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.pyopengl, name)
            assert_is(val1, val2)

    # Use webgl
    gl.use_gl('webgl')
    #
    for name in dir(gl.desktop):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.webgl, name)
            assert_is(val1, val2)

    # Touch debug wrapper stuff
    gl.use_gl('desktop debug')

    # Use desktop again
    gl.use_gl('desktop')
    #
    for name in dir(gl.desktop):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.desktop, name)
            assert_is(val1, val2)
コード例 #12
0
ファイル: test_app.py プロジェクト: Zulko/vispy
from time import sleep

from numpy.testing import assert_array_equal
from nose.tools import assert_equal, assert_true, assert_raises

from vispy.app import use_app, Canvas, Timer, MouseEvent, KeyEvent
from vispy.app.base import BaseApplicationBackend
from vispy.testing import requires_application, SkipTest, assert_is, assert_in
from vispy.util import keys, use_log_level

from vispy.gloo.program import (Program, VertexBuffer, IndexBuffer)
from vispy.gloo.shader import VertexShader, FragmentShader
from vispy.gloo.util import _screenshot
from vispy.gloo import gl

gl.use_gl('desktop debug')


def on_nonexist(self, *args):
    return


def on_mouse_move(self, *args):
    return


def _on_mouse_move(self, *args):
    return


def _test_callbacks(canvas):
コード例 #13
0
ファイル: test_app.py プロジェクト: vanossj/vispy
from numpy.testing import assert_array_equal

from vispy.app import use_app, Canvas, Timer, MouseEvent, KeyEvent
from vispy.app.base import BaseApplicationBackend
from vispy.testing import (requires_application, SkipTest, assert_is,
                           assert_in, run_tests_if_main,
                           assert_equal, assert_true, assert_raises)
from vispy.util import keys, use_log_level

from vispy.gloo.program import (Program, VertexBuffer, IndexBuffer)
from vispy.gloo.util import _screenshot
from vispy.gloo import gl
from vispy.ext.six.moves import StringIO

gl.use_gl('desktop debug')


def on_nonexist(self, *args):
    return


def on_mouse_move(self, *args):
    return


def _on_mouse_move(self, *args):
    return


def _test_callbacks(canvas):
コード例 #14
0
from vispy.gloo import gl
from vispy import app
gl.use_gl('glplus')


def init_headless():
    app.use_app('glfw')
コード例 #15
0
ファイル: test_basics.py プロジェクト: robmcmullen/vispy
def teardown_module():
    gl.use_gl()  # Reset to default
コード例 #16
0
ファイル: test_functionality.py プロジェクト: alexflint/vispy
def teardown_module():
    gl.use_gl()  # Reset to default
コード例 #17
0
ファイル: test_app.py プロジェクト: Eric89GXL/vispy
from numpy.testing import assert_array_equal

from vispy.app import use_app, Canvas, Timer, MouseEvent, KeyEvent
from vispy.app.base import BaseApplicationBackend
from vispy.testing import (requires_application, SkipTest, assert_is,
                           assert_in, run_tests_if_main,
                           assert_equal, assert_true, assert_raises)
from vispy.util import keys, use_log_level

from vispy.gloo.program import (Program, VertexBuffer, IndexBuffer)
from vispy.gloo.util import _screenshot
from vispy.gloo import gl
from vispy.ext.six.moves import StringIO

gl.use_gl('gl2 debug')


def on_nonexist(self, *args):
    return


def on_mouse_move(self, *args):
    return


def _on_mouse_move(self, *args):
    return


def _test_callbacks(canvas):
コード例 #18
0
ファイル: test_use.py プロジェクト: Calvarez20/vispy
def test_use_desktop():
    """ Testing that gl.use injects all names in gl namespace """

    # Use desktop
    gl.use_gl('gl2')
    #
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.gl2, name)
            assert_is(val1, val2)

    # Use pyopengl
    gl.use_gl('pyopengl2')
    #
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.pyopengl2, name)
            assert_is(val1, val2)
    
    # Use gl+ 
    gl.use_gl('gl+')
    # uses all ES2 names from pyopengl2 backend
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.pyopengl2, name)
            assert_is(val1, val2)
    # But provides extra names too
    for name in dir(gl.glplus):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.glplus, name)
            assert_is(val1, val2)
    
    # Use dummy
    gl.use_gl('dummy')
    #
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.dummy, name)
            assert_is(val1, val2)
    
    # Touch debug wrapper stuff
    gl.use_gl('gl2 debug')
    
    # Use desktop again
    gl.use_gl('gl2')
    #
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.gl2, name)
            assert_is(val1, val2)
コード例 #19
0
ファイル: test_use.py プロジェクト: zymspindrift/vispy
def test_use_desktop():
    """ Testing that gl.use injects all names in gl namespace """

    # Use desktop
    gl.use_gl('gl2')
    #
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.gl2, name)
            assert_is(val1, val2)

    # Use pyopengl
    gl.use_gl('pyopengl2')
    #
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.pyopengl2, name)
            assert_is(val1, val2)

    # Use gl+
    gl.use_gl('gl+')
    # uses all ES2 names from pyopengl2 backend
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.pyopengl2, name)
            assert_is(val1, val2)
    # But provides extra names too
    for name in dir(gl.glplus):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.glplus, name)
            assert_is(val1, val2)

    # Use dummy
    gl.use_gl('dummy')
    #
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.dummy, name)
            assert_is(val1, val2)

    # Touch debug wrapper stuff
    gl.use_gl('gl2 debug')

    # Use desktop again
    gl.use_gl('gl2')
    #
    for name in dir(gl.gl2):
        if name.lower().startswith('gl'):
            val1 = getattr(gl, name)
            val2 = getattr(gl.gl2, name)
            assert_is(val1, val2)
コード例 #20
0
import numpy as np
from numpy.testing import assert_array_equal
import pytest

from vispy.app import use_app, Canvas, Timer, MouseEvent, KeyEvent
from vispy.app.base import BaseApplicationBackend
from vispy.testing import (requires_application, SkipTest, assert_is,
                           assert_in, run_tests_if_main, assert_equal,
                           assert_true, assert_raises)
from vispy.util import keys, use_log_level

from vispy.gloo.program import (Program, VertexBuffer, IndexBuffer)
from vispy.gloo.util import _screenshot
from vispy.gloo import gl

gl.use_gl('gl2 debug')


def on_nonexist(self, *args):
    return


def on_mouse_move(self, *args):
    return


def _on_mouse_move(self, *args):
    return


def _test_callbacks(canvas):