Skip to content

Commit

Permalink
Reformat of texture class
Browse files Browse the repository at this point in the history
  • Loading branch information
AEspinosaDev committed Oct 28, 2024
1 parent 3d53abd commit ad9cb04
Show file tree
Hide file tree
Showing 36 changed files with 347 additions and 258 deletions.
4 changes: 2 additions & 2 deletions examples/lighting-test/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class VulkanRenderer
};
UserInterface m_interface{};

WindowBase *m_window;
Systems::RendererBase *m_renderer;
IWindow *m_window;
Systems::BaseRenderer *m_renderer;
Scene *m_scene;
Camera *camera;
Tools::Controller *m_controller;
Expand Down
3 changes: 1 addition & 2 deletions examples/renderer-app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ void VulkanRenderer::setup()

TextureHDR* envMap = new TextureHDR();
Tools::Loaders::load_HDRi(envMap, TEXTURE_PATH + "night.hdr");
Skybox* sky = new Skybox(envMap);
m_scene->add(sky);
m_scene->set_skybox(new Skybox(envMap));

m_controller = new Tools::Controller(camera, m_window);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/renderer-app/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class VulkanRenderer
};
UserInterface m_interface{};

WindowBase *m_window;
Systems::RendererBase *m_renderer;
IWindow *m_window;
Systems::BaseRenderer *m_renderer;
Scene *m_scene;
Camera *camera;
Tools::Controller *m_controller;
Expand Down
4 changes: 2 additions & 2 deletions examples/rotating-kabuto/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ int main()
float delta;
float last{0};

Core::WindowBase *window = new Core::WindowGLFW("Kabuto", 800, 600);
Core::IWindow *window = new Core::WindowGLFW("Kabuto", 800, 600);

window->init();

Systems::RendererSettings settings{};
settings.samplesMSAA = MSAASamples::MSAA_x4;
settings.clearColor = Vec4(0.0, 0.0, 0.0, 1.0);

Systems::RendererBase *renderer = new Systems::ForwardRenderer(window, settings, {});
Systems::BaseRenderer *renderer = new Systems::ForwardRenderer(window, settings, {});

Core::Camera *camera = new Core::Camera();
camera->set_position(Vec3(0.0f, 0.15f, -1.0f));
Expand Down
16 changes: 7 additions & 9 deletions include/engine/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,13 @@ typedef enum TextureFilterType
} TextureFilterType;
typedef enum ColorFormatType
{
SRGBA_8 = VK_FORMAT_R8G8B8A8_SRGB,
SRGB_8 = VK_FORMAT_R8G8B8_SRGB,
SBGRA_8 = VK_FORMAT_B8G8R8A8_SRGB,
RGBA_8,
RGB_8,
SRGBA_16,
SRGB_16,
RGBA_16,
RGB_16,
SR_8 = VK_FORMAT_R8_SRGB, //Red
SRG_8 = VK_FORMAT_R8G8_SRGB, //Red Green
SRGB_8 = VK_FORMAT_R8G8B8_SRGB, //RGB
SRGBA_8 = VK_FORMAT_R8G8B8A8_SRGB, //RGB with Alpha
SBGRA_8 = VK_FORMAT_B8G8R8A8_SRGB, //Other order
SRGBA_16F = VK_FORMAT_R16G16B16A16_SFLOAT, //HDR precission 16
SRGBA_32F = VK_FORMAT_R32G32B32A32_SFLOAT, //HDR precission 32
} ColorFormatType;
typedef enum DepthFormatType
{
Expand Down
4 changes: 2 additions & 2 deletions include/engine/core/materials/hair.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class HairMaterial : public IMaterial
bool m_coloredScatter{false};
bool m_occlusion{false};

std::unordered_map<int, Texture *> m_textures;
std::unordered_map<int, ITexture *> m_textures;

std::unordered_map<int, bool> m_textureBindingState;

virtual Graphics::MaterialUniforms get_uniforms() const;
virtual inline std::unordered_map<int, Texture *> get_textures() const
virtual inline std::unordered_map<int, ITexture *> get_textures() const
{
return m_textures;
}
Expand Down
15 changes: 8 additions & 7 deletions include/engine/core/materials/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ class IMaterial
{
}

virtual Graphics::MaterialUniforms get_uniforms() const = 0;

virtual std::unordered_map<int, ITexture *> get_textures() const = 0;

virtual std::unordered_map<int, bool> get_texture_binding_state() const = 0;

virtual void set_texture_binding_state(int id, bool state) = 0;

virtual std::string get_shaderpass_ID() const
{
return m_shaderPassID;
Expand Down Expand Up @@ -98,13 +106,6 @@ class IMaterial
{
return m_textureDescriptor;
}

virtual Graphics::MaterialUniforms get_uniforms() const = 0;

virtual std::unordered_map<int, Texture *> get_textures() const = 0;

virtual std::unordered_map<int, bool> get_texture_binding_state() const = 0;
virtual void set_texture_binding_state(int id, bool state) = 0;
};

} // namespace Core
Expand Down
20 changes: 10 additions & 10 deletions include/engine/core/materials/phong.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class PhongMaterial : public IMaterial
GLOSSINESS = 2,
SHININESS = 3,
};
std::unordered_map<int, Texture *> m_textures{
std::unordered_map<int, ITexture *> m_textures{
{ALBEDO, nullptr}, {NORMAL, nullptr}, {GLOSSINESS, nullptr}, {SHININESS, nullptr}};
std::unordered_map<int, bool> m_textureBindingState;

virtual Graphics::MaterialUniforms get_uniforms() const;
virtual inline std::unordered_map<int, Texture *> get_textures() const
virtual inline std::unordered_map<int, ITexture *> get_textures() const
{
return m_textures;
}
Expand Down Expand Up @@ -106,46 +106,46 @@ class PhongMaterial : public IMaterial
m_isDirty = true;
}
// Texture must have A channel reserved for OPACITY
inline Texture *get_color_texture()
inline ITexture *get_color_texture()
{
return m_textures[ALBEDO];
}
inline void set_color_texture(Texture *t)
inline void set_color_texture(ITexture *t)
{
m_hasColorTexture = t ? true : false;
m_textureBindingState[ALBEDO] = false;
m_textures[ALBEDO] = t;
m_isDirty = true;
}

inline Texture *get_normal_texture()
inline ITexture *get_normal_texture()
{
return m_textures[NORMAL];
}
inline void set_normal_texture(Texture *t)
inline void set_normal_texture(ITexture *t)
{
m_hasNormalTexture = t ? true : false;
m_textureBindingState[NORMAL] = false;
m_textures[NORMAL] = t;
m_isDirty = true;
}

inline Texture *get_glossiness_texture()
inline ITexture *get_glossiness_texture()
{
return m_textures[GLOSSINESS];
}
inline void set_glossiness_texture(Texture *t)
inline void set_glossiness_texture(ITexture *t)
{
m_hasGlossinessTexture = t ? true : false;
m_textureBindingState[GLOSSINESS] = false;
m_textures[GLOSSINESS] = t;
m_isDirty = true;
}
inline Texture *get_shininess_texture()
inline ITexture *get_shininess_texture()
{
return m_textures[SHININESS];
}
inline void set_shininess_texture(Texture *t)
inline void set_shininess_texture(ITexture *t)
{
m_hasGlossinessTexture = t ? true : false;
m_textureBindingState[SHININESS] = false;
Expand Down
28 changes: 14 additions & 14 deletions include/engine/core/materials/physically_based.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class PhysicallyBasedMaterial : public IMaterial
AO = 4,
};

std::unordered_map<int, Texture *> m_textures{
std::unordered_map<int, ITexture *> m_textures{
{ALBEDO, nullptr}, {NORMAL, nullptr}, {MASK_ROUGHNESS, nullptr}, {METALNESS, nullptr}, {AO, nullptr}};

std::unordered_map<int, bool> m_textureBindingState;

virtual Graphics::MaterialUniforms get_uniforms() const;
virtual inline std::unordered_map<int, Texture *> get_textures() const
virtual inline std::unordered_map<int, ITexture *> get_textures() const
{
return m_textures;
}
Expand Down Expand Up @@ -204,23 +204,23 @@ class PhysicallyBasedMaterial : public IMaterial
m_isDirty = true;
}

inline Texture *get_albedo_texture()
inline ITexture *get_albedo_texture()
{
return m_textures[ALBEDO];
}
inline void set_albedo_texture(Texture *t)
inline void set_albedo_texture(ITexture *t)
{
m_hasAlbedoTexture = t ? true : false;
m_textureBindingState[ALBEDO] = false;
m_textures[ALBEDO] = t;
m_isDirty = true;
}

inline Texture *get_normal_texture()
inline ITexture *get_normal_texture()
{
return m_textures[NORMAL];
}
inline void set_normal_texture(Texture *t)
inline void set_normal_texture(ITexture *t)
{
m_hasNormalTexture = t ? true : false;
m_textureBindingState[NORMAL] = false;
Expand All @@ -231,11 +231,11 @@ class PhysicallyBasedMaterial : public IMaterial
/*
Sets mask texture. Support for some presets of commercial game engines.
*/
inline Texture *get_mask_texture()
inline ITexture *get_mask_texture()
{
return m_textures[MASK_ROUGHNESS];
}
inline void set_mask_texture(Texture *t, MaskType preset)
inline void set_mask_texture(ITexture *t, MaskType preset)
{
m_hasMaskTexture = t ? true : false;
m_textureBindingState[MASK_ROUGHNESS] = false;
Expand All @@ -244,33 +244,33 @@ class PhysicallyBasedMaterial : public IMaterial
m_isDirty = true;
}

inline Texture *get_roughness_texture()
inline ITexture *get_roughness_texture()
{
return m_textures[MASK_ROUGHNESS];
}
inline void set_roughness_texture(Texture *t)
inline void set_roughness_texture(ITexture *t)
{
m_hasRoughnessTexture = t ? true : false;
m_textureBindingState[MASK_ROUGHNESS] = false;
m_textures[MASK_ROUGHNESS] = t;
m_isDirty = true;
}
inline Texture *get_metallic_texture()
inline ITexture *get_metallic_texture()
{
return m_textures[METALNESS];
}
inline void set_metallic_texture(Texture *t)
inline void set_metallic_texture(ITexture *t)
{
m_hasMetallicTexture = t ? true : false;
m_textureBindingState[METALNESS] = false;
m_textures[METALNESS] = t;
m_isDirty = true;
}
inline Texture *get_occlusion_texture()
inline ITexture *get_occlusion_texture()
{
return m_textures[AO];
}
inline void set_occlusion_texture(Texture *t)
inline void set_occlusion_texture(ITexture *t)
{
m_hasAOTexture = t ? true : false;
m_textureBindingState[AO] = false;
Expand Down
8 changes: 4 additions & 4 deletions include/engine/core/materials/unlit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class UnlitMaterial : public IMaterial

bool m_hasColorTexture{false};

std::unordered_map<int, Texture *> m_textures;
std::unordered_map<int, ITexture *> m_textures;
std::unordered_map<int, bool> m_textureBindingState;

virtual Graphics::MaterialUniforms get_uniforms() const;
virtual inline std::unordered_map<int, Texture *> get_textures() const
virtual inline std::unordered_map<int, ITexture *> get_textures() const
{
return m_textures;
}
Expand Down Expand Up @@ -72,12 +72,12 @@ class UnlitMaterial : public IMaterial
}

// Texture must have A channel reserved for OPACITY
inline void set_color_texture(Texture *t)
inline void set_color_texture(ITexture *t)
{
m_textures[0] = t;
m_isDirty = true;
}
inline Texture *get_color_texture()
inline ITexture *get_color_texture()
{
return m_textures[0];
}
Expand Down
3 changes: 3 additions & 0 deletions include/engine/core/renderpasses/forward_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define FORWARD_PASS_H
#include <engine/core/renderpasses/renderpass.h>
#include <engine/core/textures/texture.h>
#include <engine/core/textures/textureLDR.h>

VULKAN_ENGINE_NAMESPACE_BEGIN

Expand Down Expand Up @@ -52,6 +53,8 @@ class ForwardPass : public RenderPass
void upload_data(uint32_t frameIndex, Scene *const scene);

void connect_to_previous_images(std::vector<Graphics::Image> images);

void set_envmap_descriptor(Graphics::Image env);
};

} // namespace Core
Expand Down
5 changes: 3 additions & 2 deletions include/engine/core/renderpasses/panorama_conversion_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
#ifndef PAN_CONV_PASS_H
#define PAN_CONV_PASS_H
#include <engine/core/renderpasses/renderpass.h>
#include <engine/core/textures/textureHDR.h>

VULKAN_ENGINE_NAMESPACE_BEGIN

namespace Core
{

class PanroramaConverterPass : public RenderPass
class PanoramaConverterPass : public RenderPass
{
Graphics::DescriptorSet m_panoramaDescriptorSet;

Mesh *m_vignette;

public:
PanroramaConverterPass(Graphics::Context *ctx, Extent2D extent, Mesh *vignette)
PanoramaConverterPass(Graphics::Context *ctx, Extent2D extent, Mesh *vignette)
: RenderPass(ctx, extent, 1, 6, false), m_vignette(vignette)
{
}
Expand Down
5 changes: 5 additions & 0 deletions include/engine/core/renderpasses/renderpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ class RenderPass

#pragma endregion
#pragma region Core Functions
/*
Setups de renderpass. Init, create framebuffers, pipelines and resources ...
*/
void setup();
/*
Configures and creates the renderpass. Rendeerer will call this function when
necessary
Expand Down Expand Up @@ -218,6 +222,7 @@ class RenderPass
virtual void connect_to_previous_images(std::vector<Graphics::Image> images)
{
}

/**
* Create framebuffers and images attached to them necessary for the
* renderpass to work. It also sets the extent of the renderpass.
Expand Down
5 changes: 5 additions & 0 deletions include/engine/core/scene/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Class used to represent a 3D model instance.
*/
class Mesh : public Object3D
{
protected:
std::vector<Geometry *> m_geometry;
std::vector<IMaterial *> m_material;

Expand All @@ -73,6 +74,10 @@ class Mesh : public Object3D
static IMaterial *m_debugMaterial;
static int m_instanceCount;

Mesh(std::string name, ObjectType type) : Object3D(name, type)
{
}

public:
Mesh() : Object3D("Mesh #" + std::to_string(Mesh::m_instanceCount), MESH), m_volume(new Sphere())
{
Expand Down
Loading

0 comments on commit ad9cb04

Please sign in to comment.