File: test_textures.py

package info (click to toggle)
pyopengl 3.1.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,024 kB
  • sloc: python: 108,056; sh: 13; makefile: 8
file content (143 lines) | stat: -rw-r--r-- 5,467 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import basetestcase
import os
from OpenGL.GL import *

try:
    import numpy as np
except ImportError as err:
    np = None
from OpenGL.arrays import arraydatatype

HERE = os.path.abspath(os.path.dirname(__file__))
from OpenGL.GL.ARB import texture_rg


class TestTextures(basetestcase.BaseTest):
    def test_enable_histogram(self):
        if glInitImagingARB():
            glHistogram(GL_HISTOGRAM, 256, GL_LUMINANCE, GL_FALSE)
            glEnable(GL_HISTOGRAM)
            glDisable(GL_HISTOGRAM)
        else:
            print('No ARB imaging extension')

    if np:

        def test_glreadpixels_warray(self):
            """SF#1311265 allow passing in the array object"""
            width, height = self.width, self.height
            data = np.zeros((width, height, 3), 'B')
            image1 = glReadPixelsub(0, 0, width, height, GL_RGB, array=data)
            assert image1 is not None

        someData = [(0, 255, 0)]

        def test_glAreTexturesResident(self):
            """Test that PyOpenGL api for glAreTexturesResident is working

            Note: not currently working on AMD64 Linux for some reason
            """
            textures = glGenTextures(2)
            residents = []
            data = np.array(self.someData, 'i')
            for texture in textures:
                glBindTexture(GL_TEXTURE_2D, int(texture))
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_INT, data)
                residents.append(
                    glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_RESIDENT)
                )
            glGetError()
            result = glAreTexturesResident(textures)
            assert len(result) == 2
            for tex, expected, found in zip(textures, residents, result):
                if expected != found:
                    print(
                        (
                            'Warning: texture %s residence expected %s got %s'
                            % (tex, expected, found)
                        )
                    )

    def test_glreadpixelsf(self):
        """Issue #1979002 crash due to mis-calculation of resulting array size"""
        width, height = self.width, self.height
        readback_image1 = glReadPixelsub(0, 0, width, height, GL_RGB)
        assert readback_image1 is not None
        readback_image2 = glReadPixelsf(0, 0, width, height, GL_RGB)
        assert readback_image2 is not None

    def test_glreadpixels_is_string(self):
        """Issue #1959860 incompatable change to returning arrays reversed"""
        width, height = self.width, self.height
        readback_image1 = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE)
        assert isinstance(readback_image1, bytes), type(readback_image1)
        readback_image1 = glReadPixels(0, 0, width, height, GL_RGB, GL_BYTE)
        assert not isinstance(readback_image1, bytes), type(readback_image2)

    def test_passBackResults(self):
        """Test ALLOW_NUMPY_SCALARS to allow numpy scalars to be passed in"""
        textures = glGenTextures(2)
        glBindTexture(GL_TEXTURE_2D, textures[0])

    def test_nullTexture(self):
        """Test that we can create null textures"""
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 512, 512, 0, GL_RGB, GL_INT, None)

    def test_get_boolean_bitmap(self):
        # should not raise error
        glGetBoolean(GL_TEXTURE_2D)

    if np:

        def test_draw_bitmap_pixels(self):
            """SF#2152623 Drawing pixels as bitmaps (bits)"""
            # this core-dumps on Mesa Intel on Ubuntu 15.04 :(
            # nosetest skip would be more appropriate
            pixels = np.array([0, 0, 0, 0, 0, 0, 0, 0], 'B')
            glDrawPixels(8, 8, GL_COLOR_INDEX, GL_BITMAP, pixels)

    def test_get_max_tex_units(self):
        """SF#2895081 glGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS )"""
        units = glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS)
        assert units

    def test_glGenTextures(self):
        texture = glGenTextures(1)
        assert texture

    def test_createTargetArray(self):
        import OpenGL.GL as gl
        import OpenGL.images as images

        size = (640, 480)
        array1 = images.createTargetArray(
            gl.GL_BGRA, size, gl.GL_UNSIGNED_INT_8_8_8_8_REV
        )
        array2 = images.createTargetArray(gl.GL_RGBA, size, gl.GL_UNSIGNED_BYTE)
        array3 = images.createTargetArray(
            gl.GL_RGBA, size, gl.GL_UNSIGNED_INT_8_8_8_8_REV
        )
        if hasattr(array1, 'nbytes'):
            assert array1.nbytes == array3.nbytes
            assert array1.nbytes == array2.nbytes
        else:
            assert ctypes.sizeof(array1) == ctypes.sizeof(array3)
            assert ctypes.sizeof(array1) == ctypes.sizeof(array2)

        try:
            images.createTargetArray(gl.GL_RGBA, size, gl.GL_UNSIGNED_BYTE_3_3_2)
        except ValueError as err:
            pass
        else:
            raise RuntimeError(
                """Should have failed with insufficient components in the type to hold the format"""
            )

    def test_rg_format(self):
        # Note: this is actually only known after context creation...
        if not texture_rg.glInitTextureRgARB():
            return
        texture = glGenTextures(1)
        data = arraydatatype.GLfloatArray.asArray([0.3, 0.5])
        glBindTexture(GL_TEXTURE_2D, int(texture))
        glTexImage2D(GL_TEXTURE_2D, 0, texture_rg.GL_RG, 1, 1, 0, GL_RG, GL_FLOAT, data)