载入中...
搜索中...
未找到
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
15public:
16 OffscreenCanvas(Graphics *owner, int width, int height);
17 ~OffscreenCanvas() override;
18
19 int getWidth() const override { return width; }
20 int getHeight() const override { return height; }
21 Texture *getTexture() override { return &sampleTexture; }
22
23 void clear(std::optional<Color> color, std::optional<int> stencil,
24 std::optional<double> depth) override;
25 Color getPixel(int x, int y) override;
27
28 void draw(eve::graphics::Graphics *, const glm::mat4 &) const override {}
29 void draw(Canvas *, const glm::mat4 &) const override {}
30
31 vk::Framebuffer framebuffer() const { return fb; }
32 vk::Framebuffer framebuffer3D() const { return fb3D; }
33 vkb::ColorAttachmentImage &colorImage() { return color; }
34 vkb::DepthTarget &depthImage() { return depth; }
35 Color pendingClearColor() const { return clearColor; }
36 bool takePendingClear();
37
39 void ensure3D();
40
41private:
42 void readAllPixels(std::vector<uint8_t> &outRgba);
43
44 Graphics *owner = nullptr;
45 int width = 0;
46 int height = 0;
47 vkb::ColorAttachmentImage color;
48 vk::Framebuffer fb = nullptr;
49 vkb::DepthTarget depth;
50 vk::Framebuffer fb3D = nullptr;
51 GpuTexture sampleGpu;
52 Texture sampleTexture;
53
54 Color clearColor{0.f, 0.f, 0.f, 1.f};
55 bool hasPendingClear = true;
56};
57
58} // namespace eve::graphics::vulkan
int y
Definition Grass.cpp:135
float height
Definition Grass.cpp:235
int x
Definition Grass.cpp:135
int width
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
vkb::ColorAttachmentImage & colorImage()
Definition Canvas.h:33
vkb::DepthTarget & depthImage()
Definition Canvas.h:34
int getHeight() const override
Definition Canvas.h:20
Color getPixel(int x, int y) override
Definition Canvas.cpp:125
Texture * getTexture() override
Sampleable color buffer; screen Canvas returns nullptr.
Definition Canvas.h:21
int getWidth() const override
Definition Canvas.h:19
void clear(std::optional< Color > color, std::optional< int > stencil, std::optional< double > depth) override
Definition Canvas.cpp:91
void draw(Canvas *, const glm::mat4 &) const override
Definition Canvas.h:29
void draw(eve::graphics::Graphics *, const glm::mat4 &) const override
Draws the object with the specified transformation matrix.
Definition Canvas.h:28
vk::Framebuffer framebuffer3D() const
Definition Canvas.h:32
vk::Framebuffer framebuffer() const
Definition Canvas.h:31
image::ImageData * newImageData() override
Definition Canvas.cpp:138
void ensure3D()
Ensure a D32 depth attachment + 3D (color+depth) framebuffer exist.
Definition Canvas.cpp:82
Represents raw pixel data.
Definition ImageData.h:26
glm::vec4 Color
RGBA color used by every graphics draw call. Lives inside eve::graphics so including a graphics heade...
Definition Color.h:13