First Triangle!
This commit is contained in:
parent
ca7a41740a
commit
f511f6d771
18 changed files with 156 additions and 18 deletions
8
Engine/res/pixel.ps
Normal file
8
Engine/res/pixel.ps
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
}
|
8
Engine/res/vertex.vs
Normal file
8
Engine/res/vertex.vs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 a_Position;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(a_Position, 0.0, 1.0);
|
||||||
|
}
|
|
@ -1,6 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef LOGGER_H
|
||||||
#include "Core/Logger.h"
|
#include "Core/Logger.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#if defined(LIGHT_PLATFORM_WINDOWS)
|
#if defined(LIGHT_PLATFORM_WINDOWS)
|
||||||
#define LT_BUILD_PLATFORM "Windows"
|
#define LT_BUILD_PLATFORM "Windows"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "Events/Event.h"
|
#include "Events/Event.h"
|
||||||
|
|
||||||
#include "Graphics/GraphicsContext.h"
|
#include "Graphics/GraphicsContext.h"
|
||||||
|
#include "Graphics/Renderer.h"
|
||||||
#include "Graphics/RenderCommand.h"
|
#include "Graphics/RenderCommand.h"
|
||||||
|
|
||||||
#include "UserInterface/UserInterface.h"
|
#include "UserInterface/UserInterface.h"
|
||||||
|
@ -34,6 +35,9 @@ namespace Light {
|
||||||
m_Window->PollEvents();
|
m_Window->PollEvents();
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
|
m_Window->GetGfxContext()->GetRenderer()->Draw();
|
||||||
|
|
||||||
|
// Buffer updates
|
||||||
m_Window->GetGfxContext()->GetRenderCommand()->SwapBuffers();
|
m_Window->GetGfxContext()->GetRenderCommand()->SwapBuffers();
|
||||||
m_Window->GetGfxContext()->GetRenderCommand()->ClearBackBuffer();
|
m_Window->GetGfxContext()->GetRenderCommand()->ClearBackBuffer();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.h"
|
||||||
#include "OpenGL/glGraphicsContext.h"
|
#include "OpenGL/glGraphicsContext.h"
|
||||||
|
|
||||||
|
#include "Buffers.h"
|
||||||
|
|
||||||
|
#include "Renderer.h"
|
||||||
#include "RenderCommand.h"
|
#include "RenderCommand.h"
|
||||||
#include "UserInterface/UserInterface.h"
|
#include "UserInterface/UserInterface.h"
|
||||||
|
|
||||||
|
@ -14,8 +17,11 @@ namespace Light {
|
||||||
// terminate gfx context dependent classes
|
// terminate gfx context dependent classes
|
||||||
if (s_Context)
|
if (s_Context)
|
||||||
{
|
{
|
||||||
|
s_Context->m_Renderer.reset();
|
||||||
s_Context->m_RenderCommand.reset();
|
s_Context->m_RenderCommand.reset();
|
||||||
s_Context->m_UserInterface.reset();
|
s_Context->m_UserInterface.reset();
|
||||||
|
|
||||||
|
delete s_Context;
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine the default api
|
// determine the default api
|
||||||
|
@ -41,8 +47,7 @@ namespace Light {
|
||||||
// create gfx context dependent classes
|
// create gfx context dependent classes
|
||||||
s_Context->m_RenderCommand = std::unique_ptr<RenderCommand>(RenderCommand::Create(windowHandle));
|
s_Context->m_RenderCommand = std::unique_ptr<RenderCommand>(RenderCommand::Create(windowHandle));
|
||||||
s_Context->m_UserInterface = std::unique_ptr<UserInterface>(UserInterface::Create(windowHandle));
|
s_Context->m_UserInterface = std::unique_ptr<UserInterface>(UserInterface::Create(windowHandle));
|
||||||
// ...Renderer
|
s_Context->m_Renderer = std::unique_ptr<Renderer>(Renderer::Create(s_Context->m_RenderCommand));
|
||||||
// ...UserInterface...
|
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
LT_ENGINE_ASSERT(s_Context->m_RenderCommand, "GraphicsContext::Create: RenderCommand creation failed");
|
LT_ENGINE_ASSERT(s_Context->m_RenderCommand, "GraphicsContext::Create: RenderCommand creation failed");
|
||||||
|
|
|
@ -6,6 +6,7 @@ struct GLFWwindow;
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
class Renderer;
|
||||||
class RenderCommand;
|
class RenderCommand;
|
||||||
class UserInterface;
|
class UserInterface;
|
||||||
|
|
||||||
|
@ -23,7 +24,8 @@ namespace Light {
|
||||||
private:
|
private:
|
||||||
static GraphicsContext* s_Context;
|
static GraphicsContext* s_Context;
|
||||||
|
|
||||||
std::unique_ptr<RenderCommand> m_RenderCommand;
|
std::unique_ptr<Renderer> m_Renderer;
|
||||||
|
std::shared_ptr<RenderCommand> m_RenderCommand;
|
||||||
std::unique_ptr<UserInterface> m_UserInterface;
|
std::unique_ptr<UserInterface> m_UserInterface;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -39,6 +41,7 @@ namespace Light {
|
||||||
|
|
||||||
static inline GraphicsAPI GetGraphicsAPI() { return s_Context->m_GraphicsAPI; }
|
static inline GraphicsAPI GetGraphicsAPI() { return s_Context->m_GraphicsAPI; }
|
||||||
|
|
||||||
|
inline Renderer* GetRenderer() { return m_Renderer.get(); }
|
||||||
inline RenderCommand* GetRenderCommand() { return m_RenderCommand.get(); }
|
inline RenderCommand* GetRenderCommand() { return m_RenderCommand.get(); }
|
||||||
inline UserInterface* GetUserInterface() { return m_UserInterface.get(); }
|
inline UserInterface* GetUserInterface() { return m_UserInterface.get(); }
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ namespace Light {
|
||||||
|
|
||||||
class RenderCommand
|
class RenderCommand
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
public:
|
public:
|
||||||
RenderCommand(const RenderCommand&) = delete;
|
RenderCommand(const RenderCommand&) = delete;
|
||||||
RenderCommand& operator=(const RenderCommand&) = delete;
|
RenderCommand& operator=(const RenderCommand&) = delete;
|
||||||
|
|
63
Engine/src/Engine/Graphics/Renderer.cpp
Normal file
63
Engine/src/Engine/Graphics/Renderer.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#include "ltpch.h"
|
||||||
|
#include "Renderer.h"
|
||||||
|
|
||||||
|
#include "GraphicsContext.h"
|
||||||
|
|
||||||
|
#include "RenderCommand.h"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
Renderer* Renderer::m_Context;
|
||||||
|
|
||||||
|
Renderer::Renderer(std::shared_ptr<RenderCommand> renderCommand)
|
||||||
|
: m_RenderCommand(renderCommand)
|
||||||
|
{
|
||||||
|
m_Context = this;
|
||||||
|
|
||||||
|
m_Shader = std::unique_ptr<Shader>(Shader::Create(
|
||||||
|
R"(
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 a_Position;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(a_Position, 0.0, 1.0);
|
||||||
|
})",
|
||||||
|
R"(
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
)"));
|
||||||
|
|
||||||
|
float vertices[] =
|
||||||
|
{
|
||||||
|
-0.5f, -0.5f,
|
||||||
|
0.5f, -0.5f,
|
||||||
|
0.0f, 0.5f,
|
||||||
|
};
|
||||||
|
|
||||||
|
m_VertexBuffer = std::unique_ptr<VertexBuffer>(VertexBuffer::Create(2 * 3, vertices));
|
||||||
|
m_VertexLayout = std::unique_ptr<VertexLayout>(VertexLayout::Create(m_VertexBuffer.get(), { VertexElementType::Float2 }));
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer* Renderer::Create(std::shared_ptr<RenderCommand> renderCommand)
|
||||||
|
{
|
||||||
|
return new Renderer(renderCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::Draw()
|
||||||
|
{
|
||||||
|
m_Shader->Bind();
|
||||||
|
m_VertexBuffer->Bind();
|
||||||
|
m_VertexLayout->Bind();
|
||||||
|
m_RenderCommand->Draw(3u);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
34
Engine/src/Engine/Graphics/Renderer.h
Normal file
34
Engine/src/Engine/Graphics/Renderer.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base.h"
|
||||||
|
|
||||||
|
#include "Shader.h"
|
||||||
|
#include "Buffers.h"
|
||||||
|
#include "VertexLayout.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class RenderCommand;
|
||||||
|
|
||||||
|
class Renderer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static Renderer* m_Context;
|
||||||
|
|
||||||
|
std::shared_ptr<RenderCommand> m_RenderCommand;
|
||||||
|
|
||||||
|
std::unique_ptr<Shader> m_Shader;
|
||||||
|
std::unique_ptr<VertexBuffer> m_VertexBuffer;
|
||||||
|
std::unique_ptr<VertexLayout> m_VertexLayout;
|
||||||
|
public:
|
||||||
|
static Renderer* Create(std::shared_ptr<RenderCommand> renderCommand);
|
||||||
|
|
||||||
|
void Draw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Renderer(std::shared_ptr<RenderCommand> renderCommand);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base.h"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
class Shader
|
class Shader
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
public:
|
public:
|
||||||
static Shader* Create(const std::string& vertexPath, const std::string& pixelPath);
|
static Shader* Create(const std::string& vertexPath, const std::string& pixelPath);
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,10 @@
|
||||||
#include "OpenGL/glVertexLayout.h"
|
#include "OpenGL/glVertexLayout.h"
|
||||||
|
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.h"
|
||||||
#include "Buffers.h"
|
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
VertexLayout* VertexLayout::Create(VertexBuffer* buffer, const std::vector<VertexElementType> elements)
|
VertexLayout* VertexLayout::Create(VertexBuffer* buffer, const std::vector<VertexElementType>& elements)
|
||||||
{
|
{
|
||||||
switch (GraphicsContext::GetGraphicsAPI())
|
switch (GraphicsContext::GetGraphicsAPI())
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,9 @@ namespace Light {
|
||||||
class VertexLayout
|
class VertexLayout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static VertexLayout* Create(VertexBuffer* buffer, const std::vector<VertexElementType> elements);
|
static VertexLayout* Create(VertexBuffer* buffer, const std::vector<VertexElementType>& elements);
|
||||||
|
|
||||||
|
virtual ~VertexLayout() = default;;
|
||||||
|
|
||||||
virtual void Bind() = 0;
|
virtual void Bind() = 0;
|
||||||
virtual void UnBind() = 0;
|
virtual void UnBind() = 0;
|
||||||
|
|
|
@ -7,10 +7,13 @@ namespace Light {
|
||||||
class Layer;
|
class Layer;
|
||||||
class Event;
|
class Event;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using Raw = T*;
|
||||||
|
|
||||||
class LayerStack
|
class LayerStack
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static LayerStack* s_Context;
|
static Raw<LayerStack> s_Context;
|
||||||
|
|
||||||
std::vector<Layer*> m_Layers;
|
std::vector<Layer*> m_Layers;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
// Graphics
|
// Graphics
|
||||||
#include "Graphics/GraphicsContext.h"
|
#include "Graphics/GraphicsContext.h"
|
||||||
#include "Graphics/RenderCommand.h"
|
#include "Graphics/RenderCommand.h"
|
||||||
|
#include "Graphics/Renderer.h"
|
||||||
|
|
||||||
// Layer
|
// Layer
|
||||||
#include "Layer/Layer.h"
|
#include "Layer/Layer.h"
|
||||||
|
|
|
@ -2,11 +2,15 @@
|
||||||
#include "glGraphicsContext.h"
|
#include "glGraphicsContext.h"
|
||||||
|
|
||||||
// Required for forward declaration
|
// Required for forward declaration
|
||||||
|
#include "Graphics/Renderer.h"
|
||||||
#include "Graphics/RenderCommand.h"
|
#include "Graphics/RenderCommand.h"
|
||||||
|
#include "Graphics/Shader.h"
|
||||||
|
#include "Graphics/Buffers.h"
|
||||||
|
#include "Graphics/VertexLayout.h"
|
||||||
#include "UserInterface/UserInterface.h"
|
#include "UserInterface/UserInterface.h"
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <glfw/glfw3.h>
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "ltpch.h"
|
#include "ltpch.h"
|
||||||
#include "glShader.h"
|
#include "glShader.h"
|
||||||
|
|
||||||
#include <GLAD/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Light {
|
||||||
LT_ENGINE_ASSERT(dynamic_cast<glVertexBuffer*>(buffer), "glVertexLayout::glVertexLayout: failed to cast VertexBuffer to glVertexBuffer");
|
LT_ENGINE_ASSERT(dynamic_cast<glVertexBuffer*>(buffer), "glVertexLayout::glVertexLayout: failed to cast VertexBuffer to glVertexBuffer");
|
||||||
|
|
||||||
// elements desc
|
// elements desc
|
||||||
std::vector<glVertexElementDesc> elementsDesc(elements.size());
|
std::vector<glVertexElementDesc> elementsDesc;
|
||||||
|
|
||||||
unsigned int stride = 0u;
|
unsigned int stride = 0u;
|
||||||
for(const auto& element : elements)
|
for(const auto& element : elements)
|
||||||
|
|
|
@ -4,13 +4,13 @@ Size=400,400
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Dear ImGui Demo]
|
[Window][Dear ImGui Demo]
|
||||||
Pos=276,-1
|
Pos=-3,0
|
||||||
Size=521,536
|
Size=524,134
|
||||||
Collapsed=0
|
Collapsed=1
|
||||||
|
|
||||||
[Window][Dear ImGui Metrics/Debugger]
|
[Window][Dear ImGui Metrics/Debugger]
|
||||||
Pos=263,318
|
Pos=-5,16
|
||||||
Size=346,290
|
Size=525,114
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Table][0xC9935533,3]
|
[Table][0xC9935533,3]
|
||||||
|
|
Loading…
Add table
Reference in a new issue