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
14 public:
15 kmyGfx::Texture* obj;
17 System::String^ loadpath;
19 {
20 obj = NULL;
21 ownImage = false;
22 }
23
24 Texture(System::String^ path, System::Guid guid, int type, bool srgb, bool genmipmap, TEXTUREUSAGE usage, bool compress);
25
26 Texture(kmyGfx::Texture* t)
27 {
28 obj = t;
29 ownImage = false;
30 }
31
33 {
34 return t->obj == obj;
35 }
36
37 void Release()
38 {
39 if (ownImage && obj)obj->removeRef();
40 obj = nullptr;
41 }
42
43 void Delete()
44 {
45 if (ownImage && obj)obj->removeRef();
46 obj = nullptr;
47 }
48
50 {
51 if (!obj)return 0;
52 return obj->getWidth();
53 }
54
56 {
57 if (!obj)return 0;
58 return obj->getHeight();
59 }
60
62 {
63 if (!obj)return 0;
64 return obj->getStoredWidth();
65 }
66
68 {
69 if (!obj)return 0;
70 return obj->getStoredHeight();
71 }
72
74 {
75 if (!obj)return;
76
77 if (f == TEXTUREFILTER::kBILINEAR)obj->setMagFilter(kmyGfx::Texture::kFILTER_BILINEAR);
78 else obj->setMagFilter(kmyGfx::Texture::kFILTER_NEAREST);
79 }
80
82 {
83 if (!obj)return;
84
85 if (f == TEXTUREFILTER::kBILINEAR)obj->setMinFilter(kmyGfx::Texture::kFILTER_BILINEAR);
86 else obj->setMinFilter(kmyGfx::Texture::kFILTER_NEAREST);
87 }
88
90 {
91 if (!obj)return;
92
93 obj->setUWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
94 obj->setVWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
95 }
96
98 {
99 if (!obj)return;
100
101 obj->setUWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
102 }
103
105 {
106 if (!obj)return;
107
108 obj->setVWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
109 }
110
112 {
113 if (!obj)return;
114
115 obj->setWWrap(f == WRAPTYPE::kCLAMP ? kmyGfx::WRAPTYPE::kWRAPTYPE_CLAMP : kmyGfx::WRAPTYPE::kWRAPTYPE_REPEAT);
116 }
117
118 void setAnisotropy(float v)
119 {
120 if (obj)obj->setAnisotropy(v);
121 }
122
123 void setType(int type)
124 {
125 if (obj)obj->setType((kmyGfx::TEXTURETYPE)type);
126 }
127
129 {
130 if (obj)obj->setUsage((kmyGfx::TEXTUREUSAGE)usage);
131 }
132
133 void setCompress(bool flg)
134 {
135 if (obj)obj->setCompress(flg);
136 }
137
138 void renamePath(System::String^ path);
139
140 void create(int width, int height, bool srgb, int miplevel);
141 void create(int width, int height, TEXTUREFFORMAT format, int miplevel);
142 void enableWrite() { if (obj)obj->enableWrite(); }
143 void apply() { if (obj)obj->apply(); }
144 void storeSubPixel2DDelay(int x, int y, int w, int h, array<UINT32>^ list, TEXTUREFFORMAT format, int sx, int sy, int swidth, int level);
145 void copyTexture2DDelay(int dx, int dy, int dw, int dh, int dlevel, int sx, int sy, int slevel, Texture^ src);
146 void storeSubPixel2D(int x, int y, int w, int h, array<UINT32>^ list, TEXTUREFFORMAT format, int sx, int sy, int swidth, int level);
147 void storeSubPixel2D(int x, int y, int w, int h, u8 *list, TEXTUREFFORMAT format, int level);
148 static void getColor(System::String^ name, [System::Runtime::InteropServices::Out] array<UINT32>^% list, int% width, int% height);
149
150 static Texture^ load(System::String^ path, bool srgb, TEXTURESHAPE shape, TEXTUREUSAGE usage);
151
152 static Texture^ load(System::IO::Stream^ stream, bool srgb, bool genmipmap, TEXTURESHAPE shape, TEXTUREUSAGE usage);
153
154 static array<System::String^>^ getLoadableFileList(System::String^ path);
155
157 {
158 return kmyGfx::GfxDriver::getInstance()->getMaxTexture2DSize();
159 }
160
161 static void pushFindTextureBaseDirectory(String^ path);
162 static void popFindTextureBaseDirectory();
163
164 static int getTextureStoreJobSerial();
165 static bool textureStoreJobFinished(int serial);
166 static void textureStoreJobDispatchAll();
167
168 void getColor([System::Runtime::InteropServices::Out] array<UINT32>^% list, int level);
169
170 System::String^ getFileName();
171 System::String^ getFilePath();
172 System::Guid getGuid();
173 void setGuid(System::Guid id);
174 bool isSrgb() { return obj?obj->isSrgb():false; }
175 void setSrgb(bool b) { if(obj)obj->setSrgb(b); }
176 void setGenMipmap(bool flg) { if(obj)obj->setGenMipmap(flg); }
177
178 void addRef() { if (obj)obj->addRef(); }
179 void removeRef() { if (obj)obj->removeRef(); }
180 void reloadIfLoaded() { if (obj)obj->reloadIfLoaded(); }
181 int getRef() { return (obj == nullptr) ? -1000 : obj->getRefCount(); }
182 };
183}
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:26
System::String getFilePath()
Definition: Texture.cpp:408
void setGenMipmap(bool flg)
Definition: Texture.h:176
bool isEqual(SharpKmyGfx::Texture^ t)
Definition: Texture.h:32
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:209
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:142
void setSrgb(bool b)
Definition: Texture.h:175
Texture()
Definition: Texture.h:18
System::Guid getGuid()
Definition: Texture.cpp:418
void removeRef()
Definition: Texture.h:179
int getStoredWidth()
Definition: Texture.h:61
void setAnisotropy(float v)
Definition: Texture.h:118
int getStoredHeight()
Definition: Texture.h:67
void setMinFilter(TEXTUREFILTER f)
Definition: Texture.h:81
int getRef()
Definition: Texture.h:181
int getHeight()
Definition: Texture.h:55
bool isSrgb()
Definition: Texture.h:174
void setCompress(bool flg)
Definition: Texture.h:133
static void textureStoreJobDispatchAll()
Definition: Texture.cpp:86
static int getMaxTexture2DSize()
Definition: Texture.h:156
static array< System::String^> getLoadableFileList(System::String^ path)
Definition: Texture.cpp:122
void create(int width, int height, bool srgb, int miplevel)
Definition: Texture.cpp:162
void getColor([System::Runtime::InteropServices::Out] array< UINT32 >^% list, int level)
void reloadIfLoaded()
Definition: Texture.h:180
int getWidth()
Definition: Texture.h:49
static void pushFindTextureBaseDirectory(String^ path)
Definition: Texture.cpp:50
void setWrap(WRAPTYPE f)
Definition: Texture.h:89
void setType(int type)
Definition: Texture.h:123
void setWWrap(WRAPTYPE f)
Definition: Texture.h:111
void renamePath(System::String^ path)
Definition: Texture.cpp:149
System::String getFileName()
Definition: Texture.cpp:398
static int getTextureStoreJobSerial()
Definition: Texture.cpp:70
static Texture load(System::String^ path, bool srgb, TEXTURESHAPE shape, TEXTUREUSAGE usage)
kmyGfx::Texture * obj
Definition: Texture.h:15
Texture(System::String^ path, System::Guid guid, int type, bool srgb, bool genmipmap, TEXTUREUSAGE usage, bool compress)
static bool textureStoreJobFinished(int serial)
Definition: Texture.cpp:78
void setGuid(System::Guid id)
Definition: Texture.cpp:440
void setUWrap(WRAPTYPE f)
Definition: Texture.h:97
void Release()
Definition: Texture.h:37
static Texture load(System::IO::Stream^ stream, bool srgb, bool genmipmap, TEXTURESHAPE shape, TEXTUREUSAGE usage)
System::String loadpath
Definition: Texture.h:17
void setMagFilter(TEXTUREFILTER f)
Definition: Texture.h:73
static void popFindTextureBaseDirectory()
Definition: Texture.cpp:62
void setVWrap(WRAPTYPE f)
Definition: Texture.h:104
void copyTexture2DDelay(int dx, int dy, int dw, int dh, int dlevel, int sx, int sy, int slevel, Texture^ src)
Definition: Texture.cpp:202
bool ownImage
Definition: Texture.h:16
void setUsage(TEXTUREUSAGE usage)
Definition: Texture.h:128
void addRef()
Definition: Texture.h:178
void apply()
Definition: Texture.h:143
void Delete()
Definition: Texture.h:43
Definition: Asset.h:4
TEXTURESHAPE
Definition: GfxTypes.h:199
TEXTUREFFORMAT
Definition: GfxTypes.h:156
TEXTUREUSAGE
Definition: GfxTypes.h:192
TEXTUREFILTER
Definition: GfxTypes.h:145
WRAPTYPE
Definition: GfxTypes.h:150