23#ifndef VCL_BGFX_DRAWABLE_DRAWABLE_ENVIRONMENT_H
24#define VCL_BGFX_DRAWABLE_DRAWABLE_ENVIRONMENT_H
26#include <vclib/bgfx/buffers.h>
27#include <vclib/bgfx/texture.h>
28#include <vclib/bgfx/uniform.h>
29#include <vclib/render/settings/pbr_viewer_settings.h>
31#include <vclib/base.h>
35#include <bx/allocator.h>
48 enum class FileFormat { UNKNOWN, HDR, EXR, KTX, DDS };
51 static const uint BRDF_LU_TEXTURE_SIZE = 1024;
54 const Uniform mHdrSamplerUniform =
55 Uniform(
"s_hdr", bgfx::UniformType::Sampler);
57 const Uniform mEnvCubeSamplerUniform =
58 Uniform(
"s_env0", bgfx::UniformType::Sampler);
60 const Uniform mIrradianceCubeSamplerUniform =
61 Uniform(
"s_irradiance", bgfx::UniformType::Sampler);
63 const Uniform mSpecularCubeSamplerUniform =
64 Uniform(
"s_specular", bgfx::UniformType::Sampler);
66 const Uniform mBrdfLutSamplerUniform =
67 Uniform(
"s_brdf_lut", bgfx::UniformType::Sampler);
70 std::string mImagePath;
114 enum class TextureType { RAW_CUBE, IRRADIANCE, SPECULAR, BRDF_LUT };
124 ~DrawableEnvironment() =
default;
126 DrawableEnvironment& operator=(
const DrawableEnvironment& other) =
delete;
128 DrawableEnvironment& operator=(DrawableEnvironment&& other)
134 void swap(DrawableEnvironment& other)
137 swap(mImagePath, other.mImagePath);
138 swap(mSpecularMipLevels, other.mSpecularMipLevels);
139 swap(mHdrTexture, other.mHdrTexture);
140 swap(mCubeMapTexture, other.mCubeMapTexture);
141 swap(mIrradianceTexture, other.mIrradianceTexture);
142 swap(mSpecularTexture, other.mSpecularTexture);
143 swap(mBrdfLuTexture, other.mBrdfLuTexture);
146 friend void swap(DrawableEnvironment& first, DrawableEnvironment& second)
151 const std::string& imagePath()
const {
return mImagePath; }
153 std::string imageFileName()
const
158 uint8_t specularMipLevels()
const {
return mSpecularMipLevels; }
160 void drawBackground(uint viewId,
const PBRViewerSettings& settings)
const;
165 uint samplerFlags = BGFX_SAMPLER_UVW_CLAMP)
const;
176 bimg::ImageContainer*
loadImage(std::string imagePath);
181 const bimg::ImageContainer&
image,
A class representing an environment for PBR rendering.
Definition drawable_environment.h:46
FileFormat getFileFormat(const std::string &imagePath)
Determines the file format of the given image based on its extension.
Definition drawable_environment.cpp:126
void setAndGenerateTextures(const bimg::ImageContainer &image, uint viewId)
Sets up the environment textures based on the given image.
Definition drawable_environment.cpp:215
void generateTextures(const bimg::ImageContainer &image, uint cubeSide, uint8_t cubeMips, uint viewId)
Generates the necessary environment textures (cubemap, irradiance map, specular map,...
Definition drawable_environment.cpp:302
static vcl::VertexBuffer fullScreenTriangle()
Sets and returns the buffer for the full-screen triangle for background drawing.
Definition drawable_environment.cpp:438
void bindTexture(TextureType type, uint stage, uint samplerFlags=BGFX_SAMPLER_UVW_CLAMP) const
Binds the specified environment texture to the given texture stage.
Definition drawable_environment.cpp:91
TextureType
Types of environment textures managed by the DrawableEnvironment class.
Definition drawable_environment.h:114
void drawBackground(uint viewId, const PBRViewerSettings &settings) const
Draws the environment in the background.
Definition drawable_environment.cpp:65
bimg::ImageContainer * loadImage(std::string imagePath)
Loads the image from the specified file path.
Definition drawable_environment.cpp:148
bool canDraw() const
Checks if the environment is ready to be drawn.
Definition drawable_environment.h:171
static std::string fileNameWithExtension(const std::string &fullpath)
Get the filename with extension of a file.
Definition file_info.h:240
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
Manages a BGFX texture.
Definition texture.h:45
bool isValid() const
Checks if the Texture holds valid BGFX texture handle.
Definition texture.h:133
The VertexBuffer manages the lifetime of a bgfx::VertexBufferHandle.
Definition vertex_buffer.h:43
constexpr uint UINT_NULL
The UINT_NULL value represent a null value of uint that is the maximum value that can be represented ...
Definition base.h:49