Files
NazaraEngine/src/Nazara/Graphics/ColorBackground.cpp
Gawaboumga bbac0838dd Include-What-You-Use (#137)
* IWYU Core

* IWYU Noise

* IWYU Utility

* IWYU Audio

* IWYU Platform

* IWYU Lua

* IWYU Network

* IWYU Physics2D

* IWYU Physics3D

* IWYU Renderer

* IWYU Graphics

* IWYU NDKServer

* IWYU Fix

* Try to fix compilation

* Other fixes
2017-10-01 11:17:09 +02:00

114 lines
2.5 KiB
C++

// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/ColorBackground.hpp>
#include <Nazara/Core/ParameterList.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/UberShaderInstance.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
namespace
{
/*!
* \brief Defines render states
* \return RenderStates for the color background
*/
RenderStates BuildRenderStates()
{
RenderStates states;
states.cullingSide = FaceSide_Back;
states.depthFunc = RendererComparison_Equal;
states.depthBuffer = true;
states.depthWrite = false;
states.faceCulling = true;
return states;
}
}
/*!
* \ingroup graphics
* \class Nz::ColorBackground
* \brief Graphics class that represents a background with uniform color
*/
/*!
* \brief Constructs a ColorBackground object with a color
*
* \param color Uniform color (by default Black)
*/
ColorBackground::ColorBackground(const Color& color) :
m_color(color)
{
m_uberShader = UberShaderLibrary::Get("Basic");
ParameterList list;
list.SetParameter("UNIFORM_VERTEX_DEPTH", true);
m_uberShaderInstance = m_uberShader->Get(list);
const Shader* shader = m_uberShaderInstance->GetShader();
m_materialDiffuseUniform = shader->GetUniformLocation("MaterialDiffuse");
m_vertexDepthUniform = shader->GetUniformLocation("VertexDepth");
}
/*!
* \brief Draws this relatively to the viewer
*
* \param viewer Viewer for the background
*/
void ColorBackground::Draw(const AbstractViewer* viewer) const
{
NazaraUnused(viewer);
static RenderStates states(BuildRenderStates());
Renderer::SetRenderStates(states);
m_uberShaderInstance->Activate();
const Shader* shader = m_uberShaderInstance->GetShader();
shader->SendColor(m_materialDiffuseUniform, m_color);
shader->SendFloat(m_vertexDepthUniform, 1.f);
Renderer::DrawFullscreenQuad();
}
/*!
* \brief Gets the background type
* \return Type of background
*/
BackgroundType ColorBackground::GetBackgroundType() const
{
return BackgroundType_Color;
}
/*!
* \brief Gets the color of the background
* \return Background color
*/
Color ColorBackground::GetColor() const
{
return m_color;
}
/*!
* \brief Sets the color of the background
*
* \param color Background color
*/
void ColorBackground::SetColor(const Color& color)
{
m_color = color;
}
}