载入中...
搜索中...
未找到
IResourceFactory.h
浏览该文件的文档.
1#pragma once
2
3// Narrow resource-factory interface of the Graphics backend.
4// Consumers that only create textures / meshes / shaders / canvases (model3d,
5// animation, avatar, sceneloader) depend on this instead of the full
6// graphics::Graphics god class.
7
8#include <cstdint>
9#include <span>
10#include <string>
11#include <vector>
12#include "common/BorrowedRef.h"
13#include "common/Result.h"
14
15#include <assimp/matrix4x4.h>
16
17struct aiMesh;
18
19namespace eve::font {
20class FontData;
21}
22
23namespace eve::image {
24class ImageData;
25}
26
27namespace eve::graphics {
28
29class Canvas;
30class Font;
31class Mesh;
32class Shader;
33class Texture;
34struct TextureCreateInfo;
35struct TextureSampler;
36
39public:
41 virtual ~IResourceFactory() = default;
42
44 virtual Texture *newTexture(int width, int height, const uint8_t *rgba, bool repeatU = false,
45 bool repeatV = false) = 0;
47 virtual Texture *newTexture(int width, int height, const uint8_t *rgba,
48 const TextureCreateInfo &info) = 0;
58 [[nodiscard]] virtual Result<Texture *> newTextureMipChain(uint32_t width, uint32_t height, uint32_t levels,
59 std::span<const uint8_t> rgba) {
60 (void)width;
61 (void)height;
62 (void)levels;
63 (void)rgba;
66 "explicit texture mip upload is unavailable", {}, {},
67 "graphics.texture.mips"));
68 }
77 [[nodiscard]] virtual Result<Texture *> newTextureArrayRgba16f(uint32_t width, uint32_t height, uint32_t layers,
78 std::span<const uint16_t> rgbaHalf) {
79 (void)width;
80 (void)height;
81 (void)layers;
82 (void)rgbaHalf;
85 DiagnosticCode::Unsupported, "RGBA16F texture arrays are unavailable", {}, {}, "graphics.texture.array"));
86 }
100 [[nodiscard]] virtual Result<Texture *> newTexture3DRgba8(uint32_t width, uint32_t height, uint32_t depth,
101 std::span<const uint8_t> rgba) {
102 (void)width;
103 (void)height;
104 (void)depth;
105 (void)rgba;
108 DiagnosticCode::Unsupported, "RGBA8 3D textures are unavailable", {}, {}, "graphics.texture.volume"));
109 }
111 virtual Texture *newCubemap(int faceSize, const uint8_t *rgbaFaces) = 0;
113 virtual Texture *newCubemap(int faceSize, const uint8_t *rgbaFaces,
114 const TextureCreateInfo &info) = 0;
129 [[nodiscard]] virtual ResultRef<Texture> newSharedTexture(image::ImageData *data, const std::string &contentKey) {
130 (void)data;
131 (void)contentKey;
133 "immutable texture sharing is unavailable", {}, {},
134 "graphics.texture.shared"));
135 }
138 bool repeatV = false) = 0;
141 const TextureCreateInfo &info) = 0;
144 bool generateMipmaps, float maxAnisotropy,
145 const std::string &filter, const std::string &mipmap,
146 float lodBias = 0.f) = 0;
148 virtual void setTextureSampler(Texture *texture, const TextureSampler &sampler) = 0;
150 virtual Texture *newTextureFromFile(const std::string &filename) = 0;
152 virtual Texture *newTextureFromFileRepeated(const std::string &filename, bool repeatU,
153 bool repeatV) = 0;
155 virtual bool reloadTextureFromFile(const std::string &filename) = 0;
157 virtual float getMaxAnisotropy() const = 0;
159 virtual bool releaseTexture(Texture *texture) = 0;
160
162 virtual Mesh *newMeshFromAssimp(const ::aiMesh &mesh) = 0;
164 virtual Mesh *newMeshFromAssimp(const ::aiMesh &mesh, const aiMatrix4x4 &worldTransform) = 0;
166 virtual Mesh *newMeshFromArrays(const float *posXYZ, const float *nrmXYZ, const float *uvST,
167 int vertexCount, const uint32_t *indices, int indexCount) = 0;
175 virtual Mesh *newMeshFromArraysColored(const float *posXYZ, const float *nrmXYZ, const float *uvST,
176 const float *colorRGBA, int vertexCount,
177 const uint32_t *indices, int indexCount) = 0;
179 virtual bool updateMeshVertices(Mesh *mesh, const float *posXYZ, const float *nrmXYZ,
180 const float *uvST, int vertexCount, const uint32_t *indices,
181 int indexCount) = 0;
183 virtual bool bakeMeshMorph(Mesh *mesh) = 0;
185 virtual Mesh *newMeshSphere(int slices, int stacks) = 0;
187 virtual Mesh *newMeshCylinder(int slices, int stacks, bool caps) = 0;
189 virtual Mesh *newMeshCube(float size) = 0;
191 virtual bool releaseMesh(Mesh *mesh) = 0;
192
194 virtual Shader *newShaderFromSpv(const std::vector<uint32_t> &vertSpv,
195 const std::vector<uint32_t> &fragSpv) = 0;
197 virtual Shader *newShaderFromSpvFile(const std::string &vertPath,
198 const std::string &fragPath) = 0;
200 virtual Shader *newShader(const std::string &vertGlsl, const std::string &fragGlsl) = 0;
201
209 virtual Shader *newShaderFromWgsl(const std::string &vertWgsl,
210 const std::string &fragWgsl) = 0;
212 virtual Shader *newMeshShaderFromSpv(const std::vector<uint32_t> &vertSpv,
213 const std::vector<uint32_t> &fragSpv) = 0;
215 virtual Shader *newMeshShaderFromWgsl(const std::string &vertWgsl,
216 const std::string &fragWgsl) = 0;
218 virtual Shader *newMeshShader(const std::string &vertGlsl, const std::string &fragGlsl) = 0;
220 virtual Shader *newHairShaderFromSpv(const std::vector<uint32_t> &vertSpv,
221 const std::vector<uint32_t> &fragSpv) = 0;
223 virtual bool releaseShader(Shader *shader) = 0;
224
226 virtual Canvas *newCanvas(int width, int height) = 0;
228 virtual Font *newFont(font::FontData *data, std::string charset) = 0;
229};
230
231} // namespace eve::graphics
Vocabulary aliases for nullable and checked borrowed references.
std::uint32_t vertexCount
std::uint32_t indexCount
vk::UniqueSampler sampler
std::vector< std::uint32_t > indices
std::uint32_t height
std::uint32_t width
Mesh * mesh
Shader * shader
Move-only, checked operation results for the common layer.
bool repeatV
std::string filter
std::string mipmap
bool repeatU
float size
Definition TreeMesh.cpp:156
std::uint32_t depth
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
CPU-side decoded font face (FreeType FT_Face + owned font bytes). Does not upload to GPU — rasterize ...
Definition FontData.h:25
Canvas public API.
Definition Canvas.h:17
GPU-side font: wraps a decoded font::FontData and rasterizes a fixed set of codepoints into a single ...
Definition Font.h:35
Texture / mesh / shader / canvas creation and release.
virtual Shader * newMeshShader(const std::string &vertGlsl, const std::string &fragGlsl)=0
Creates a mesh shader. @ownership Caller deletes unless documented otherwise.
virtual bool updateMeshVertices(Mesh *mesh, const float *posXYZ, const float *nrmXYZ, const float *uvST, int vertexCount, const uint32_t *indices, int indexCount)=0
Updates mesh vertices.
virtual Shader * newShader(const std::string &vertGlsl, const std::string &fragGlsl)=0
Creates a shader. @ownership Caller deletes unless documented otherwise.
virtual float getMaxAnisotropy() const =0
Returns the max anisotropy.
virtual Texture * newTexture(image::ImageData *data)=0
Creates a texture. @ownership Caller deletes unless documented otherwise.
virtual void setTextureSampler(Texture *texture, const TextureSampler &sampler)=0
Sets the texture sampler.
virtual Canvas * newCanvas(int width, int height)=0
Creates a canvas. @ownership Caller deletes unless documented otherwise.
virtual Result< Texture * > newTexture3DRgba8(uint32_t width, uint32_t height, uint32_t depth, std::span< const uint8_t > rgba)
Upload one tightly packed linear RGBA8 3D sampled texture.
virtual Texture * newTextureFromImageData(image::ImageData *data, const TextureCreateInfo &info)=0
Creates a texture from image data. @ownership Caller deletes unless documented otherwise.
virtual Result< Texture * > newTextureArrayRgba16f(uint32_t width, uint32_t height, uint32_t layers, std::span< const uint16_t > rgbaHalf)
Upload a sampled 2D array of tightly packed linear RGBA16F texels.
virtual Shader * newShaderFromSpvFile(const std::string &vertPath, const std::string &fragPath)=0
Creates a shader from spv file. @ownership Caller deletes unless documented otherwise.
virtual Font * newFont(font::FontData *data, std::string charset)=0
Creates a font. @ownership Caller deletes unless documented otherwise.
virtual ResultRef< Texture > newSharedTexture(image::ImageData *data, const std::string &contentKey)
Reuse or upload immutable RGBA8 pixels under a caller-provided content key.
virtual Shader * newHairShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Creates a hair shader from spv. @ownership Caller deletes unless documented otherwise.
virtual Result< Texture * > newTextureMipChain(uint32_t width, uint32_t height, uint32_t levels, std::span< const uint8_t > rgba)
Upload complete explicit linear RGBA8 mips without regenerating pixels.
virtual bool releaseMesh(Mesh *mesh)=0
Release mesh.
virtual Texture * newTexture(int width, int height, const uint8_t *rgba, bool repeatU=false, bool repeatV=false)=0
Creates a texture. @ownership Caller deletes unless documented otherwise.
virtual 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)=0
Creates a texture with sampler. @ownership Caller deletes unless documented otherwise.
virtual bool reloadTextureFromFile(const std::string &filename)=0
Reloads texture from file.
virtual Texture * newCubemap(int faceSize, const uint8_t *rgbaFaces)=0
Creates a cubemap. @ownership Caller deletes unless documented otherwise.
virtual Mesh * newMeshSphere(int slices, int stacks)=0
Creates a mesh sphere. @ownership Caller deletes unless documented otherwise.
virtual Shader * newShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Creates a shader from spv. @ownership Caller deletes unless documented otherwise.
virtual Mesh * newMeshCylinder(int slices, int stacks, bool caps)=0
Creates a mesh cylinder. @ownership Caller deletes unless documented otherwise.
virtual Mesh * newMeshFromArrays(const float *posXYZ, const float *nrmXYZ, const float *uvST, int vertexCount, const uint32_t *indices, int indexCount)=0
Creates a mesh from arrays. @ownership Caller deletes unless documented otherwise.
virtual Shader * newShaderFromWgsl(const std::string &vertWgsl, const std::string &fragWgsl)=0
Create a 2D custom shader from WGSL source (WebGPU backend). Empty vert → default textured vertex sha...
virtual Shader * newMeshShaderFromWgsl(const std::string &vertWgsl, const std::string &fragWgsl)=0
Create a WebGPU Mesh3D shader; an empty stage selects the matching engine default.
virtual Shader * newMeshShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Create a Mesh3D shader; an empty stage selects the matching engine default.
virtual Texture * newTextureFromFileRepeated(const std::string &filename, bool repeatU, bool repeatV)=0
Creates a texture from file repeated. @ownership Caller deletes unless documented otherwise.
virtual ~IResourceFactory()=default
Releases IResourceFactory resources.
virtual Texture * newTexture(int width, int height, const uint8_t *rgba, const TextureCreateInfo &info)=0
Creates a texture. @ownership Caller deletes unless documented otherwise.
virtual Mesh * newMeshFromArraysColored(const float *posXYZ, const float *nrmXYZ, const float *uvST, const float *colorRGBA, int vertexCount, const uint32_t *indices, int indexCount)=0
Create a mesh with a packed linear RGBA vertex-color stream.
virtual Mesh * newMeshCube(float size)=0
Creates a mesh cube. @ownership Caller deletes unless documented otherwise.
virtual bool releaseTexture(Texture *texture)=0
Release texture.
virtual Texture * newTextureFromFile(const std::string &filename)=0
Creates a texture from file. @ownership Caller deletes unless documented otherwise.
virtual Texture * newTextureFromImageData(image::ImageData *data, bool repeatU=false, bool repeatV=false)=0
Creates a texture from image data. @ownership Caller deletes unless documented otherwise.
virtual Texture * newTexture(image::ImageData *data, const TextureCreateInfo &info)=0
Creates a texture. @ownership Caller deletes unless documented otherwise.
virtual Mesh * newMeshFromAssimp(const ::aiMesh &mesh)=0
Creates a mesh from assimp. @ownership Caller deletes unless documented otherwise.
virtual bool releaseShader(Shader *shader)=0
Release shader.
virtual Texture * newCubemap(int faceSize, const uint8_t *rgbaFaces, const TextureCreateInfo &info)=0
Creates a cubemap. @ownership Caller deletes unless documented otherwise.
virtual bool bakeMeshMorph(Mesh *mesh)=0
Bake mesh morph.
virtual Mesh * newMeshFromAssimp(const ::aiMesh &mesh, const aiMatrix4x4 &worldTransform)=0
Creates a mesh from assimp. @ownership Caller deletes unless documented otherwise.
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:25
Custom GPU program.
Definition Shader.h:39
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
Represents raw pixel data.
Definition ImageData.h:38
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
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...
glm::uvec4 info