载入中...
搜索中...
未找到
Texture.cpp
浏览该文件的文档.
1#include "graphics/Texture.h"
2
3#include "graphics/Graphics.h"
4
5#include <cmath>
6#include <cstring>
7#include <glm/glm.hpp>
8
9namespace eve::graphics {
10
11Texture::Texture() = default;
12
14 // GPU lifetime is owned by Graphics backend for now (tracked until Graphics destroy).
15 gpuHandle = nullptr;
16}
17
19 graphics_ = graphics;
20 filePixelsPending_ = graphics != nullptr;
21}
22
23void Texture::clearDeferredFilePixels() { filePixelsPending_ = false; }
24
25void Texture::realizeFilePixelsIfNeeded() const {
26 if (filePixelsPending_ && graphics_) graphics_->ensureFileTexturesReady();
27}
28
29int Texture::getWidth() const {
30 realizeFilePixelsIfNeeded();
31 return width;
32}
33
34int Texture::getHeight() const {
35 realizeFilePixelsIfNeeded();
36 return height;
37}
38
40 realizeFilePixelsIfNeeded();
41 return pixelWidth;
42}
43
45 realizeFilePixelsIfNeeded();
46 return pixelHeight;
47}
48
50 realizeFilePixelsIfNeeded();
51 return mipmapCount;
52}
53
55 premultipliedAlpha_ = value != nullptr && std::strcmp(value, "premultiplied") == 0;
56}
57
58const char* Texture::getAlphaConvention() const { return premultipliedAlpha_ ? "premultiplied" : "straight"; }
59
60void Texture::draw(Graphics*, const glm::mat4&) const {
61 // Declarative path uses RenderSystem; immediate draw left for later.
62}
63
64void Texture::drawOcclusion(Graphics* gfx, const glm::mat4& matrix) const {
65 if (!gfx || !getCastOcclusion()) return;
66 // Treat matrix as 2D affine: translation in column 3, scale from basis lengths.
67 const float x = matrix[3][0];
68 const float y = matrix[3][1];
69 const float w = std::sqrt(matrix[0][0] * matrix[0][0] + matrix[0][1] * matrix[0][1]);
70 const float h = std::sqrt(matrix[1][0] * matrix[1][0] + matrix[1][1] * matrix[1][1]);
71 if (w <= 0.f || h <= 0.f) return;
72 gfx->drawOcclusionTexture(const_cast<Texture*>(this), x, y, w, h);
73}
74
75} // namespace eve::graphics
double y
double x
float w
Definition AnimClip.cpp:738
int h
Object::Ptr value
glm::dmat4 matrix
Graphics * graphics
bool getCastOcclusion() const
When false, skipped by Graphics::drawOcclusion / volumetric occluder passes.
Definition Drawable.h:31
virtual void drawOcclusionTexture(Texture *texture, float x, float y, float w, float h)
Draws occlusion texture.
void ensureFileTexturesReady()
Finish CPU decode and GPU upload for outstanding newTextureFromFile results. @thread Game/render thre...
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
void clearDeferredFilePixels()
Clears deferred file pixels.
Definition Texture.cpp:23
int getMipmapCount() const
Returns the mipmap count.
Definition Texture.cpp:49
void markDeferredFilePixels(Graphics *graphics)
Mark deferred file pixels.
Definition Texture.cpp:18
~Texture() override
Texture.
Definition Texture.cpp:13
void draw(Graphics *gfx, const glm::mat4 &matrix) const override
Draws .
Definition Texture.cpp:60
void drawOcclusion(Graphics *gfx, const glm::mat4 &matrix) const override
Black silhouette using texture alpha (volumetric occlusion map).
Definition Texture.cpp:64
const char * getAlphaConvention() const
Returns the alpha convention spelling.
Definition Texture.cpp:58
int getPixelWidth() const
Returns the pixel width.
Definition Texture.cpp:39
int getPixelHeight() const
Returns the pixel height.
Definition Texture.cpp:44
void setAlphaConvention(const char *value)
Declare whether RGB is straight or already multiplied by alpha.
Definition Texture.cpp:54
int getWidth() const
Returns the width.
Definition Texture.cpp:29
int getHeight() const
Returns the height.
Definition Texture.cpp:34
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25