载入中...
搜索中...
未找到
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; }
59
61 void ensure3D();
62
63private:
64 void readAllPixels(std::vector<uint8_t> &outRgba);
65 void readAllHDRPixels(std::vector<uint8_t> &outRgba16f);
66
67 Graphics *owner = nullptr;
68 int width = 0;
69 int height = 0;
70 vkb::ColorAttachmentImage color;
71 vk::Framebuffer fb = nullptr;
72 vkb::DepthTarget depth;
73 vk::Framebuffer fb3D = nullptr;
74 GpuTexture sampleGpu;
75 Texture sampleTexture;
76
77 Color clearColor{0.f, 0.f, 0.f, 1.f};
78 bool hasPendingClear = true;
79 bool hdr = false;
80};
81
82} // namespace eve::graphics::vulkan
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
std::uint32_t height
std::uint32_t width
Canvas public API.
Definition Canvas.h:17
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
EVENGINE_API_BACKENDS public API.
Definition Graphics.h:342
OffscreenCanvas public API.
Definition Canvas.h:15
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:156
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:59
void clear(std::optional< Color > color, std::optional< int > stencil, std::optional< double > depth) override
Clears .
Definition Canvas.cpp:93
image::ImageData * newHDRImageData() override
Creates a hdr image data. @ownership Caller deletes unless documented otherwise.
Definition Canvas.cpp:177
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:78
image::ImageData * newImageData() override
Creates a image data. @ownership Caller deletes unless documented otherwise.
Definition Canvas.cpp:169
void ensure3D()
Ensure a D32 depth attachment + 3D (color+depth) framebuffer exist.
Definition Canvas.cpp:84
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:257