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