Added Multisample anti-aliasing (MSAA)
parent
02ffdcfe23
commit
f2318803e5
|
@ -90,4 +90,8 @@ void CDefaultFramebuffer::Unbind()
|
|||
{
|
||||
}
|
||||
|
||||
void CDefaultFramebuffer::CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight)
|
||||
{
|
||||
}
|
||||
|
||||
} // end of Gfx
|
||||
|
|
|
@ -112,6 +112,9 @@ public:
|
|||
|
||||
//! Unbinds this framebuffer from context
|
||||
virtual void Unbind() = 0;
|
||||
|
||||
//! Copies content of color buffer to screen
|
||||
virtual void CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -161,6 +164,9 @@ public:
|
|||
|
||||
//! Unbinds this framebuffer from context
|
||||
virtual void Unbind() OVERRIDE;
|
||||
|
||||
//! Copies content of color buffer to screen
|
||||
virtual void CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight) OVERRIDE;
|
||||
};
|
||||
|
||||
} // end of Gfx
|
||||
|
|
|
@ -121,6 +121,8 @@ CEngine::CEngine(CApplication *app)
|
|||
m_offscreenShadowRendering = false;
|
||||
m_qualityShadows = false;
|
||||
m_shadowRange = 0.0f;
|
||||
m_multisample = 1;
|
||||
|
||||
m_totoMode = true;
|
||||
m_lensMode = true;
|
||||
m_waterMode = true;
|
||||
|
@ -183,6 +185,12 @@ CEngine::CEngine(CApplication *app)
|
|||
m_qualityShadows = (value > 2);
|
||||
}
|
||||
|
||||
int samples;
|
||||
if (GetProfile().GetIntProperty("Setup", "MSAA", samples))
|
||||
{
|
||||
m_multisample = samples;
|
||||
}
|
||||
|
||||
m_shadowColor = 0.5f;
|
||||
|
||||
m_defaultTexParams.format = TEX_IMG_AUTO;
|
||||
|
@ -2718,6 +2726,16 @@ bool CEngine::GetShadowRange()
|
|||
return m_shadowRange;
|
||||
}
|
||||
|
||||
void CEngine::SetMultiSample(int value)
|
||||
{
|
||||
m_multisample = value;
|
||||
}
|
||||
|
||||
bool CEngine::GetMultiSample()
|
||||
{
|
||||
return m_multisample;
|
||||
}
|
||||
|
||||
void CEngine::SetDirty(bool mode)
|
||||
{
|
||||
m_dirty = mode;
|
||||
|
@ -3209,16 +3227,15 @@ void CEngine::Render()
|
|||
|
||||
m_device->SetClearColor(color);
|
||||
|
||||
// Render shadow map
|
||||
if (m_drawWorld && m_shadowMapping)
|
||||
RenderShadowMap();
|
||||
|
||||
// Begin the scene
|
||||
m_device->BeginScene();
|
||||
|
||||
if (m_drawWorld)
|
||||
{
|
||||
if (m_shadowMapping)
|
||||
RenderShadowMap();
|
||||
|
||||
Draw3DScene();
|
||||
}
|
||||
|
||||
m_app->StartPerformanceCounter(PCNT_RENDER_INTERFACE);
|
||||
DrawInterface();
|
||||
|
@ -3230,6 +3247,28 @@ 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();
|
||||
|
||||
|
@ -3492,6 +3531,19 @@ 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()
|
||||
|
|
|
@ -1155,6 +1155,12 @@ public:
|
|||
bool GetShadowRange();
|
||||
//@}
|
||||
|
||||
//@{
|
||||
//! Management of shadow range
|
||||
void SetMultiSample(int value);
|
||||
bool GetMultiSample();
|
||||
//@}
|
||||
|
||||
//@{
|
||||
//! Management mode of toto
|
||||
void SetTotoMode(bool present);
|
||||
|
@ -1483,6 +1489,8 @@ protected:
|
|||
float m_shadowColor;
|
||||
//! Shadow range
|
||||
float m_shadowRange;
|
||||
//! Number of samples for multisample rendering
|
||||
int m_multisample;
|
||||
|
||||
//! Map of loaded textures (by name)
|
||||
std::map<std::string, Texture> m_texNameMap;
|
||||
|
|
|
@ -246,6 +246,16 @@ void CGLFramebuffer::Unbind()
|
|||
m_currentFBO = 0;
|
||||
}
|
||||
|
||||
void CGLFramebuffer::CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight)
|
||||
{
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
|
||||
glBlitFramebuffer(fromX, fromY, fromX + fromWidth, fromY + fromHeight, toX, toY, toX + toWidth, toY + toHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_currentFBO);
|
||||
}
|
||||
|
||||
// CGLFramebufferEXT
|
||||
GLuint CGLFramebufferEXT::m_currentFBO = 0;
|
||||
|
||||
|
@ -468,4 +478,14 @@ void CGLFramebufferEXT::Unbind()
|
|||
m_currentFBO = 0;
|
||||
}
|
||||
|
||||
void CGLFramebufferEXT::CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight)
|
||||
{
|
||||
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_fbo);
|
||||
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
|
||||
|
||||
glBlitFramebufferEXT(fromX, fromY, fromX + fromWidth, fromY + fromHeight, toX, toY, toX + toWidth, toY + toHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_currentFBO);
|
||||
}
|
||||
|
||||
} // end of Gfx
|
||||
|
|
|
@ -70,6 +70,8 @@ public:
|
|||
virtual void Bind() OVERRIDE;
|
||||
|
||||
virtual void Unbind() OVERRIDE;
|
||||
|
||||
virtual void CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight) OVERRIDE;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -118,6 +120,8 @@ public:
|
|||
virtual void Bind() OVERRIDE;
|
||||
|
||||
virtual void Unbind() OVERRIDE;
|
||||
|
||||
virtual void CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight) OVERRIDE;
|
||||
};
|
||||
|
||||
} // end of Gfx
|
||||
|
|
Loading…
Reference in New Issue