diff --git a/sources/enduro2d/core/render_impl/render_opengl.cpp b/sources/enduro2d/core/render_impl/render_opengl.cpp index 0d8b8f50..a4004db7 100644 --- a/sources/enduro2d/core/render_impl/render_opengl.cpp +++ b/sources/enduro2d/core/render_impl/render_opengl.cpp @@ -980,6 +980,7 @@ namespace e2d { E2D_ASSERT(is_in_main_thread()); E2D_ASSERT(ibuffer); + E2D_ASSERT(!indices.empty()); const std::size_t buffer_offset = offset * ibuffer->state().decl().bytes_per_index(); E2D_ASSERT(indices.size() + buffer_offset <= ibuffer->state().size()); E2D_ASSERT(indices.size() % ibuffer->state().decl().bytes_per_index() == 0); @@ -1001,6 +1002,7 @@ namespace e2d { E2D_ASSERT(is_in_main_thread()); E2D_ASSERT(vbuffer); + E2D_ASSERT(!vertices.empty()); const std::size_t buffer_offset = offset * vbuffer->state().decl().bytes_per_vertex(); E2D_ASSERT(vertices.size() + buffer_offset <= vbuffer->state().size()); E2D_ASSERT(vertices.size() % vbuffer->state().decl().bytes_per_vertex() == 0); @@ -1026,6 +1028,7 @@ namespace e2d convert_image_data_format_to_pixel_declaration(img.format()); if ( tex->decl() != decl ) { state_->dbg().error("RENDER: Failed to update texture:\n" + "--> Incompatible pixel formats:\n" "--> Texture format: %0\n" "--> Image format: %1", pixel_declaration::pixel_type_to_cstr(tex->decl().type()), @@ -1042,6 +1045,8 @@ namespace e2d { E2D_ASSERT(is_in_main_thread()); E2D_ASSERT(tex); + E2D_ASSERT(!pixels.empty()); + E2D_ASSERT(region.size.x > 0 && region.size.y > 0); E2D_ASSERT(region.position.x < tex->size().x && region.position.y < tex->size().y); E2D_ASSERT(region.position.x + region.size.x <= tex->size().x); E2D_ASSERT(region.position.y + region.size.y <= tex->size().y); @@ -1137,6 +1142,7 @@ namespace e2d { E2D_ASSERT(tex); E2D_ASSERT(tex->decl().is_color() && !tex->decl().is_compressed()); + E2D_ASSERT(region.size.x > 0 && region.size.y > 0); E2D_ASSERT(region.position.x + region.size.x <= tex->size().x); E2D_ASSERT(region.position.y + region.size.y <= tex->size().y); @@ -1163,6 +1169,7 @@ namespace e2d image& result) { E2D_ASSERT(rt); + E2D_ASSERT(region.size.x > 0 && region.size.y > 0); E2D_ASSERT(region.position.x + region.size.x <= rt->size().x); E2D_ASSERT(region.position.y + region.size.y <= rt->size().y); grab_framebuffer_content( @@ -1177,6 +1184,7 @@ namespace e2d const b2u& region, image& result) { + E2D_ASSERT(region.size.x > 0 && region.size.y > 0); E2D_ASSERT(region.position.x + region.size.x <= state_->wnd().real_size().x); E2D_ASSERT(region.position.y + region.size.y <= state_->wnd().real_size().y); grab_framebuffer_content( diff --git a/untests/sources/untests_core/render.cpp b/untests/sources/untests_core/render.cpp index affaa51d..a7413e8d 100644 --- a/untests/sources/untests_core/render.cpp +++ b/untests/sources/untests_core/render.cpp @@ -195,7 +195,7 @@ TEST_CASE("render"){ buffer src; src.resize(((tex->size().x * tex->decl().bits_per_pixel()) / 8u) * tex->size().y); - for (auto& c : src) { + for ( auto& c : src ) { c = rand() % 255; } r.update_texture(tex, src, b2u(0, 0, 128, 128)); @@ -211,7 +211,7 @@ TEST_CASE("render"){ buffer src; src.resize(((tex->size().x * tex->decl().bits_per_pixel()) / 8u) * tex->size().y); - for (auto& c : src) { + for ( auto& c : src ) { c = rand() % 255; } r.update_texture(tex, src, b2u(0, 0, 128, 128)); @@ -225,7 +225,7 @@ TEST_CASE("render"){ REQUIRE(dst.format() == image_data_format::rgba8); REQUIRE(dst.data().size() == src.size()*4); bool equal = true; - for (size_t i = 0; i < src.size(); ++i) { + for ( size_t i = 0; i < src.size(); ++i ) { equal &= (src.data()[i] == dst.data().data()[i*4+3]); } REQUIRE(equal); @@ -237,7 +237,7 @@ TEST_CASE("render"){ buffer src; src.resize(((tex->size().x * tex->decl().bits_per_pixel()) / 8u) * tex->size().y); - for (auto& c : src) { + for ( auto& c : src ) { c = rand() % 255; } r.update_texture(tex, src, b2u(0, 0, 128, 128)); @@ -247,11 +247,11 @@ TEST_CASE("render"){ if ( dst.format() == image_data_format::rgb8 ) { REQUIRE(src == dst.data()); } else { - // OpenGL ES 2 may not support Alpha8 format + // OpenGL ES 2 may not support RGB8 format REQUIRE(dst.format() == image_data_format::rgba8); REQUIRE(dst.data().size() == src.size()*4/3); bool equal = true; - for (size_t i = 0, j = 0; i < src.size(); i += 3, j += 4) { + for ( size_t i = 0, j = 0; i < src.size(); i += 3, j += 4 ) { equal &= (src.data()[i+0] == dst.data().data()[j+0]); equal &= (src.data()[i+1] == dst.data().data()[j+1]); equal &= (src.data()[i+2] == dst.data().data()[j+2]); @@ -265,7 +265,7 @@ TEST_CASE("render"){ buffer src; src.resize(((tex->size().x * tex->decl().bits_per_pixel()) / 8u) * tex->size().y); - for (auto& c : src) { + for ( auto& c : src ) { c = rand() % 255; } r.update_texture(tex, src, b2u(0, 0, 57, 31)); @@ -281,7 +281,7 @@ TEST_CASE("render"){ buffer src; src.resize(((31 * tex->decl().bits_per_pixel()) / 8u) * 44); - for (auto& c : src) { + for ( auto& c : src ) { c = rand() % 255; } r.update_texture(tex, src, b2u(22, 17, 31, 44)); @@ -295,16 +295,29 @@ TEST_CASE("render"){ bool equal = true; const size_t bpp = tex->decl().bits_per_pixel() / 8; - for (u32 y = 0; y < 44; ++y) { + for ( u32 y = 0; y < 44; ++y ) { const u8* dst_row = dst.data().data() + ((y + 17) * 128 + 22) * bpp; const u8* src_row = src.data() + (y * 31 * bpp); - for (u32 x = 0; x < 31 * bpp; ++x) { - auto s = src_row[x]; - auto d = dst_row[x]; - equal &= (s == d); + for ( u32 x = 0; x < 31 * bpp; ++x ) { + equal &= (src_row[x] == dst_row[x]); } } REQUIRE(equal); } + { + texture_ptr tex = r.create_texture(v2u(128,128), pixel_declaration::pixel_type::rgba8); + REQUIRE(tex != nullptr); + + buffer src; + src.resize(((31 * tex->decl().bits_per_pixel()) / 8u) * 44); + for ( auto& c : src ) { + c = rand() % 255; + } + + image img(v2u(31, 44), image_data_format::ga8, src); + REQUIRE_THROWS_AS( + r.update_texture(tex, img, v2u(11,27)), + bad_render_operation); + } } }