Skip to content

Commit

Permalink
Textures Basically Working (I think)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomheeleynz committed Nov 26, 2022
1 parent c23b30a commit 0ed6fc3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
36 changes: 32 additions & 4 deletions Arcane/src/Arcane/Platform/OpenGL/OpenGLDescriptorSet.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,57 @@
#include "OpenGLDescriptorSet.h"
#include "OpenGLTexture.h"

#include<glad/glad.h>

namespace Arcane
{
OpenGLDescriptorSet::OpenGLDescriptorSet(DescriptorSetSpecs& setSpecs, std::initializer_list<DescriptorLayoutSpecs> layoutSpecs)
{

for (DescriptorLayoutSpecs spec : layoutSpecs) {
m_Textures[{spec.Binding, spec.Name}] = nullptr;
}
}

OpenGLDescriptorSet::OpenGLDescriptorSet(DescriptorSetSpecs& setSpecs, std::vector<DescriptorLayoutSpecs> layoutSpecs)
{

}

void OpenGLDescriptorSet::AddImageSampler(Texture* texture, uint32_t setNum, uint32_t bindingNum)
{

std::map<std::pair<int, std::string>, Texture*>::iterator it;
for (it = m_Textures.begin(); it != m_Textures.end(); it++) {
if (it->first.first == bindingNum) {
it->second = texture;
}
}
}

void OpenGLDescriptorSet::AddImageSampler(Framebuffer* framebuffer, uint32_t setNum, uint32_t bindingNum)
{

}

void OpenGLDescriptorSet::AddUniformBuffer(UniformBuffer* buffer, uint32_t setNum, uint32_t bindingNum)
{
}

void OpenGLDescriptorSet::BindTextures(uint32_t shaderID)
{
int textureCount = 0;

std::map<std::pair<int, std::string>, Texture*>::iterator it;
for (it = m_Textures.begin(); it != m_Textures.end(); it++) {
// Cast Texture to opengl texture
OpenGLTexture* openglTexture = static_cast<OpenGLTexture*>(it->second);

// Get Texture Uniform Name
std::string uniformName = it->first.second;

// Set Uniform Value
glUniform1i(glGetUniformLocation(shaderID, uniformName.c_str()), textureCount);

// Set Active Texture
glActiveTexture(GL_TEXTURE + textureCount);
glBindTexture(GL_TEXTURE_2D, openglTexture->GetTextureID());
}
}
}
6 changes: 5 additions & 1 deletion Arcane/src/Arcane/Platform/OpenGL/OpenGLDescriptorSet.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <map>
#include "Arcane/Renderer/DescriptorSet.h"

namespace Arcane
Expand All @@ -14,7 +15,10 @@ namespace Arcane
void AddImageSampler(Texture* texture, uint32_t setNum, uint32_t bindingNum) override;
void AddImageSampler(Framebuffer* framebuffer, uint32_t setNum, uint32_t bindingNum) override;
void AddUniformBuffer(UniformBuffer* buffer, uint32_t setNum, uint32_t bindingNum) override;

// OpenGL Specific Functions
void BindTextures(uint32_t shaderID);
private:

std::map<std::pair<int, std::string>, Texture*> m_Textures;
};
}
7 changes: 7 additions & 0 deletions Arcane/src/Arcane/Platform/OpenGL/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "OpenGLPipeline.h"
#include "OpenGLBuffer.h"
#include "OpenGLVertexDescriptor.h"
#include "OpenGLDescriptorSet.h"
#include "OpenGLShader.h"

#include <glad/glad.h>

Expand Down Expand Up @@ -94,6 +96,8 @@ namespace Arcane
OpenGLPipeline* openglPipeline = static_cast<OpenGLPipeline*>(pipeline);
OpenGLVertexDescriptor* vertexDescriptor = static_cast<OpenGLVertexDescriptor*>(openglPipeline->GetSpec().descriptor);
OpenGLIndexBuffer* indexBuffer = static_cast<OpenGLIndexBuffer*>(vertexBuffer->GetIndexBuffer());
OpenGLDescriptorSet* descriptorSet = static_cast<OpenGLDescriptorSet*>(openglPipeline->GetSpec().DescriptorSets[0]);
OpenGLShader* shader = static_cast<OpenGLShader*>(openglPipeline->GetSpec().shader);

// Bind Shader
openglPipeline->BindShader();
Expand All @@ -106,6 +110,9 @@ namespace Arcane
openglPipeline->BindVertexDescriptor();
indexBuffer->Bind();

// Bind Descriptor Sets
descriptorSet->BindTextures(shader->GetShaderID());

// Draw
glDrawElements(GL_TRIANGLES, indexBuffer->GetCount(), GL_UNSIGNED_INT, 0);

Expand Down
2 changes: 2 additions & 0 deletions Arcane/src/Arcane/Platform/OpenGL/OpenGLShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Arcane

void Bind();
void UnBind();

uint32_t GetShaderID() { return m_ShaderProgram; }
private:
uint32_t m_ShaderProgram;
};
Expand Down
2 changes: 2 additions & 0 deletions Arcane/src/Arcane/Platform/OpenGL/OpenGLTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Arcane
void UpdateTexture(std::string filename) override;
void UpdateTexture(Texture* texture) override;
void UpdateTexture(float r, float g, float b, float a) override;

uint32_t GetTextureID() { return m_TextureID; }
private:
uint32_t m_TextureID;
};
Expand Down
8 changes: 3 additions & 5 deletions EnchantingTable/src/OpenGLTestLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ void OpenGLTestLayer::OnAttach()

// Shader
m_Shader = Arcane::Shader::Create(
".\\src\\EditorAssets\\Shaders\\TriangleVert.spv",
".\\src\\EditorAssets\\Shaders\\TriangleFrag.spv"
".\\src\\EditorAssets\\Shaders\\ScreenVert.spv",
".\\src\\EditorAssets\\Shaders\\ScreenFrag.spv"
);

// Framebuffer Setup
Expand Down Expand Up @@ -57,7 +57,7 @@ void OpenGLTestLayer::OnAttach()
descriptorSetSpecs.SetNumber = 0;
m_DescriptorSet = Arcane::DescriptorSet::Create(
descriptorSetSpecs, {
{0, 1, Arcane::DescriptorType::SAMPLER, "Texture", Arcane::DescriptorLocation::VERTEX}
{0, 1, Arcane::DescriptorType::SAMPLER, "texSampler", Arcane::DescriptorLocation::FRAGMENT}
}
);

Expand All @@ -70,8 +70,6 @@ void OpenGLTestLayer::OnAttach()
pipelineSpecs.renderPass = m_RenderPass;
pipelineSpecs.DescriptorSets = { m_DescriptorSet };
m_Pipeline = Arcane::Pipeline::Create(pipelineSpecs);


}

void OpenGLTestLayer::OnDetach()
Expand Down

0 comments on commit 0ed6fc3

Please sign in to comment.