Skip to content

Commit

Permalink
Refactoring of texture functionalities (4/5). Almost finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Zang3th committed Jul 18, 2024
1 parent 5b55f26 commit 5047a68
Show file tree
Hide file tree
Showing 29 changed files with 395 additions and 352 deletions.
14 changes: 7 additions & 7 deletions Apps/GreenWorld/GreenWorldApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace GW
Engine::ResourceManager::LoadShader("SpriteShaderGreyscale", "../Res/Shader/GreenWorld/Sprite_VS.glsl", "../Res/Shader/GreenWorld/SpriteGreyscale_FS.glsl");

//Textures
Engine::ResourceManager::LoadTextureAtlas("ParticleTextureAtlas", "../Res/Assets/Textures/GreenWorld/SmokeAtlas.png", 8);
Engine::ResourceManager::LoadTexture("TerrainGrassTexture", "../Res/Assets/Textures/GreenWorld/Grass.jpg");
Engine::ResourceManager::LoadTexture("TerrainColormap", "../Res/Assets/Textures/GreenWorld/Colormap128.png");
Engine::ResourceManager::LoadTexture("WaterDuDvMap", "../Res/Assets/Textures/GreenWorld/DuDvMap.png");
Engine::ResourceManager::LoadTexture("WaterNormalMap", "../Res/Assets/Textures/GreenWorld/WaterNormalMap.png");
Engine::ResourceManager::LoadGLTextureAtlas("ParticleTextureAtlas", "../Res/Assets/Textures/GreenWorld/SmokeAtlas.png", 8);
Engine::ResourceManager::LoadGLTexture("TerrainGrassTexture", "../Res/Assets/Textures/GreenWorld/Grass.jpg");
Engine::ResourceManager::LoadGLTexture("TerrainColormap", "../Res/Assets/Textures/GreenWorld/Colormap128.png");
Engine::ResourceManager::LoadGLTexture("WaterDuDvMap", "../Res/Assets/Textures/GreenWorld/DuDvMap.png");
Engine::ResourceManager::LoadGLTexture("WaterNormalMap", "../Res/Assets/Textures/GreenWorld/WaterNormalMap.png");

//Heightmap
Engine::ResourceManager::LoadHeightmap("TerrainHeightmap", "../Res/Assets/Textures/GreenWorld/Heightmap128.bmp");
Expand Down Expand Up @@ -57,7 +57,7 @@ namespace GW
_shadowRenderer = new Engine::ShadowRenderer(8192, 8192, glm::ortho(-90.0f, 90.0f, -90.0f, 90.0f, 110.0f, 210.0f), "ShadowCreateShader");
_sceneRenderer->AddLightProjection(_shadowRenderer->GetLightProjection());
Engine::RenderManager::Submit(_shadowRenderer);

_waterRenderer = new Engine::WaterRenderer();
Engine::RenderManager::Submit(_waterRenderer);

Expand Down Expand Up @@ -92,7 +92,7 @@ namespace GW

AddObjects();
AddSprites();

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions Apps/GreenWorld/GreenWorldApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace GW
Engine::SpriteRenderer* _spriteRenderer = nullptr;
Engine::Scope<GreenWorldInterface> _interface;
Engine::Scope<Engine::Audio> _audio;

void LoadResources() override;
void AddObjects();
void AddSprites();
Expand All @@ -27,7 +27,7 @@ namespace GW

//Not needed in this app because we only use a general 3D camera controller to handle input.
void ProcessInput() override {}

[[nodiscard]] bool Init() override;
};
}
2 changes: 1 addition & 1 deletion Apps/GreenWorld/GreenWorldInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace GW
CenterText("Textures:");
ImGui::Separator();
ImGui::NewLine();
CenterText(Engine::ResourceManager::OutputTextureStorage().c_str());
CenterText(Engine::ResourceManager::OutputGLTextureStorage().c_str());
}
ImGui::End();
}
Expand Down
8 changes: 4 additions & 4 deletions Apps/Liquefied/LiquefiedApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Liq
Engine::ResourceManager::LoadShader("GridShader", "../Res/Shader/Liquefied/Grid_VS.glsl", "../Res/Shader/Liquefied/Grid_FS.glsl");

//Textures
Engine::ResourceManager::LoadTextureToBuffer("TurbineTexture", "../Res/Assets/Textures/Liquefied/Turbine_512.png");
Engine::ResourceManager::LoadTextureToBuffer("ObstacleTexture", "../Res/Assets/Textures/Liquefied/Box_512.png");
Engine::ResourceManager::LoadTextureToBuffer("TestTexture", "../Res/Assets/Textures/Liquefied/Test_1C_1G_8Px.png");
Engine::ResourceManager::LoadTextureBuffer("TurbineTexture", "../Res/Assets/Textures/Liquefied/Turbine_512.png");
Engine::ResourceManager::LoadTextureBuffer("ObstacleTexture", "../Res/Assets/Textures/Liquefied/Box_512.png");
Engine::ResourceManager::LoadTextureBuffer("TestTexture", "../Res/Assets/Textures/Liquefied/Test_1C_1G_8Px.png");
}

void LiquefiedApp::AddBorderCells() const
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace Liq
// turbinePos,
// turbineSize
// );
_gridRenderer->AddTextureSubsampled
_gridRenderer->AddTextureBufferSubsampled
(
// "ObstacleTexture",
"TestTexture",
Expand Down
14 changes: 7 additions & 7 deletions Engine/Rendering/Buffers/FrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ namespace Engine
GLCall(glDrawBuffer(GL_COLOR_ATTACHMENT0))
}

Texture* FrameBuffer::CreateTextureAttachment(const std::string& name, uint32 width, uint32 height)
GLTexture* FrameBuffer::CreateTextureAttachment(const std::string& name, uint32 width, uint32 height)
{
//Create and configure texture
_texture = ResourceManager::CreateTexture(name, width, height, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);
_texture = ResourceManager::CreateGLTexture(name, width, height, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);

//Attach texture
GLCall(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->GetTextureID(), 0))

return _texture;
}

Texture* FrameBuffer::CreateDepthTextureAttachment(const std::string& name, const uint32 width, const uint32 height)
GLTexture* FrameBuffer::CreateDepthTextureAttachment(const std::string& name, const uint32 width, const uint32 height)
{
//Create and configure depth texture
_depthTexture = ResourceManager::CreateTexture(name, width, height, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT);
_depthTexture = ResourceManager::CreateGLTexture(name, width, height, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT);

//Attach depth texture
GLCall(glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _depthTexture->GetTextureID(), 0))
Expand All @@ -79,13 +79,13 @@ namespace Engine
GLCall(glBindFramebuffer(GL_FRAMEBUFFER, 0))
}

Texture* FrameBuffer::GetTexture() const
GLTexture* FrameBuffer::GetTexture() const
{
return _texture;
}

Texture* FrameBuffer::GetDepthTexture() const
GLTexture* FrameBuffer::GetDepthTexture() const
{
return _depthTexture;
}
}
}
12 changes: 6 additions & 6 deletions Engine/Rendering/Buffers/FrameBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Engine
{
private:
uint32 _fboID, _depthBufferID;
Texture *_texture, *_depthTexture;
GLTexture *_texture, *_depthTexture;

public:
FrameBuffer();
Expand All @@ -21,11 +21,11 @@ namespace Engine
void Bind(uint32 width, uint32 height) const;
void Unbind() const;
void SetColorAttachment0();
Texture* CreateTextureAttachment(const std::string& name, uint32 width, uint32 height);
Texture* CreateDepthTextureAttachment(const std::string& name, uint32 width, uint32 height);
GLTexture* CreateTextureAttachment(const std::string& name, uint32 width, uint32 height);
GLTexture* CreateDepthTextureAttachment(const std::string& name, uint32 width, uint32 height);
void CreateDepthBufferAttachment(uint32 width, uint32 height);
void DeleteColorBufferAttachment() const;
[[nodiscard]] Texture* GetTexture() const;
[[nodiscard]] Texture* GetDepthTexture() const;
[[nodiscard]] GLTexture* GetTexture() const;
[[nodiscard]] GLTexture* GetDepthTexture() const;
};
}
}
18 changes: 9 additions & 9 deletions Engine/Rendering/Renderables/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "glm.hpp"
#include "Types.hpp"
#include "Texture.hpp"
#include "GLTexture.hpp"

#include <vector>

Expand All @@ -11,13 +11,13 @@ namespace Engine
struct Mesh
{
public:
std::vector<glm::vec3> vertices;
std::vector<glm::vec2> texCoords;
std::vector<glm::vec3> normals;
std::vector<glm::vec3> tangents;
std::vector<uint32> indices;
std::vector<Texture*> textures;
int32 gotDiffuseTex = 0;
int32 gotNormalMap = 0;
std::vector<glm::vec3> vertices;
std::vector<glm::vec2> texCoords;
std::vector<glm::vec3> normals;
std::vector<glm::vec3> tangents;
std::vector<uint32> indices;
std::vector<GLTexture*> glTextures;
int32 gotDiffuseTex = 0;
int32 gotNormalMap = 0;
};
}
20 changes: 10 additions & 10 deletions Engine/Rendering/Renderables/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Engine
Model::Model(const Mesh* mesh)
: _model(glm::mat4(1.0f)),
_position(0.0f),
_textures(mesh->textures),
_glTextures(mesh->glTextures),
_verticeCount(mesh->indices.size()),
_gotDiffuseTex(mesh->gotDiffuseTex), _gotNormalMap(mesh->gotNormalMap),
_rotationX(0.0f), _rotationY(0.0f), _rotationZ(0.0f),
Expand Down Expand Up @@ -82,9 +82,9 @@ namespace Engine
return _gotNormalMap;
}

[[nodiscard]] const std::vector<Texture*>* Model::GetTextures() const
[[nodiscard]] const std::vector<GLTexture*>* Model::GetGLTextures() const
{
return &_textures;
return &_glTextures;
}

void Model::BindBuffers() const
Expand Down Expand Up @@ -127,26 +127,26 @@ namespace Engine
SetModelMatrix();
}

void Model::AddTexture(Texture* texture)
void Model::AddGLTexture(GLTexture* glTexture)
{
_textures.push_back(texture);
_glTextures.push_back(glTexture);
}

void Model::AddTextureToSlot(Texture* texture, uint32_t slot)
void Model::AddGLTextureToSlot(GLTexture* glTexture, uint32_t slot)
{
if(_textures.empty())
if(_glTextures.empty())
{
for(uint32_t i = 0; i < slot; i++)
{
_textures.push_back(nullptr);
_glTextures.push_back(nullptr);
}
}

_textures.insert(_textures.begin() + slot, texture);
_glTextures.insert(_glTextures.begin() + slot, glTexture);
}

void Model::SetDiffuseTexture()
{
_gotDiffuseTex = true;
}
}
}
40 changes: 20 additions & 20 deletions Engine/Rendering/Renderables/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "VertexArray.hpp"
#include "VertexBuffer.hpp"
#include "IndexBuffer.hpp"
#include "Texture.hpp"
#include "GLTexture.hpp"
#include "Shader.hpp"
#include "glm.hpp"
#include "gtc/matrix_transform.hpp"
Expand All @@ -18,35 +18,35 @@ namespace Engine
class Model
{
private:
Scope<VertexArray> _vao;
Scope<VertexBuffer> _vboVert, _vboTex, _vboNorm, _vboTang;
Scope<IndexBuffer> _ibo;
glm::mat4 _model;
glm::vec3 _position;
std::vector<Texture*> _textures;
uint32 _verticeCount;
int32 _gotDiffuseTex, _gotNormalMap;
float _rotationX, _rotationY, _rotationZ;
float _size;
Scope<VertexArray> _vao;
Scope<VertexBuffer> _vboVert, _vboTex, _vboNorm, _vboTang;
Scope<IndexBuffer> _ibo;
glm::mat4 _model;
glm::vec3 _position;
std::vector<GLTexture*> _glTextures;
uint32 _verticeCount;
int32 _gotDiffuseTex, _gotNormalMap;
float _rotationX, _rotationY, _rotationZ;
float _size;

void InitGpuStorage(const Mesh* mesh);
void SetModelMatrix();

public:
explicit Model(const Mesh* mesh);
[[nodiscard]] glm::mat4 GetModelMatrix() const;
[[nodiscard]] uint32 GetVerticeCount() const;
[[nodiscard]] int32 GotDiffuseTex() const;
[[nodiscard]] int32 GotNormalMap() const;
[[nodiscard]] const std::vector<Texture*>* GetTextures() const;
explicit Model(const Mesh* mesh);
[[nodiscard]] glm::mat4 GetModelMatrix() const;
[[nodiscard]] uint32 GetVerticeCount() const;
[[nodiscard]] int32 GotDiffuseTex() const;
[[nodiscard]] int32 GotNormalMap() const;
[[nodiscard]] const std::vector<GLTexture*>* GetGLTextures() const;

void BindBuffers() const;
void UnbindBuffers() const;
void ChangePosition(const glm::vec3& position);
void ChangeRotation(const glm::vec3& rotation);
void ChangeSize(float size);
void AddTexture(Texture* texture);
void AddTextureToSlot(Texture* texture, uint32_t slot);
void AddGLTexture(GLTexture* glTexture);
void AddGLTextureToSlot(GLTexture* glTexture, uint32_t slot);
void SetDiffuseTexture();
};
}
}
20 changes: 10 additions & 10 deletions Engine/Rendering/Renderables/ObjLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Engine
std::string objFullFilepath = baseFilepath + "/" + filename + ".obj";

if(!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, objFullFilepath.c_str(), baseFilepath.c_str()))
{
Logger::Error("Failed", "OBJ-Loading", objFullFilepath);
{
Logger::Error("Failed", "OBJ-Loading", objFullFilepath);
}
else
{
Expand All @@ -29,12 +29,12 @@ namespace Engine

//Additional error checking to catch edge cases
if(!warn.empty())
{
Logger::Warn("Warning", "tinyobj", warn);
{
Logger::Warn("Warning", "tinyobj", warn);
}
if(!err.empty())
{
Logger::Error("Error", "tinyobj", err);
{
Logger::Error("Error", "tinyobj", err);
}

//Iterate over all shapes
Expand Down Expand Up @@ -79,8 +79,8 @@ namespace Engine
//Load diffuse texture
std::string textureFilepath = baseFilepath + "/" + materials[i].diffuse_texname;
std::string textureName = filename + "DiffuseTexture";
ResourceManager::LoadTexture(textureName, textureFilepath);
mesh.textures.push_back(ResourceManager::GetTexture(textureName));
ResourceManager::LoadGLTexture(textureName, textureFilepath);
mesh.glTextures.push_back(ResourceManager::GetGLTexture(textureName));
mesh.gotDiffuseTex = 1;
}

Expand All @@ -90,8 +90,8 @@ namespace Engine
//Load bump map
std::string textureFilepath = baseFilepath + "/" + materials[i].bump_texname;
std::string textureName = filename + "NormalTexture";
ResourceManager::LoadTexture(textureName, textureFilepath);
mesh.textures.push_back(ResourceManager::GetTexture(textureName));
ResourceManager::LoadGLTexture(textureName, textureFilepath);
mesh.glTextures.push_back(ResourceManager::GetGLTexture(textureName));
mesh.gotNormalMap = 1;
}

Expand Down
Loading

0 comments on commit 5047a68

Please sign in to comment.