Logo
Texture.h
1#pragma once
2
3#include "Types.h"
4#include "gfx/Texture.h"
5
6using namespace System::Runtime::InteropServices;
7
8namespace XXSharpKmyGfx{
9
10 ref class GameView;
11
12 private ref class Texture {
13
14 bool managedResourceAttached = false;
15
16 public:
17 kmyGfx::Texture* obj;
18 bool deleteAsCreator = false;
19 System::String^ loadpath;
20 Texture()
21 {
22 obj = NULL;
23 deleteAsCreator = true;
24 }
25
26 Texture(System::String^ path, System::Guid guid, int type, bool srgb, bool genmipmap, TEXTUREUSAGE usage, bool compress, PREMULTIPLIEDTYPE premultiplied);
27
28 Texture(kmyGfx::Texture* t)
29 {
30 obj = t;
31 deleteAsCreator = false;
32 if(t)t->addExRef();
33 }
34
35 Texture^ makeNewReference()
36 {
37 return gcnew Texture(obj);
38 }
39
40 ~Texture()
41 {
42 Release();
43 }
44
45 void managedResourceAttach()
46 {
47 if (managedResourceAttached) {
48 DBGPRINTF("[warn] texture attached to multiple managed resource. (%s)", obj ? obj->getFileName() : "nullobj");
49 }
50 managedResourceAttached = true;
51 }
52
53 void managedResourceDetach()
54 {
55 if (!managedResourceAttached) {
56 DBGPRINTF("[warn] unattached texture was detached. (%s)", obj ? obj->getFileName() : "nullobj");
57 }
58 managedResourceAttached = false;
59 }
60
61 bool isEqual(XXSharpKmyGfx::Texture^ t)
62 {
63 if (!t)return false;
64 return t->obj == obj;
65 }
66
67 void Release()
68 {
69 if (obj) {
70 obj->removeExRef();
71 if (deleteAsCreator) {
72 obj->removeRef();
73 }
74 obj = nullptr;
75 }
76 }
77
78 void Delete()
79 {
80 if (obj) {
81 obj->removeExRef();
82 if (deleteAsCreator) {
83 obj->removeRef();
84 }
85 obj = nullptr;
86 }
87 }
88
89 int getWidth()
90 {
91 if (!obj)return 0;
92 return obj->getWidth();
93 }
94
95 int getHeight()
96 {
97 if (!obj)return 0;
98 return obj->getHeight();
99 }
100
101 int getStoredWidth()
102 {
103 if (!obj)return 0;
104 return obj->getStoredWidth();
105 }
106
107 int getStoredHeight()
108 {
109 if (!obj)return 0;
110 return obj->getStoredHeight();
111 }
112
113 void setMagFilter(TEXTUREFILTER f)
114 {
115 if (!obj)return;
116
117 if (f == TEXTUREFILTER::kBILINEAR)obj->setMagFilter(kmyGfx::Texture::kFILTER_BILINEAR);
118 else obj->setMagFilter(kmyGfx::Texture::kFILTER_NEAREST);
119 }
120
121 void setMinFilter(TEXTUREFILTER f)
122 {
123 if (!obj)return;
124
125 if (f == TEXTUREFILTER::kBILINEAR)obj->setMinFilter(kmyGfx::Texture::kFILTER_BILINEAR);
126 else obj->setMinFilter(kmyGfx::Texture::kFILTER_NEAREST);
127 }
128
129 void setWrap(WRAPTYPE f)
130 {
131 if (!obj)return;
132
133 obj->setUWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
134 obj->setVWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
135 }
136
137 void setUWrap(WRAPTYPE f)
138 {
139 if (!obj)return;
140
141 obj->setUWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
142 }
143
144 void setVWrap(WRAPTYPE f)
145 {
146 if (!obj)return;
147
148 obj->setVWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
149 }
150
151 void setWWrap(WRAPTYPE f)
152 {
153 if (!obj)return;
154
155 obj->setWWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
156 }
157
158 void setAnisotropy(float v)
159 {
160 if (obj)obj->setAnisotropy(v);
161 }
162
163 void setType(int type)
164 {
165 if (obj)obj->setType((kmyGfx::TEXTURETYPE)type);
166 }
167
168 void setUsage(TEXTUREUSAGE usage)
169 {
170 if (obj)obj->setUsage((kmyGfx::TEXTUREUSAGE)usage);
171 }
172
173 void setCompress(bool flg)
174 {
175 if (obj)obj->setCompress(flg);
176 }
177
178 void setPremultiplied(PREMULTIPLIEDTYPE premultiplied)
179 {
180 if (obj)obj->setPremultiplied((kmyGfx::PremultipliedType)premultiplied);
181 }
182
183 bool isReloadRequired() { return obj ? obj->m_reloadRequired : false; }
184
185 void renamePath(System::String^ path);
186
187 void create(int width, int height, bool srgb, int miplevel);
188 void create(int width, int height, TEXTUREFFORMAT format, int miplevel);
189 void enableWrite() { if (obj)obj->enableWrite(); }
190 void apply() { if (obj)obj->apply(); }
191 void storeSubPixel2DDelay(int x, int y, int w, int h, array<UINT32>^ list, TEXTUREFFORMAT format, int sx, int sy, int swidth, int level);
192 void copyTexture2DDelay(int dx, int dy, int dw, int dh, int dlevel, int sx, int sy, int slevel, Texture^ src);
193 void storeSubPixel2D(int x, int y, int w, int h, array<UINT32>^ list, TEXTUREFFORMAT format, int sx, int sy, int swidth, int level);
194 void storeSubPixel2D(int x, int y, int w, int h, u8 *list, TEXTUREFFORMAT format, int level);
195 static void getColor(System::String^ name, [System::Runtime::InteropServices::Out] array<UINT32>^% list, int% width, int% height);
196
197 static Texture^ load(System::String^ path, bool srgb, TEXTURESHAPE shape, TEXTUREUSAGE usage);
198
199 static Texture^ load(System::IO::Stream^ stream, bool srgb, bool genmipmap, TEXTURESHAPE shape, TEXTUREUSAGE usage);
200
201 static array<System::String^>^ getLoadableFileList(System::String^ path);
202
203 static int getMaxTexture2DSize()
204 {
205 return kmyGfx::GfxDriver::getInstance()->getMaxTexture2DSize();
206 }
207
208 static void pushFindTextureBaseDirectory(String^ path);
209 static void popFindTextureBaseDirectory();
210
211 static int getTextureStoreJobSerial();
212 static bool textureStoreJobFinished(int serial);
213 static void textureStoreJobDispatchAll();
214 static void textureStoreJobWaitQueuedJobFinished();
215
216 static void forceReloadFileTextures() {
217 kmyGfx::Texture::forceReloadFileTextures();
218 }
219
220 void getColor([System::Runtime::InteropServices::Out] array<UINT32>^% list, int level);
221
222 System::String^ getFileName();
223 System::String^ getFilePath();
224 System::Guid getGuid();
225 void setGuid(System::Guid id);
226 bool isSrgb() { return obj?obj->isSrgb():false; }
227 void setSrgb(bool b) { if(obj)obj->setSrgb(b); }
228 void setGenMipmap(bool flg) { if(obj)obj->setGenMipmap(flg); }
229
230 void addRef() { if (obj)obj->addRef(); }
231 void removeRef() { if (obj)obj->removeRef(); }
232 void reloadIfLoaded() { if (obj)obj->reloadIfLoaded(); }
233 int getRef() { return (obj == nullptr) ? -1000 : obj->getRefCount(); }
234
235 TEXTUREFFORMAT getTextureFormat()
236 {
237 if (obj)
238 {
239 auto format = obj->getFormat();
240 return static_cast<TEXTUREFFORMAT>(format);
241 }
242 // return static_cast<TEXTUREFFORMAT>(kmyGfx::kTEXTUREFORMAT_INVALID);
243 return TEXTUREFFORMAT::kINVALID;
244 }
245 };
246}
TEXTUREFFORMAT
Definition: GfxTypes.cs:43