def test_init(self): a = gl.Mesh() b = gl.Mesh(gl.MeshPrimitive.LINE_LOOP) c = gl.Mesh(MeshPrimitive.LINES) self.assertNotEqual(a.id, 0) self.assertNotEqual(b.id, 0) self.assertNotEqual(c.id, 0) self.assertEqual(a.primitive, gl.MeshPrimitive.TRIANGLES) self.assertEqual(b.primitive, gl.MeshPrimitive.LINE_LOOP) self.assertEqual(c.primitive, gl.MeshPrimitive.LINES)
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()
def test_set_primitive_invalid(self): a = gl.Mesh() with self.assertRaisesRegex( TypeError, "expected MeshPrimitive or gl.MeshPrimitive, got <class 'str'>" ): a.primitive = "ahaha"
def test_set_primitive(self): a = gl.Mesh() a.primitive = gl.MeshPrimitive.TRIANGLE_STRIP self.assertEqual(a.primitive, gl.MeshPrimitive.TRIANGLE_STRIP) a.primitive = MeshPrimitive.POINTS self.assertEqual(a.primitive, gl.MeshPrimitive.POINTS)
def test_add_buffer(self): buffer = gl.Buffer() buffer_refcount = sys.getrefcount(buffer) # Adding a buffer to the mesh should increase its ref count mesh = gl.Mesh() mesh.add_vertex_buffer(buffer, 0, 8, gl.Attribute(gl.Attribute.Kind.GENERIC, 2, gl.Attribute.Components.TWO, gl.Attribute.DataType.FLOAT)) self.assertEqual(len(mesh.buffers), 1) self.assertIs(mesh.buffers[0], buffer) self.assertEqual(sys.getrefcount(buffer), buffer_refcount + 1) # Deleting the mesh should decrease it again del mesh self.assertEqual(sys.getrefcount(buffer), buffer_refcount)
def test_set_index_buffer(self): buffer = gl.Buffer() buffer_refcount = sys.getrefcount(buffer) # Adding a buffer to the mesh should increase its ref count mesh = gl.Mesh() self.assertEqual(mesh.is_indexed(), False) mesh.set_index_buffer(buffer, 0, MeshIndexType.UNSIGNED_SHORT, 0, 2) self.assertEqual(mesh.is_indexed(), True) self.assertEqual(sys.getrefcount(buffer), buffer_refcount + 1) # Deleting the mesh should decrease it again del mesh self.assertEqual(sys.getrefcount(buffer), buffer_refcount)
def __init__(self): configuration = self.Configuration() configuration.title = "Magnum Python Triangle Example" Application.__init__(self, configuration) buffer = gl.Buffer() buffer.set_data( array.array('f', [ -0.5, -0.5, 1.0, 0.0, 0.0, 0.5, -0.5, 0.0, 1.0, 0.0, 0.0, 0.5, 0.0, 0.0, 1.0 ])) self._mesh = gl.Mesh() self._mesh.count = 3 self._mesh.add_vertex_buffer(buffer, 0, 5 * 4, shaders.VertexColor2D.POSITION) self._mesh.add_vertex_buffer(buffer, 2 * 4, 5 * 4, shaders.VertexColor2D.COLOR3) self._shader = shaders.VertexColor2D()
def test_set_count(self): a = gl.Mesh() a.count = 15 self.assertEqual(a.count, 15)