示例#1
0
    def test_minification_filter_invalid(self):
        a = gl.Texture2D()

        with self.assertRaisesRegex(
                TypeError,
                "expected SamplerFilter, gl.SamplerFilter or a two-element tuple"
        ):
            a.minification_filter = 3
        with self.assertRaisesRegex(
                TypeError,
                "expected a tuple with SamplerFilter or gl.SamplerFilter as the first element"
        ):
            a.minification_filter = (3, SamplerMipmap.BASE)
        with self.assertRaisesRegex(
                TypeError,
                "expected a tuple with SamplerMipmap or gl.SamplerMipmap as the second element"
        ):
            a.minification_filter = (SamplerFilter.NEAREST, 3)
        with self.assertRaisesRegex(
                TypeError,
                "expected a tuple with SamplerFilter or gl.SamplerFilter as the first element"
        ):
            a.minification_filter = (3, SamplerMipmap.BASE)

        # List doesn't work ATM, sorry
        with self.assertRaisesRegex(
                TypeError,
                "expected SamplerFilter, gl.SamplerFilter or a two-element tuple"
        ):
            a.minification_filter = [
                gl.SamplerFilter.LINEAR, gl.SamplerMipmap.LINEAR
            ]
    def test_uniforms_bindings_errors(self):
        a = shaders.Phong()
        with self.assertRaisesRegex(
                AttributeError,
                "the shader was not created with alpha mask enabled"):
            a.alpha_mask = 0.3
        with self.assertRaisesRegex(ValueError, "expected 1 items but got 0"):
            a.light_positions = []
        with self.assertRaisesRegex(ValueError, "expected 1 items but got 0"):
            a.light_colors = []

        texture = gl.Texture2D()
        with self.assertRaisesRegex(
                AttributeError,
                "the shader was not created with ambient texture enabled"):
            a.bind_ambient_texture(texture)
        with self.assertRaisesRegex(
                AttributeError,
                "the shader was not created with diffuse texture enabled"):
            a.bind_diffuse_texture(texture)
        with self.assertRaisesRegex(
                AttributeError,
                "the shader was not created with specular texture enabled"):
            a.bind_specular_texture(texture)
        with self.assertRaisesRegex(
                AttributeError,
                "the shader was not created with normal texture enabled"):
            a.bind_normal_texture(texture)
        with self.assertRaisesRegex(
                AttributeError,
                "the shader was not created with any textures enabled"):
            a.bind_textures(diffuse=texture)
示例#3
0
    def __init__(self):
        configuration = self.Configuration()
        configuration.title = "Magnum Python Textured Triangle Example"
        Application.__init__(self, configuration)

        buffer = gl.Buffer()
        buffer.set_data(array.array('f', [
            -0.5, -0.5, 0.0, 0.0,
             0.5, -0.5, 1.0, 0.0,
             0.0,  0.5, 0.5, 1.0
        ]))

        self._mesh = gl.Mesh()
        self._mesh.count = 3
        self._mesh.add_vertex_buffer(buffer, 0, 4*4,
            TexturedTriangleShader.POSITION)
        self._mesh.add_vertex_buffer(buffer, 2*4, 4*4,
            TexturedTriangleShader.TEXTURE_COORDINATES)

        importer = trade.ImporterManager().load_and_instantiate('TgaImporter')
        importer.open_file(os.path.join(os.path.dirname(__file__),
                                        '../textured-triangle/stone.tga'))
        image = importer.image2d(0)

        self._texture = gl.Texture2D()
        self._texture.wrapping = gl.SamplerWrapping.CLAMP_TO_EDGE
        self._texture.minification_filter = gl.SamplerFilter.LINEAR
        self._texture.magnification_filter = gl.SamplerFilter.LINEAR
        self._texture.set_storage(1, gl.TextureFormat.RGB8, image.size)
        self._texture.set_sub_image(0, Vector2i(), image)

        # or self._shader = shaders.Flat2D(shaders.Flat2D.Flags.TEXTURED)
        self._shader = TexturedTriangleShader()
示例#4
0
    def test_uniforms_bindings(self):
        a = shaders.PhongGL(
            shaders.PhongGL.Flags.ALPHA_MASK
            | shaders.PhongGL.Flags.AMBIENT_TEXTURE
            | shaders.PhongGL.Flags.DIFFUSE_TEXTURE
            | shaders.PhongGL.Flags.SPECULAR_TEXTURE
            | shaders.PhongGL.Flags.NORMAL_TEXTURE
            | shaders.PhongGL.Flags.TEXTURE_TRANSFORMATION, 2)
        a.diffuse_color = (0.5, 1.0, 0.9)
        a.transformation_matrix = Matrix4.translation(Vector3.x_axis())
        a.projection_matrix = Matrix4.zero_init()
        a.light_positions = [(0.5, 1.0, 0.3, 1.0), Vector4()]
        a.light_colors = [Color3(), Color3()]
        a.light_specular_colors = [Color3(), Color3()]
        a.light_ranges = [0.5, 100]
        a.normal_texture_scale = 0.3
        a.alpha_mask = 0.3
        a.texture_matrix = Matrix3()

        texture = gl.Texture2D()
        texture.set_storage(1, gl.TextureFormat.RGBA8, Vector2i(8))
        a.bind_ambient_texture(texture)
        a.bind_diffuse_texture(texture)
        a.bind_specular_texture(texture)
        a.bind_normal_texture(texture)
        a.bind_textures(ambient=texture,
                        diffuse=texture,
                        specular=texture,
                        normal=texture)
示例#5
0
    def test_border_color(self):
        a = gl.Texture2D()

        # Both three- and four-component should work
        a.border_color = Color3()
        a.border_color = Color4()

        if not magnum.TARGET_GLES2:
            a.border_color = Vector4ui()
            a.border_color = Vector4i()
    def test_uniforms_bindings(self):
        a = shaders.Flat3D(shaders.Flat3D.Flags.TEXTURED
                           | shaders.Flat3D.Flags.ALPHA_MASK)
        a.color = (0.5, 1.0, 0.9)
        a.transformation_projection_matrix = Matrix4.translation(
            Vector3.x_axis())
        a.alpha_mask = 0.3

        texture = gl.Texture2D()
        texture.set_storage(1, gl.TextureFormat.RGBA8, Vector2i(8))
        a.bind_texture(texture)
示例#7
0
    def test_set_storage_subimage(self):
        a = gl.Texture2D()
        a.set_storage(levels=5, internal_format=gl.TextureFormat.RGBA8,
            size=Vector2i(16))
        a.set_sub_image(0, Vector2i(), ImageView2D(PixelFormat.RGBA8_UNORM, Vector2i(16)))
        a.generate_mipmap()

        if not magnum.TARGET_GLES:
            # This is in ES3.2 too, but we don't have a way to check for
            # extensions / version yet
            self.assertEqual(a.image_size(0), Vector2i(16, 16))
    def test_uniforms_bindings_errors(self):
        a = shaders.Flat2D()
        with self.assertRaisesRegex(
                AttributeError,
                "the shader was not created with alpha mask enabled"):
            a.alpha_mask = 0.3

        texture = gl.Texture2D()
        with self.assertRaisesRegex(
                AttributeError,
                "the shader was not created with texturing enabled"):
            a.bind_texture(texture)
示例#9
0
    def test_minification_filter(self):
        a = gl.Texture2D()

        # Both generic and GL value should work
        a.minification_filter = gl.SamplerFilter.LINEAR
        a.minification_filter = SamplerFilter.LINEAR

        # A tuple as well -- any combination
        a.minification_filter = (gl.SamplerFilter.LINEAR, gl.SamplerMipmap.LINEAR)
        a.minification_filter = (gl.SamplerFilter.LINEAR, SamplerMipmap.LINEAR)
        a.minification_filter = (SamplerFilter.LINEAR, gl.SamplerMipmap.LINEAR)
        a.minification_filter = (SamplerFilter.LINEAR, SamplerMipmap.LINEAR)
示例#10
0
    def test_border_color_invalid(self):
        a = gl.Texture2D()

        if not magnum.TARGET_GLES2:
            with self.assertRaisesRegex(TypeError, "expected Color3, Color4, Vector4ui or Vector4i"):
                a.border_color = 3
        else:
            # On ES2 this is handled by pybind itself, so the message is
            # different
            with self.assertRaisesRegex(TypeError, "incompatible function arguments"):
                a.border_color = 3

            # This should raise a type error on ES2, as only floats are
            # supported
            with self.assertRaisesRegex(TypeError, "incompatible function arguments"):
                a.border_color = Vector4ui()
示例#11
0
 def test_set_image(self):
     a = gl.Texture2D()
     a.set_image(level=0,
                 internal_format=gl.TextureFormat.RGBA8,
                 image=ImageView2D(PixelFormat.RGBA8_UNORM, Vector2i(16)))
示例#12
0
    def test_wrapping_invalid(self):
        a = gl.Texture2D()

        with self.assertRaisesRegex(
                TypeError, "expected SamplerWrapping or gl.SamplerWrapping"):
            a.wrapping = 3
示例#13
0
    def test_wrapping(self):
        a = gl.Texture2D()

        # Both generic and GL value should work
        a.wrapping = gl.SamplerWrapping.REPEAT
        a.wrapping = SamplerWrapping.REPEAT
示例#14
0
    def test_magnification_filter_invalid(self):
        a = gl.Texture2D()

        with self.assertRaisesRegex(
                TypeError, "expected SamplerFilter or gl.SamplerFilter"):
            a.magnification_filter = 3
示例#15
0
    def test_magnification_filter(self):
        a = gl.Texture2D()

        # Both generic and GL value should work
        a.magnification_filter = gl.SamplerFilter.LINEAR
        a.magnification_filter = SamplerFilter.LINEAR