载入中...
搜索中...
未找到
IGraphics2D.h
浏览该文件的文档.
1#pragma once
2
3// Narrow 2D-drawing interface of the Graphics backend.
4//
5// Consumers that only draw 2D (map tiles, particles, UI, camera previews)
6// depend on this interface instead of the full graphics::Graphics god class:
7// changing the 2D surface no longer ripples into 3D consumers and vice versa.
8// The concrete backend class implements all facets; methods here are pure
9// virtual so no backend can silently skip a draw.
10
11#include "graphics/BlendMode.h"
12#include "graphics/Color.h"
13
14#include <glm/mat4x4.hpp>
15#include <glm/vec2.hpp>
16
17#include <cstdint>
18#include <string>
19#include <vector>
20
21namespace eve::graphics {
22
23class Canvas;
24class Camera2D;
25class Drawable;
26class Font;
27class Shader;
28class Texture;
29struct Lighting2DUBO;
30
33public:
34 virtual ~IGraphics2D() = default;
35
37 virtual void clearScreen() = 0;
38 virtual void setBackgroundColorRGBA(float r, float g, float b, float a = 1.f) = 0;
39 virtual void drawSolidRectRGBA(float x, float y, float w, float h, float r, float g, float b,
40 float a = 1.f) = 0;
41 virtual void drawTexturedRectRGBA(Texture *texture, float x, float y, float w, float h,
42 float r, float g, float b, float a = 1.f) = 0;
43
44 virtual void drawSolidRect(float x, float y, float w, float h, const Color &color,
45 BlendMode blend = BlendMode::Alpha) = 0;
46 virtual void drawSolidRectRotated(float cx, float cy, float w, float h, float degrees,
47 const Color &color,
48 BlendMode blend = BlendMode::Alpha) = 0;
49
50 virtual void drawTexturedRect(Texture *texture, float x, float y, float w, float h,
51 const Color &color) = 0;
52 virtual void drawTexturedRectShader(Texture *texture, Shader *shader, float x, float y, float w,
53 float h, const Color &color) = 0;
54 virtual void drawTexturedRectUV(Texture *texture, float x, float y, float w, float h, float u0,
55 float v0, float u1, float v1, const Color &color) = 0;
56 virtual void drawTexturedRectShaderUV(Texture *texture, Shader *shader, float x, float y,
57 float w, float h, float u0, float v0, float u1, float v1,
58 const Color &color, bool rotatedUV = false,
59 BlendMode blend = BlendMode::Alpha) = 0;
60 virtual void drawTexturedRectShaderUVRotated(Texture *texture, Shader *shader, float cx,
61 float cy, float w, float h, float degrees,
62 float u0, float v0, float u1, float v1,
63 const Color &color, bool rotatedUV = false,
64 BlendMode blend = BlendMode::Alpha) = 0;
66 float x, float y, float w, float h,
67 const Color &tint) = 0;
68
70 virtual void drawTexturedRectLitUV(Texture *albedo, Texture *normal, float x, float y, float w,
71 float h, float u0, float v0, float u1, float v1,
72 const Color &color) = 0;
74 virtual void setLighting2D(const Lighting2DUBO &ubo) = 0;
75
77 virtual void setCanvas(Canvas *canvas) = 0;
78 virtual bool isCanvasActive() const = 0;
79 virtual Canvas *getCanvas() const = 0;
80
82 virtual void setShader(Shader *shader) = 0;
83 virtual void setShader() = 0;
84 virtual Shader *getShader() const = 0;
85
87 virtual void setFont(Font *font) = 0;
88 virtual Font *getFont() const = 0;
90 virtual void print(const std::string &text, float x, float y,
91 const Color &color = Color(1.f, 1.f, 1.f, 1.f), float scale = 1.f) = 0;
92
93 virtual void draw(Drawable *drawable, const glm::mat4 &m) = 0;
94 virtual void drawOcclusion(Drawable *drawable, const glm::mat4 &m) = 0;
95 virtual void drawOcclusionSolid(float x, float y, float w, float h) = 0;
96 virtual void drawOcclusionTexture(Texture *texture, float x, float y, float w, float h) = 0;
97
99 virtual void pushValidationScope() = 0;
100 virtual void popValidationScope() = 0;
101};
102
103} // namespace eve::graphics
float cx
Definition CardTypes.cpp:31
float cy
Definition CardTypes.cpp:32
float degrees
Definition CardTypes.cpp:33
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
int h
int w
float depth
uint32_t a
uint32_t b
Texture * normal
Texture * albedo
Shader * shader
image::ImageData::Colorf color
float scale
Definition TreeMesh.cpp:122
float m[16]
Drawable base (textures, meshes, canvases).
Definition Drawable.h:17
GPU-side font: wraps a decoded font::FontData and rasterizes a fixed set of codepoints into a single ...
Definition Font.h:32
2D immediate-mode drawing surface (screen or offscreen Canvas).
Definition IGraphics2D.h:32
virtual void setLighting2D(const Lighting2DUBO &ubo)=0
Upload per-frame / per-canvas 2D lighting constants.
virtual void setFont(Font *font)=0
Font used by print(); nullptr = none set.
virtual void drawTexturedRectRGBA(Texture *texture, float x, float y, float w, float h, float r, float g, float b, float a=1.f)=0
virtual void drawSolidRectRGBA(float x, float y, float w, float h, float r, float g, float b, float a=1.f)=0
virtual void drawTexturedRect(Texture *texture, float x, float y, float w, float h, const Color &color)=0
virtual void pushValidationScope()=0
Backend GPU validation scopes (WebGPU).
virtual void setShader()=0
virtual void setBackgroundColorRGBA(float r, float g, float b, float a=1.f)=0
virtual void drawTexturedRectUV(Texture *texture, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const Color &color)=0
virtual void print(const std::string &text, float x, float y, const Color &color=Color(1.f, 1.f, 1.f, 1.f), float scale=1.f)=0
Draws UTF-8 text with the current font (throws when unset).
virtual Font * getFont() const =0
virtual void drawTexturedRectShader(Texture *texture, Shader *shader, float x, float y, float w, float h, const Color &color)=0
virtual void drawTexturedRectLitUV(Texture *albedo, Texture *normal, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const Color &color)=0
Lit 2D draw (albedo + normal map); normal may be null → flat.
virtual void popValidationScope()=0
virtual void drawSolidRectRotated(float cx, float cy, float w, float h, float degrees, const Color &color, BlendMode blend=BlendMode::Alpha)=0
virtual void drawSolidRect(float x, float y, float w, float h, const Color &color, BlendMode blend=BlendMode::Alpha)=0
virtual void drawTexturedRectShaderDepth(Texture *color, Texture *depth, Shader *shader, float x, float y, float w, float h, const Color &tint)=0
virtual void clearScreen()=0
Clears the current draw target to the background color.
virtual void draw(Drawable *drawable, const glm::mat4 &m)=0
virtual void setCanvas(Canvas *canvas)=0
Draw target; nullptr → screen.
virtual Canvas * getCanvas() const =0
virtual void drawOcclusionSolid(float x, float y, float w, float h)=0
virtual bool isCanvasActive() const =0
virtual void setShader(Shader *shader)=0
Custom fragment pipeline for subsequent textured 2D draws.
virtual void drawOcclusion(Drawable *drawable, const glm::mat4 &m)=0
virtual void drawOcclusionTexture(Texture *texture, float x, float y, float w, float h)=0
virtual ~IGraphics2D()=default
virtual Shader * getShader() const =0
virtual void drawTexturedRectShaderUV(Texture *texture, Shader *shader, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const Color &color, bool rotatedUV=false, BlendMode blend=BlendMode::Alpha)=0
virtual void drawTexturedRectShaderUVRotated(Texture *texture, Shader *shader, float cx, float cy, float w, float h, float degrees, float u0, float v0, float u1, float v1, const Color &color, bool rotatedUV=false, BlendMode blend=BlendMode::Alpha)=0
Custom GPU program.
Definition Shader.h:30
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6
glm::vec4 Color
RGBA color used by every graphics draw call. Lives inside eve::graphics so including a graphics heade...
Definition Color.h:13
BlendMode
2D quad blend mode (drawn in draw order within a layer).
Definition BlendMode.h:6