|
@@ -1,9 +1,13 @@
|
|
|
from panda3d import core
|
|
from panda3d import core
|
|
|
|
|
+import os
|
|
|
import struct
|
|
import struct
|
|
|
import pytest
|
|
import pytest
|
|
|
from _pytest.outcomes import Failed
|
|
from _pytest.outcomes import Failed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+SHADERS_DIR = core.Filename.from_os_specific(os.path.dirname(__file__))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
# This is the template for the compute shader that is used by run_glsl_test.
|
|
# This is the template for the compute shader that is used by run_glsl_test.
|
|
|
# It defines an assert() macro that writes failures to a buffer, indexed by
|
|
# It defines an assert() macro that writes failures to a buffer, indexed by
|
|
|
# line number.
|
|
# line number.
|
|
@@ -102,6 +106,19 @@ def run_glsl_test(gsg, body, preamble="", inputs={}, version=150, exts=set()):
|
|
|
pytest.fail("{0} GLSL assertions triggered:\n{1}".format(count, formatted))
|
|
pytest.fail("{0} GLSL assertions triggered:\n{1}".format(count, formatted))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def run_glsl_compile_check(gsg, vert_path, frag_path, expect_fail=False):
|
|
|
|
|
+ """Compile supplied GLSL shader paths and check for errors"""
|
|
|
|
|
+ shader = core.Shader.load(core.Shader.SL_GLSL, vert_path, frag_path)
|
|
|
|
|
+ assert shader is not None
|
|
|
|
|
+
|
|
|
|
|
+ shader.prepare_now(gsg.prepared_objects, gsg)
|
|
|
|
|
+ assert shader.is_prepared(gsg.prepared_objects)
|
|
|
|
|
+ if expect_fail:
|
|
|
|
|
+ assert shader.get_error_flag()
|
|
|
|
|
+ else:
|
|
|
|
|
+ assert not shader.get_error_flag()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def test_glsl_test(gsg):
|
|
def test_glsl_test(gsg):
|
|
|
"Test to make sure that the GLSL tests work correctly."
|
|
"Test to make sure that the GLSL tests work correctly."
|
|
|
|
|
|
|
@@ -329,3 +346,24 @@ def test_glsl_write_extract_image_buffer(gsg):
|
|
|
|
|
|
|
|
assert struct.unpack('I', tex1.get_ram_image()) == (123,)
|
|
assert struct.unpack('I', tex1.get_ram_image()) == (123,)
|
|
|
assert struct.unpack('i', tex2.get_ram_image()) == (-456,)
|
|
assert struct.unpack('i', tex2.get_ram_image()) == (-456,)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def test_glsl_compile_error(gsg):
|
|
|
|
|
+ """Test getting compile errors from bad shaders"""
|
|
|
|
|
+ vert_path = core.Filename(SHADERS_DIR, 'glsl_bad.vert')
|
|
|
|
|
+ frag_path = core.Filename(SHADERS_DIR, 'glsl_simple.frag')
|
|
|
|
|
+ run_glsl_compile_check(gsg, vert_path, frag_path, expect_fail=True)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def test_glsl_from_file(gsg):
|
|
|
|
|
+ """Test compiling GLSL shaders from files"""
|
|
|
|
|
+ vert_path = core.Filename(SHADERS_DIR, 'glsl_simple.vert')
|
|
|
|
|
+ frag_path = core.Filename(SHADERS_DIR, 'glsl_simple.frag')
|
|
|
|
|
+ run_glsl_compile_check(gsg, vert_path, frag_path)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def test_glsl_includes(gsg):
|
|
|
|
|
+ """Test preprocessing includes in GLSL shaders"""
|
|
|
|
|
+ vert_path = core.Filename(SHADERS_DIR, 'glsl_include.vert')
|
|
|
|
|
+ frag_path = core.Filename(SHADERS_DIR, 'glsl_simple.frag')
|
|
|
|
|
+ run_glsl_compile_check(gsg, vert_path, frag_path)
|