void CHeightTexture::Update() { needUpdate = false; if (!fbo.IsValid() || !shader->IsValid() || (heightMapTexture->GetTextureID() == 0)) return UpdateCPU(); fbo.Bind(); glViewport(0,0, texSize.x, texSize.y); shader->Enable(); glDisable(GL_BLEND); glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, paletteTex); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, heightMapTexture->GetTextureID()); glBegin(GL_QUADS); glVertex2f(0.f, 0.f); glVertex2f(0.f, 1.f); glVertex2f(1.f, 1.f); glVertex2f(1.f, 0.f); glEnd(); shader->Disable(); glViewport(globalRendering->viewPosX,0,globalRendering->viewSizeX,globalRendering->viewSizeY); FBO::Unbind(); // cleanup glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); }
void CHeightTexture::Update() { needUpdate = false; if (!fbo.IsValid() || !shader->IsValid() || (heightMapTexture->GetTextureID() == 0)) return UpdateCPU(); fbo.Bind(); glViewport(0, 0, texSize.x, texSize.y); glDisable(GL_BLEND); glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, paletteTex); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, heightMapTexture->GetTextureID()); GL::RenderDataBuffer0* rdb = GL::GetRenderBuffer0(); shader->Enable(); rdb->SafeAppend(VERTS, sizeof(VERTS) / sizeof(VERTS[0])); rdb->Submit(GL_QUADS); shader->Disable(); glViewport(globalRendering->viewPosX, 0, globalRendering->viewSizeX, globalRendering->viewSizeY); FBO::Unbind(); // cleanup glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); }
void CLosTexture::Update() { if (!fbo.IsValid() || !shader->IsValid() || uploadTex == 0) return UpdateCPU(); if (losHandler->globalLOS[gu->myAllyTeam]) { fbo.Bind(); glViewport(0, 0, texSize.x, texSize.y); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glViewport(globalRendering->viewPosX, 0, globalRendering->viewSizeX, globalRendering->viewSizeY); FBO::Unbind(); glBindTexture(GL_TEXTURE_2D, texture); glGenerateMipmap(GL_TEXTURE_2D); return; } infoTexPBO.Bind(); uint8_t* infoTexMem = reinterpret_cast<uint8_t*>(infoTexPBO.MapBuffer()); const uint16_t* myLos = &losHandler->los.losMaps[gu->myAllyTeam].front(); memcpy(infoTexMem, myLos, texSize.x * texSize.y * texChannels * sizeof(uint16_t)); infoTexPBO.UnmapBuffer(); //Trick: Upload the ushort as 2 ubytes, and then check both for `!=0` in the shader. // Faster than doing it on the CPU! And uploading it as shorts would be slow, cause the GPU // has no native support for them and so the transformation would happen on the CPU, too. glBindTexture(GL_TEXTURE_2D, uploadTex); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texSize.x, texSize.y, GL_RG, GL_UNSIGNED_BYTE, infoTexPBO.GetPtr()); infoTexPBO.Invalidate(); infoTexPBO.Unbind(); // do post-processing on the gpu (los-checking & scaling) fbo.Bind(); glViewport(0, 0, texSize.x, texSize.y); glDisable(GL_BLEND); GL::RenderDataBuffer0* rdb = GL::GetRenderBuffer0(); shader->Enable(); rdb->SafeAppend(VERTS, sizeof(VERTS) / sizeof(VERTS[0])); rdb->Submit(GL_QUADS); shader->Disable(); glViewport(globalRendering->viewPosX, 0, globalRendering->viewSizeX, globalRendering->viewSizeY); FBO::Unbind(); // generate mipmaps glBindTexture(GL_TEXTURE_2D, texture); glGenerateMipmap(GL_TEXTURE_2D); }
void CRadarTexture::Update() { if (!fbo.IsValid() || !shader->IsValid() || uploadTexRadar == 0 || uploadTexJammer == 0) return UpdateCPU(); if (losHandler->globalLOS[gu->myAllyTeam]) { fbo.Bind(); glViewport(0,0, texSize.x, texSize.y); glClearColor(1.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glViewport(globalRendering->viewPosX,0,globalRendering->viewSizeX,globalRendering->viewSizeY); FBO::Unbind(); glBindTexture(GL_TEXTURE_2D, texture); glGenerateMipmap(GL_TEXTURE_2D); return; } const int jammerAllyTeam = modInfo.separateJammers ? gu->myAllyTeam : 0; infoTexPBO.Bind(); const size_t arraySize = texSize.x * texSize.y * sizeof(unsigned short); auto infoTexMem = reinterpret_cast<unsigned char*>(infoTexPBO.MapBuffer()); const unsigned short* myRadar = &losHandler->radar.losMaps[gu->myAllyTeam].front(); const unsigned short* myJammer = &losHandler->jammer.losMaps[jammerAllyTeam].front(); memcpy(infoTexMem, myRadar, arraySize); infoTexMem += arraySize; memcpy(infoTexMem, myJammer, arraySize); infoTexPBO.UnmapBuffer(); //Trick: Upload the ushort as 2 ubytes, and then check both for `!=0` in the shader. // Faster than doing it on the CPU! And uploading it as shorts would be slow, cause the GPU // has no native support for them and so the transformation would happen on the CPU, too. glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, uploadTexRadar); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texSize.x, texSize.y, GL_RG, GL_UNSIGNED_BYTE, infoTexPBO.GetPtr()); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, uploadTexJammer); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texSize.x, texSize.y, GL_RG, GL_UNSIGNED_BYTE, infoTexPBO.GetPtr(arraySize)); infoTexPBO.Invalidate(); infoTexPBO.Unbind(); // do post-processing on the gpu (los-checking & scaling) fbo.Bind(); glViewport(0,0, texSize.x, texSize.y); shader->Enable(); glDisable(GL_BLEND); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, infoTextureHandler->GetInfoTexture("los")->GetTexture()); glBegin(GL_QUADS); glVertex2f(-1.f, -1.f); glVertex2f(-1.f, +1.f); glVertex2f(+1.f, +1.f); glVertex2f(+1.f, -1.f); glEnd(); shader->Disable(); glViewport(globalRendering->viewPosX,0,globalRendering->viewSizeX,globalRendering->viewSizeY); FBO::Unbind(); // generate mipmaps glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); }