added more asserts, fixed code style

This commit is contained in:
andrey.zhirnov
2019-07-22 18:42:38 +03:00
parent 72da243995
commit a689e42441
2 changed files with 34 additions and 13 deletions

View File

@@ -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(

View File

@@ -247,7 +247,7 @@ 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;
@@ -299,12 +299,25 @@ TEST_CASE("render"){
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);
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);
}
}
}