Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shader uniform tests not passing + add sprite test suite #190

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added projects/xUnit/datafiles/spriteAdd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions projects/xUnit/objects/objRunner/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ testFramework.addSuite(ResourceCameraTestSuite);
testFramework.addSuite(ResourceEventsTestSuite);
testFramework.addSuite(ResourceLayersTestSuite);
testFramework.addSuite(ResourceSequenceTestSuite);
testFramework.addSuite(ResourceSpriteTestSuite);
testFramework.addSuite(ResourceTimeSourceTestSuite);

socket = undefined;
Expand Down
6 changes: 3 additions & 3 deletions projects/xUnit/options/html5/options_html5.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/xUnit/options/mac/options_mac.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ function BasicShaderTestSuite() : TestSuite() constructor {

// Clear surface
draw_clear(c_black);
gpu_push_state();
gpu_set_blendenable(false);
// Start using shader
shader_set(test_shader);
Expand All @@ -303,7 +304,7 @@ function BasicShaderTestSuite() : TestSuite() constructor {
// Draw rectangle
draw_rect(rect);
// Stop using shader
gpu_set_blendenable(true);
gpu_pop_state();
shader_reset();

// End draw buffer comparison
Expand Down Expand Up @@ -369,10 +370,15 @@ function BasicShaderTestSuite() : TestSuite() constructor {

// Start using shader
shader_set(test_shader);
// Disable alpha blending
gpu_push_state();
gpu_set_blendenable(false);
// Set the color uniform
shader_set_uniform_f_array(uni_color, _color);
// Draw rectangle
draw_rect(rect);
// Restore alpha blending settings
gpu_pop_state();
// Stop using shader
shader_reset();

Expand Down Expand Up @@ -452,10 +458,15 @@ function BasicShaderTestSuite() : TestSuite() constructor {

// Start using shader
shader_set(test_shader);
// Disable alpha blending
gpu_push_state();
gpu_set_blendenable(false);
// Set the color uniform
shader_set_uniform_f_buffer(uni_color, color_buffer, 0, 4);
// Draw rectangle
draw_rect(rect);
// Restore alpha blending settings
gpu_pop_state();
// Stop using shader
shader_reset();

Expand Down Expand Up @@ -527,10 +538,15 @@ function BasicShaderTestSuite() : TestSuite() constructor {

// Start using shader
shader_set(test_shader);
// Disable alpha blending
gpu_push_state();
gpu_set_blendenable(false);
// Set the color uniform
shader_set_uniform_i(uni_color, _red, _green, _blue, _alpha);
// Draw rectangle
draw_rect(rect);
// Restore alpha blending settings
gpu_pop_state();
// Stop using shader
shader_reset();

Expand Down Expand Up @@ -596,10 +612,15 @@ function BasicShaderTestSuite() : TestSuite() constructor {

// Start using shader
shader_set(test_shader);
// Disable alpha blending
gpu_push_state();
gpu_set_blendenable(false);
// Set the color uniform
shader_set_uniform_i_array(uni_color, _color);
// Draw rectangle
draw_rect(rect);
// Restore alpha blending settings
gpu_pop_state();
// Stop using shader
shader_reset();

Expand Down Expand Up @@ -661,12 +682,13 @@ function BasicShaderTestSuite() : TestSuite() constructor {

// Start using shader
shader_set(test_shader);
gpu_push_state();
gpu_set_blendenable(false);
// Set the sampler texture
texture_set_stage(sampler, _texture);
// Draw rectangle with correct uvs for the sample texture
draw_texture_rect(rect, _uvs);
gpu_set_blendenable(true);
gpu_pop_state();
// Stop using shader
shader_reset();

Expand Down Expand Up @@ -983,6 +1005,7 @@ function BasicShaderTestSuite() : TestSuite() constructor {
shader_set(test_shader);

// Enable Z writing and testing for 3D rendering
gpu_push_state();
gpu_set_zwriteenable(true);
gpu_set_ztestenable(true);

Expand All @@ -993,9 +1016,8 @@ function BasicShaderTestSuite() : TestSuite() constructor {
// Draw cube
vertex_submit(cube_mesh, pr_trianglelist, -1);

// Disable Z writing and testing
gpu_set_zwriteenable(false);
gpu_set_ztestenable(false);
// Restore Z writing and testing
gpu_pop_state();

// Stop using shader
shader_reset();
Expand Down Expand Up @@ -1059,6 +1081,7 @@ function BasicShaderTestSuite() : TestSuite() constructor {
shader_set(test_shader);

// Enable Z writing and testing for 3D rendering
gpu_push_state();
gpu_set_zwriteenable(true);
gpu_set_ztestenable(true);

Expand All @@ -1069,9 +1092,8 @@ function BasicShaderTestSuite() : TestSuite() constructor {
// Draw cube
vertex_submit(cube_mesh, pr_trianglelist, -1);

// Disable Z writing and testing
gpu_set_zwriteenable(false);
gpu_set_ztestenable(false);
// Restore Z writing and testing
gpu_pop_state();

// Stop using shader
shader_reset();
Expand Down Expand Up @@ -1135,6 +1157,7 @@ function BasicShaderTestSuite() : TestSuite() constructor {
shader_set(test_shader);

// Enable Z writing and testing for 3D rendering
gpu_push_state();
gpu_set_zwriteenable(true);
gpu_set_ztestenable(true);

Expand All @@ -1145,9 +1168,8 @@ function BasicShaderTestSuite() : TestSuite() constructor {
// Draw cube
vertex_submit(plane_mesh, pr_trianglelist, -1);

// Disable Z writing and testing
gpu_set_zwriteenable(false);
gpu_set_ztestenable(false);
// Restore Z writing and testing
gpu_pop_state();

// Stop using shader
shader_reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function BasicShaderUniformsTestSuite() : TestSuite() constructor {
draw_frame = 0;
},
ev_draw: function() {
gpu_push_state();

// Initialise test name and fail message to use in buffer comparison
var _test_path = "ShaderUniformTests/AlphaTest/Off";
var _test_fail_message = test_current().name +", failed draw buffer comparison with alpha testing off";
Expand Down Expand Up @@ -49,13 +51,12 @@ function BasicShaderUniformsTestSuite() : TestSuite() constructor {
// Stop using shader
shader_reset();

// Restore alpha testing and reference value
gpu_pop_state();

// End draw buffer comparison
end_draw_comparison(_test_surface, _test_path, _test_fail_message);

// Disable alpha testing and set reference value back to 0
gpu_set_alphatestenable(false);
gpu_set_alphatestref(0);

// Increment frame counter
draw_frame++;
}
Expand Down Expand Up @@ -412,7 +413,7 @@ function BasicShaderUniformsTestSuite() : TestSuite() constructor {
verify_shader_compiled(test_shader);

// Generate a grid of rects to display matrix data
rects = generate_rect_grid(SHADER_TEST_DEFAULT_SIZE, SHADER_TEST_DEFAULT_SIZE, 4, 4);
rects = generate_rect_grid(0.5, 0.5, 4, 4, -1, -1);

// Get uniform handles for the expected matrix value and initial world view projection matrix value
u_expected_matrix = shader_get_uniform(test_shader, "u_expected_matrix");
Expand Down Expand Up @@ -444,30 +445,53 @@ function BasicShaderUniformsTestSuite() : TestSuite() constructor {
return;
}

// Start draw buffer comparison
// Start draw buffer comparison (this sets some initial view and proj. matrices)
var _test_surface = start_draw_comparison(SHADER_TEST_DEFAULT_SIZE * 4, SHADER_TEST_DEFAULT_SIZE * 4);

// Start using shader
shader_set(test_shader);

// Set uniform for initial world view projection matrix
var _world_view_projection = matrix_multiply(matrix_multiply(matrix_get(matrix_world), matrix_get(matrix_view)), matrix_get(matrix_projection));
shader_set_uniform_matrix_array(u_initial_matrix_world_view_projection, _world_view_projection);
// Note: On OpenGL platforms the projection matrix is flipped on Y axis internally, so
// we need to remove the flip, otherwise we won't get the correct result!
var _platforms_opengl = [os_macosx, os_linux]; // TODO: More here?
var _is_opengl = array_contains(_platforms_opengl, os_type);

// This we will use to draw a rectangle for each entry of a matrix
var _matrix_wvp = matrix_build_identity();
if (!_is_opengl)
{
_matrix_wvp[5] = -1;
}
shader_set_uniform_matrix_array(u_initial_matrix_world_view_projection, _matrix_wvp);

// Set uniform for expected matrix
var _expected_matrix = matrix_multiply(matrix_multiply(matrix_get(matrix_world), matrix_get(matrix_view)), matrix_get(matrix_projection));
if (_set_value)
if (!_set_value)
{
// If it should be set this frame, build a new matrix to set it as
_expected_matrix = [ 1, 0, 1, 0,
0, 0, 0, 1,
0, 0, 0, 1,
1, 0, 1, 0 ]
matrix_set(matrix_world, _expected_matrix);
matrix_set(matrix_view, _expected_matrix);
matrix_set(matrix_projection, _expected_matrix);
_expected_matrix = matrix_multiply(matrix_multiply(matrix_get(matrix_world), matrix_get(matrix_view)), matrix_get(matrix_projection));
// Unset - expected matrix is WxVxP
if (_is_opengl)
{
matrix_set(matrix_projection, matrix_multiply(matrix_get(matrix_projection), [
1, 0, 0, 0,
0, -1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
]));
}
}
else
{
// Set - provide our own matrices
var _matrix = [
1, 0, 1, 0,
0, 0, 0, 1,
0, 0, 0, 1,
1, 0, 1, 0
];
matrix_set(matrix_world, _matrix);
matrix_set(matrix_view, _matrix);
matrix_set(matrix_projection, _matrix);
}

var _expected_matrix = matrix_multiply(matrix_multiply(matrix_get(matrix_world), matrix_get(matrix_view)), matrix_get(matrix_projection));
shader_set_uniform_matrix_array(u_expected_matrix, _expected_matrix);

// Draw grid of rectangles
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function ResourceSpriteTestSuite() : TestSuite() constructor {

addFact("sprite_add", function() {

var _sprite = sprite_add("spriteAdd.png", 1, false, false, 0, 0);
assert_true(sprite_exists(_sprite), test_current().name + ", didn't return a valid sprite");
assert_true(sprite_get_number(_sprite) == 1, test_current().name + ", added sprite doesnt' have the correct number of subimages");

var _sprite_width = 64;
var _sprite_height = 64;
assert_true(sprite_get_width(_sprite) == _sprite_width, test_current().name + ", added sprite doesn't have the correct width");
assert_true(sprite_get_height(_sprite) == _sprite_height, test_current().name + ", added sprite doesn't have the correct height");

var _surface = surface_create(_sprite_width, _sprite_height);
surface_set_target(_surface);
gpu_push_state();
gpu_set_blendenable(false);
draw_sprite(_sprite, 0, 0, 0);
gpu_pop_state();
surface_reset_target();

var _buffer = buffer_create(buffer_sizeof(buffer_u32) * _sprite_width * _sprite_height, buffer_fixed, 1);
buffer_get_surface(_buffer, _surface, 0);

var _color = buffer_peek(_buffer, 0, buffer_u32);
assert_equals(_color, 0x00_3F_7F_FF, test_current().name + ", added sprite doesn't preserve color when alpha is 0");

sprite_delete(_sprite);
assert_false(sprite_exists(_sprite), test_current().name + ", failed to delete added sprite");

surface_free(_surface);
buffer_delete(_buffer);
});

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading