载入中...
搜索中...
未找到
GraphicsImageFactoryAdapter.cpp
浏览该文件的文档.
2
4#include "graphics/Texture.h"
5
6#include <limits>
7
8namespace eve::asset_graphics {
9namespace {
10
11} // namespace
12
14 std::uint32_t width, std::uint32_t height, const std::uint8_t* pixels, bool srgb) {
15 if (width > static_cast<std::uint32_t>(std::numeric_limits<int>::max()) ||
16 height > static_cast<std::uint32_t>(std::numeric_limits<int>::max()) || !pixels)
18 "RGBA8 upload arguments exceed graphics limits",
19 {}, {}, "asset.graphics.image.adapter"));
20 if (srgb)
22 DiagnosticCode::Unsupported, "legacy graphics adapter requires Cooked linear RGBA8 pixels", {}, {},
23 "asset.graphics.image.adapter"));
24 graphics::Texture* texture = factory_.newTexture(static_cast<int>(width),
25 static_cast<int>(height), pixels);
26 if (!texture)
28 DiagnosticCode::Failed, "graphics backend rejected RGBA8 upload", {}, {}, "asset.graphics.image.adapter"));
30}
31
33 uint32_t levels,
34 std::span<const uint8_t> pixels) {
35 return factory_.newTextureMipChain(width, height, levels, pixels);
36}
37
39 uint32_t depth,
40 std::span<const uint8_t> pixels) {
41 return factory_.newTexture3DRgba8(width, height, depth, pixels);
42}
43
45 if (!texture)
47 "cannot release a null graphics texture", {}, {},
48 "asset.graphics.image.adapter"));
49 if (!factory_.releaseTexture(texture))
51 "graphics backend rejected texture release", {}, {},
52 "asset.graphics.image.adapter"));
53 // Successful backend release transfers the detached CPU facade to this caller.
54 delete texture;
55 return Result<void>::success();
56}
57
58} // namespace eve::asset_graphics
Transactional EVIMG runtime texture loading.
std::uint32_t height
std::uint32_t width
uint8_t * pixels
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 success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Result< graphics::Texture * > uploadRgba8Volume(uint32_t width, uint32_t height, uint32_t depth, std::span< const uint8_t > pixels) override
Upload one tightly packed linear RGBA8 volume.
Result< graphics::Texture * > uploadRgba8MipChain(uint32_t width, uint32_t height, uint32_t levels, std::span< const uint8_t > pixels) override
Upload complete explicit linear RGBA8 mips without regeneration.
Result< graphics::Texture * > uploadRgba8(std::uint32_t width, std::uint32_t height, const std::uint8_t *pixels, bool srgb) override
Upload one tightly packed, top-down RGBA8 image.
Result< void > releaseImage(graphics::Texture *texture) override
Release a texture previously returned by this factory.
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 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 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 bool releaseTexture(Texture *texture)=0
Release texture.
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18