Skip to content

Commit

Permalink
Some bug fixes & performance tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Sep 3, 2013
1 parent 1ef14c0 commit 451e939
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 22 deletions.
15 changes: 11 additions & 4 deletions Sources/Draw/GLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,18 @@ namespace spades {
imageRenderer = new GLImageRenderer(this);

waterRenderer = NULL;
ambientShadowRenderer = NULL;
radiosityRenderer = NULL;
mapShadowRenderer = NULL;
mapShadowRenderer = NULL;
mapRenderer = NULL;
flatMapRenderer = NULL;
ambientShadowRenderer = NULL;
shadowMapRenderer = NULL;
modelManager = NULL;
spriteRenderer = NULL;
longSpriteRenderer = NULL;
modelRenderer = NULL;

lastTime = 0;

sceneUsedInThisFrame = false;
Expand Down Expand Up @@ -145,9 +155,6 @@ namespace spades {
SPLog("GLRenderer initializing for 3D rendering");
shadowMapRenderer = GLShadowMapShader::CreateShadowMapRenderer(this);
modelManager = new GLModelManager(this);
mapShadowRenderer = NULL;
mapRenderer = NULL;
flatMapRenderer = NULL;
if(r_softParticles)
spriteRenderer = new GLSoftSpriteRenderer(this);
else
Expand Down
89 changes: 71 additions & 18 deletions Sources/Draw/GLWaterRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,13 @@ namespace spades {
bitmap.resize(w * h);
std::fill(updateBitmap.begin(), updateBitmap.end(),
0xffffffffUL);
std::fill(bitmap.begin(), bitmap.end(),
0xffffffffUL);

device->TexSubImage2D(IGLDevice::Texture2D,
0, 0, 0, w, h,
IGLDevice::BGRA, IGLDevice::UnsignedByte,
bitmap.data());

// create wave tank simlation
waveTank = new FFTWaveTank();//new StandardWaveTank(256);
Expand Down Expand Up @@ -820,7 +827,7 @@ namespace spades {
r = (r * r + 128) >> 8;
g = (g * g + 128) >> 8;
b = (b * b + 128) >> 8;
return r|(g<<8)|(b<<16);
return b|(g<<8)|(r<<16);
}

void GLWaterRenderer::Update(float dt) {
Expand Down Expand Up @@ -852,36 +859,82 @@ namespace spades {
{
GLProfiler profiler(device, "Upload Water Color Texture");
device->BindTexture(IGLDevice::Texture2D, texture);
bool fullUpdate = true;
for(size_t i = 0; i < updateBitmap.size(); i++){
int y = i / updateBitmapPitch;
int x = (i - y * updateBitmapPitch) * 32;
if(updateBitmap[i] == 0)
continue;


uint32_t pixels[32];
if(updateBitmap[i] == 0){
fullUpdate = false;
break;
}
}

if(fullUpdate) {
uint32_t *pixels = bitmap.data();
bool modified = false;
for(int j = 0; j < 32; j++){
uint32_t col = map->GetColor(x+j, y, 63);
int x = 0, y = 0;
for(int i = w * h; i > 0; i--){
uint32_t col = map->GetColor(x, y, 63);

x++;
if(x == w){
x = 0; y++;
}

col = LinearlizeColor(col);

if(pixels[j] != col)
if(*pixels != col)
modified = true;
else
else{
pixels++;
continue;
pixels[j] = col;
//pixels[j] = GeneratePixel(x + j, y);
}
*(pixels++) = col;
}

if(modified) {
device->TexSubImage2D(IGLDevice::Texture2D,
0, x, y, 32, 1,
IGLDevice::RGBA, IGLDevice::UnsignedByte,
pixels);
0, 0, 0, w, h,
IGLDevice::BGRA, IGLDevice::UnsignedByte,
bitmap.data());
}

updateBitmap[i] = 0;

for(size_t i = 0; i < updateBitmap.size(); i++){
updateBitmap[i] = 0;
}
}else{
// partial update
for(size_t i = 0; i < updateBitmap.size(); i++){
int y = i / updateBitmapPitch;
int x = (i - y * updateBitmapPitch) * 32;
if(updateBitmap[i] == 0)
continue;


uint32_t *pixels = bitmap.data() + x + y * w;
bool modified = false;
for(int j = 0; j < 32; j++){
uint32_t col = map->GetColor(x+j, y, 63);

col = LinearlizeColor(col);

if(pixels[j] != col)
modified = true;
else
continue;
pixels[j] = col;
//pixels[j] = GeneratePixel(x + j, y);
}

if(modified) {
device->TexSubImage2D(IGLDevice::Texture2D,
0, x, y, 32, 1,
IGLDevice::BGRA, IGLDevice::UnsignedByte,
pixels);
}

updateBitmap[i] = 0;
}
// partial update - done
}
}
}
Expand Down

0 comments on commit 451e939

Please sign in to comment.