-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
974fe04
commit 00be11c
Showing
17 changed files
with
265 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
#include "OpenGLPipeline.h" | ||
|
||
#include "OpenGLShader.h" | ||
#include "OpenGLVertexDescriptor.h" | ||
|
||
namespace Arcane | ||
{ | ||
OpenGLPipeline::OpenGLPipeline(PipelineSpecification& spec) | ||
{ | ||
m_Spec = spec; | ||
} | ||
|
||
void OpenGLPipeline::BindShader() | ||
{ | ||
OpenGLShader* shader = static_cast<OpenGLShader*>(m_Spec.shader); | ||
shader->Bind(); | ||
} | ||
|
||
void OpenGLPipeline::BindVertexDescriptor() | ||
{ | ||
OpenGLVertexDescriptor* vertexDescriptor = static_cast<OpenGLVertexDescriptor*>(m_Spec.descriptor); | ||
vertexDescriptor->Bind(); | ||
} | ||
|
||
void OpenGLPipeline::UnbindShader() | ||
{ | ||
OpenGLShader* shader = static_cast<OpenGLShader*>(m_Spec.shader); | ||
shader->UnBind(); | ||
} | ||
|
||
void OpenGLPipeline::UnbindVertexDescriptor() | ||
{ | ||
OpenGLVertexDescriptor* vertexDescriptor = static_cast<OpenGLVertexDescriptor*>(m_Spec.descriptor); | ||
vertexDescriptor->UnBind(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Arcane/src/Arcane/Platform/OpenGL/OpenGLVertexDescriptor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "OpenGLVertexDescriptor.h" | ||
|
||
namespace Arcane | ||
{ | ||
OpenGLVertexDescriptor::OpenGLVertexDescriptor(std::initializer_list<VertexType> vertexTypes) | ||
{ | ||
// Generate VAO | ||
glGenVertexArrays(1, &m_VAO); | ||
glBindVertexArray(m_VAO); | ||
|
||
// Calculate Stride | ||
uint32_t stride = 0; | ||
for (auto element : vertexTypes) | ||
{ | ||
switch (element) | ||
{ | ||
case VertexType::float1: | ||
{ | ||
stride += sizeof(float); | ||
break; | ||
} | ||
case VertexType::float2: | ||
{ | ||
stride += sizeof(float) * 2; | ||
break; | ||
} | ||
case VertexType::float3: | ||
{ | ||
stride += sizeof(float) * 3; | ||
break; | ||
} | ||
case VertexType::float4: | ||
{ | ||
stride += sizeof(float) * 4; | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
// Attribute Arrays | ||
uint32_t count = 0; | ||
uint32_t offset = 0; | ||
for (auto element : vertexTypes) | ||
{ | ||
switch (element) | ||
{ | ||
case VertexType::float1: | ||
{ | ||
stride += sizeof(float); | ||
break; | ||
} | ||
case VertexType::float2: | ||
{ | ||
stride += sizeof(float) * 2; | ||
break; | ||
} | ||
case VertexType::float3: | ||
{ | ||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride, (void*)offset); | ||
glEnableVertexAttribArray(count); | ||
offset += 3 * sizeof(float); | ||
count += 1; | ||
break; | ||
} | ||
case VertexType::float4: | ||
{ | ||
stride += sizeof(float) * 4; | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
glBindVertexArray(0); | ||
} | ||
|
||
void OpenGLVertexDescriptor::Bind() | ||
{ | ||
glBindVertexArray(m_VAO); | ||
} | ||
|
||
void OpenGLVertexDescriptor::UnBind() | ||
{ | ||
glBindVertexArray(0); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Arcane/src/Arcane/Platform/OpenGL/OpenGLVertexDescriptor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "Arcane/Renderer/VertexDescriptor.h" | ||
|
||
#include <glad/glad.h> | ||
#include <iostream> | ||
|
||
namespace Arcane | ||
{ | ||
class OpenGLVertexDescriptor : public VertexDescriptor | ||
{ | ||
public: | ||
OpenGLVertexDescriptor(std::initializer_list<VertexType> vertexTypes); | ||
|
||
void Bind(); | ||
void UnBind(); | ||
private: | ||
uint32_t m_VAO; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#version 330 | ||
layout (location = 0) out vec4 FragColor; | ||
|
||
void main() | ||
{ | ||
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#version 330 | ||
layout (location = 0) in vec3 aPos; | ||
|
||
void main() | ||
{ | ||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.