载入中...
搜索中...
未找到
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// Incomplete glm::mat4 is enough for const-reference parameters.
16#include <glm/fwd.hpp>
17
18struct aiMesh;
19
20namespace eve::font {
21class FontData;
22}
23
24namespace eve::image {
25class ImageData;
26}
27
28namespace eve::graphics {
29
30class Canvas;
31class Font;
32class Mesh;
33class Shader;
34class Texture;
35struct TextureCreateInfo;
36struct TextureSampler;
37
40public:
42 virtual ~IResourceFactory() = default;
43
45 virtual Texture *newTexture(int width, int height, const uint8_t *rgba, bool repeatU = false,
46 bool repeatV = false) = 0;
48 virtual Texture *newTexture(int width, int height, const uint8_t *rgba,
49 const TextureCreateInfo &info) = 0;
59 [[nodiscard]] virtual Result<Texture *> newTextureMipChain(uint32_t width, uint32_t height, uint32_t levels,
60 std::span<const uint8_t> rgba) {
61 (void)width;
62 (void)height;
63 (void)levels;
64 (void)rgba;
67 "explicit texture mip upload is unavailable", {}, {},
68 "graphics.texture.mips"));
69 }
78 [[nodiscard]] virtual Result<Texture *> newTextureArrayRgba16f(uint32_t width, uint32_t height, uint32_t layers,
79 std::span<const uint16_t> rgbaHalf) {
80 (void)width;
81 (void)height;
82 (void)layers;
83 (void)rgbaHalf;
86 DiagnosticCode::Unsupported, "RGBA16F texture arrays are unavailable", {}, {}, "graphics.texture.array"));
87 }
101 [[nodiscard]] virtual Result<Texture *> newTexture3DRgba8(uint32_t width, uint32_t height, uint32_t depth,
102 std::span<const uint8_t> rgba) {
103 (void)width;
104 (void)height;
105 (void)depth;
106 (void)rgba;
109 DiagnosticCode::Unsupported, "RGBA8 3D textures are unavailable", {}, {}, "graphics.texture.volume"));
110 }
112 virtual Texture *newCubemap(int faceSize, const uint8_t *rgbaFaces) = 0;
114 virtual Texture *newCubemap(int faceSize, const uint8_t *rgbaFaces,
115 const TextureCreateInfo &info) = 0;
130 [[nodiscard]] virtual ResultRef<Texture> newSharedTexture(image::ImageData *data, const std::string &contentKey) {
131 (void)data;
132 (void)contentKey;
134 "immutable texture sharing is unavailable", {}, {},
135 "graphics.texture.shared"));
136 }
139 bool repeatV = false) = 0;
142 const TextureCreateInfo &info) = 0;
145 bool generateMipmaps, float maxAnisotropy,
146 const std::string &filter, const std::string &mipmap,
147 float lodBias = 0.f) = 0;
161 virtual Texture *newTextureFromFile(const std::string &filename) = 0;
170 [[nodiscard]] virtual ResultRef<Texture> loadTexture(const std::string &filename) {
171 (void)filename;
173 "resident file texture loading is unavailable", {}, {},
174 "graphics.texture.load"));
175 }
177 virtual Texture *newTextureFromFileRepeated(const std::string &filename, bool repeatU,
178 bool repeatV) = 0;
180 virtual bool reloadTextureFromFile(const std::string &filename) = 0;
182 virtual float getMaxAnisotropy() const = 0;
184 virtual bool releaseTexture(Texture *texture) = 0;
185
187 virtual Mesh *newMeshFromAssimp(const ::aiMesh &mesh) = 0;
192 virtual Mesh* newMeshFromAssimp(const ::aiMesh& mesh, const glm::mat4& worldTransform) = 0;
194 virtual Mesh *newMeshFromArrays(const float *posXYZ, const float *nrmXYZ, const float *uvST,
195 int vertexCount, const uint32_t *indices, int indexCount) = 0;
203 virtual Mesh *newMeshFromArraysColored(const float *posXYZ, const float *nrmXYZ, const float *uvST,
204 const float *colorRGBA, int vertexCount,
205 const uint32_t *indices, int indexCount) = 0;
208 virtual bool updateMeshVertices(Mesh *mesh, const float *posXYZ, const float *nrmXYZ,
209 const float *uvST, int vertexCount, const uint32_t *indices,
210 int indexCount) = 0;
212 virtual bool bakeMeshMorph(Mesh *mesh) = 0;
214 virtual Mesh *newMeshSphere(int slices, int stacks) = 0;
216 virtual Mesh *newMeshCylinder(int slices, int stacks, bool caps) = 0;
218 virtual Mesh *newMeshCube(float size) = 0;
220 virtual bool releaseMesh(Mesh *mesh) = 0;
221
223 virtual Shader *newShaderFromSpv(const std::vector<uint32_t> &vertSpv,
224 const std::vector<uint32_t> &fragSpv) = 0;
226 virtual Shader *newShaderFromSpvFile(const std::string &vertPath,
227 const std::string &fragPath) = 0;
229 virtual Shader *newShader(const std::string &vertGlsl, const std::string &fragGlsl) = 0;
230
238 virtual Shader *newShaderFromWgsl(const std::string &vertWgsl,
239 const std::string &fragWgsl) = 0;
241 virtual Shader *newMeshShaderFromSpv(const std::vector<uint32_t> &vertSpv,
242 const std::vector<uint32_t> &fragSpv) = 0;
244 virtual Shader *newMeshShaderFromWgsl(const std::string &vertWgsl,
245 const std::string &fragWgsl) = 0;
247 virtual Shader *newMeshShader(const std::string &vertGlsl, const std::string &fragGlsl) = 0;
249 virtual Shader *newHairShaderFromSpv(const std::vector<uint32_t> &vertSpv,
250 const std::vector<uint32_t> &fragSpv) = 0;
252 virtual bool releaseShader(Shader *shader) = 0;
253
255 virtual Canvas *newCanvas(int width, int height) = 0;
257 virtual Font *newFont(font::FontData *data, std::string charset) = 0;
258};
259
260} // 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
OceanMeshSettings mesh
Texture * texture
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:158
std::uint32_t depth
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
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. @cost Linear conversion/upload per changed stream; amortize by submitting only...
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
Set desired sampler state; equal state is a no-op and repeated edits coalesce. @thread Graphics threa...
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 > loadTexture(const std::string &filename)
Load a ready path-cached texture without requiring caller-managed tasks.
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 Mesh * newMeshFromAssimp(const ::aiMesh &mesh, const glm::mat4 &worldTransform)=0
Creates a mesh from assimp, baking a column-major world transform into positions. @ownership Caller d...
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
Load a path-cached file texture; cache hits return the same resource without I/O or upload....
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.
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:26
Custom GPU program.
Definition Shader.h:41
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
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