mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
tests: add unit test for writing to and extracting buffer textures
This commit is contained in:
parent
00888518fe
commit
c5dd683366
@ -1,4 +1,5 @@
|
|||||||
from panda3d import core
|
from panda3d import core
|
||||||
|
import struct
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.outcomes import Failed
|
from _pytest.outcomes import Failed
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ layout(r8ui) uniform writeonly uimageBuffer _triggered;
|
|||||||
|
|
||||||
void _reset() {{
|
void _reset() {{
|
||||||
imageStore(_triggered, 0, uvec4(0, 0, 0, 0));
|
imageStore(_triggered, 0, uvec4(0, 0, 0, 0));
|
||||||
|
memoryBarrier();
|
||||||
}}
|
}}
|
||||||
|
|
||||||
void _assert(bool cond, int line) {{
|
void _assert(bool cond, int line) {{
|
||||||
@ -275,3 +277,40 @@ def test_glsl_pta_mat4(gsg):
|
|||||||
assert(pta[1][3] == vec4(28, 29, 30, 31));
|
assert(pta[1][3] == vec4(28, 29, 30, 31));
|
||||||
"""
|
"""
|
||||||
run_glsl_test(gsg, code, preamble, {'pta': pta}), code
|
run_glsl_test(gsg, code, preamble, {'pta': pta}), code
|
||||||
|
|
||||||
|
|
||||||
|
def test_glsl_write_extract_image_buffer(gsg):
|
||||||
|
# Tests that we can write to a buffer texture on the GPU, and then extract
|
||||||
|
# the data on the CPU. We test two textures since there was in the past a
|
||||||
|
# where it would only work correctly for one texture.
|
||||||
|
tex1 = core.Texture("tex1")
|
||||||
|
tex1.set_clear_color(0)
|
||||||
|
tex1.setup_buffer_texture(1, core.Texture.T_unsigned_int, core.Texture.F_r32i,
|
||||||
|
core.GeomEnums.UH_static)
|
||||||
|
tex2 = core.Texture("tex2")
|
||||||
|
tex2.set_clear_color(0)
|
||||||
|
tex2.setup_buffer_texture(1, core.Texture.T_int, core.Texture.F_r32i,
|
||||||
|
core.GeomEnums.UH_static)
|
||||||
|
|
||||||
|
preamble = """
|
||||||
|
layout(r32ui) uniform uimageBuffer tex1;
|
||||||
|
layout(r32i) uniform iimageBuffer tex2;
|
||||||
|
"""
|
||||||
|
code = """
|
||||||
|
assert(imageLoad(tex1, 0).r == 0);
|
||||||
|
assert(imageLoad(tex2, 0).r == 0);
|
||||||
|
imageStore(tex1, 0, uvec4(123));
|
||||||
|
imageStore(tex2, 0, ivec4(-456));
|
||||||
|
memoryBarrier();
|
||||||
|
assert(imageLoad(tex1, 0).r == 123);
|
||||||
|
assert(imageLoad(tex2, 0).r == -456);
|
||||||
|
"""
|
||||||
|
|
||||||
|
run_glsl_test(gsg, code, preamble, {'tex1': tex1, 'tex2': tex2})
|
||||||
|
|
||||||
|
engine = core.GraphicsEngine.get_global_ptr()
|
||||||
|
assert engine.extract_texture_data(tex1, gsg)
|
||||||
|
assert engine.extract_texture_data(tex2, gsg)
|
||||||
|
|
||||||
|
assert struct.unpack('I', tex1.get_ram_image()) == (123,)
|
||||||
|
assert struct.unpack('i', tex2.get_ram_image()) == (-456,)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user