Skip to content

Commit 960f627

Browse files
author
NiDragon
committed
Texture/Image Update
Textures can now be updated instead of recreated for better performance. Image will no longer crash when creating an IMAGE_RGB format image.
1 parent 0f54bea commit 960f627

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Core/Contents/Source/PolyGLTexture.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,10 @@ void OpenGLTexture::setGLInfo(GLuint textureID, GLuint frameBufferID) {
122122
}
123123

124124
void OpenGLTexture::setTextureData(char *data) {
125-
/*
125+
memcpy(textureData, data, width * height * pixelSize);
126+
126127
glBindTexture(GL_TEXTURE_2D, textureID);
127-
glDrawBuffer(GL_AUX0);
128-
glDrawPixels(width, height, glTextureType, pixelType, data);
129-
glReadBuffer(GL_AUX0);
130-
// glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 128, 128, 0);
131-
*/
128+
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, glTextureType, pixelType, textureData);
132129
}
133130

134131
OpenGLTexture::~OpenGLTexture() {

Core/Contents/Source/PolyImage.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,19 @@ void Image::drawLine(int x0, int y0, int x1, int y1, Color col) {
392392
}
393393

394394
void Image::fill(Color color) {
395-
unsigned int val = color.getUint();
396-
unsigned int *imageData32 = (unsigned int*) imageData;
397-
for(int i=0; i< width*height; i++) {
398-
imageData32[i] = val;
395+
if(imageType == Image::IMAGE_RGB) {
396+
for(int i = 0; i < width*height*pixelSize; i+=3) {
397+
imageData[i] = color.r;
398+
imageData[i+1] = color.g;
399+
imageData[i+2] = color.b;
400+
}
401+
} else {
402+
unsigned int val = color.getUint();
403+
unsigned int *imageData32 = (unsigned int*) imageData;
404+
405+
for(int i=0; i< width*height; i++) {
406+
imageData32[i] = val;
407+
}
399408
}
400409
}
401410

0 commit comments

Comments
 (0)