Skip to content
Permalink
Browse files

render: fixed regression in max polygon size check

added max size check to hardware renderer
  • Loading branch information
JaCzekanski committed Sep 1, 2019
1 parent a0505bc commit 0bc0c9f8b906dcbce09b7e4af824ba91eb711f91
@@ -22,7 +22,7 @@ void Render::drawLine(gpu::GPU* gpu, const primitive::Line& line) {

// TODO: Clip line in drawRectangle

// Skip rendering when distence between vertices is bigger than 1023x511
// Skip rendering when distance between vertices is bigger than 1023x511
if (abs(x0 - x1) >= 1024) return;
if (abs(y0 - y1) >= 512) return;

@@ -144,19 +144,28 @@ INLINE void triangle(GPU* gpu, const ivec2 pos[3], const ivec3 color[3], const i
const int area = orient2d(pos[0], pos[1], pos[2]);
if (area == 0) return;

const ivec2 min = ivec2( //
gpu->minDrawingX(std::min({pos[0].x, pos[1].x, pos[2].x})), //
gpu->minDrawingY(std::min({pos[0].y, pos[1].y, pos[2].y})) //
ivec2 min( //
std::min({pos[0].x, pos[1].x, pos[2].x}), //
std::min({pos[0].y, pos[1].y, pos[2].y}) //
);
const ivec2 max = ivec2( //
gpu->maxDrawingX(std::max({pos[0].x, pos[1].x, pos[2].x})), //
gpu->maxDrawingY(std::max({pos[0].y, pos[1].y, pos[2].y})) //
ivec2 max( //
std::max({pos[0].x, pos[1].x, pos[2].x}), //
std::max({pos[0].y, pos[1].y, pos[2].y}) //
);

// Skip rendering when distence between vertices is bigger than 1023x511
const ivec2 size = max - min;
if (size.x >= 1024 || size.y >= 512) return;

min = ivec2( //
gpu->minDrawingX(min.x), //
gpu->minDrawingY(min.y) //
);
max = ivec2( //
gpu->maxDrawingX(max.x), //
gpu->maxDrawingY(max.t) //
);

// https://fgiesen.wordpress.com/2013/02/10/optimizing-the-basic-rasterizer/

// Delta constants
@@ -36,6 +36,8 @@ INLINE void rectangle(GPU* gpu, const primitive::Rect& rect) {
const bool isBlended = !rect.isRawTexture;
constexpr bool isTextured = bits != ColorDepth::NONE;

if (rect.size.x >= 1024 || rect.size.y >= 512) return;

const ivec2 pos( //
rect.pos.x + gpu->drawingOffsetX, //
rect.pos.y + gpu->drawingOffsetY //
@@ -420,6 +420,24 @@ void OpenGL::renderVertices(gpu::GPU* gpu) {
auto type = mapType(buffer[i].type);
int count = type == GL_TRIANGLES ? 3 : 2;

// Skip rendering when distance between vertices is bigger than 1023x511
bool skipRender = false;
for (int j = 0; j < count; j++) {
auto& v0 = buffer[i + j];
auto& v1 = buffer[i + ((j + 1) % count)];
int x = abs(v0.position[0] - v1.position[0]);
int y = abs(v0.position[1] - v1.position[1]);
if (x >= 1024 || y >= 1024) {
skipRender = true;
break;
}
}

if (skipRender) {
i += count;
continue;
}

if (transparency && buffer[i].flags & gpu::Vertex::SemiTransparency) {
auto semi = static_cast<Transparency>((buffer[i].flags >> 5) & 3);
if (semi == Transparency::Bby2plusFby2) {

0 comments on commit 0bc0c9f

Please sign in to comment.
You can’t perform that action at this time.