- ConstantBuffers
- Added ConstantBuffers - Updated GLAD to have GL_ARB_shading_language_420pack extensions
This commit is contained in:
parent
b8ca0099cb
commit
91a0c92fe7
21 changed files with 211 additions and 26 deletions
12
Dependencies/GLAD/include/glad/glad.h
vendored
12
Dependencies/GLAD/include/glad/glad.h
vendored
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
|
||||
OpenGL loader generated by glad 0.1.34 on Tue May 25 14:15:38 2021.
|
||||
OpenGL loader generated by glad 0.1.34 on Sun Jul 4 22:51:05 2021.
|
||||
|
||||
Language/Generator: C/C++
|
||||
Specification: gl
|
||||
APIs: gl=4.6
|
||||
Profile: core
|
||||
Extensions:
|
||||
|
||||
GL_ARB_shading_language_420pack
|
||||
Loader: True
|
||||
Local files: False
|
||||
Omit khrplatform: False
|
||||
Reproducible: False
|
||||
|
||||
Commandline:
|
||||
--profile="core" --api="gl=4.6" --generator="c" --spec="gl" --extensions=""
|
||||
--profile="core" --api="gl=4.6" --generator="c" --spec="gl" --extensions="GL_ARB_shading_language_420pack"
|
||||
Online:
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.6
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.6&extensions=GL_ARB_shading_language_420pack
|
||||
*/
|
||||
|
||||
|
||||
|
@ -3686,6 +3686,10 @@ typedef void (APIENTRYP PFNGLPOLYGONOFFSETCLAMPPROC)(GLfloat factor, GLfloat uni
|
|||
GLAPI PFNGLPOLYGONOFFSETCLAMPPROC glad_glPolygonOffsetClamp;
|
||||
#define glPolygonOffsetClamp glad_glPolygonOffsetClamp
|
||||
#endif
|
||||
#ifndef GL_ARB_shading_language_420pack
|
||||
#define GL_ARB_shading_language_420pack 1
|
||||
GLAPI int GLAD_GL_ARB_shading_language_420pack;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
11
Dependencies/GLAD/src/glad.c
vendored
11
Dependencies/GLAD/src/glad.c
vendored
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
|
||||
OpenGL loader generated by glad 0.1.34 on Tue May 25 14:15:38 2021.
|
||||
OpenGL loader generated by glad 0.1.34 on Sun Jul 4 22:51:05 2021.
|
||||
|
||||
Language/Generator: C/C++
|
||||
Specification: gl
|
||||
APIs: gl=4.6
|
||||
Profile: core
|
||||
Extensions:
|
||||
|
||||
GL_ARB_shading_language_420pack
|
||||
Loader: True
|
||||
Local files: False
|
||||
Omit khrplatform: False
|
||||
Reproducible: False
|
||||
|
||||
Commandline:
|
||||
--profile="core" --api="gl=4.6" --generator="c" --spec="gl" --extensions=""
|
||||
--profile="core" --api="gl=4.6" --generator="c" --spec="gl" --extensions="GL_ARB_shading_language_420pack"
|
||||
Online:
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.6
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.6&extensions=GL_ARB_shading_language_420pack
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -973,6 +973,7 @@ PFNGLVIEWPORTARRAYVPROC glad_glViewportArrayv = NULL;
|
|||
PFNGLVIEWPORTINDEXEDFPROC glad_glViewportIndexedf = NULL;
|
||||
PFNGLVIEWPORTINDEXEDFVPROC glad_glViewportIndexedfv = NULL;
|
||||
PFNGLWAITSYNCPROC glad_glWaitSync = NULL;
|
||||
int GLAD_GL_ARB_shading_language_420pack = 0;
|
||||
static void load_GL_VERSION_1_0(GLADloadproc load) {
|
||||
if(!GLAD_GL_VERSION_1_0) return;
|
||||
glad_glCullFace = (PFNGLCULLFACEPROC)load("glCullFace");
|
||||
|
@ -1735,7 +1736,7 @@ static void load_GL_VERSION_4_6(GLADloadproc load) {
|
|||
}
|
||||
static int find_extensionsGL(void) {
|
||||
if (!get_exts()) return 0;
|
||||
(void)&has_ext;
|
||||
GLAD_GL_ARB_shading_language_420pack = has_ext("GL_ARB_shading_language_420pack");
|
||||
free_exts();
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -6,13 +6,16 @@ R"(
|
|||
layout(location = 0) in vec3 a_Position;
|
||||
layout(location = 1) in vec4 a_Color;
|
||||
|
||||
uniform mat4 u_ViewProjection;
|
||||
layout(std140, binding = 0) uniform ub_ViewProjection
|
||||
{
|
||||
mat4 viewProjection;
|
||||
};
|
||||
|
||||
out vec4 vso_FragmentColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
|
||||
gl_Position = viewProjection * vec4(a_Position, 1.0);
|
||||
vso_FragmentColor = a_Color;
|
||||
}
|
||||
-GLSL
|
||||
|
|
|
@ -6,7 +6,10 @@ R"(
|
|||
layout(location = 0) in vec3 a_Position;
|
||||
layout(location = 1) in vec2 a_TexCoord;
|
||||
|
||||
uniform mat4 u_ViewProjection;
|
||||
layout(std140, binding = 0) uniform ub_ViewProjection
|
||||
{
|
||||
mat4 u_ViewProjection;
|
||||
};
|
||||
|
||||
out vec2 vso_TexCoord;
|
||||
|
||||
|
@ -25,10 +28,16 @@ struct VertexOut
|
|||
float4 Position : SV_Position;
|
||||
};
|
||||
|
||||
VertexOut main(float3 InPosition : POSITION, float2 InTexChoord : TEXCHOORD)
|
||||
cbuffer cb_ViewProjection : register(b0)
|
||||
{
|
||||
row_major matrix viewProjection;
|
||||
}
|
||||
|
||||
|
||||
VertexOut main(float3 InPosition : POSITION, float2 InTexChoord : TEXCOORD)
|
||||
{
|
||||
VertexOut vso;
|
||||
vso.Position = float4(InPosition, 1.0);
|
||||
vso.Position = mul(float4(InPosition, 1.0), viewProjection);
|
||||
vso.TexChoord = InTexChoord;
|
||||
|
||||
return vso;
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Light {
|
|||
|
||||
void Camera::CalculateView()
|
||||
{
|
||||
m_View = glm::lookAt(glm::vec3(m_Position, -100.0f), glm::vec3(m_Position, 0.0f), m_Up);
|
||||
m_View = glm::lookAt(glm::vec3(m_Position, 100.0f), glm::vec3(m_Position, 0.0f), m_Up);
|
||||
}
|
||||
|
||||
void Camera::CalculateProjection()
|
||||
|
|
|
@ -13,6 +13,23 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
//* CONSTANT_BUFFER *//
|
||||
ConstantBuffer* ConstantBuffer::Create(ConstantBufferIndex index, unsigned int size, std::shared_ptr<SharedContext> sharedContext)
|
||||
{
|
||||
switch (GraphicsContext::GetGraphicsAPI())
|
||||
{
|
||||
case GraphicsAPI::OpenGL:
|
||||
return new glConstantBuffer(index, size);
|
||||
|
||||
case GraphicsAPI::DirectX: LT_WIN(
|
||||
return new dxConstantBuffer(index, size, std::static_pointer_cast<dxSharedContext>(sharedContext));)
|
||||
|
||||
default:
|
||||
LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//* VERTEX_BUFFER *//
|
||||
VertexBuffer* VertexBuffer::Create(float* vertices, unsigned int stride, unsigned int count, std::shared_ptr<SharedContext> sharedContext)
|
||||
{
|
||||
|
|
|
@ -6,12 +6,31 @@ namespace Light {
|
|||
|
||||
class SharedContext;
|
||||
|
||||
enum ConstantBufferIndex
|
||||
{
|
||||
ViewProjection = 0u
|
||||
};
|
||||
|
||||
//* CONSTANT_BUFFER *//
|
||||
class ConstantBuffer
|
||||
{
|
||||
public:
|
||||
static ConstantBuffer* Create(ConstantBufferIndex index, unsigned int size, std::shared_ptr<SharedContext> sharedContext);
|
||||
|
||||
virtual void Bind() = 0;
|
||||
|
||||
virtual void* Map() = 0;
|
||||
virtual void UnMap() = 0;
|
||||
};
|
||||
|
||||
//* VERTEX_BUFFER *//
|
||||
class VertexBuffer
|
||||
{
|
||||
public:
|
||||
static VertexBuffer* Create(float* vertices, unsigned int stride, unsigned int count, std::shared_ptr<SharedContext> sharedContext);
|
||||
|
||||
virtual ~VertexBuffer() = default;
|
||||
|
||||
virtual void* Map() = 0;
|
||||
virtual void UnMap() = 0;
|
||||
|
||||
|
@ -28,6 +47,8 @@ namespace Light {
|
|||
public:
|
||||
static IndexBuffer* Create(unsigned int* indices, unsigned int count, std::shared_ptr<SharedContext> sharedContext);
|
||||
|
||||
virtual ~IndexBuffer() = default;
|
||||
|
||||
virtual void Bind() = 0;
|
||||
virtual void UnBind() = 0;
|
||||
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
|
||||
#include "RenderCommand.h"
|
||||
#include "Texture.h"
|
||||
#include "Buffers.h"
|
||||
|
||||
#include "Camera/Camera.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace Light {
|
||||
|
||||
|
@ -16,6 +23,8 @@ namespace Light {
|
|||
s_Context = this;
|
||||
|
||||
m_RenderCommand = std::unique_ptr<RenderCommand>(RenderCommand::Create(windowHandle, sharedContext));
|
||||
|
||||
m_ViewProjectionBuffer = std::unique_ptr<ConstantBuffer>(ConstantBuffer::Create(ConstantBufferIndex::ViewProjection, sizeof(glm::mat4), sharedContext));
|
||||
}
|
||||
|
||||
Renderer* Renderer::Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext)
|
||||
|
@ -106,15 +115,19 @@ namespace Light {
|
|||
|
||||
void Renderer::BeginSceneImpl(const Camera& camera)
|
||||
{
|
||||
glm::mat4* map = (glm::mat4*)m_ViewProjectionBuffer->Map();
|
||||
map[0] = camera.GetProjection() * camera.GetView();
|
||||
m_ViewProjectionBuffer->UnMap();
|
||||
|
||||
m_QuadRenderer.Map();
|
||||
m_TextureRenderer.Map();
|
||||
|
||||
m_QuadRenderer.SetCamera(camera);
|
||||
m_TextureRenderer.SetCamera(camera);
|
||||
}
|
||||
|
||||
void Renderer::EndSceneImpl()
|
||||
{
|
||||
m_QuadRenderer.UnMap();
|
||||
m_TextureRenderer.UnMap();
|
||||
|
||||
//** QUAD_RENDERER **//
|
||||
if (m_QuadRenderer.GetQuadCount())
|
||||
{
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "Base.h"
|
||||
|
||||
#include "Buffers.h"
|
||||
|
||||
#include "RendererPrograms/QuadRendererProgram.h"
|
||||
#include "RendererPrograms/TextureRendererProgram.h"
|
||||
|
||||
|
@ -28,6 +30,7 @@ namespace Light {
|
|||
TextureRendererProgram m_TextureRenderer;
|
||||
|
||||
std::unique_ptr<RenderCommand> m_RenderCommand;
|
||||
std::unique_ptr<ConstantBuffer> m_ViewProjectionBuffer;
|
||||
|
||||
public:
|
||||
static Renderer* Create(GLFWwindow* windowHandle, std::shared_ptr<SharedContext> sharedContext);
|
||||
|
|
|
@ -51,9 +51,13 @@ namespace Light {
|
|||
m_MapEnd = m_MapCurrent + m_MaxVertices;
|
||||
}
|
||||
|
||||
void QuadRendererProgram::Bind()
|
||||
void QuadRendererProgram::UnMap()
|
||||
{
|
||||
m_VertexBuffer->UnMap();
|
||||
}
|
||||
|
||||
void QuadRendererProgram::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
m_VertexLayout->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
|
|
|
@ -45,6 +45,8 @@ namespace Light {
|
|||
void SetCamera(const Camera& camera) override;
|
||||
|
||||
void Map() override;
|
||||
void UnMap() override;
|
||||
|
||||
void Bind() override;
|
||||
|
||||
inline QuadVertexData* GetMapCurrent() { return m_MapCurrent; }
|
||||
|
|
|
@ -10,7 +10,10 @@ namespace Light {
|
|||
{
|
||||
virtual void SetCamera(const Camera& camera) = 0;
|
||||
|
||||
|
||||
virtual void Map() = 0;
|
||||
virtual void UnMap() = 0;
|
||||
|
||||
virtual void Bind() = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -51,9 +51,13 @@ namespace Light {
|
|||
m_MapEnd = m_MapCurrent + m_MaxVertices;
|
||||
}
|
||||
|
||||
void TextureRendererProgram::Bind()
|
||||
void TextureRendererProgram::UnMap()
|
||||
{
|
||||
m_VertexBuffer->UnMap();
|
||||
}
|
||||
|
||||
void TextureRendererProgram::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
m_VertexLayout->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
|
|
|
@ -45,6 +45,8 @@ namespace Light {
|
|||
void SetCamera(const Camera& camera) override;
|
||||
|
||||
void Map() override;
|
||||
void UnMap() override;
|
||||
|
||||
void Bind() override;
|
||||
|
||||
inline TextureVertexData* GetMapCurrent() { return m_MapCurrent; }
|
||||
|
|
|
@ -5,6 +5,38 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
dxConstantBuffer::dxConstantBuffer(ConstantBufferIndex index, unsigned int size, std::shared_ptr<dxSharedContext> sharedContext)
|
||||
: m_Context(sharedContext), m_Index((int)index)
|
||||
{
|
||||
D3D11_BUFFER_DESC bufferDesc = { };
|
||||
|
||||
bufferDesc.ByteWidth = size;
|
||||
bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
|
||||
HRESULT hr;
|
||||
DXC(m_Context->GetDevice()->CreateBuffer(&bufferDesc, nullptr, &m_Buffer));
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
}
|
||||
|
||||
void dxConstantBuffer::Bind()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
}
|
||||
|
||||
void* dxConstantBuffer::Map()
|
||||
{
|
||||
m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf());
|
||||
m_Context->GetDeviceContext()->Map(m_Buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_Map);
|
||||
return m_Map.pData;
|
||||
}
|
||||
|
||||
void dxConstantBuffer::UnMap()
|
||||
{
|
||||
m_Context->GetDeviceContext()->Unmap(m_Buffer.Get(), NULL);
|
||||
}
|
||||
|
||||
//* VERTEX_BUFFER *//
|
||||
dxVertexBuffer::dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, std::shared_ptr<dxSharedContext> sharedContext)
|
||||
: m_Stride(stride), m_Context(sharedContext)
|
||||
|
|
|
@ -10,6 +10,26 @@ namespace Light {
|
|||
|
||||
class dxSharedContext;
|
||||
|
||||
//* INDEX_BUFFER *//
|
||||
class dxConstantBuffer : public ConstantBuffer
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<dxSharedContext> m_Context;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> m_Buffer;
|
||||
D3D11_MAPPED_SUBRESOURCE m_Map;
|
||||
|
||||
unsigned int m_Index;
|
||||
|
||||
public:
|
||||
dxConstantBuffer(ConstantBufferIndex index, unsigned int size, std::shared_ptr<dxSharedContext> sharedContext);
|
||||
|
||||
void Bind() override;
|
||||
|
||||
void* Map() override;
|
||||
void UnMap() override;
|
||||
};
|
||||
|
||||
//* VERTEX_BUFFER *//
|
||||
class dxVertexBuffer : public VertexBuffer
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Light {
|
|||
0u,
|
||||
D3D11_APPEND_ALIGNED_ELEMENT,
|
||||
D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0u });
|
||||
0u });
|
||||
}
|
||||
|
||||
std::shared_ptr<dxShader> dxpShader = std::dynamic_pointer_cast<dxShader>(shader);
|
||||
|
|
|
@ -5,6 +5,37 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
//** CONSTANT_BUFFER **//
|
||||
glConstantBuffer::glConstantBuffer(ConstantBufferIndex index, unsigned int size)
|
||||
: m_Index((int)index)
|
||||
{
|
||||
glCreateBuffers(1, &m_BufferID);
|
||||
glNamedBufferData(m_BufferID, size, nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
Bind();
|
||||
}
|
||||
|
||||
glConstantBuffer::~glConstantBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_BufferID);
|
||||
}
|
||||
|
||||
void glConstantBuffer::Bind()
|
||||
{
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, m_Index, m_BufferID);
|
||||
}
|
||||
|
||||
void* glConstantBuffer::Map()
|
||||
{
|
||||
void* map = glMapNamedBuffer(m_BufferID, GL_WRITE_ONLY);
|
||||
return map;
|
||||
}
|
||||
|
||||
void glConstantBuffer::UnMap()
|
||||
{
|
||||
glUnmapNamedBuffer(m_BufferID);
|
||||
}
|
||||
|
||||
//** VERTEX_BUFFER **//
|
||||
glVertexBuffer::glVertexBuffer(float* vertices, unsigned int count)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,21 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
class glConstantBuffer : public ConstantBuffer
|
||||
{
|
||||
private:
|
||||
unsigned int m_BufferID, m_Index;
|
||||
|
||||
public:
|
||||
glConstantBuffer(ConstantBufferIndex index, unsigned int size);
|
||||
~glConstantBuffer();
|
||||
|
||||
void Bind() override;
|
||||
|
||||
void* Map() override;
|
||||
void UnMap() override;
|
||||
};
|
||||
|
||||
//** VERTEX_BUFFER **//
|
||||
class glVertexBuffer : public VertexBuffer
|
||||
{
|
||||
|
|
|
@ -26,6 +26,8 @@ namespace Light {
|
|||
// load opengl (glad)
|
||||
LT_ENGINE_ASSERT(gladLoadGLLoader((GLADloadproc)glfwGetProcAddress), "glGraphicsContext::glGraphicsContext: failed to initialize opengl (glad)");
|
||||
|
||||
SetDebugMessageCallback();
|
||||
|
||||
// #todo: add blender
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
|
|
@ -45,11 +45,10 @@ public:
|
|||
|
||||
bool OnKeyPressed(const Light::KeyPressedEvent& event) override
|
||||
{
|
||||
// #todo: add input class
|
||||
if (event.GetKey() == 65) // GLFW_KEY_A
|
||||
m_Direction.x += 1.0f;
|
||||
m_Direction.x += -1.0f;
|
||||
if(event.GetKey() == 68) // GLFW_KEY_D
|
||||
m_Direction.x += -1.0f;
|
||||
m_Direction.x += 1.0f;
|
||||
|
||||
if (event.GetKey() == 87) // GLFW_KEY_W
|
||||
m_Direction.y += 1.0f;
|
||||
|
@ -63,9 +62,9 @@ public:
|
|||
{
|
||||
// #todo: add input class
|
||||
if (event.GetKey() == 65) // GLFW_KEY_A
|
||||
m_Direction.x -= 1.0f;
|
||||
if (event.GetKey() == 68) // GLFW_KEY_D
|
||||
m_Direction.x -= -1.0f;
|
||||
if (event.GetKey() == 68) // GLFW_KEY_D
|
||||
m_Direction.x -= 1.0f;
|
||||
|
||||
if (event.GetKey() == 87) // GLFW_KEY_W
|
||||
m_Direction.y -= 1.0f;
|
||||
|
|
Loading…
Add table
Reference in a new issue