Camera ClearColor
- Camera now has a clear color - The backbuffer is now cleared using the currently bound camera's clear color
This commit is contained in:
parent
0513ae009f
commit
4abde46290
9 changed files with 21 additions and 13 deletions
|
@ -6,8 +6,8 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Camera::Camera(const glm::vec2& position, float aspectRatio, float zoomLevel)
|
||||
: m_Up(0.0f, 1.0f, 0.0f), m_Position(position), m_AspectRatio(aspectRatio), m_ZoomLevel(zoomLevel)
|
||||
Camera::Camera(const glm::vec2& position, float aspectRatio, float zoomLevel, const glm::vec4& clearColor /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */)
|
||||
: m_Up(0.0f, 1.0f, 0.0f), m_Position(position), m_AspectRatio(aspectRatio), m_ZoomLevel(zoomLevel), m_ClearColor(clearColor)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,10 @@ namespace Light {
|
|||
glm::mat4 m_Projection;
|
||||
glm::mat4 m_View;
|
||||
|
||||
glm::vec4 m_ClearColor;
|
||||
|
||||
public:
|
||||
Camera(const glm::vec2& position, float aspectRatio, float zoomLevel);
|
||||
Camera(const glm::vec2& position, float aspectRatio, float zoomLevel, const glm::vec4& clearColor = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f));
|
||||
|
||||
// CAMERA //
|
||||
void CalculateView();
|
||||
|
@ -30,6 +32,8 @@ namespace Light {
|
|||
inline const glm::mat4& GetView() const { return m_View; }
|
||||
inline const glm::mat4& GetProjection() const { return m_Projection; }
|
||||
|
||||
inline const glm::vec4& GetClearColor() const { return m_ClearColor; }
|
||||
|
||||
// CAMERA_CONTROLLER //
|
||||
void Move(const glm::vec2& position);
|
||||
};
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "Base.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
struct GLFWwindow;
|
||||
|
||||
namespace Light {
|
||||
|
@ -19,7 +21,7 @@ namespace Light {
|
|||
virtual ~RenderCommand() = default;
|
||||
|
||||
virtual void SwapBuffers() = 0;
|
||||
virtual void ClearBackBuffer() = 0;
|
||||
virtual void ClearBackBuffer(const glm::vec4& clearColor) = 0;
|
||||
|
||||
virtual void Draw(unsigned int count) = 0;
|
||||
virtual void DrawIndexed(unsigned int count) = 0;
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace Light {
|
|||
void Renderer::EndFrame()
|
||||
{
|
||||
m_RenderCommand->SwapBuffers();
|
||||
m_RenderCommand->ClearBackBuffer();
|
||||
m_RenderCommand->ClearBackBuffer(m_Camera->GetClearColor());
|
||||
}
|
||||
|
||||
void Renderer::BeginSceneImpl(const std::shared_ptr<Camera>& camera, const std::shared_ptr<Framebuffer>& targetFrameBuffer /* = nullptr */)
|
||||
|
@ -135,8 +135,9 @@ namespace Light {
|
|||
m_RenderCommand->DefaultTargetFramebuffer();
|
||||
|
||||
|
||||
m_Camera = camera;
|
||||
glm::mat4* map = (glm::mat4*)m_ViewProjectionBuffer->Map();
|
||||
map[0] = camera->GetProjection() * camera->GetView();
|
||||
map[0] = m_Camera->GetProjection() * m_Camera->GetView();
|
||||
m_ViewProjectionBuffer->UnMap();
|
||||
|
||||
m_QuadRenderer.Map();
|
||||
|
|
|
@ -46,6 +46,8 @@ namespace Light {
|
|||
|
||||
std::shared_ptr<Framebuffer> m_TargetFramebuffer;
|
||||
|
||||
std::shared_ptr<Camera> m_Camera;
|
||||
|
||||
public:
|
||||
static Renderer* Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext);
|
||||
|
||||
|
|
|
@ -26,10 +26,9 @@ namespace Light {
|
|||
#endif
|
||||
}
|
||||
|
||||
void dxRenderCommand::ClearBackBuffer()
|
||||
void dxRenderCommand::ClearBackBuffer(const glm::vec4& clearColor)
|
||||
{
|
||||
float colors[] = { 0.1, 0.35f, 0.46f, 1.0f }; // #todo: use a local variable for this
|
||||
m_Context->GetDeviceContext()->ClearRenderTargetView(m_Context->GetRenderTargetView().Get(), colors);
|
||||
m_Context->GetDeviceContext()->ClearRenderTargetView(m_Context->GetRenderTargetView().Get(), &clearColor[0]);
|
||||
}
|
||||
|
||||
void dxRenderCommand::Draw(unsigned int count)
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Light {
|
|||
dxRenderCommand(std::shared_ptr<dxSharedContext> sharedContext);
|
||||
|
||||
virtual void SwapBuffers() override;
|
||||
virtual void ClearBackBuffer() override;
|
||||
virtual void ClearBackBuffer(const glm::vec4& clearColor) override;
|
||||
|
||||
virtual void Draw(unsigned int count) override;
|
||||
virtual void DrawIndexed(unsigned int count) override;
|
||||
|
|
|
@ -15,9 +15,9 @@ namespace Light {
|
|||
glfwSwapBuffers(m_WindowHandle);
|
||||
}
|
||||
|
||||
void glRenderCommand::ClearBackBuffer()
|
||||
void glRenderCommand::ClearBackBuffer(const glm::vec4& clearColor)
|
||||
{
|
||||
glClearColor(0.25f, 0.45f, 0.91f, 1.0f); // #todo: use a variable for this
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Light {
|
|||
glRenderCommand(GLFWwindow* windowHandle);
|
||||
|
||||
void SwapBuffers() override;
|
||||
void ClearBackBuffer() override;
|
||||
void ClearBackBuffer(const glm::vec4& clearColor) override;
|
||||
|
||||
void Draw(unsigned int count) override;
|
||||
void DrawIndexed(unsigned int count) override;
|
||||
|
|
Loading…
Add table
Reference in a new issue