载入中...
搜索中...
未找到
Graphics.h
浏览该文件的文档.
1#pragma once
2
3#include <assimp/matrix4x4.h>
4#include <cstdint>
5#include <glm/glm.hpp>
6#include <memory>
7#include <optional>
8#include <string>
9#include <vector>
10#include "common/Module.h"
12#include "graphics/BlendMode.h"
13#include "graphics/Canvas.h"
14#include "graphics/Color.h"
15#include "graphics/Font.h"
18#include "graphics/IPostFX.h"
20
21struct aiMesh;
22
23namespace eve::graphics {
24
25class AmbientOcclusion;
26class AntiAliasing;
27class Camera3D;
28class Drawable;
29class GBuffer;
30class GlobalIllumination;
31class GrassField;
32class Material;
33class Mesh;
34class Outline;
35class Quad;
36class RenderControl;
37class ScreenSpaceReflection;
38class Shader;
39class Texture;
40class Volumetric;
41class Water;
42class Waterfall;
43struct ClusteredLightingUpload;
44struct Lighting2DUBO;
45struct Lighting3DPack;
46struct ShadowUpload;
47struct TextureCreateInfo;
48struct TextureSampler;
49
50class Graphics : public Module,
51 public Canvas,
52 public IWindowSurfaceHost,
53 public IGraphics2D,
54 public IGraphics3D,
55 public IResourceFactory,
56 public IPostFX {
57public:
59 Graphics();
60 ~Graphics() override;
61
65 virtual void reset();
66
68 virtual void clearScreen();
69 virtual void setBackgroundColorRGBA(float r, float g, float b, float a = 1.f);
70 virtual void drawSolidRectRGBA(float x, float y, float w, float h, float r, float g, float b, float a = 1.f);
71 virtual void drawTexturedRectRGBA(Texture *texture, float x, float y, float w, float h, float r, float g, float b,
72 float a = 1.f);
77 bool repeatV = false);
80
86 bool generateMipmaps, float maxAnisotropy,
87 const std::string &filter, const std::string &mipmap,
88 float lodBias = 0.f);
89
91 virtual void setTextureSamplerParams(Texture *texture, const std::string &filter, const std::string &mipmap,
92 float maxAnisotropy, float lodBias);
93
94 virtual void present() = 0;
95
97 virtual std::string getBackendName() const = 0;
98
104 virtual bool supportsGBufferPost() const { return true; }
105
110 virtual void initWithWindow(void *nativeWindow) = 0;
111
115 virtual void setViewportSize(int width, int height, int pixelwidth, int pixelheight) = 0;
116
117 int getWidth() const { return width; }
118 int getHeight() const { return height; }
119 int getPixelWidth() const { return pixelWidth; }
120 int getPixelHeight() const { return pixelHeight; }
121
122 double getCurrentDPIScale() const {
123 return (width > 0) ? double(pixelWidth) / double(width) : 1.0;
124 }
125 double getScreenDPIScale() const { return getCurrentDPIScale(); }
126
128 virtual void drawSolidRect(float x, float y, float w, float h, const Color &color,
129 BlendMode blend = BlendMode::Alpha) = 0;
130
132 virtual void drawSolidRectRotated(float cx, float cy, float w, float h, float degrees,
133 const Color &color,
134 BlendMode blend = BlendMode::Alpha) = 0;
135
139 virtual Texture *newTexture(int width, int height, const uint8_t *rgba, bool repeatU = false,
140 bool repeatV = false) = 0;
141
145 virtual Texture *newTexture(int width, int height, const uint8_t *rgba,
146 const TextureCreateInfo &info) = 0;
147
152 virtual Texture *newCubemap(int faceSize, const uint8_t *rgbaFaces) = 0;
153
155 virtual Texture *newCubemap(int faceSize, const uint8_t *rgbaFaces,
156 const TextureCreateInfo &info) = 0;
157
160
162 virtual Texture *newTexture(image::ImageData *data, const TextureCreateInfo &info) = 0;
163
168 virtual void setTextureSampler(Texture *texture, const TextureSampler &sampler) = 0;
169
171 virtual float getMaxAnisotropy() const = 0;
172
175 virtual Texture *newTextureFromFile(const std::string &filename) = 0;
179 Texture *newTextureFromFileRepeated(const std::string &filename, bool repeatU, bool repeatV);
180
182 virtual bool reloadTextureFromFile(const std::string &filename) = 0;
183
200 virtual bool releaseTexture(Texture *texture) {
201 (void)texture;
202 return false;
203 }
204
207 virtual void drawTexturedRect(Texture *texture, float x, float y, float w, float h,
208 const Color &color) = 0;
209
211 virtual void drawTexturedRectShader(Texture *texture, Shader *shader, float x, float y, float w,
212 float h, const Color &color) = 0;
213
215 virtual void drawTexturedRectUV(Texture *texture, float x, float y, float w, float h, float u0,
216 float v0, float u1, float v1, const Color &color) = 0;
217
219 virtual void drawTexturedRectShaderUV(Texture *texture, Shader *shader, float x, float y,
220 float w, float h, float u0, float v0, float u1, float v1,
221 const Color &color, bool rotatedUV = false,
222 BlendMode blend = BlendMode::Alpha) = 0;
223
229 float cy, float w, float h, float degrees,
230 float u0, float v0, float u1, float v1,
231 const Color &color, bool rotatedUV = false,
232 BlendMode blend = BlendMode::Alpha) = 0;
233
239 float x, float y, float w, float h,
240 const Color &tint) = 0;
241
246 virtual void drawTexturedRectLitUV(Texture *albedo, Texture *normal, float x, float y, float w,
247 float h, float u0, float v0, float u1, float v1,
248 const Color &color) = 0;
249
251 virtual void setLighting2D(const Lighting2DUBO &ubo) = 0;
252
254 Quad *newQuad(int x, int y, int w, int h);
255
258 virtual Mesh *newMeshFromAssimp(const ::aiMesh &mesh) = 0;
259
265 virtual Mesh *newMeshFromAssimp(const ::aiMesh &mesh, const aiMatrix4x4 &worldTransform) = 0;
266
272 virtual Mesh *newMeshFromArrays(const float *posXYZ, const float *nrmXYZ, const float *uvST,
273 int vertexCount, const uint32_t *indices, int indexCount) = 0;
274
284 virtual bool updateMeshVertices(Mesh *mesh, const float *posXYZ, const float *nrmXYZ,
285 const float *uvST, int vertexCount, const uint32_t *indices,
286 int indexCount) = 0;
287
292 virtual bool bakeMeshMorph(Mesh *mesh) = 0;
293
298 virtual Mesh *newMeshSphere(int slices = 32, int stacks = 16) = 0;
299
305 virtual Mesh *newMeshCylinder(int slices = 32, int stacks = 1, bool caps = true) = 0;
306
311 Mesh *newMeshCube(float size = 1.f);
312
324 virtual bool releaseMesh(Mesh *mesh) {
325 (void)mesh;
326 return false;
327 }
328
330 virtual void render3D();
336 virtual void renderScene3DToCanvas(Canvas *canvas, Camera3D *camera);
337 virtual void setDirectionalLight(float dx, float dy, float dz, float r = 1.f, float g = 1.f, float b = 1.f);
338
345 virtual void drawScene3DRGBA(float x, float y, float w, float h, float r = 1.f, float g = 1.f, float b = 1.f,
346 float a = 1.f);
348 void drawScene3D(float x, float y, float w, float h) {
349 drawScene3DRGBA(x, y, w, h, 1.f, 1.f, 1.f, 1.f);
350 }
351
353 virtual void drawCanvasRGBA(Canvas *canvas, float x, float y, float w, float h, float r = 1.f, float g = 1.f,
354 float b = 1.f, float a = 1.f);
355 void drawCanvas(Canvas *canvas, float x, float y, float w, float h) {
356 drawCanvasRGBA(canvas, x, y, w, h, 1.f, 1.f, 1.f, 1.f);
357 }
358
363 virtual void pushValidationScope() = 0;
364 virtual void popValidationScope() = 0;
365
371
377
383 virtual void beginGBufferPass(int width, int height) = 0;
384 virtual void drawMeshGBuffer(Mesh *mesh, const glm::mat4 &mvp, const glm::mat4 &model,
385 float nearZ, float farZ, Texture *albedo = nullptr,
386 float tintR = 1.f, float tintG = 1.f, float tintB = 1.f) = 0;
393 virtual void drawMeshGBufferAlpha(Mesh *mesh, const glm::mat4 &mvp, const glm::mat4 &model,
394 float nearZ, float farZ, Texture *albedo = nullptr,
395 float tintR = 1.f, float tintG = 1.f,
396 float tintB = 1.f) = 0;
397 virtual void endGBufferPass() = 0;
398
406 virtual void begin3DFrame() = 0;
407
415 virtual void begin3DFrameToCanvas(Canvas *canvas) = 0;
416 virtual void end3DFrameToCanvas() = 0;
417
420 virtual void setMesh3DViewProj(const glm::mat4 &viewProj) = 0;
421
423 virtual void setMesh3DView(const glm::mat4 &view) = 0;
424
426 virtual void setMesh3DClip(float nearZ, float farZ) = 0;
427
432 virtual Texture *getSceneColorTexture() { return nullptr; }
433
442 Mesh *mesh = nullptr;
443 glm::mat4 model{1.f};
444 glm::vec4 idColor{0.f, 0.f, 0.f, 1.f};
445 };
446 virtual image::ImageData *renderEntityIdMask(const std::vector<EntityIdDraw> &draws,
447 const glm::mat4 &viewProj, int width, int height) {
448 (void)draws;
449 (void)viewProj;
450 (void)width;
451 (void)height;
452 return nullptr;
453 }
454
461 virtual image::ImageData *readGBufferToImageData(const std::string &name) {
462 (void)name;
463 return nullptr;
464 }
465
467 virtual void drawMesh(Mesh *mesh, const glm::mat4 &model, Texture *texture, const Color &tint) = 0;
468
470 virtual void drawMeshShader(Mesh *mesh, const glm::mat4 &model, Texture *texture, const Color &tint,
471 Shader *shader) = 0;
472
475
478
485
487 virtual void setMesh3DMaterial(float metallic, float roughness) = 0;
488
494 virtual void setMesh3DTexCellBomb(float cellScale, float strength, float rotAmount = 1.f) = 0;
495
501 virtual void setMesh3DParallax(float scale, float minLayers = 8.f, float maxLayers = 32.f) = 0;
502
504 virtual void setMesh3DLighting(const Lighting3DPack &pack) = 0;
505
511 virtual void setCloudShadows(float strength, float worldCell, float time, float windSpeed,
512 float windAngle, float coverage, float detail) = 0;
513
519
525 virtual void setMesh3DClusteredActive(bool active) = 0;
526
528 virtual void setMesh3DLight(const glm::vec3 &dir, const glm::vec3 &color) = 0;
529
531 virtual void setMesh3DCameraPos(const glm::vec3 &eye) = 0;
532
541 virtual void drawVoxelFaceInstances(const uint32_t *packed, int count, float originX,
542 float originY, float originZ, const std::string &faceDir,
543 Texture *atlas, int tilesPerRow = 16,
544 const uint32_t *ao = nullptr) = 0;
545
551 virtual void setMesh3DEnv(Texture *cube, float intensity) = 0;
552
554 virtual void setMesh3DShadows(const ShadowUpload &upload) = 0;
555
557 virtual void setMesh3DShadowReceive(bool receive) = 0;
558
564 virtual void beginShadowPass(int cascadeIndex) = 0;
565 virtual void drawMeshShadow(Mesh *mesh, const glm::mat4 &lightMVP) = 0;
573 virtual void drawMeshShadowAlpha(Mesh *mesh, const glm::mat4 &lightMVP,
574 Texture *albedo = nullptr) = 0;
575 virtual void endShadowPass() = 0;
576
579 bool v = frameHad3D;
580 return v;
581 }
582 bool had3DThisFrame() const { return frameHad3D; }
583
586
593
598 bool saveFramePng(const std::string &path);
599
604 virtual void setVSync(bool enabled) { vsyncEnabled = enabled; }
605 bool isVSync() const { return vsyncEnabled; }
606
612 virtual void setMsaaSamples(int samples) { msaaSamples = samples > 0 ? samples : 0; }
613 virtual int getMsaaSamples() const { return msaaSamples; }
614
616 void setActive(bool active) override {
618 if (active)
620 }
621 bool isActive() const { return graphicsActive; }
622
624 virtual void markSwapchainDirty() {}
625
631 void requestSurfaceRecreate() override {}
632
646 virtual void onNativeWindowDestroyed() {
647 for (auto &cb : windowDestroyedCallbacks_) cb.first(cb.second);
650 }
651
654 presentOverlayFn_ = nullptr;
655 presentOverlayUser_ = nullptr;
656 }
657
663 using WindowDestroyedCallback = void (*)(void *userdata);
665 windowDestroyedCallbacks_.emplace_back(cb, userdata);
666 }
667
672 using PresentOverlayFn = void (*)(void *userdata, void *commandBuffer);
673 void setPresentOverlay(PresentOverlayFn fn, void *userdata) {
675 presentOverlayUser_ = userdata;
676 }
679
687 Font *newFont(font::FontData *data, std::string charset = Font::defaultCharset());
688
690 virtual void setFont(Font *font) { currentFont = font; }
691 Font *getFont() const { return currentFont; }
692
697 virtual void print(const std::string &text, float x, float y, const Color &color = Color(1.f, 1.f, 1.f, 1.f),
698 float scale = 1.f);
699
700 virtual void setShader(Shader *shader);
701 virtual void setShader();
702
703 Shader *getShader() const { return currentShader; }
704
709 virtual Shader *newShaderFromSpv(const std::vector<uint32_t> &vertSpv,
710 const std::vector<uint32_t> &fragSpv) = 0;
711
713 virtual Shader *newShaderFromSpvFile(const std::string &vertPath, const std::string &fragPath) = 0;
714 Shader *newShaderFromSpvFile(const std::string &fragPath) {
715 return newShaderFromSpvFile(std::string(), fragPath);
716 }
717
722 virtual Shader *newShader(const std::string &vertGlsl, const std::string &fragGlsl) = 0;
723 Shader *newShader(const std::string &fragGlsl) { return newShader(std::string(), fragGlsl); }
724
729 virtual Shader *newMeshShaderFromSpv(const std::vector<uint32_t> &vertSpv,
730 const std::vector<uint32_t> &fragSpv) = 0;
738 virtual Shader *newMeshShaderFromWgsl(const std::string &vertWgsl,
739 const std::string &fragWgsl) = 0;
740 virtual Shader *newMeshShader(const std::string &vertGlsl, const std::string &fragGlsl) = 0;
741 Shader *newMeshShader(const std::string &fragGlsl) {
742 return newMeshShader(std::string(), fragGlsl);
743 }
744
749 virtual Shader *newHairShaderFromSpv(const std::vector<uint32_t> &vertSpv,
750 const std::vector<uint32_t> &fragSpv) = 0;
753
768 virtual bool releaseShader(Shader *shader) {
769 (void)shader;
770 return false;
771 }
772
778
784
791
796 Water *newWater();
797
799 virtual Canvas *newCanvas(int width, int height) = 0;
800
802 virtual void setCanvas(Canvas *canvas) = 0;
803 void setCanvas() { setCanvas(nullptr); }
804
805 virtual bool isCanvasActive() const = 0;
806 virtual Canvas *getCanvas() const = 0;
807
813
819
825
831
837
847
853
854 virtual void draw(Drawable *drawable, const glm::mat4 &m);
855
860 virtual void drawOcclusion(Drawable *drawable, const glm::mat4 &m);
861 virtual void drawOcclusionSolid(float x, float y, float w, float h);
862 virtual void drawOcclusionTexture(Texture *texture, float x, float y, float w, float h);
863 // void draw(Texture *texture, Quad *quad, const glm::mat4 &m);
864 // void drawLayer(Texture *texture, int layer, const glm::mat4 &m);
865 // void drawLayer(Texture *texture, int layer, Quad *quad, const glm::mat4 &m);
866 // void drawInstanced(Mesh *mesh, const glm::mat4 &m, int instancecount);
867
868
872 void points(const std::vector<glm::vec2> &positions, const std::vector<Color> &colors);
873
879 void polyline(const glm::mat4 *vertices, size_t count);
880
888 void rectangle(std::string mode, float x, float y, float w, float h);
889
901 void rectangle(std::string mode, float x, float y, float w, float h, float rx, float ry, int points);
902 void rectangle(std::string mode, float x, float y, float w, float h, float rx, float ry);
903
912 void circle(std::string mode, float x, float y, float radius, int points);
913 void circle(std::string mode, float x, float y, float radius);
914
924 void ellipse(std::string mode, float x, float y, float a, float b, int points);
925 void ellipse(std::string mode, float x, float y, float a, float b);
926
938 void arc(std::string mode, std::string arcmode, float x, float y, float radius, float angle1, float angle2,
939 int points);
940 void arc(std::string mode, std::string arcmode, float x, float y, float radius, float angle1, float angle2);
941
948 void polygon(std::string mode, const std::vector<glm::vec2> &vertices, bool skipLastFilledVertex = true);
949
950
951 void push(bool all);
952 void pop();
953
954 const glm::mat4 &getTransform() const;
955 const glm::mat4 &getProjection() const;
956
957 void rotate(float r);
958 void scale(float x, float y = 1.0f);
959 void translate(float x, float y);
960 void origin();
961
962 // void applyTransform(love::math::Transform *transform);
963 // void replaceTransform(love::math::Transform *transform);
964
965 glm::vec2 transformPoint(glm::vec2 point);
966 glm::vec2 inverseTransformPoint(glm::vec2 point);
967
968 // virtual void draw(const DrawCommand &cmd) = 0;
969 // virtual void draw(const DrawIndexedCommand &cmd) = 0;
970 // virtual void drawQuads(int start, int count, const vertex::Attributes &attributes, const vertex::BufferBindings &buffers, Texture *texture) = 0;
971
972protected:
973 int width = 0;
974 int height = 0;
975 int pixelWidth = 0;
976 int pixelHeight = 0;
977 Color backgroundColor{0.1f, 0.1f, 0.12f, 1.0f};
978 bool frameHad3D = false;
980 bool recordingEngine3D_ = false;
982 bool vsyncEnabled = true;
983 bool graphicsActive = true;
984 int msaaSamples = 4;
986 void *presentOverlayUser_ = nullptr;
987 std::vector<std::pair<WindowDestroyedCallback, void *>> windowDestroyedCallbacks_;
989 Font *currentFont = nullptr;
990 std::unique_ptr<RenderControl> renderControl_;
991 std::unique_ptr<AmbientOcclusion> pipelineAO_;
992 std::unique_ptr<GlobalIllumination> pipelineGI_;
993 std::unique_ptr<AntiAliasing> pipelineAA_;
994 std::unique_ptr<Outline> pipelineOutline_;
995
998};
999
1000} // namespace eve::graphics
bool active
Definition CardTypes.cpp:34
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
uint32_t c
float roughness
Texture * normal
Texture * albedo
float metallic
glm::vec3 eye
Mesh * mesh
glm::mat4 viewProj
Shader * shader
glm::mat4 view
glm::mat4 model
const char * name
Definition RockMesh.cpp:21
bool repeatV
std::string filter
std::string mipmap
bool repeatU
SettlementPipeline::Stage fn
bool enabled
int v
image::ImageData::Colorf color
float scale
Definition TreeMesh.cpp:122
std::vector< V3 > points
Definition TreeMesh.cpp:126
V3 dir
Definition TreeMesh.cpp:121
float m[16]
Render-surface host for the window module (provided by graphics).
CPU-side decoded font face (FreeType FT_Face + owned font bytes). Does not upload to GPU — rasterize ...
Definition FontData.h:23
Screen-space ambient occlusion.
Classic image-space anti-aliasing.
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
static std::string defaultCharset()
Printable ASCII (0x20..0x7E), used when no explicit charset is given.
Definition Font.cpp:58
Screen-space single-bounce GI (SSGI).
virtual void reset()
Resets the current color, background color, line style, and so forth.
Definition Graphics.cpp:740
virtual void setFont(Font *font)
Font used by subsequent print() calls; nullptr = none set.
Definition Graphics.h:690
virtual Texture * newCubemap(int faceSize, const uint8_t *rgbaFaces)=0
Create an RGBA8 cubemap from 6 faces packed as +X,-X,+Y,-Y,+Z,-Z (each faceSize×faceSize,...
virtual void beginShadowPass(int cascadeIndex)=0
Depth-only shadow pass for one cascade layer (0..2). Draws are recorded into the next begin3DFrame co...
virtual void setTextureSamplerParams(Texture *texture, const std::string &filter, const std::string &mipmap, float maxAnisotropy, float lodBias)
Update sampler state without re-uploading pixels (filter / mip / aniso / LOD bias).
Definition Graphics.cpp:919
virtual void draw(Drawable *drawable, const glm::mat4 &m)
Definition Graphics.cpp:848
std::vector< std::pair< WindowDestroyedCallback, void * > > windowDestroyedCallbacks_
Definition Graphics.h:987
Volumetric * newVolumetric()
Volumetric light + fog (screenspace / raymarch / fog). Caller owns Volumetric*; its Shaders are owned...
Definition Graphics.cpp:749
virtual image::ImageData * renderEntityIdMask(const std::vector< EntityIdDraw > &draws, const glm::mat4 &viewProj, int width, int height)
Definition Graphics.h:446
virtual void onNativeWindowDestroyed()
Called by the Window module when the native window backing the render surface is destroyed (window cl...
Definition Graphics.h:646
void(*)(void *userdata) WindowDestroyedCallback
Register a callback invoked when the native window is destroyed. Used by the UI backend to tear down ...
Definition Graphics.h:663
bool consumeFrameHad3D()
True after begin3DFrame until present completes.
Definition Graphics.h:578
void drawCanvas(Canvas *canvas, float x, float y, float w, float h)
Definition Graphics.h:355
virtual bool releaseMesh(Mesh *mesh)
Eagerly releases a mesh created by this Graphics.
Definition Graphics.h:324
void ellipse(std::string mode, float x, float y, float a, float b)
virtual std::string getBackendName() const =0
Renderer backend id used by sibling modules (e.g. Gpgpu).
int getPixelHeight() const
Definition Graphics.h:120
virtual void setDirectionalLight(float dx, float dy, float dz, float r=1.f, float g=1.f, float b=1.f)
Definition Graphics.cpp:167
virtual void setVSync(bool enabled)
Prefer uncapped present (IMMEDIATE/MAILBOX) when false, vsync (MAILBOX/FIFO) when true....
Definition Graphics.h:604
virtual void drawMeshGBufferAlpha(Mesh *mesh, const glm::mat4 &mvp, const glm::mat4 &model, float nearZ, float farZ, Texture *albedo=nullptr, float tintR=1.f, float tintG=1.f, float tintB=1.f)=0
GBuffer fill with alpha-cutout discard (card/billboard geometry such as sprite-stack slices): same ou...
std::unique_ptr< AntiAliasing > pipelineAA_
Definition Graphics.h:993
virtual void setShader()
Definition Graphics.cpp:747
virtual Shader * newMeshShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Create a Mesh3D custom shader (MeshVertex + Frame UBO + albedo). Empty vert → default mesh3d....
void setBackgroundColor(const Color &c)
Definition Graphics.h:585
virtual void setMesh3DShadows(const ShadowUpload &upload)=0
Upload CSM constants for subsequent default mesh draws (active=false disables).
void ellipse(std::string mode, float x, float y, float a, float b, int points)
Draws an ellipse using the specified arguments.
virtual void endGBufferPass()=0
bool isVSync() const
Definition Graphics.h:605
virtual void setMesh3DClip(float nearZ, float farZ)=0
Near/far used to pack linear depth into scene color A (SSGI).
void setActive(bool active) override
Pause/resume presenting (Android background / foreground).
Definition Graphics.h:616
void translate(float x, float y)
virtual Mesh * newMeshCylinder(int slices=32, int stacks=1, bool caps=true)=0
Procedural Y-up cylinder (radius 1, height 2 centered at origin). slices = longitude divisions; stack...
std::unique_ptr< Outline > pipelineOutline_
Definition Graphics.h:994
Shader * newHairShader()
Built-in hair shader with default anisotropic parameters.
Definition Graphics.cpp:781
virtual void setMesh3DMaterial(float metallic, float roughness)=0
Metallic (0..1) and roughness (0..1) for the next default mesh draw.
Texture * newTextureWithSampler(image::ImageData *data, bool repeatU, bool repeatV, bool generateMipmaps, float maxAnisotropy, const std::string &filter, const std::string &mipmap, float lodBias=0.f)
Script-friendly texture create: filter = "linear"|"nearest", mipmap = "none"|"linear"|"nearest"....
Definition Graphics.cpp:903
void polyline(const glm::mat4 *vertices, size_t count)
Draws a series of lines connecting the given vertices.
virtual void drawOcclusionTexture(Texture *texture, float x, float y, float w, float h)
Definition Graphics.cpp:860
virtual void setBackgroundColorRGBA(float r, float g, float b, float a=1.f)
Definition Graphics.cpp:867
bool isScreenReadbackEnabled() const
Definition Graphics.h:592
GrassField * newGrassField()
Dense + sparse stylized grass field. Caller owns GrassField*; its Mesh / Shader / Texture are owned b...
Definition Graphics.cpp:785
AmbientOcclusion * newAmbientOcclusion()
Screen-space ambient occlusion (ssao / hbao / gtao). Caller owns AmbientOcclusion*; its Shaders are o...
Definition Graphics.cpp:751
virtual bool releaseTexture(Texture *texture)
Eagerly releases a texture created by this Graphics.
Definition Graphics.h:200
Quad * newQuad(int x, int y, int w, int h)
Pixel-space atlas rect. Caller owns Quad* (not tracked by Graphics).
Definition Graphics.cpp:931
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
UV draw with an explicit Shader (nullptr = default textured pipeline).
virtual Shader * newMeshShader(const std::string &vertGlsl, const std::string &fragGlsl)=0
virtual void setMesh3DViewProj(const glm::mat4 &viewProj)=0
virtual image::ImageData * readGBufferToImageData(const std::string &name)
Read a G-buffer attachment back to CPU as RGBA8. name is one of "depth" (RGBA8 linear depth),...
Definition Graphics.h:461
virtual void drawMesh(Mesh *mesh, const glm::mat4 &model, Texture *texture, const Color &tint)=0
Draw one mesh with model matrix. Requires begin3DFrame() (or an open swapchain pass).
virtual void drawMeshGBuffer(Mesh *mesh, const glm::mat4 &mvp, const glm::mat4 &model, float nearZ, float farZ, Texture *albedo=nullptr, float tintR=1.f, float tintG=1.f, float tintB=1.f)=0
virtual Texture * newTexture(image::ImageData *data)=0
Create texture from ImageData (RGBA8 required for now).
virtual void setMesh3DCameraPos(const glm::vec3 &eye)=0
Camera eye used by mesh shaders that need view/rim (stored in Mesh3DUBO).
Color getBackgroundColor() const
Definition Graphics.h:584
void addWindowDestroyedCallback(WindowDestroyedCallback cb, void *userdata)
Definition Graphics.h:664
virtual void setMsaaSamples(int samples)
Hardware MSAA sample count for the 3D scene color pass (0 disables, then 2/4/8 are used when the devi...
Definition Graphics.h:612
virtual void endShadowPass()=0
bool recordingEngine3D_
True while RenderSystem3D is submitting (AO / engine overlays).
Definition Graphics.h:980
virtual void setLighting2D(const Lighting2DUBO &ubo)=0
Upload per-frame / per-canvas 2D lighting constants for subsequent lit draws.
void arc(std::string mode, std::string arcmode, float x, float y, float radius, float angle1, float angle2, int points)
Draws an arc using the specified arguments.
Waterfall * newWaterfall()
Flowing waterfall (falling water sheet) with sky reflection, downward velocity streaks and animated f...
Definition Graphics.cpp:787
virtual Mesh * newMeshFromAssimp(const ::aiMesh &mesh)=0
GlobalIllumination * pipelineGlobalIllumination()
Definition Graphics.cpp:764
virtual void setMesh3DClusteredActive(bool active)=0
Cheap per-draw toggle for the already-uploaded clustered light table. Unlike setMesh3DClusteredLighti...
Shader * newGrassShader()
t3ssel8r-style grass billboard shader (alpha test + shadow two-tone). Owned by Graphics....
Definition Graphics.cpp:783
virtual Mesh * newMeshFromAssimp(const ::aiMesh &mesh, const aiMatrix4x4 &worldTransform)=0
Like newMeshFromAssimp, but bakes an Assimp node world transform into positions and transforms normal...
bool saveFramePng(const std::string &path)
Save the last presented frame to a PNG at path. Enables screen readback if needed....
Definition Graphics.cpp:828
double getScreenDPIScale() const
Definition Graphics.h:125
Outline * newOutline()
Screen-space model outline (t3ssel8r-style) from GBuffer depth + normal. Caller owns Outline*; its Sh...
Definition Graphics.cpp:753
glm::vec2 inverseTransformPoint(glm::vec2 point)
virtual void begin3DFrameToCanvas(Canvas *canvas)=0
Open a 3D render pass targeting an offscreen Canvas (color + depth) at the canvas size....
glm::vec2 transformPoint(glm::vec2 point)
virtual void setMesh3DEnv(Texture *cube, float intensity)=0
Specular IBL environment for subsequent default mesh draws. cube must be from newCubemap (or nullptr ...
virtual void drawScene3DRGBA(float x, float y, float w, float h, float r=1.f, float g=1.f, float b=1.f, float a=1.f)
Composite this frame's 3D scene color into a rect (screen or active Canvas). virtual * Call after ren...
Definition Graphics.cpp:147
virtual void setMesh3DTexCellBomb(float cellScale, float strength, float rotAmount=1.f)=0
Texture cell bombing for the next default mesh draw (breaks tiling). cellScale: cells per UV unit (ty...
virtual void drawMeshShadow(Mesh *mesh, const glm::mat4 &lightMVP)=0
virtual void renderScene3DToCanvas(Canvas *canvas, Camera3D *camera)
Definition Graphics.cpp:127
virtual Canvas * getCanvas() const =0
virtual void initWithWindow(void *nativeWindow)=0
Bind to an existing native window (SDL_Window*) and create Vulkan device/swapchain....
Shader * prepareSceneColorResolveShader(Texture *scene)
FXAA resolve shader that writes opaque RGB (ignores scene-color depth alpha).
Definition Graphics.cpp:131
void rectangle(std::string mode, float x, float y, float w, float h, float rx, float ry, int points)
Variant of rectangle that draws a rounded rectangle.
Mesh * newMeshCube(float size=1.f)
Procedural cube (edge length size, centered at origin, outward CCW for RH Y-up), with per-face normal...
Definition Graphics.cpp:790
virtual void popValidationScope()=0
void arc(std::string mode, std::string arcmode, float x, float y, float radius, float angle1, float angle2)
void rectangle(std::string mode, float x, float y, float w, float h, float rx, float ry)
virtual void drawTexturedRectRGBA(Texture *texture, float x, float y, float w, float h, float r, float g, float b, float a=1.f)
Definition Graphics.cpp:873
virtual void pushValidationScope()=0
Backend hooks so the platform-independent render3D() can wrap its work in a GPU validation error scop...
virtual void beginGBufferPass(int width, int height)=0
Depth/normal(/albedo) fill pass for mid/post effects. One-shot submit (like shadow); call before begi...
virtual void setMesh3DClusteredLighting(const ClusteredLightingUpload &upload)=0
Enable clustered forward path for subsequent default mesh draws (SSBO light lists)....
virtual void setMesh3DParallax(float scale, float minLayers=8.f, float maxLayers=32.f)=0
Parallax occlusion mapping for the next default mesh draw. scale: UV displacement strength (0=off)....
void rectangle(std::string mode, float x, float y, float w, float h)
Draws a rectangle.
void circle(std::string mode, float x, float y, float radius)
void clearPresentOverlay()
Drop the present overlay callback (window gone; re-register on UI init).
Definition Graphics.h:653
virtual Shader * newShader(const std::string &vertGlsl, const std::string &fragGlsl)=0
Compile GLSL source with glslc (must be on PATH). Empty vertGlsl → default textured vert....
virtual void drawCanvasRGBA(Canvas *canvas, float x, float y, float w, float h, float r=1.f, float g=1.f, float b=1.f, float a=1.f)
Draw a Canvas color buffer as a textured rect (same batch order as other 2D).
Definition Graphics.cpp:160
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
UV draw rotated degrees clockwise (screen Y-down) around the rect center. texture may be null → solid...
virtual Texture * newTexture(int width, int height, const uint8_t *rgba, bool repeatU=false, bool repeatV=false)=0
Outline * pipelineOutline()
Pipeline-owned Outline used by RenderSystem3D when the "outline" feature is on.
Definition Graphics.cpp:774
virtual bool reloadTextureFromFile(const std::string &filename)=0
Reload a path-cached texture from disk in place (pointer stable). False if unbound.
virtual bool updateMeshVertices(Mesh *mesh, const float *posXYZ, const float *nrmXYZ, const float *uvST, int vertexCount, const uint32_t *indices, int indexCount)=0
In-place update of a mesh's vertex/index data (CPU -> host-visible VBO). Mirrors bakeMeshMorph: the u...
Font * newFont(font::FontData *data, std::string charset=Font::defaultCharset())
Build a GPU font (glyph atlas texture) from decoded font data. Rasterizes charset (UTF-8,...
Definition Graphics.cpp:934
virtual void setMesh3DView(const glm::mat4 &view)=0
Camera view matrix for subsequent drawMesh (view-space depth / CSM select).
Material * newMaterial()
Create a Material asset (shading model + textures + PBR knobs). Caller owns Material*; not tracked by...
Definition Graphics.cpp:171
virtual void setCloudShadows(float strength, float worldCell, float time, float windSpeed, float windAngle, float coverage, float detail)=0
Dynamic cloud shadows cast on the ground by the default PBR mesh path. strength 0 disables (no change...
AntiAliasing * newAntiAliasing()
Classic image-space AA (FXAA / SMAA / SSAA / NFAA). Caller owns AntiAliasing*; its Shaders are owned ...
Definition Graphics.cpp:779
const glm::mat4 & getProjection() const
Shader * newShader(const std::string &fragGlsl)
Definition Graphics.h:723
virtual Shader * newHairShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Hair/fur card shader (alpha blend + Kajiya-Kay). Empty vert → mesh3d_hair.vert. Owned by Graphics.
virtual void drawSolidRectRotated(float cx, float cy, float w, float h, float degrees, const Color &color, BlendMode blend=BlendMode::Alpha)=0
Rotated solid quad degrees clockwise (screen Y-down) around (cx, cy).
virtual void drawMeshShadowAlpha(Mesh *mesh, const glm::mat4 &lightMVP, Texture *albedo=nullptr)=0
Shadow pass draw with alpha-cutout discard (card/billboard geometry such as sprite-stack slices): tra...
Texture * newTextureFromImageData(image::ImageData *data, bool repeatU=false, bool repeatV=false)
Definition Graphics.cpp:878
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)
Draws UTF-8 text with the current font (see setFont), baseline-aligned so that (x,...
Definition Graphics.cpp:936
virtual void setMesh3DLight(const glm::vec3 &dir, const glm::vec3 &color)=0
Directional light for subsequent drawMesh calls (world-space direction toward surface).
virtual bool releaseShader(Shader *shader)
Eagerly releases a shader created by this Graphics.
Definition Graphics.h:768
virtual void drawVoxelFaceInstances(const uint32_t *packed, int count, float originX, float originY, float originZ, const std::string &faceDir, Texture *atlas, int tilesPerRow=16, const uint32_t *ao=nullptr)=0
Instanced voxel face rectangles (32-bit packed instances). ao: optional per-instance ambient-occlusio...
virtual void setCanvas(Canvas *canvas)=0
nullptr or this → screen. Switching flushes pending draws to the previous target.
bool had3DThisFrame() const
Definition Graphics.h:582
virtual bool isCanvasActive() const =0
virtual float getMaxAnisotropy() const =0
Device max supported anisotropy (1 if unsupported). Valid after initWithWindow.
std::unique_ptr< RenderControl > renderControl_
Definition Graphics.h:990
virtual void markSwapchainDirty()
Request swapchain recreation on next present/begin3DFrame.
Definition Graphics.h:624
bool isActive() const
Definition Graphics.h:621
const glm::mat4 & getTransform() const
virtual Texture * newTextureFromFile(const std::string &filename)=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
Draw a textured sub-rect (atlas / tile UVs). texture may be null → solid.
void scale(float x, float y=1.0f)
virtual Texture * newTexture(int width, int height, const uint8_t *rgba, const TextureCreateInfo &info)=0
virtual int getMsaaSamples() const
Definition Graphics.h:613
virtual void present()=0
virtual void drawOcclusionSolid(float x, float y, float w, float h)
Definition Graphics.cpp:856
AntiAliasing * pipelineAntiAliasing()
Definition Graphics.cpp:769
virtual void setMesh3DSceneDepth(Texture *depth)=0
Optional scene hardware depth (G-buffer hwDepth, Vulkan NDC z) bound to mesh3d shader binding 7....
AmbientOcclusion * pipelineAmbientOcclusion()
Pipeline-owned AO / GI / AA used by RenderSystem3D when features "ao" / "gi" / "aa" are enabled....
Definition Graphics.cpp:759
virtual void render3D()
Run RenderSystem3D (begin3DFrame + draw visible Renderable3D).
Definition Graphics.cpp:117
virtual bool bakeMeshMorph(Mesh *mesh)=0
If mesh morph weights are dirty, bake blended positions and upload to the GPU VBO....
Shader * getShader() const
Definition Graphics.h:703
virtual Shader * newShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Create a custom 2D shader from SPIR-V words (vert + frag). Owned by Graphics. Vertex stage may be emp...
virtual void setMesh3DShadowReceive(bool receive)=0
Per-draw: when false, shadow sampling is forced off for the next mesh draw.
virtual bool supportsGBufferPost() const
Whether gbuffer-based post-process shaders (AO, GI) can be created on this backend....
Definition Graphics.h:104
Texture * newTextureFromFileRepeated(const std::string &filename, bool repeatU, bool repeatV)
Definition Graphics.cpp:893
virtual void begin3DFrame()=0
Begin a 3D frame: shadow/gbuffer (if pending) then a sampleable scene color pass (color+depth)....
ScreenSpaceReflection * newScreenSpaceReflection()
Screen-space reflections (ray-marched over scene color + hw depth). Caller owns ScreenSpaceReflection...
Definition Graphics.cpp:757
std::unique_ptr< GlobalIllumination > pipelineGI_
Definition Graphics.h:992
void points(const std::vector< glm::vec2 > &positions, const std::vector< Color > &colors)
Draws a series of points at the specified positions.
void requestSurfaceRecreate() override
Request recreation of the platform render surface on the next frame (Android background/foreground de...
Definition Graphics.h:631
std::unique_ptr< AmbientOcclusion > pipelineAO_
Definition Graphics.h:991
virtual void setTextureSampler(Texture *texture, const TextureSampler &sampler)=0
Recreate the sampler for an existing texture (keeps image / mip chain). No-op when texture is null or...
void polygon(std::string mode, const std::vector< glm::vec2 > &vertices, bool skipLastFilledVertex=true)
Draws a polygon with an arbitrary number of vertices.
virtual void drawTexturedRect(Texture *texture, float x, float y, float w, float h, const Color &color)=0
void drawScene3D(float x, float y, float w, float h)
Script-friendly 4-arg form (simplesquirrel does not apply C++ defaults).
Definition Graphics.h:348
Shader * newShaderFromSpvFile(const std::string &fragPath)
Definition Graphics.h:714
virtual Texture * getSceneColorTexture()
Sampleable 3D color target for the current frame (RGB = lit, A = linear depth). Valid after begin3DFr...
Definition Graphics.h:432
virtual void drawMeshShader(Mesh *mesh, const glm::mat4 &model, Texture *texture, const Color &tint, Shader *shader)=0
Draw mesh with an explicit Mesh3D Shader (nullptr = default PBR pipeline).
virtual void drawSolidRectRGBA(float x, float y, float w, float h, float r, float g, float b, float a=1.f)
Definition Graphics.cpp:869
virtual void drawOcclusion(Drawable *drawable, const glm::mat4 &m)
Volumetric occlusion helpers (shadow-pass analogue for light shafts). drawOcclusion skips drawables w...
Definition Graphics.cpp:852
RenderControl * getRenderControl()
Shared compilable 3D render control (features → pass list + GBuffer). Owned by Graphics; valid for th...
Definition Graphics.cpp:173
virtual Mesh * newMeshFromArrays(const float *posXYZ, const float *nrmXYZ, const float *uvST, int vertexCount, const uint32_t *indices, int indexCount)=0
Upload a triangle mesh from packed CPU arrays. Owned by Graphics. posXYZ required (vertexCount*3)....
Font * getFont() const
Definition Graphics.h:691
virtual void clearScreen()
Script-friendly wrappers (r,g,b[,a] floats — no Color type in Squirrel).
Definition Graphics.cpp:865
virtual void drawSolidRect(float x, float y, float w, float h, const Color &color, BlendMode blend=BlendMode::Alpha)=0
Internal immediate-mode helper used by RenderSystem / Batcher.
Water * newWater()
Dynamic water surface (sky reflection + animated edge waves + middle drop ripples)....
Definition Graphics.cpp:788
PresentOverlayFn presentOverlayFn_
Definition Graphics.h:985
Shader * newMeshShader(const std::string &fragGlsl)
Definition Graphics.h:741
virtual void end3DFrameToCanvas()=0
PresentOverlayFn getPresentOverlay() const
Definition Graphics.h:677
virtual Canvas * newCanvas(int width, int height)=0
Create an offscreen render target (sampleable). Owned by Graphics.
void(*)(void *userdata, void *commandBuffer) PresentOverlayFn
Optional overlay drawn inside the swapchain render pass (before end). Used by declarative UI (ImGui)....
Definition Graphics.h:672
virtual Shader * newMeshShaderFromWgsl(const std::string &vertWgsl, const std::string &fragWgsl)=0
Create a Mesh3D custom shader from WGSL source (WebGPU backend). The WGSL must declare the engine's F...
virtual void setScreenReadbackEnabled(bool enabled)
When true, each present copies the swapchain to a CPU buffer for getPixel/newImageData....
Definition Graphics.h:591
int getPixelWidth() const
Definition Graphics.h:119
virtual Mesh * newMeshSphere(int slices=32, int stacks=16)=0
Procedural UV sphere (radius 1, Y-up). Owned by Graphics. slices = longitude divisions,...
virtual Texture * newTexture(image::ImageData *data, const TextureCreateInfo &info)=0
Create texture from ImageData with sampler / mipmap options.
virtual void setViewportSize(int width, int height, int pixelwidth, int pixelheight)=0
Sets the current graphics display viewport dimensions.
GlobalIllumination * newGlobalIllumination()
Screen-space single-bounce GI. Caller owns GlobalIllumination*; its Shaders are owned by Graphics.
Definition Graphics.cpp:755
int getHeight() const
Definition Graphics.h:118
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). Uses Lighting2DUBO from setLighting2D. normal may be null → treate...
void * getPresentOverlayUser() const
Definition Graphics.h:678
void setPresentOverlay(PresentOverlayFn fn, void *userdata)
Definition Graphics.h:673
void circle(std::string mode, float x, float y, float radius, int points)
Draws a circle using the specified arguments.
virtual Shader * newShaderFromSpvFile(const std::string &vertPath, const std::string &fragPath)=0
Load SPIR-V from files via Filesystem (empty vertPath → default textured vert).
virtual void drawTexturedRectShader(Texture *texture, Shader *shader, float x, float y, float w, float h, const Color &color)=0
Draw with an explicit Shader (nullptr = default textured pipeline).
double getCurrentDPIScale() const
Definition Graphics.h:122
virtual void setMesh3DNormalTexture(Texture *normal)=0
Optional normal map for the next drawMesh / drawMeshShader (nullptr = flat).
virtual void setMesh3DHeightTexture(Texture *height)=0
Optional height map for parallax (R channel; nullptr = flat / off).
virtual Texture * newCubemap(int faceSize, const uint8_t *rgbaFaces, const TextureCreateInfo &info)=0
Cubemap with mipmap / sampler options (IBL-friendly when generateMipmaps=true).
virtual void setMesh3DLighting(const Lighting3DPack &pack)=0
Per-frame ambient + up to 8 lights packed into Mesh3DUBO.
virtual void drawTexturedRectShaderDepth(Texture *color, Texture *depth, Shader *shader, float x, float y, float w, float h, const Color &tint)=0
Fullscreen/post draw sampling color at binding 0 and depth at binding 1 (hardware D32,...
Dense grass + sparse dark tufts on a mesh. Caller owns GrassField*; GPU Mesh / Shader / Texture are o...
Definition Grass.h:124
2D immediate-mode drawing surface (screen or offscreen Canvas).
Definition IGraphics2D.h:32
3D frame / mesh / light / shadow rendering surface.
Definition IGraphics3D.h:28
Post-process / special-effect object factory.
Definition IPostFX.h:21
Texture / mesh / shader / canvas creation and release.
Packages shading method + surface parameters into one attachable asset.
Definition Material.h:26
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:18
Screen-space model outline (t3ssel8r-style), computed from the GBuffer hardware depth + world-normal ...
Definition Outline.h:31
Pixel-space sub-rectangle of a Texture (atlas cell / sprite frame). UV conversion uses the texture's ...
Definition Quad.h:9
Declarative, compilable 3D render control.
Screen-space reflections (SSR) as a fullscreen post pass.
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
Volumetric light + fog.
Definition Volumetric.h:27
Dynamic water surface with sky reflection and animated ripples.
Definition Water.h:33
Flowing waterfall (falling water sheet) rendered on a vertical plane.
Definition Waterfall.h:34
Represents raw pixel data.
Definition ImageData.h:26
卡牌游戏 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
constexpr uint32_t Water
Definition Semantic.h:14
CPU-built clustered lighting upload for one frame/camera. Point lights are clustered; directional lig...
Per-pixel mesh entity-ID pass. Renders each EntityIdDraw's mesh with the given flat idColor (RGB enco...
Definition Graphics.h:441
Options for Graphics::newTexture / newCubemap. When generateMipmaps is true and sampler....
Sampler state for a Texture (filter, wrap, mip LOD, anisotropy). Defaults match historical engine beh...