1
0
forked from 0ad/0ad

Adds view bounds test for an ortho camera and removes commented code after 44f8d2c6f5.

This was SVN commit r25441.
This commit is contained in:
Vladislav Belov 2021-05-15 13:47:48 +00:00
parent 44f8d2c6f5
commit 3ebff376cc
2 changed files with 69 additions and 5 deletions

View File

@ -421,4 +421,71 @@ public:
}
}
void test_viewport_bounds_ortho()
{
SViewPort viewPort;
viewPort.m_X = 0;
viewPort.m_Y = 0;
viewPort.m_Width = 512;
viewPort.m_Height = 512;
CCamera camera;
camera.SetViewPort(viewPort);
camera.LookAlong(
CVector3D(0.0f, 0.0f, 0.0f),
CVector3D(0.0f, 0.0f, 1.0f),
CVector3D(0.0f, 1.0f, 0.0f)
);
camera.SetOrthoProjection(1.0f, 101.0f, 2.0f);
camera.UpdateFrustum();
struct TestCase
{
CBoundingBoxAligned worldSpaceBoundingBox;
CBoundingBoxAligned expectedViewPortBoundingBox;
};
const TestCase testCases[] = {
// A box is in front of the camera.
{
{{-1.0f, 0.0f, 5.0f}, {1.0f, 0.0f, 7.0f}},
{{-1.0f, 0.0f, -1.1599f}, {1.0f, 0.0f,-1.1200f}}
},
// A box is out of the camera view.
{
{{-10.0f, -1.0f, 5.0f}, {-8.0f, 1.0f, 7.0f}},
{}
},
{
{{-1.0f, -10.0f, 5.0f}, {1.0f, -8.0f, 7.0f}},
{}
},
// The camera is inside a box.
{
{{-1.0f, 0.0f, -7.0f}, {1.0f, 0.0f, 7.0f}},
{{-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}}
},
// A box intersects with the near plane.
{
{{-1.0f, 0.0f, 0.5f}, {1.0f, 0.0f, 7.0f}},
{{-1.0f, 0.0f, -1.1599f}, {1.0f, 0.0f, -1.1599f}}
},
};
for (const TestCase& testCase : testCases)
{
TS_ASSERT(testCase.worldSpaceBoundingBox[0].X <= testCase.worldSpaceBoundingBox[1].X);
TS_ASSERT(testCase.worldSpaceBoundingBox[0].Y <= testCase.worldSpaceBoundingBox[1].Y);
TS_ASSERT(testCase.worldSpaceBoundingBox[0].Z <= testCase.worldSpaceBoundingBox[1].Z);
const CBoundingBoxAligned result =
camera.GetBoundsInViewPort(testCase.worldSpaceBoundingBox);
if (testCase.expectedViewPortBoundingBox.IsEmpty())
{
TS_ASSERT(result.IsEmpty());
}
else
CompareBoundingBoxes(result, testCase.expectedViewPortBoundingBox);
}
}
};

View File

@ -1086,8 +1086,8 @@ void CRenderer::RenderRefractions(const CShaderDefines& context, const CBounding
screenScissor.x2 = (GLint)ceil((refractionScissor[1].X*0.5f+0.5f)*vpWidth);
screenScissor.y2 = (GLint)ceil((refractionScissor[1].Y*0.5f+0.5f)*vpHeight);
//glEnable(GL_SCISSOR_TEST);
//glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1);
glEnable(GL_SCISSOR_TEST);
glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1);
// try binding the framebuffer
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, wm.m_RefractionFbo);
@ -1095,9 +1095,6 @@ void CRenderer::RenderRefractions(const CShaderDefines& context, const CBounding
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1);
// Render terrain and models
RenderPatches(context, CULL_REFRACTIONS);
ogl_WarnIfError();