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 public enum class TEXTUREFILTER{
13 };
14
15 public enum class WRAPTYPE{
16 kREPEAT,
17 kCLAMP,
18 kMIRROR,
19 };
20
21 public enum class TEXTUREFFORMAT{
22
23 kINVALID = -1,
24 kRGBA,
25 kRGB8,
26 kR8,
27 kR16,
28 kR16F,
30 kRGB32F,
35 kSRGBA8,
36 kSRGB8,
38
45
52
53 kCOUNT,
54 };
55
56 public enum class TEXTUREUSAGE
57 {
59 kNormal,
60 k2D,
61 };
62
63 public enum class TEXTURESHAPE
64 {
65 k2D,
66 kCube,
67 k3D
68 };
69
70 ref class GameView;
71
72 public ref class Texture {
73
74 public:
75 kmyGfx::Texture* obj;
77 System::String^ loadpath;
79 {
80 obj = NULL;
81 ownImage = false;
82 }
83
84 Texture(System::String^ path, System::Guid guid, int type);
85
86 Texture(kmyGfx::Texture* t)
87 {
88 obj = t;
89 ownImage = false;
90 }
91
92 void Release()
93 {
94 if (ownImage && obj)obj->removeRef();
95 obj = nullptr;
96 }
97
98 void Delete()
99 {
100 if (ownImage && obj)obj->removeRef();
101 obj = nullptr;
102 }
103
105 {
106 if (!obj)return 0;
107 return obj->getWidth();
108 }
109
111 {
112 if (!obj)return 0;
113 return obj->getHeight();
114 }
115
117 {
118 if (!obj)return 0;
119 return obj->getStoredWidth();
120 }
121
123 {
124 if (!obj)return 0;
125 return obj->getStoredHeight();
126 }
127
129 {
130 if (!obj)return;
131
132 if (f == TEXTUREFILTER::kBILINEAR)obj->setMagFilter(kmyGfx::Texture::kFILTER_BILINEAR);
133 else obj->setMagFilter(kmyGfx::Texture::kFILTER_NEAREST);
134 }
135
137 {
138 if (!obj)return;
139
140 if (f == TEXTUREFILTER::kBILINEAR)obj->setMinFilter(kmyGfx::Texture::kFILTER_BILINEAR);
141 else obj->setMinFilter(kmyGfx::Texture::kFILTER_NEAREST);
142 }
143
145 {
146 if (!obj)return;
147
148 obj->setUWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
149 obj->setVWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
150 }
151
153 {
154 if (!obj)return;
155
156 obj->setUWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
157 }
158
160 {
161 if (!obj)return;
162
163 obj->setVWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
164 }
165
167 {
168 if (!obj)return;
169
170 obj->setWWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
171 }
172
173 void setAnisotropy(float v)
174 {
175 if (obj)obj->setAnisotropy(v);
176 }
177
178 void setType(int type)
179 {
180 if (obj)obj->setType((kmyGfx::TEXTURETYPE)type);
181 }
182
184 {
185 if (obj)obj->setUsage((kmyGfx::TEXTUREUSAGE)usage);
186 }
187
188 void setCompress(bool flg)
189 {
190 if (obj)obj->setCompress(flg);
191 }
192
193 void renamePath(System::String^ path);
194
195 void create(int width, int height, bool srgb, int miplevel);
196 void create(int width, int height, TEXTUREFFORMAT format, int miplevel);
197 void enableWrite() { if (obj)obj->enableWrite(); }
198 void apply() { if (obj)obj->apply(); }
199 void storeSubPixel2DDelay(int x, int y, int w, int h, array<UINT32>^ list, TEXTUREFFORMAT format, int sx, int sy, int swidth, int level);
200 void copyTexture2DDelay(int dx, int dy, int dw, int dh, int dlevel, int sx, int sy, int slevel, Texture^ src);
201 void storeSubPixel2D(int x, int y, int w, int h, array<UINT32>^ list, TEXTUREFFORMAT format, int sx, int sy, int swidth, int level);
202 void storeSubPixel2D(int x, int y, int w, int h, u8 *list, TEXTUREFFORMAT format, int level);
203 static void getColor(System::String^ name, [System::Runtime::InteropServices::Out] array<UINT32>^% list, int% width, int% height);
204
205 static Texture^ load(System::String^ path, bool srgb, TEXTURESHAPE shape, TEXTUREUSAGE usage);
206
207 static Texture^ load(System::IO::Stream^ stream, bool srgb, bool genmipmap, TEXTURESHAPE shape, TEXTUREUSAGE usage);
208
209 static array<System::String^>^ getLoadableFileList(System::String^ path);
210
212 {
213 return kmyGfx::GfxDriver::getInstance()->getMaxTexture2DSize();
214 }
215
216 static void pushFindTextureBaseDirectory(String^ path);
217 static void popFindTextureBaseDirectory();
218
219 static int getTextureStoreJobSerial();
220 static bool textureStoreJobFinished(int serial);
221 static void textureStoreJobDispatchAll();
222
223 void getColor([System::Runtime::InteropServices::Out] array<UINT32>^% list, int level);
224
225 System::String^ getFileName();
226 System::String^ getFilePath();
227 System::Guid getGuid();
228 void setGuid(System::Guid id);
229 bool isSrgb() { return obj?obj->isSrgb():false; }
230 void setSrgb(bool b) { if(obj)obj->setSrgb(b); }
231 void setGenMipmap(bool flg) { if(obj)obj->setGenMipmap(flg); }
232
233 void addRef() { if (obj)obj->addRef(); }
234 void removeRef() { if (obj)obj->removeRef(); }
235 void reloadIfLoaded() { if (obj)obj->reloadIfLoaded(); }
236 int getRef() { return (obj == nullptr) ? -1000 : obj->getRefCount(); }
237
238 void saveNativeTexture(System::String^ path);
239 void setNativeTexturePath(System::String^ path);
240
241 };
242
243 public ref class Buffer
244 {
245 public:
246 static int getBufferStoreJobSerial();
247 static bool bufferStoreJobFinished(int serial);
248 static void bufferStoreJobDispatchAll();
249 };
250
251
252
253
254}
Definition: Texture.h:244
static bool bufferStoreJobFinished(int serial)
Definition: Texture.cpp:427
static void bufferStoreJobDispatchAll()
Definition: Texture.cpp:433
static int getBufferStoreJobSerial()
Definition: Texture.cpp:421
Definition: Texture.h:72
static void getColor(System::String^ name, [System::Runtime::InteropServices::Out] array< UINT32 >^% list, int% width, int% height)
Texture(kmyGfx::Texture *t)
Definition: Texture.h:86
System::String getFilePath()
Definition: Texture.cpp:372
void setGenMipmap(bool flg)
Definition: Texture.h:231
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:184
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:197
void setSrgb(bool b)
Definition: Texture.h:230
Texture()
Definition: Texture.h:78
Texture(System::String^ path, System::Guid guid, int type)
System::Guid getGuid()
Definition: Texture.cpp:380
void removeRef()
Definition: Texture.h:234
int getStoredWidth()
Definition: Texture.h:116
void setAnisotropy(float v)
Definition: Texture.h:173
int getStoredHeight()
Definition: Texture.h:122
void setMinFilter(TEXTUREFILTER f)
Definition: Texture.h:136
int getRef()
Definition: Texture.h:236
int getHeight()
Definition: Texture.h:110
bool isSrgb()
Definition: Texture.h:229
void setCompress(bool flg)
Definition: Texture.h:188
static void textureStoreJobDispatchAll()
Definition: Texture.cpp:74
static int getMaxTexture2DSize()
Definition: Texture.h:211
static array< System::String^> getLoadableFileList(System::String^ path)
Definition: Texture.cpp:107
void create(int width, int height, bool srgb, int miplevel)
Definition: Texture.cpp:143
void getColor([System::Runtime::InteropServices::Out] array< UINT32 >^% list, int level)
void setNativeTexturePath(System::String^ path)
Definition: Texture.cpp:413
void reloadIfLoaded()
Definition: Texture.h:235
int getWidth()
Definition: Texture.h:104
static void pushFindTextureBaseDirectory(String^ path)
Definition: Texture.cpp:46
void saveNativeTexture(System::String^ path)
Definition: Texture.cpp:406
void setWrap(WRAPTYPE f)
Definition: Texture.h:144
void setType(int type)
Definition: Texture.h:178
void setWWrap(WRAPTYPE f)
Definition: Texture.h:166
void renamePath(System::String^ path)
Definition: Texture.cpp:132
System::String getFileName()
Definition: Texture.cpp:364
static int getTextureStoreJobSerial()
Definition: Texture.cpp:62
static Texture load(System::String^ path, bool srgb, TEXTURESHAPE shape, TEXTUREUSAGE usage)
kmyGfx::Texture * obj
Definition: Texture.h:75
static bool textureStoreJobFinished(int serial)
Definition: Texture.cpp:68
void setGuid(System::Guid id)
Definition: Texture.cpp:401
void setUWrap(WRAPTYPE f)
Definition: Texture.h:152
void Release()
Definition: Texture.h:92
static Texture load(System::IO::Stream^ stream, bool srgb, bool genmipmap, TEXTURESHAPE shape, TEXTUREUSAGE usage)
System::String loadpath
Definition: Texture.h:77
void setMagFilter(TEXTUREFILTER f)
Definition: Texture.h:128
static void popFindTextureBaseDirectory()
Definition: Texture.cpp:56
void setVWrap(WRAPTYPE f)
Definition: Texture.h:159
void copyTexture2DDelay(int dx, int dy, int dw, int dh, int dlevel, int sx, int sy, int slevel, Texture^ src)
Definition: Texture.cpp:179
bool ownImage
Definition: Texture.h:76
void setUsage(TEXTUREUSAGE usage)
Definition: Texture.h:183
void addRef()
Definition: Texture.h:233
void apply()
Definition: Texture.h:198
void Delete()
Definition: Texture.h:98
Definition: Billboard.cpp:4
TEXTURESHAPE
Definition: Texture.h:64
TEXTUREFFORMAT
Definition: Texture.h:21
TEXTUREUSAGE
Definition: Texture.h:57
TEXTUREFILTER
Definition: Texture.h:10
WRAPTYPE
Definition: Texture.h:15