Skip to content

Commit 6ef84f3

Browse files
committed
Fixed texture issues
1 parent ac14a97 commit 6ef84f3

1 file changed

Lines changed: 31 additions & 15 deletions

File tree

engine/core/texture/Texture.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,25 @@ Texture::Texture(const Texture& rhs){
107107
}
108108

109109
Texture& Texture::operator=(const Texture& rhs){
110-
render = rhs.render;
111-
framebuffer = rhs.framebuffer;
112-
type = rhs.type;
113-
id = rhs.id;
114-
for (int i = 0; i < 6; i++){
115-
paths[i] = rhs.paths[i];
110+
if (this != &rhs) {
111+
destroy();
112+
render = rhs.render;
113+
framebuffer = rhs.framebuffer;
114+
type = rhs.type;
115+
id = rhs.id;
116+
for (int i = 0; i < 6; i++){
117+
paths[i] = rhs.paths[i];
118+
}
119+
data = rhs.data;
120+
numFaces = rhs.numFaces;
121+
loadFromPath = rhs.loadFromPath;
122+
releaseDataAfterLoad = rhs.releaseDataAfterLoad;
123+
needLoad = rhs.needLoad;
124+
minFilter = rhs.minFilter;
125+
magFilter = rhs.magFilter;
126+
wrapU = rhs.wrapU;
127+
wrapV = rhs.wrapV;
116128
}
117-
data = rhs.data;
118-
numFaces = rhs.numFaces;
119-
loadFromPath = rhs.loadFromPath;
120-
releaseDataAfterLoad = rhs.releaseDataAfterLoad;
121-
needLoad = rhs.needLoad;
122-
minFilter = rhs.minFilter;
123-
magFilter = rhs.magFilter;
124-
wrapU = rhs.wrapU;
125-
wrapV = rhs.wrapV;
126129

127130
return *this;
128131
}
@@ -184,6 +187,8 @@ void Texture::setPath(const std::string& path){
184187
this->loadFromPath = true;
185188
this->releaseDataAfterLoad = true;
186189
this->needLoad = true;
190+
191+
this->render = TexturePool::get(id);
187192
}
188193

189194
void Texture::setData(const std::string& id, TextureData data){
@@ -200,10 +205,16 @@ void Texture::setData(const std::string& id, TextureData data){
200205
this->data = std::make_shared<std::array<TextureData,6>>();
201206
this->data->at(0) = data;
202207
this->data = TextureDataPool::get(id, *this->data.get());
208+
209+
this->render = TexturePool::get(id);
203210
}
204211

205212
void Texture::setId(const std::string& id){
206213
this->id = id;
214+
if (!id.empty()) {
215+
this->render = TexturePool::get(id);
216+
this->data = TextureDataPool::get(id);
217+
}
207218
}
208219

209220
void Texture::setCubeMap(const std::string& path){
@@ -225,6 +236,7 @@ void Texture::setCubeMap(const std::string& path){
225236
this->needLoad = true;
226237

227238
this->id = "cube|" + path;
239+
this->render = TexturePool::get(id);
228240
}
229241

230242
void Texture::setCubePath(size_t index, const std::string& path){
@@ -252,6 +264,7 @@ void Texture::setCubePath(size_t index, const std::string& path){
252264
id = id + "|" + paths[f];
253265
}
254266
this->id = id;
267+
this->render = TexturePool::get(id);
255268
}
256269

257270
void Texture::setCubePaths(const std::string& front, const std::string& back,
@@ -282,6 +295,7 @@ void Texture::setCubePaths(const std::string& front, const std::string& back,
282295
id = id + "|" + paths[f];
283296
}
284297
this->id = id;
298+
this->render = TexturePool::get(id);
285299
}
286300

287301
void Texture::setCubeDatas(const std::string& id, TextureData front, TextureData back, TextureData left, TextureData right, TextureData up, TextureData down){
@@ -306,6 +320,8 @@ void Texture::setCubeDatas(const std::string& id, TextureData front, TextureData
306320
this->data->at(2) = up;
307321
this->data->at(3) = down;
308322
this->data = TextureDataPool::get(id, *this->data.get());
323+
324+
this->render = TexturePool::get(id);
309325
}
310326

311327
void Texture::setFramebuffer(Framebuffer* framebuffer){

0 commit comments

Comments
 (0)