Beispiel #1
0
 def test_using_multiple(self):
     " Test multiple shaders with-block "
     prog1 = ShaderProgram.new_program()
     prog1.attach(*self.get_objects())
     prog1.link()
     
     prog2 = ShaderProgram.new_program()
     prog2.attach(*self.get_objects('shader2'))
     prog2.link()
     
     self.assertIsNone(current_program(), 'Current program is not None')
     with prog1.using():
         self.assertEqual(current_program(), prog1, 'Program 1 is not in use')
         with prog2.using():
             self.assertEqual(current_program(), prog2, 'Program 2 is not in use')
         self.assertEqual(current_program(), prog1, 'Program 1 is not in use')
     self.assertIsNone(current_program(), 'Current program is not None')
Beispiel #2
0
 def test_valid(self):
     " Test if generated programs are valid"
     prog1 = ShaderProgram.new_program()
     prog2 = ShaderProgram(8000, owned = True)
     
     self.assertTrue(prog1.valid())
     self.assertFalse(prog2.valid())
     self.assertTrue(prog1)
     self.assertFalse(prog2)
Beispiel #3
0
 def test_using(self):
     " Test shader with-block "
     prog = ShaderProgram.new_program()
     prog.attach(*self.get_objects())
     prog.link()
     self.assertIsNone(current_program(), 'Current program is not None')
     with prog.using():
         self.assertEqual(current_program(), prog, 'Program is not in use')
     self.assertIsNone(current_program(), 'Current program is not None')
Beispiel #4
0
 def test_use_remove(self):
     " Test use and clear "
     prog = ShaderProgram.new_program()
     vert, frag = self.get_objects()
     prog.attach(vert, frag)
     prog.link()
     prog.use()
     self.assertEqual(current_program(), prog, 'Program is not in use')
     ShaderProgram.clear()
     self.assertIsNone(current_program(), 'Current program is not None')
Beispiel #5
0
 def test_link_fail(self):
     "Test a shader program that links incorrectly"
     prog = ShaderProgram.new_program()
     vert, frag = self.get_objects('shader2')
     prog.attach(vert, frag)
     
     self.assertEqual(GL_TRUE, frag.compiled, 'frag compilation failed')        
     self.assertFalse(prog.link(), 'link was successful')
     self.assertEqual(GL_FALSE, prog.link_status, 'link status is not false')
     
     logs = prog.logs
     self.assertNotEqual(0, prog.log_length, 'log length is 0')
     self.assertEqual(prog.log_length, len(logs), 'log_length do not match returned log length')
     self.assertIn('Function: secret_method( is not implemented', logs, 'error not found')
Beispiel #6
0
 def test_link(self):
     "Test if a shader program links correctly"
     prog = ShaderProgram.new_program()
     vert, frag = self.get_objects('shader2')
     lib = ShaderObject.fragment()
     
     with open(frag_path('frag_lib')) as f:
         lib.source = f.read()
         self.assertTrue(lib.compile(), 'lib did not compile successfully')
     
     prog.attach(vert, frag, lib)
     
     self.assertEqual(GL_FALSE, prog.link_status, 'link status is not false')
     self.assertTrue(prog.link(), 'link was not successful')
     self.assertEqual(GL_TRUE, prog.link_status, 'link status is not true')
Beispiel #7
0
 def test_detach(self):
     "Test if shader objects are detached correctly"
     prog = ShaderProgram.new_program()
     vert, frag = self.get_objects()
     prog.attach(vert, frag)
     
     prog.detach(vert)
     self.assertEqual(1, prog.shaders_count, 'prog do not have 1 shader linked')
     
     shaders = prog.shaders()
     self.assertEqual(1, len(shaders), 'shaders length is not 1')
     self.assertIn(frag, shaders, 'frag is not in the returned shader objects')
     self.assertNotIn(vert, shaders, 'vert is in the returned shader objects')
     
     self.assertTrue(vert.owned)
     self.assertFalse(frag.owned)
Beispiel #8
0
 def test_attach(self):
     "Test if shader objects are attached correctly"
     prog = ShaderProgram.new_program()
     vert, frag = self.get_objects()
     
     self.assertEqual(0, prog.shaders_count, 'prog have shaders linked')
     prog.attach(vert, frag)
     self.assertEqual(2, prog.shaders_count, 'prog do not have 2 shaders linked')
     
     shaders = prog.shaders()
     self.assertEqual(2, len(shaders), 'shaders length is not 2')
     self.assertIn(vert, shaders, 'vert is not in the returned shader objects')
     self.assertIn(frag, shaders, 'frag is not in the returned shader objects')
     
     self.assertFalse(vert.owned)
     self.assertFalse(frag.owned)
Beispiel #9
0
 def test_freeing(self):
     " Test if programs are freed correctly "
     prog = ShaderProgram.new_program()
     vert, frag = self.get_objects()
     prog.attach(vert, frag)
     
     # Warning, borrowed_obj do not own the underlying shader so it will not be freed automatically
     borrowed_prog = ShaderProgram(glCreateProgram(), owned=False)
     
     pid = prog.pid
     pid2 = borrowed_prog.pid
     del prog
     del borrowed_prog
     gc.collect()
     
     self.assertEqual(glIsProgram(pid), GL_FALSE, 'Program was not freed')
     self.assertEqual(glIsProgram(pid2), GL_TRUE, 'Program was freed')
     self.assertFalse(vert.valid(), 'vert was not freed')
     self.assertFalse(frag.valid(), 'frag was not freed')
     
     # Free the program object
     glDeleteProgram(pid2)        
Beispiel #10
0
 def test_repr(self):
     prog = ShaderProgram.new_program()
     self.assertEqual('ShaderProgram {}'.format(prog.pid), repr(prog), "Repr do not match")
Beispiel #11
0
 def test_eq(self):
     prog = ShaderProgram.new_program()
     prog_clone = ShaderProgram(prog.pid)
     
     self.assertEqual(prog, prog_clone, 'prog and prog clone are not equal')        
Beispiel #12
0
 def test_create(self):
     " Test if programs are created correctly "
     prog = ShaderProgram.new_program()
     self.assertIs(ShaderProgram, type(prog), 'prog is not a shader program')