Small corrections in MSAA implementation

master
Tomasz Kapuściński 2015-06-22 23:42:01 +02:00
parent 90bf51ba54
commit 3cc2857372
2 changed files with 54 additions and 35 deletions

View File

@ -3240,9 +3240,13 @@ void CEngine::Render()
// Begin the scene
m_device->BeginScene();
UseMSAA(true);
if (m_drawWorld)
Draw3DScene();
UseMSAA(false);
m_app->StartPerformanceCounter(PCNT_RENDER_INTERFACE);
DrawInterface();
m_app->StopPerformanceCounter(PCNT_RENDER_INTERFACE);
@ -3253,28 +3257,6 @@ void CEngine::Render()
void CEngine::Draw3DScene()
{
if (m_multisample > 1)
{
CFramebuffer* framebuffer = m_device->GetFramebuffer("multisample");
if (framebuffer == nullptr)
{
CFramebuffer* screen = m_device->GetFramebuffer("default");
FramebufferParams params;
params.width = screen->GetWidth();
params.height = screen->GetHeight();
params.depth = 24;
params.samples = m_multisample;
framebuffer = m_device->CreateFramebuffer("multisample", params);
}
framebuffer->Bind();
m_device->Clear();
}
if (m_groundSpotVisible)
UpdateGroundSpotTextures();
@ -3537,19 +3519,6 @@ void CEngine::Draw3DScene()
if (m_lensMode) DrawForegroundImage(); // draws the foreground
if (! m_overFront) DrawOverColor(); // draws the foreground color
if (m_multisample > 1)
{
CFramebuffer* framebuffer = m_device->GetFramebuffer("multisample");
framebuffer->Unbind();
CFramebuffer* screen = m_device->GetFramebuffer("default");
int width = screen->GetWidth();
int height = screen->GetHeight();
framebuffer->CopyToScreen(0, 0, width, height, 0, 0, width, height);
}
}
void CEngine::RenderShadowMap()
@ -3915,6 +3884,54 @@ void CEngine::UseShadowMapping(bool enable)
}
}
void CEngine::UseMSAA(bool enable)
{
if (m_multisample < 2) return;
if (enable)
{
if (m_multisample > 1)
{
CFramebuffer* framebuffer = m_device->GetFramebuffer("multisample");
if (framebuffer == nullptr)
{
CFramebuffer* screen = m_device->GetFramebuffer("default");
FramebufferParams params;
params.width = screen->GetWidth();
params.height = screen->GetHeight();
params.depth = 24;
params.samples = m_multisample;
framebuffer = m_device->CreateFramebuffer("multisample", params);
}
framebuffer->Bind();
m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, true);
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, true);
m_device->Clear();
}
}
else
{
if (m_multisample > 1)
{
CFramebuffer* framebuffer = m_device->GetFramebuffer("multisample");
framebuffer->Unbind();
CFramebuffer* screen = m_device->GetFramebuffer("default");
int width = screen->GetWidth();
int height = screen->GetHeight();
framebuffer->CopyToScreen(0, 0, width, height, 0, 0, width, height);
}
}
}
void CEngine::DrawObject(const EngineBaseObjDataTier& p4)
{
if (p4.staticBufferId != 0)

View File

@ -1260,6 +1260,8 @@ protected:
void RenderShadowMap();
//! Enables or disables shadow mapping
void UseShadowMapping(bool enable);
//! Enables or disables MSAA
void UseMSAA(bool enable);
//! Draw 3D object
void DrawObject(const EngineBaseObjDataTier& p4);
//! Draws the user interface over the scene