Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
GHI.h
Go to the documentation of this file.
1#pragma once
2
5#include "RenderCore/Shader.h"
9#include "RenderCore/Mesh.h"
10
11#include <Utility/INoCopyAndMove.h>
12#include <Common/logging.h>
13#include <Common/assertion.h>
14#include <Common/primitive_type.h>
15#include <Math/math_fwd.h>
16#include <Utility/TSpan.h>
17
18#include <cstddef>
19#include <type_traits>
20#include <source_location>
21#include <string>
22#include <memory>
23
24namespace ph::editor::ghi
25{
26
28
29class Mesh;
30
34class GHI : private INoCopyAndMove
35{
36public:
37 static std::string toString(EGraphicsAPI apiType);
38
39public:
40 explicit GHI(EGraphicsAPI apiType);
41 virtual ~GHI();
42
47 virtual void load() = 0;
48
53 virtual void unload() = 0;
54
61 virtual void setViewport(uint32 xPx, uint32 yPx, uint32 widthPx, uint32 heightPx) = 0;
62
63 virtual void clearBuffer(EClearTarget target) = 0;
64
65 virtual void setClearColor(const math::Vector4F& color) = 0;
66
67 virtual void draw(Mesh& mesh, EMeshDrawMode drawMode) = 0;
68
69 virtual void swapBuffers() = 0;
70
74 virtual bool tryUploadPixelData(
75 TextureHandle handle,
76 TSpanView<std::byte> pixelData,
77 EPixelFormat pixelFormat,
78 EPixelComponent pixelComponent) = 0;
79
81 TextureHandle handle,
82 const math::Vector2UI& regionOriginPx,
83 const math::Vector2UI& regionSizePx,
84 TSpanView<std::byte> pixelData,
85 EPixelFormat pixelFormat,
86 EPixelComponent pixelComponent) = 0;
87
89
91 uint32 attachmentIdx,
92 TextureHandle textureHandle,
93 FramebufferHandle framebufferHandle) = 0;
94
95 virtual std::shared_ptr<Shader> createShader(
96 std::string name,
97 EShadingStage shadingStage,
98 std::string shaderSource) = 0;
99
100 virtual std::shared_ptr<ShaderProgram> createShaderProgram(
101 std::string name,
102 const ShaderSetInfo& shaders) = 0;
103
104 virtual std::shared_ptr<VertexStorage> createVertexStorage(
105 const VertexGroupFormatInfo& format,
106 std::size_t numVertices,
107 EStorageUsage usage) = 0;
108
109 virtual std::shared_ptr<IndexStorage> createIndexStorage(
110 EStorageElement indexType,
111 std::size_t numIndices,
112 EStorageUsage usage) = 0;
113
114 virtual std::shared_ptr<Mesh> createMesh(
115 const MeshVertexLayoutInfo& layout,
116 TSpanView<std::shared_ptr<VertexStorage>> vertexStorages,
117 const std::shared_ptr<IndexStorage>& indexStorage) = 0;
118
120
121 template<EGraphicsAPI API_TYPE, typename CommandCallingFunctor>
122 void rawCommand(
123 CommandCallingFunctor functor,
124 std::source_location srcLocation = std::source_location::current());
125
126private:
132 virtual void beginRawCommand() = 0;
133 virtual void endRawCommand() = 0;
135
136 EGraphicsAPI m_apiType;
137};
138
139template<EGraphicsAPI API_TYPE, typename CommandCallingFunctor>
140inline void GHI::rawCommand(
141 CommandCallingFunctor functor,
142 const std::source_location srcLocation)
143{
144 static_assert(std::is_invocable_v<CommandCallingFunctor>,
145 "must be callable without any argument");
146
147 if(API_TYPE != m_apiType)
148 {
149 PH_LOG(GHI, Error,
150 "cannot call raw command of type {} under current GHI type {}, "
151 "skipping command at {}({}:{})",
152 toString(API_TYPE), toString(m_apiType), srcLocation.file_name(), srcLocation.line(), srcLocation.column());
153
154 return;
155 }
156
157 beginRawCommand();
158 functor();
159 endRawCommand();
160}
161
162}// end namespace ph::editor::ghi
Definition ghi_infos.h:88
Graphics API abstraction.
Definition GHI.h:35
virtual std::shared_ptr< IndexStorage > createIndexStorage(EStorageElement indexType, std::size_t numIndices, EStorageUsage usage)=0
virtual void setClearColor(const math::Vector4F &color)=0
void rawCommand(CommandCallingFunctor functor, std::source_location srcLocation=std::source_location::current())
Definition GHI.h:140
virtual void attachTextureToFramebuffer(uint32 attachmentIdx, TextureHandle textureHandle, FramebufferHandle framebufferHandle)=0
virtual TextureNativeHandle tryGetTextureNativeHandle(TextureHandle handle)=0
virtual DeviceCapabilityInfo getDeviceCapabilities()
Definition GHI.cpp:28
virtual std::shared_ptr< Shader > createShader(std::string name, EShadingStage shadingStage, std::string shaderSource)=0
virtual void load()=0
Load and initiate the GHI. load() and unload() must be called on the same thread. All remaining metho...
virtual std::shared_ptr< Mesh > createMesh(const MeshVertexLayoutInfo &layout, TSpanView< std::shared_ptr< VertexStorage > > vertexStorages, const std::shared_ptr< IndexStorage > &indexStorage)=0
virtual bool tryUploadPixelDataTo2DRegion(TextureHandle handle, const math::Vector2UI &regionOriginPx, const math::Vector2UI &regionSizePx, TSpanView< std::byte > pixelData, EPixelFormat pixelFormat, EPixelComponent pixelComponent)=0
virtual void swapBuffers()=0
static std::string toString(EGraphicsAPI apiType)
Definition GHI.cpp:9
virtual void clearBuffer(EClearTarget target)=0
virtual void unload()=0
Unload and clean up the GHI. Must be called on the same thread as load(). See load() for more informa...
virtual void draw(Mesh &mesh, EMeshDrawMode drawMode)=0
GHI(EGraphicsAPI apiType)
Definition GHI.cpp:22
virtual std::shared_ptr< VertexStorage > createVertexStorage(const VertexGroupFormatInfo &format, std::size_t numVertices, EStorageUsage usage)=0
virtual std::shared_ptr< ShaderProgram > createShaderProgram(std::string name, const ShaderSetInfo &shaders)=0
virtual bool tryUploadPixelData(TextureHandle handle, TSpanView< std::byte > pixelData, EPixelFormat pixelFormat, EPixelComponent pixelComponent)=0
Try to upload pixel data to a texture.
virtual void setViewport(uint32 xPx, uint32 yPx, uint32 widthPx, uint32 heightPx)=0
Set how NDC corresponds to pixels on the display.
Definition Mesh.h:42
Definition ghi_infos.h:46
Definition PlatformDisplay.h:13
EPixelFormat
Definition ghi_enums.h:31
std::variant< std::monostate, uint64 > TextureNativeHandle
Definition ghi_fwd.h:52
EStorageElement
Definition ghi_enums.h:70
EClearTarget
Definition EClearTarget.h:11
EShadingStage
Definition ghi_enums.h:104
EStorageUsage
Definition ghi_enums.h:86
EMeshDrawMode
Definition ghi_enums.h:93
EGraphicsAPI
Definition EGraphicsAPI.h:7
EPixelComponent
Definition ghi_enums.h:42
PH_DECLARE_LOG_GROUP(GHI)