def testSetUniform(self): # note how the API changes here to be more pythonic as # we have no pass by reference here shader = pyngl.ShaderLib.instance() shaderName = 'TestUniform' self.assertTrue( shader.loadShader(shaderName, sourcedir + 'testUniformVertex.glsl', sourcedir + 'testUniformFragment.glsl', pyngl.ErrorExit.OFF)) shader.use(shaderName) shader.setUniform('testFloat', 2.25) result = shader.getUniform1f('testFloat') self.assertAlmostEqual(result, 2.25, delta=3) shader.setUniform("testVec2", 0.5, 2.0) resultVec2 = shader.getUniformVec2("testVec2") self.assertAlmostEqual(resultVec2.m_x, 0.5, delta=3) self.assertAlmostEqual(resultVec2.m_y, 2.0, delta=3) x, y = shader.getUniform2f("testVec2") self.assertAlmostEqual(resultVec2.m_x, 0.5, delta=3) self.assertAlmostEqual(resultVec2.m_y, 2.0, delta=3) shader.setUniform('testVec3', 0.5, 2.0, -22.2) resultF1, resultF2, resultF3 = shader.getUniform3f('testVec3') self.assertAlmostEqual(resultF1, 0.5, delta=3) self.assertAlmostEqual(resultF2, 2.0, delta=3) self.assertAlmostEqual(resultF3, -22.2, delta=3) resultVec3 = shader.getUniformVec3('testVec3') self.assertAlmostEqual(resultVec3.m_x, 0.5, delta=3) self.assertAlmostEqual(resultVec3.m_y, 2.0, delta=3) self.assertAlmostEqual(resultVec3.m_z, -22.2, delta=3) shader.setUniform('testVec4', 0.5, 2.0, -22.2, 1230.4) resultF1, resultF2, resultF3, resultF4 = shader.getUniform4f( 'testVec4') self.assertAlmostEqual(resultF1, 0.5, delta=3) self.assertAlmostEqual(resultF2, 2.0, delta=3) self.assertAlmostEqual(resultF3, -22.2, delta=3) self.assertAlmostEqual(resultF4, 1230.4, delta=3) resultVec4 = shader.getUniformVec4('testVec4') self.assertAlmostEqual(resultVec4.m_x, 0.5, delta=3) self.assertAlmostEqual(resultVec4.m_y, 2.0, delta=3) self.assertAlmostEqual(resultVec4.m_z, -22.2, delta=3) self.assertAlmostEqual(resultVec4.m_w, 1230.4, delta=3) shader.setUniform('testMat2', pyngl.Mat2()) result = shader.getUniformMat2('testMat2') self.assertTrue(result == pyngl.Mat2()) shader.setUniform('testMat3', pyngl.Mat3()) result = shader.getUniformMat3('testMat3') self.assertTrue(result == pyngl.Mat3()) shader.setUniform('testMat4', pyngl.Mat4()) result = shader.getUniformMat4('testMat4') self.assertTrue(result == pyngl.Mat4())
def testPlus(self) : t1=pyngl.Mat2(1,2,3,4) t2=pyngl.Mat2(5,6,7,8) res=t1+t2 result=pyngl.Mat2(6,8,10,12) self.assertTrue(res == result)
def testMat3xReal(self) : test=pyngl.Mat2(1,2,3,4) test*=4.0 result=pyngl.Mat2(4,8,12,16) self.assertTrue(test==result)
def testMat3xEquals(self) : test=pyngl.Mat2(1,2,3,4) t2=pyngl.Mat2(5,6,7,8) test*=t2 result=pyngl.Mat2(19,22,43,50) self.assertTrue(test == result)
def testPlusEqual(self) : t1=pyngl.Mat2(1,2,3,4) t2=pyngl.Mat2(5,6,7,8) t1+=t2 result=pyngl.Mat2(6,8,10,12) self.assertTrue(t1 == result)
def testScale(self) : test=pyngl.Mat2() test.scale(1.0,2.0) result=pyngl.Mat2(1,0,0,2) self.assertTrue(test == result)
def testMat2xMat2(self) : t1=pyngl.Mat2(1,2,3,4) t2=pyngl.Mat2(5,6,7,8) test=t1*t2 result=pyngl.Mat2(19,22,43,50) self.assertTrue(test == result)
def testSizeof(self): test=pyngl.Mat2() self.assertTrue( test.sizeof()==4*ctypes.sizeof(ctypes.c_float))
def testTranspose(self) : test=pyngl.Mat2(1,2,3,4) test.transpose() result=pyngl.Mat2(1,3,2,4) self.assertTrue(test == result)
def testAssignOperator(self) : test=pyngl.Mat2(2.0) copy=test result=pyngl.Mat2(2.0,0.0,0.0,2.0) self.assertTrue( copy==result)
def testCopyCtor(self) : test=pyngl.Mat2(2.0) copy=pyngl.Mat2(test) result=pyngl.Mat2(2.0,0.0,0.0,2.0) self.assertTrue( copy==result)
def testFloatCtor(self) : test=pyngl.Mat2(2.0) result=pyngl.Mat2(2.0,0.0,0.0,2.0) self.assertTrue( test==result)
def testIdentity(self) : test=pyngl.Mat2(1,2,3,4) test.identity() result=pyngl.Mat2() self.assertTrue( test==result)
def testNull(self) : test=pyngl.Mat2() test.null() result=pyngl.Mat2(0.0) self.assertTrue( test==result)
def testdefaultCtor(self): test=pyngl.Mat2() result=pyngl.Mat2(1,0,0,1) self.assertTrue( test==result)
def testVec2xMat2(self) : t1=pyngl.Mat2() test=pyngl.Vec2(2,1) test=test*t1; result=pyngl.Vec2(2,1) self.assertTrue(test==result)