Etterna 0.74.4
Loading...
Searching...
No Matches
RageTexture.h
1/* RageTexture - Abstract class for a texture and metadata. */
2
3#ifndef RAGE_TEXTURE_H
4#define RAGE_TEXTURE_H
5
6#include "RageTextureID.h"
7#include "RageUtil/Misc/RageTimer.h"
8#include "RageUtil/Misc/RageTypes.h"
9
10struct lua_State;
11struct RageSurface;
12
14{
15 public:
16 RageTexture(const RageTextureID& file);
17 virtual ~RageTexture() = 0;
18 virtual void Update(float /* fDeltaTime */) {}
19 virtual void Reload() {}
20 virtual void Invalidate() {
21 } /* only called by RageTextureManager::InvalidateTextures */
22 [[nodiscard]] virtual auto GetTexHandle() const
23 -> intptr_t = 0; // accessed by RageDisplay
24
25 // movie texture/animated texture stuff
26 virtual void SetPosition(float /* fSeconds */) {} // seek
27 virtual void DecodeSeconds(float /* fSeconds */) {} // decode
28 virtual void SetPlaybackRate(float /*unused*/) {}
29 [[nodiscard]] virtual auto IsAMovie() const -> bool { return false; }
30 virtual void SetLooping(bool /*unused*/) {}
31
32 [[nodiscard]] auto GetSourceWidth() const -> int { return m_iSourceWidth; }
33 [[nodiscard]] auto GetSourceHeight() const -> int
34 {
35 return m_iSourceHeight;
36 }
37 [[nodiscard]] auto GetTextureWidth() const -> int
38 {
39 return m_iTextureWidth;
40 }
41 [[nodiscard]] auto GetTextureHeight() const -> int
42 {
43 return m_iTextureHeight;
44 }
45 [[nodiscard]] auto GetImageWidth() const -> int { return m_iImageWidth; }
46 [[nodiscard]] auto GetImageHeight() const -> int { return m_iImageHeight; }
47
48 [[nodiscard]] auto GetFramesWide() const -> int { return m_iFramesWide; }
49 [[nodiscard]] auto GetFramesHigh() const -> int { return m_iFramesHigh; }
50
51 [[nodiscard]] auto GetSourceFrameWidth() const -> int
52 {
53 return GetSourceWidth() / GetFramesWide();
54 }
55 [[nodiscard]] auto GetSourceFrameHeight() const -> int
56 {
57 return GetSourceHeight() / GetFramesHigh();
58 }
59 [[nodiscard]] auto GetTextureFrameWidth() const -> int
60 {
61 return GetTextureWidth() / GetFramesWide();
62 }
63 [[nodiscard]] auto GetTextureFrameHeight() const -> int
64 {
65 return GetTextureHeight() / GetFramesHigh();
66 }
67 [[nodiscard]] auto GetImageFrameWidth() const -> int
68 {
69 return GetImageWidth() / GetFramesWide();
70 }
71 [[nodiscard]] auto GetImageFrameHeight() const -> int
72 {
73 return GetImageHeight() / GetFramesHigh();
74 }
75
76 // Use these to convert between the different coordinate systems:
77 [[nodiscard]] auto GetSourceToImageCoordsRatioX() const -> float
78 {
79 return float(GetImageWidth()) / GetSourceWidth();
80 }
81 [[nodiscard]] auto GetImageToTexCoordsRatioX() const -> float
82 {
83 return 1.0F / GetTextureWidth();
84 }
85 [[nodiscard]] auto GetSourceToTexCoordsRatioX() const -> float
86 {
87 return GetSourceToImageCoordsRatioX() * GetImageToTexCoordsRatioX();
88 }
89 [[nodiscard]] auto GetSourceToImageCoordsRatioY() const -> float
90 {
91 return float(GetImageHeight()) / GetSourceHeight();
92 }
93 [[nodiscard]] auto GetImageToTexCoordsRatioY() const -> float
94 {
95 return 1.0F / GetTextureHeight();
96 }
97 [[nodiscard]] auto GetSourceToTexCoordsRatioY() const -> float
98 {
99 return GetSourceToImageCoordsRatioY() * GetImageToTexCoordsRatioY();
100 }
101
102 [[nodiscard]] auto GetTextureCoordRect(int frameNo) const -> const RectF*;
103 [[nodiscard]] auto GetNumFrames() const -> int
104 {
105 return m_iFramesWide * m_iFramesHigh;
106 }
107
108 // Used by RageTextureManager. Order is important; see
109 // RageTextureManager.cpp.
110 [[nodiscard]] auto GetPolicy() const -> const RageTextureID::TexPolicy&
111 {
112 return m_ID.Policy;
113 }
114 auto GetPolicy() -> RageTextureID::TexPolicy& { return m_ID.Policy; }
115 int m_iRefCount;
116 bool m_bWasUsed;
117 RageTimer m_lastRefTime;
118
119 // The ID that we were asked to load:
120 [[nodiscard]] auto GetID() const -> const RageTextureID& { return m_ID; }
121
122 static void GetFrameDimensionsFromFileName(const std::string& sPath,
123 int* puFramesWide,
124 int* puFramesHigh,
125 int source_width = 0,
126 int source_height = 0);
127
128 virtual auto GetAverageColor(unsigned increment = 1) const -> const RageColor;
129
130 // Lua
131 virtual void PushSelf(lua_State* L);
132
133 private:
134 /* We might change settings when loading (due to hints, hardware
135 * limitations, etc). The data actually loaded is here: */
136 RageTextureID m_ID;
137
138 protected:
139 int m_iSourceWidth,
140 m_iSourceHeight; // dimensions of the original image loaded from disk
141 int m_iTextureWidth,
142 m_iTextureHeight; // dimensions of the texture in memory
143 int m_iImageWidth, m_iImageHeight; // dimensions of the image in the texture
144 int m_iFramesWide, m_iFramesHigh; // The number of frames of animation in
145 // each row and column of this texture
146 std::vector<RectF> m_TextureCoordRects; // size = m_iFramesWide * m_iFramesHigh
147 RageSurface* m_pSurface{ nullptr };
148
149 virtual void CreateFrameRects();
150};
151
152#endif
Definition RageTexture.h:14
Definition RageTimer.h:9
Definition RageTypes.h:332
Definition RageSurface.h:90
Definition RageTextureID.h:12