载入中...
搜索中...
未找到
Canvas.h
浏览该文件的文档.
1#pragma once
2
3#include "graphics/Canvas.h"
4#include "graphics/Texture.h"
6#include "vkbuilder.hpp"
7#include <memory>
8#include <optional>
9#include <vector>
10#include <cstdint>
11
12namespace eve::graphics::vulkan {
13
16public:
18 OffscreenCanvas(Graphics *owner, int width, int height, bool hdr = false);
20 ~OffscreenCanvas() override;
21
23 int getWidth() const override { return width; }
25 int getHeight() const override { return height; }
27 Texture *getTexture() override { return &sampleTexture; }
28
30 void clear(std::optional<Color> color, std::optional<int> stencil,
31 std::optional<double> depth) override;
33 Color getPixel(int x, int y) override;
39
41 void draw(eve::graphics::Graphics*, const glm::mat4&) const override {}
43 void draw(Canvas*, const glm::mat4&) const override {}
44
46 vk::Framebuffer framebuffer() const { return fb; }
48 vk::Framebuffer framebuffer3D() const { return fb3D; }
50 vkb::ColorAttachmentImage &colorImage() { return color; }
52 vkb::DepthTarget &depthImage() { return depth; }
54 Color pendingClearColor() const { return clearColor; }
56 bool takePendingClear();
58 bool isHDR() const { return hdr; }
60 Graphics *owningGraphics() const { return owner; }
61
63 void ensure3D();
64
65private:
66 void readAllPixels(std::vector<uint8_t> &outRgba);
67 void readAllHDRPixels(std::vector<uint8_t> &outRgba16f);
68
69 Graphics *owner = nullptr;
70 int width = 0;
71 int height = 0;
72 vkb::ColorAttachmentImage color;
73 vk::Framebuffer fb = nullptr;
74 vkb::DepthTarget depth;
75 vk::Framebuffer fb3D = nullptr;
76 GpuTexture sampleGpu;
77 Texture sampleTexture;
78
79 Color clearColor{0.f, 0.f, 0.f, 1.f};
80 bool hasPendingClear = true;
81 bool hdr = false;
82};
83
84} // namespace eve::graphics::vulkan
double y
double x
std::uint32_t height
std::uint32_t width
std::shared_ptr< OceanGpuSpectrum > owner
Canvas public API.
Definition Canvas.h:17
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
EVENGINE_API_BACKENDS public API.
Definition Graphics.h:360
OffscreenCanvas public API.
Definition Canvas.h:15
Graphics * owningGraphics() const
Borrow the creating Graphics; valid only while this canvas is alive.
Definition Canvas.h:60
vkb::ColorAttachmentImage & colorImage()
Color image.
Definition Canvas.h:50
vkb::DepthTarget & depthImage()
Depth image.
Definition Canvas.h:52
int getHeight() const override
Returns the height.
Definition Canvas.h:25
Color pendingClearColor() const
Pending clear color.
Definition Canvas.h:54
Color getPixel(int x, int y) override
Returns the pixel.
Definition Canvas.cpp:158
Texture * getTexture() override
Returns the texture.
Definition Canvas.h:27
int getWidth() const override
Returns the width.
Definition Canvas.h:23
~OffscreenCanvas() override
Releases OffscreenCanvas resources.
Definition Canvas.cpp:60
void clear(std::optional< Color > color, std::optional< int > stencil, std::optional< double > depth) override
Clears .
Definition Canvas.cpp:94
image::ImageData * newHDRImageData() override
Creates a hdr image data. @ownership Caller deletes unless documented otherwise.
Definition Canvas.cpp:179
bool isHDR() const
True when hdr.
Definition Canvas.h:58
void draw(Canvas *, const glm::mat4 &) const override
Draws .
Definition Canvas.h:43
void draw(eve::graphics::Graphics *, const glm::mat4 &) const override
Draws .
Definition Canvas.h:41
vk::Framebuffer framebuffer3D() const
Framebuffer 3 d.
Definition Canvas.h:48
vk::Framebuffer framebuffer() const
Framebuffer.
Definition Canvas.h:46
bool takePendingClear()
Take pending clear.
Definition Canvas.cpp:79
image::ImageData * newImageData() override
Creates a image data. @ownership Caller deletes unless documented otherwise.
Definition Canvas.cpp:171
void ensure3D()
Ensure a D32 depth attachment + 3D (color+depth) framebuffer exist.
Definition Canvas.cpp:85
Represents raw pixel data.
Definition ImageData.h:38
eve::Color Color
RGBA color used by every graphics draw call. Lives inside eve::graphics so including a graphics heade...
Definition Color.h:13
GpuTexture public API.
Definition Graphics.h:264