12#include <unordered_map>
13#include <unordered_set>
249 std::shared_ptr<RenderTarget>
backBuffer()
const {
return _backBuffer; }
252 virtual void draw(
const Primitive& primitive,
const std::shared_ptr<IndexBuffer>& indexBuffer =
nullptr,
253 int numInstances = 1,
int indirectSlot = -1,
bool first =
true,
bool last =
true) = 0;
256 const Vector3& cameraPosition,
bool enableNormalMaps,
float exposure,
258 int toneMapping = 0) {}
260 const Vector3& skyDomeCenter =
Vector3(0,0,0),
bool isDome =
false,
261 Texture* skyboxCubeMap =
nullptr) {}
274 const std::string& sourceCode =
"");
278 void setVertexBuffer(
const std::shared_ptr<VertexBuffer>& vertexBuffer,
const size_t slot = 0)
293 virtual void setDepthBias(
float depthBias,
float slopeScale,
float clamp) {}
312 const void* cellData,
size_t cellSize)
323 const float* cellsCountByBoundsSize,
324 int cellsX,
int cellsY,
int cellsZ,
int maxLightsPerCell,
325 int numClusteredLights)
329 (void)cellsCountByBoundsSize;
333 (void)maxLightsPerCell;
334 (void)numClusteredLights;
339 void setStencilState(
const std::shared_ptr<StencilParameters>& stencilFront =
nullptr,
340 const std::shared_ptr<StencilParameters>& stencilBack =
nullptr)
363 float vx()
const {
return _vx; }
364 float vy()
const {
return _vy; }
365 float vw()
const {
return _vw; }
366 float vh()
const {
return _vh; }
367 int sx()
const {
return _sx; }
368 int sy()
const {
return _sy; }
369 int sw()
const {
return _sw; }
370 int sh()
const {
return _sh; }
374 if (slot < _quadTextureBindings.size()) {
375 _quadTextureBindings[slot] = texture;
380 _quadTextureBindings.fill(
nullptr);
386 return slot < _quadTextureBindings.size() ? _quadTextureBindings[slot] :
nullptr;
405 virtual std::shared_ptr<VertexBuffer>
createVertexBuffer(
const std::shared_ptr<VertexFormat>& format,
409 const std::vector<uint8_t>& data = {}) = 0;
416 virtual std::pair<int, int>
size()
const = 0;
463 const std::shared_ptr<VertexFormat>& format,
464 int numVertices,
void* nativeBuffer) { (void)nativeBuffer;
return nullptr; }
469 const Matrix4& viewProjectionPrevious,
const Matrix4& viewProjectionInverse,
470 const std::array<float, 4>& jitters,
const std::array<float, 4>& cameraParams,
471 bool highQuality,
bool historyValid) {}
477 virtual void computeDispatch(
const std::vector<Compute*>& computes,
const std::string& label =
"") {}
481 _textures.push_back(texture);
490 const auto it = _shaderCache.find(name);
491 return it != _shaderCache.end() ? it->second :
nullptr;
495 _shaderCache[name] = shader;
501 void setBackBuffer(
const std::shared_ptr<RenderTarget>& target) { _backBuffer = target; }
531 int _renderPassIndex;
537 std::shared_ptr<RenderTarget> _backBuffer;
539 std::shared_ptr<VertexBuffer> _quadVertexBuffer;
540 std::array<Texture*, 8> _quadTextureBindings{};
541 bool _quadRenderActive =
false;
542 bool _hdrPass =
false;
543 bool _atmosphereEnabled =
false;
553 std::shared_ptr<DynamicBuffers> _dynamicBuffers;
555 std::shared_ptr<GpuProfiler> _gpuProfiler;
559 float _maxPixelRatio;
561 int _shaderSwitchesPerFrame = 0;
562 int _drawCallsPerFrame = 0;
564 int _renderTargetCreationTime = 0;
566 bool _contextLost =
false;
568 std::pair<int, int> _clientRect;
570 std::unordered_set<std::map<void*, void*>*> _mapsToClear;
572 std::vector<VertexBuffer*> _buffers;
574 std::vector<int> _primsPerFrame;
578 std::unordered_set<RenderTarget*> _targets;
582 std::vector<std::shared_ptr<Texture>> _textures;
584 Texture* _sceneDepthMap =
nullptr;
585 Texture* _reflectionMap =
nullptr;
586 Texture* _reflectionDepthMap =
nullptr;
587 Texture* _ssaoForwardTexture =
nullptr;
590 std::unordered_map<std::string, std::shared_ptr<Shader>> _shaderCache;
Abstract GPU interface for resource creation, state management, and draw submission.
virtual std::shared_ptr< Shader > createShader(const ShaderDefinition &definition, const std::string &sourceCode="")
void setCachedShader(const std::string &name, const std::shared_ptr< Shader > &shader)
std::shared_ptr< RenderTarget > renderTarget() const
void setHdrPass(bool hdr)
void setSsaoForwardTexture(Texture *tex)
Texture * reflectionMap() const
void removeTarget(RenderTarget *target)
virtual void onFrameStart()
virtual void setAtmosphereUniforms(const void *data, size_t size)
virtual void executeDofBlurPass(const DofBlurPassParams ¶ms)
std::shared_ptr< StencilParameters > _stencilBack
Texture * quadTextureBinding(const size_t slot) const
virtual void computeDispatch(const std::vector< Compute * > &computes, const std::string &label="")
void setShader(const std::shared_ptr< Shader > &shader)
virtual bool supportsCompute() const
std::shared_ptr< Shader > getCachedShader(const std::string &name) const
virtual void setTransformUniforms(const Matrix4 &viewProjection, const Matrix4 &model)
bool atmosphereEnabled() const
virtual void executeComposePass(const ComposePassParams ¶ms)
void setRenderTarget(const std::shared_ptr< RenderTarget > &target)
void setSceneDepthMap(Texture *depthMap)
const Material * _material
void setStencilState(const std::shared_ptr< StencilParameters > &stencilFront=nullptr, const std::shared_ptr< StencilParameters > &stencilBack=nullptr)
void setMaterial(const Material *material)
virtual void endRenderPass(RenderPass *renderPass)=0
std::shared_ptr< RenderTarget > backBuffer() const
void setVertexBuffer(const std::shared_ptr< VertexBuffer > &vertexBuffer, const size_t slot=0)
const ReflectionBlurParams & reflectionBlurParams() const
void setBackBuffer(const std::shared_ptr< RenderTarget > &target)
void setBlendState(const std::shared_ptr< BlendState > &blendState)
int drawCallsPerFrame() const
Texture * reflectionDepthMap() const
void recordDrawCall(int count=1)
virtual void setLightingUniforms(const Color &ambientColor, const std::vector< GpuLightData > &lights, const Vector3 &cameraPosition, bool enableNormalMaps, float exposure, const FogParams &fogParams=FogParams{}, const ShadowParams &shadowParams=ShadowParams{}, int toneMapping=0)
virtual void executeCoCPass(const CoCPassParams ¶ms)
void setAtmosphereEnabled(bool value)
Enable/disable atmosphere scattering for the current frame.
virtual void executeDepthAwareBlurPass(const DepthAwareBlurPassParams ¶ms, bool horizontal)
void setCullMode(const CullMode cullMode)
virtual void setDynamicBatchPalette(const void *data, size_t size)
virtual std::unique_ptr< gpu::HardwareTexture > createGPUTexture(Texture *texture)=0
virtual void setClusterGridParams(const float *boundsMin, const float *boundsRange, const float *cellsCountByBoundsSize, int cellsX, int cellsY, int cellsZ, int maxLightsPerCell, int numClusteredLights)
void setReflectionDepthMap(Texture *tex)
virtual void onFrameEnd()
virtual std::pair< int, int > size() const =0
virtual std::shared_ptr< IndexBuffer > createIndexBuffer(IndexFormat format, int numIndices, const std::vector< uint8_t > &data={})=0
void resetDrawCallsPerFrame()
const std::array< Texture *, 8 > & quadTextureBindings() const
virtual void executeSsaoPass(const SsaoPassParams ¶ms)
virtual void startRenderPass(RenderPass *renderPass)=0
std::shared_ptr< StencilParameters > _stencilFront
std::shared_ptr< RenderTarget > _renderTarget
virtual ~GraphicsDevice()
virtual void setDepthBias(float depthBias, float slopeScale, float clamp)
virtual void executeTAAPass(Texture *sourceTexture, Texture *historyTexture, Texture *depthTexture, const Matrix4 &viewProjectionPrevious, const Matrix4 &viewProjectionInverse, const std::array< float, 4 > &jitters, const std::array< float, 4 > &cameraParams, bool highQuality, bool historyValid)
virtual void setScissor(int x, int y, int w, int h)
virtual void setIndirectDrawBuffer(void *nativeBuffer)
std::shared_ptr< Shader > _shader
virtual void setEnvironmentUniforms(Texture *envAtlas, float skyboxIntensity, float skyboxMip, const Vector3 &skyDomeCenter=Vector3(0, 0, 0), bool isDome=false, Texture *skyboxCubeMap=nullptr)
friend class VertexBuffer
void setReflectionMap(Texture *tex)
bool quadRenderActive() const
void setQuadRenderActive(const bool active)
CullMode cullMode() const
virtual std::shared_ptr< RenderTarget > createRenderTarget(const RenderTargetOptions &options)=0
virtual void setResolution(int width, int height)=0
void setDepthState(const std::shared_ptr< DepthState > &depthState)
void resizeCanvas(int width, int height)
void setQuadTextureBinding(const size_t slot, Texture *texture)
void addTexture(const std::shared_ptr< Texture > &texture)
Texture * ssaoForwardTexture() const
std::vector< std::shared_ptr< VertexBuffer > > _vertexBuffers
virtual void setViewport(float x, float y, float w, float h)
virtual void draw(const Primitive &primitive, const std::shared_ptr< IndexBuffer > &indexBuffer=nullptr, int numInstances=1, int indirectSlot=-1, bool first=true, bool last=true)=0
void setReflectionBlurParams(const ReflectionBlurParams ¶ms)
std::shared_ptr< BlendState > _blendState
void clearQuadTextureBindings()
virtual std::shared_ptr< VertexBuffer > createVertexBuffer(const std::shared_ptr< VertexFormat > &format, int numVertices, const VertexBufferOptions &options=VertexBufferOptions{})=0
virtual void setClusterBuffers(const void *lightData, size_t lightSize, const void *cellData, size_t cellSize)
bool insideRenderPass() const
const Material * material() const
std::shared_ptr< VertexBuffer > quadVertexBuffer()
std::shared_ptr< DepthState > _depthState
int renderVersion() const
virtual std::shared_ptr< VertexBuffer > createVertexBufferFromNativeBuffer(const std::shared_ptr< VertexFormat > &format, int numVertices, void *nativeBuffer)
Texture * sceneDepthMap() const
Base class for GPU materials — owns uniform data, texture bindings, blend/depth state,...
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
RGBA color with floating-point components in [0, 1].
float sourceInvResolutionY
float sourceInvResolutionX
Per-light GPU data uploaded to the lighting uniform buffer.
4x4 column-major transformation matrix with SIMD acceleration.
static Matrix4 identity()
Describes how vertex and index data should be interpreted for a draw call.
struct visutwin::canvas::ShadowParams::LocalShadow localShadows[kMaxLocalShadows]
static constexpr int kMaxLocalShadows
float shadowMatrixPalette[64]
float shadowCascadeDistances[4]
float projectionScaleRadius
float minHorizonAngleSineSquared
3D vector for positions, directions, and normals with multi-backend SIMD acceleration.