Skip to content

Commit

Permalink
Refactor various Graphics/ classes with clearer names
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Aug 27, 2024
1 parent 3041060 commit fee3c80
Show file tree
Hide file tree
Showing 46 changed files with 503 additions and 495 deletions.
20 changes: 10 additions & 10 deletions src/oscar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ add_library(oscar STATIC

Graphics/Detail/CPUDataType.h
Graphics/Detail/CPUImageFormat.h
Graphics/Detail/DepthStencilFormatHelpers.h
Graphics/Detail/DepthStencilFormatList.h
Graphics/Detail/DepthStencilFormatTraits.h
Graphics/Detail/DepthStencilRenderBufferFormatHelpers.h
Graphics/Detail/DepthStencilRenderBufferFormatList.h
Graphics/Detail/DepthStencilRenderBufferFormatTraits.h
Graphics/Detail/ShaderLocations.h
Graphics/Detail/ShaderPropertyTypeList.h
Graphics/Detail/ShaderPropertyTypeTraits.h
Expand Down Expand Up @@ -104,8 +104,8 @@ add_library(oscar STATIC

Graphics/OpenGL/CPUDataTypeOpenGLTraits.h
Graphics/OpenGL/CPUImageFormatOpenGLTraits.h
Graphics/OpenGL/DepthStencilFormatOpenGLTraits.h
Graphics/OpenGL/DepthStencilFormatOpenGLHelpers.h
Graphics/OpenGL/DepthStencilRenderBufferFormatOpenGLTraits.h
Graphics/OpenGL/DepthStencilRenderBufferFormatOpenGLHelpers.h
Graphics/OpenGL/Gl.cpp
Graphics/OpenGL/Gl.h
Graphics/OpenGL/TextureFormatOpenGLTraits.h
Expand Down Expand Up @@ -139,15 +139,16 @@ add_library(oscar STATIC
Graphics/Color.h
Graphics/ColorHSLA.h
Graphics/ColorHSLA.cpp
Graphics/ColorRenderBufferFormat.h
Graphics/ColorRenderBufferParams.h
Graphics/ColorSpace.h
Graphics/Color32.h
Graphics/Cubemap.h
Graphics/CubemapFace.h
Graphics/CullMode.h
Graphics/DepthFunction.h
Graphics/DepthRenderBufferParams.h
Graphics/DepthStencilFormat.h
Graphics/DepthStencilRenderBufferFormat.h
Graphics/DepthStencilRenderBufferParams.h
Graphics/DestinationBlendingFactor.h
Graphics/Geometries.h
Graphics/Graphics.h
Expand All @@ -167,16 +168,15 @@ add_library(oscar STATIC
Graphics/RenderTarget.cpp
Graphics/RenderTarget.h
Graphics/RenderTargetColorAttachment.h
Graphics/RenderTargetDepthAttachment.h
Graphics/RenderTargetDepthStencilAttachment.h
Graphics/RenderTexture.h
Graphics/RenderTextureFormat.h
Graphics/RenderTextureParams.h
Graphics/RenderTextureReadWrite.h
Graphics/Scene.h
Graphics/Shader.h
Graphics/ShaderPropertyType.h
Graphics/SharedColorRenderBuffer.h
Graphics/SharedDepthRenderBuffer.h
Graphics/SharedDepthStencilRenderBuffer.h
Graphics/Snorm.h
Graphics/Snorm8.h
Graphics/SourceBlendingFactor.h
Expand Down
10 changes: 5 additions & 5 deletions src/oscar/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
#include <oscar/Graphics/CameraProjection.h>
#include <oscar/Graphics/Color.h>
#include <oscar/Graphics/ColorHSLA.h>
#include <oscar/Graphics/ColorRenderBufferFormat.h>
#include <oscar/Graphics/ColorRenderBufferParams.h>
#include <oscar/Graphics/ColorSpace.h>
#include <oscar/Graphics/Color32.h>
#include <oscar/Graphics/Cubemap.h>
#include <oscar/Graphics/CubemapFace.h>
#include <oscar/Graphics/CullMode.h>
#include <oscar/Graphics/DepthFunction.h>
#include <oscar/Graphics/DepthRenderBufferParams.h>
#include <oscar/Graphics/DepthStencilFormat.h>
#include <oscar/Graphics/DepthStencilRenderBufferFormat.h>
#include <oscar/Graphics/DepthStencilRenderBufferParams.h>
#include <oscar/Graphics/DestinationBlendingFactor.h>
#include <oscar/Graphics/Geometries.h>
#include <oscar/Graphics/Graphics.h>
Expand All @@ -34,16 +35,15 @@
#include <oscar/Graphics/RenderBufferStoreAction.h>
#include <oscar/Graphics/RenderTarget.h>
#include <oscar/Graphics/RenderTargetColorAttachment.h>
#include <oscar/Graphics/RenderTargetDepthAttachment.h>
#include <oscar/Graphics/RenderTargetDepthStencilAttachment.h>
#include <oscar/Graphics/RenderTexture.h>
#include <oscar/Graphics/RenderTextureFormat.h>
#include <oscar/Graphics/RenderTextureParams.h>
#include <oscar/Graphics/RenderTextureReadWrite.h>
#include <oscar/Graphics/Scene.h>
#include <oscar/Graphics/Shader.h>
#include <oscar/Graphics/ShaderPropertyType.h>
#include <oscar/Graphics/SharedColorRenderBuffer.h>
#include <oscar/Graphics/SharedDepthRenderBuffer.h>
#include <oscar/Graphics/SharedDepthStencilRenderBuffer.h>
#include <oscar/Graphics/Snorm.h>
#include <oscar/Graphics/Snorm8.h>
#include <oscar/Graphics/SourceBlendingFactor.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace osc
{
// format of the "color" (albedo) part of a render
enum class RenderTextureFormat {
enum class ColorRenderBufferFormat {
Red8, // careful: `Red8` has previously caused an explosion on some Intel machines (#418)
ARGB32,

Expand All @@ -20,5 +20,5 @@ namespace osc
DefaultHDR = ARGBFloat16,
};

std::ostream& operator<<(std::ostream&, RenderTextureFormat);
std::ostream& operator<<(std::ostream&, ColorRenderBufferFormat);
}
4 changes: 2 additions & 2 deletions src/oscar/Graphics/ColorRenderBufferParams.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <oscar/Graphics/AntiAliasingLevel.h>
#include <oscar/Graphics/RenderTextureFormat.h>
#include <oscar/Graphics/ColorRenderBufferFormat.h>
#include <oscar/Graphics/RenderTextureReadWrite.h>
#include <oscar/Graphics/TextureDimensionality.h>
#include <oscar/Maths/Vec2.h>
Expand All @@ -14,7 +14,7 @@ namespace osc
Vec2i dimensions = {1, 1};
TextureDimensionality dimensionality = TextureDimensionality::Tex2D;
AntiAliasingLevel anti_aliasing_level = AntiAliasingLevel{1};
RenderTextureFormat format = RenderTextureFormat::Default;
ColorRenderBufferFormat format = ColorRenderBufferFormat::Default;
RenderTextureReadWrite read_write = RenderTextureReadWrite::Default;
};
}
16 changes: 0 additions & 16 deletions src/oscar/Graphics/DepthStencilFormat.h

This file was deleted.

23 changes: 23 additions & 0 deletions src/oscar/Graphics/DepthStencilRenderBufferFormat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <iosfwd>

namespace osc
{
enum class DepthStencilRenderBufferFormat {

// two-component, 32-bit packed, with 24 unsigned normalized bits for
// the depth (D) component and 8 unsigned integer bits for the stencil (S)
// component
D24_UNorm_S8_UInt,

// 32-bit signed floating point format for the depth (D) component
D32_SFloat,

NUM_OPTIONS,

Default = D24_UNorm_S8_UInt,
};

std::ostream& operator<<(std::ostream&, DepthStencilRenderBufferFormat);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#pragma once

#include <oscar/Graphics/AntiAliasingLevel.h>
#include <oscar/Graphics/DepthStencilFormat.h>
#include <oscar/Graphics/DepthStencilRenderBufferFormat.h>
#include <oscar/Graphics/RenderTextureReadWrite.h>
#include <oscar/Graphics/TextureDimensionality.h>
#include <oscar/Maths/Vec2.h>

namespace osc
{
struct DepthRenderBufferParams final {
struct DepthStencilRenderBufferParams final {

friend bool operator==(const DepthRenderBufferParams&, const DepthRenderBufferParams&) = default;
friend bool operator==(const DepthStencilRenderBufferParams&, const DepthStencilRenderBufferParams&) = default;

Vec2i dimensions = {1, 1};
TextureDimensionality dimensionality = TextureDimensionality::Tex2D;
AntiAliasingLevel anti_aliasing_level = AntiAliasingLevel{1};
DepthStencilFormat format = DepthStencilFormat::Default;
DepthStencilRenderBufferFormat format = DepthStencilRenderBufferFormat::Default;
};
}
48 changes: 0 additions & 48 deletions src/oscar/Graphics/Detail/DepthStencilFormatHelpers.h

This file was deleted.

12 changes: 0 additions & 12 deletions src/oscar/Graphics/Detail/DepthStencilFormatList.h

This file was deleted.

48 changes: 48 additions & 0 deletions src/oscar/Graphics/Detail/DepthStencilRenderBufferFormatHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <oscar/Graphics/Detail/CPUDataType.h>
#include <oscar/Graphics/Detail/CPUImageFormat.h>
#include <oscar/Graphics/Detail/DepthStencilRenderBufferFormatList.h>
#include <oscar/Graphics/Detail/DepthStencilRenderBufferFormatTraits.h>
#include <oscar/Utils/CStringView.h>

#include <array>

namespace osc::detail
{
constexpr bool has_stencil_component(DepthStencilRenderBufferFormat format)
{
constexpr auto lut = []<DepthStencilRenderBufferFormat... Formats>(OptionList<DepthStencilRenderBufferFormat, Formats...>) {
return std::to_array({ DepthStencilRenderBufferFormatTraits<Formats>::has_stencil_component... });
}(DepthStencilRenderBufferFormatList{});

return lut.at(to_index(format));
}

constexpr CStringView get_label(DepthStencilRenderBufferFormat format)
{
constexpr auto lut = []<DepthStencilRenderBufferFormat... Formats>(OptionList<DepthStencilRenderBufferFormat, Formats...>) {
return std::to_array({ DepthStencilRenderBufferFormatTraits<Formats>::label... });
}(DepthStencilRenderBufferFormatList{});

return lut.at(to_index(format));
}

constexpr CPUImageFormat equivalent_cpu_image_format_of(DepthStencilRenderBufferFormat format)
{
constexpr auto lut = []<DepthStencilRenderBufferFormat... Formats>(OptionList<DepthStencilRenderBufferFormat, Formats...>) {
return std::to_array({ DepthStencilRenderBufferFormatTraits<Formats>::equivalent_cpu_image_format... });
}(DepthStencilRenderBufferFormatList{});

return lut.at(to_index(format));
}

constexpr CPUDataType equivalent_cpu_datatype_of(DepthStencilRenderBufferFormat format)
{
constexpr auto lut = []<DepthStencilRenderBufferFormat... Formats>(OptionList<DepthStencilRenderBufferFormat, Formats...>) {
return std::to_array({ DepthStencilRenderBufferFormatTraits<Formats>::equivalent_cpu_datatype... });
}(DepthStencilRenderBufferFormatList{});

return lut.at(to_index(format));
}
}
12 changes: 12 additions & 0 deletions src/oscar/Graphics/Detail/DepthStencilRenderBufferFormatList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <oscar/Graphics/DepthStencilRenderBufferFormat.h>
#include <oscar/Utils/EnumHelpers.h>

namespace osc::detail
{
using DepthStencilRenderBufferFormatList = OptionList<DepthStencilRenderBufferFormat,
DepthStencilRenderBufferFormat::D24_UNorm_S8_UInt,
DepthStencilRenderBufferFormat::D32_SFloat
>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

#include <oscar/Graphics/Detail/CPUDataType.h>
#include <oscar/Graphics/Detail/CPUImageFormat.h>
#include <oscar/Graphics/DepthStencilFormat.h>
#include <oscar/Graphics/DepthStencilRenderBufferFormat.h>
#include <oscar/Utils/CStringView.h>

namespace osc::detail
{
template<DepthStencilFormat>
struct DepthStencilFormatTraits;
template<DepthStencilRenderBufferFormat>
struct DepthStencilRenderBufferFormatTraits;

template<>
struct DepthStencilFormatTraits<DepthStencilFormat::D24_UNorm_S8_UInt> final {
struct DepthStencilRenderBufferFormatTraits<DepthStencilRenderBufferFormat::D24_UNorm_S8_UInt> final {
static inline constexpr bool has_stencil_component = true;
static inline constexpr CStringView label = "D24_UNorm_S8_UInt";
static inline constexpr CPUImageFormat equivalent_cpu_image_format = CPUImageFormat::DepthStencil;
static inline constexpr CPUDataType equivalent_cpu_datatype = CPUDataType::UnsignedInt24_8;
};

template<>
struct DepthStencilFormatTraits<DepthStencilFormat::D32_SFloat> final {
struct DepthStencilRenderBufferFormatTraits<DepthStencilRenderBufferFormat::D32_SFloat> final {
static inline constexpr bool has_stencil_component = false;
static inline constexpr CStringView label = "D32_SFloat";
static inline constexpr CPUImageFormat equivalent_cpu_image_format = CPUImageFormat::Depth;
Expand Down
Loading

0 comments on commit fee3c80

Please sign in to comment.