Logo
Texture.h
1#pragma once
2
3#include "Types.h"
4#include "gfx/Texture.h"
5
6using namespace System::Runtime::InteropServices;
7
8namespace SharpKmyGfx{
9
10 ref class GameView;
11
12 public ref class Texture {
13
15
16 public:
17 kmyGfx::Texture* obj;
18 bool deleteAsCreator = false;
19 System::String^ loadpath;
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
36 {
37 return gcnew Texture(obj);
38 }
39
41 {
42 Release();
43 }
44
46 {
48 DBGPRINTF("[warn] texture attached to multiple managed resource. (%s)", obj ? obj->getFileName() : "nullobj");
49 }
51 }
52
54 {
56 DBGPRINTF("[warn] unattached texture was detached. (%s)", obj ? obj->getFileName() : "nullobj");
57 }
59 }
60
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
90 {
91 if (!obj)return 0;
92 return obj->getWidth();
93 }
94
96 {
97 if (!obj)return 0;
98 return obj->getHeight();
99 }
100
102 {
103 if (!obj)return 0;
104 return obj->getStoredWidth();
105 }
106
108 {
109 if (!obj)return 0;
110 return obj->getStoredHeight();
111 }
112
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
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
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
138 {
139 if (!obj)return;
140
141 obj->setUWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
142 }
143
145 {
146 if (!obj)return;
147
148 obj->setVWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
149 }
150
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
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
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
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();
215
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
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);
244 }
245 };
246}
Definition: Texture.h:12
static void getColor(System::String^ name, [System::Runtime::InteropServices::Out] array< UINT32 >^% list, int% width, int% height)
Texture(kmyGfx::Texture *t)
Definition: Texture.h:28
System::String getFilePath()
Definition: Texture.cpp:430
void setGenMipmap(bool flg)
Definition: Texture.h:228
bool isEqual(SharpKmyGfx::Texture^ t)
Definition: Texture.h:61
void storeSubPixel2DDelay(int x, int y, int w, int h, array< UINT32 >^ list, TEXTUREFFORMAT format, int sx, int sy, int swidth, int level)
Definition: Texture.cpp:217
void managedResourceAttach()
Definition: Texture.h:45
static void forceReloadFileTextures()
Definition: Texture.h:216
void storeSubPixel2D(int x, int y, int w, int h, array< UINT32 >^ list, TEXTUREFFORMAT format, int sx, int sy, int swidth, int level)
void enableWrite()
Definition: Texture.h:189
void setSrgb(bool b)
Definition: Texture.h:227
Texture()
Definition: Texture.h:20
System::Guid getGuid()
Definition: Texture.cpp:440
void removeRef()
Definition: Texture.h:231
int getStoredWidth()
Definition: Texture.h:101
void setAnisotropy(float v)
Definition: Texture.h:158
int getStoredHeight()
Definition: Texture.h:107
void setMinFilter(TEXTUREFILTER f)
Definition: Texture.h:121
int getRef()
Definition: Texture.h:233
int getHeight()
Definition: Texture.h:95
bool isSrgb()
Definition: Texture.h:226
bool managedResourceAttached
Definition: Texture.h:14
void setCompress(bool flg)
Definition: Texture.h:173
static void textureStoreJobDispatchAll()
Definition: Texture.cpp:89
TEXTUREFFORMAT getTextureFormat()
Definition: Texture.h:235
static int getMaxTexture2DSize()
Definition: Texture.h:203
Texture makeNewReference()
Definition: Texture.h:35
static array< System::String^> getLoadableFileList(System::String^ path)
Definition: Texture.cpp:132
void create(int width, int height, bool srgb, int miplevel)
Definition: Texture.cpp:172
void getColor([System::Runtime::InteropServices::Out] array< UINT32 >^% list, int level)
void reloadIfLoaded()
Definition: Texture.h:232
void setPremultiplied(PREMULTIPLIEDTYPE premultiplied)
Definition: Texture.h:178
int getWidth()
Definition: Texture.h:89
static void pushFindTextureBaseDirectory(String^ path)
Definition: Texture.cpp:53
void setWrap(WRAPTYPE f)
Definition: Texture.h:129
void setType(int type)
Definition: Texture.h:163
void setWWrap(WRAPTYPE f)
Definition: Texture.h:151
static void textureStoreJobWaitQueuedJobFinished()
Definition: Texture.cpp:96
bool isReloadRequired()
Definition: Texture.h:183
~Texture()
Definition: Texture.h:40
void renamePath(System::String^ path)
Definition: Texture.cpp:159
System::String getFileName()
Definition: Texture.cpp:420
static int getTextureStoreJobSerial()
Definition: Texture.cpp:73
static Texture load(System::String^ path, bool srgb, TEXTURESHAPE shape, TEXTUREUSAGE usage)
kmyGfx::Texture * obj
Definition: Texture.h:17
void managedResourceDetach()
Definition: Texture.h:53
static bool textureStoreJobFinished(int serial)
Definition: Texture.cpp:81
bool deleteAsCreator
Definition: Texture.h:18
void setGuid(System::Guid id)
Definition: Texture.cpp:462
void setUWrap(WRAPTYPE f)
Definition: Texture.h:137
Texture(System::String^ path, System::Guid guid, int type, bool srgb, bool genmipmap, TEXTUREUSAGE usage, bool compress, PREMULTIPLIEDTYPE premultiplied)
void Release()
Definition: Texture.h:67
static Texture load(System::IO::Stream^ stream, bool srgb, bool genmipmap, TEXTURESHAPE shape, TEXTUREUSAGE usage)
System::String loadpath
Definition: Texture.h:19
void setMagFilter(TEXTUREFILTER f)
Definition: Texture.h:113
static void popFindTextureBaseDirectory()
Definition: Texture.cpp:65
void setVWrap(WRAPTYPE f)
Definition: Texture.h:144
void copyTexture2DDelay(int dx, int dy, int dw, int dh, int dlevel, int sx, int sy, int slevel, Texture^ src)
Definition: Texture.cpp:210
void setUsage(TEXTUREUSAGE usage)
Definition: Texture.h:168
void addRef()
Definition: Texture.h:230
void apply()
Definition: Texture.h:190
void Delete()
Definition: Texture.h:78
Definition: Asset.h:4
PREMULTIPLIEDTYPE
Definition: GfxTypes.h:199
TEXTURESHAPE
Definition: GfxTypes.h:206
TEXTUREFFORMAT
Definition: GfxTypes.h:156
TEXTUREUSAGE
Definition: GfxTypes.h:192
TEXTUREFILTER
Definition: GfxTypes.h:145
WRAPTYPE
Definition: GfxTypes.h:150