mirror of
https://github.com/glest/glest-source.git
synced 2025-08-29 02:40:17 +02:00
- added FBO's for map preview rendering, which improves fps in the custom menu for video cards that support Frame Buffer Objects
This commit is contained in:
@@ -4391,17 +4391,20 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame,
|
|||||||
void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
||||||
int screenPosX, int screenPosY,
|
int screenPosX, int screenPosY,
|
||||||
Texture2D **renderToTexture) {
|
Texture2D **renderToTexture) {
|
||||||
float alt=0;
|
|
||||||
float showWater=0;
|
|
||||||
int renderMapHeight=64;
|
|
||||||
int renderMapWidth=64;
|
|
||||||
float cellSize=2;
|
|
||||||
float playerCrossSize=2;
|
|
||||||
float clientW=renderMapWidth*cellSize;
|
|
||||||
float clientH=renderMapHeight*cellSize;;
|
|
||||||
|
|
||||||
|
static bool supportFBOs = Texture2DGl().supports_FBO_RBO();
|
||||||
|
//static bool supportFBOs = false;
|
||||||
const Metrics &metrics= Metrics::getInstance();
|
const Metrics &metrics= Metrics::getInstance();
|
||||||
|
|
||||||
|
float alt = 0;
|
||||||
|
float showWater = 0;
|
||||||
|
int renderMapHeight = 64;
|
||||||
|
int renderMapWidth = 64;
|
||||||
|
float cellSize = 2;
|
||||||
|
float playerCrossSize = 2;
|
||||||
|
float clientW = renderMapWidth * cellSize;
|
||||||
|
float clientH = renderMapHeight * cellSize;;
|
||||||
|
|
||||||
// stretch small maps to 128x128
|
// stretch small maps to 128x128
|
||||||
if(map->getW() < map->getH()) {
|
if(map->getW() < map->getH()) {
|
||||||
cellSize = cellSize * renderMapHeight / map->getH();
|
cellSize = cellSize * renderMapHeight / map->getH();
|
||||||
@@ -4412,30 +4415,18 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
/*
|
if(supportFBOs == true && renderToTexture != NULL) {
|
||||||
if(renderToTexture != NULL) {
|
|
||||||
Config &config= Config::getInstance();
|
Config &config= Config::getInstance();
|
||||||
Texture2D::Filter textureFilter = strToTextureFilter(config.getString("Filter"));
|
Texture2D::Filter textureFilter = strToTextureFilter(config.getString("Filter"));
|
||||||
int maxAnisotropy = config.getInt("FilterMaxAnisotropy");
|
int maxAnisotropy = config.getInt("FilterMaxAnisotropy");
|
||||||
|
|
||||||
*renderToTexture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
|
*renderToTexture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
|
||||||
Texture2DGl *texture = static_cast<Texture2DGl *>(*renderToTexture);
|
Texture2DGl *texture = static_cast<Texture2DGl *>(*renderToTexture);
|
||||||
//texture->setFormat(Texture::fAlpha);
|
|
||||||
texture->setMipmap(false);
|
texture->setMipmap(false);
|
||||||
Pixmap2D *pixmapScreenShot = texture->getPixmap();
|
Pixmap2D *pixmapScreenShot = texture->getPixmap();
|
||||||
pixmapScreenShot->init(metrics.getVirtualW(), metrics.getVirtualH(), 3);
|
pixmapScreenShot->init(metrics.getVirtualW(), metrics.getVirtualH(), 4);
|
||||||
//pixmapScreenShot->init(map->getW(),map->getH(),3);
|
|
||||||
//pixmapScreenShot->init(200, 360, 3);
|
|
||||||
texture->setForceCompressionDisabled(true);
|
texture->setForceCompressionDisabled(true);
|
||||||
texture->init(textureFilter,maxAnisotropy);
|
texture->init(textureFilter,maxAnisotropy);
|
||||||
|
|
||||||
|
|
||||||
//texture->initFrameBuffer();
|
|
||||||
//texture->attachFrameBufferToTexture();
|
|
||||||
|
|
||||||
//texture->initRenderBuffer();
|
|
||||||
//texture->attachRenderBuffer();
|
|
||||||
|
|
||||||
texture->setup_FBO_RBO();
|
texture->setup_FBO_RBO();
|
||||||
|
|
||||||
if(texture->checkFrameBufferStatus() == false) {
|
if(texture->checkFrameBufferStatus() == false) {
|
||||||
@@ -4445,46 +4436,66 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
*renderToTexture=NULL;
|
*renderToTexture=NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
if(supportFBOs == true && renderToTexture != NULL) {
|
||||||
|
cellSize =1;
|
||||||
|
clientW = metrics.getVirtualW();
|
||||||
|
clientH = metrics.getVirtualH();
|
||||||
|
int mapMaxDimensionSize = std::max(map->getW(),map->getH());
|
||||||
|
switch(mapMaxDimensionSize) {
|
||||||
|
case 8:
|
||||||
|
cellSize = 96;
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
cellSize = 48;
|
||||||
|
break;
|
||||||
|
case 32:
|
||||||
|
cellSize = 24;
|
||||||
|
break;
|
||||||
|
case 64:
|
||||||
|
cellSize = 12;
|
||||||
|
break;
|
||||||
|
case 128:
|
||||||
|
cellSize = 6;
|
||||||
|
break;
|
||||||
|
case 256:
|
||||||
|
cellSize = 3;
|
||||||
|
break;
|
||||||
|
case 512:
|
||||||
|
cellSize = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glFrontFace(GL_CW);
|
glFrontFace(GL_CW);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
//glDisable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
//glViewport(screenPosX, screenPosY, metrics.getVirtualW(),metrics.getVirtualH());
|
|
||||||
// glOrtho(0, clientW, 0, clientH, -1, 1);
|
|
||||||
|
|
||||||
//glOrtho(screenPosX, screenPosX+clientW, screenPosY+clientH, screenPosY, 0, 1);
|
GLint viewport[4]; // Where The original Viewport Values Will Be Stored
|
||||||
|
|
||||||
|
if(supportFBOs == true && renderToTexture != NULL) {
|
||||||
|
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||||
|
glOrtho(0, clientW, 0, clientH, 0, 1);
|
||||||
|
glViewport(0, 0, clientW, clientH);
|
||||||
|
}
|
||||||
|
else {
|
||||||
glOrtho(0, metrics.getVirtualW(), 0, metrics.getVirtualH(), 0, 1);
|
glOrtho(0, metrics.getVirtualW(), 0, metrics.getVirtualH(), 0, 1);
|
||||||
//gluOrtho2D (0, metrics.getVirtualW(), 0, metrics.getVirtualH());
|
}
|
||||||
|
|
||||||
//glEnable( GL_SCISSOR_TEST );
|
|
||||||
//glScissor(screenPosX, screenPosY,metrics.getVirtualW(), metrics.getVirtualH());
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
if(supportFBOs == false || renderToTexture == NULL) {
|
||||||
glTranslatef(static_cast<float>(screenPosX),static_cast<float>(screenPosY)-clientH,0.0f);
|
glTranslatef(static_cast<float>(screenPosX),static_cast<float>(screenPosY)-clientH,0.0f);
|
||||||
|
}
|
||||||
//glEnable( GL_SCISSOR_TEST );
|
|
||||||
//glScissor(screenPosX, screenPosY,screenPosX-clientW, screenPosY-clientH);
|
|
||||||
|
|
||||||
//int newX = screenPosX - (metrics.getVirtualW() / 2);
|
|
||||||
//int newY = screenPosY - (metrics.getVirtualH() / 2);
|
|
||||||
//int newX = 0;
|
|
||||||
//int newY = 0;
|
|
||||||
//glTranslatef(static_cast<float>(newX),static_cast<float>(newY),0.0f);
|
|
||||||
|
|
||||||
glPushAttrib(GL_CURRENT_BIT);
|
glPushAttrib(GL_CURRENT_BIT);
|
||||||
//glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
|
|
||||||
glLineWidth(1);
|
glLineWidth(1);
|
||||||
//glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
glColor3f(0, 0, 0);
|
glColor3f(0, 0, 0);
|
||||||
|
|
||||||
for (int j = 0; j < map->getH(); j++) {
|
for (int j = 0; j < map->getH(); j++) {
|
||||||
@@ -4567,10 +4578,10 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool found = false;
|
// bool found = false;
|
||||||
|
|
||||||
//height lines
|
//height lines
|
||||||
// if (!found) {
|
// if (!found) {
|
||||||
|
|
||||||
//left
|
//left
|
||||||
if (i > 0 && map->getHeight(i - 1, j) > map->getHeight(i, j)) {
|
if (i > 0 && map->getHeight(i - 1, j) > map->getHeight(i, j)) {
|
||||||
@@ -4605,7 +4616,7 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
glVertex2f((i + 1) * cellSize, clientH - j * cellSize);
|
glVertex2f((i + 1) * cellSize, clientH - j * cellSize);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//resources
|
//resources
|
||||||
if(renderAll == true) {
|
if(renderAll == true) {
|
||||||
@@ -4627,12 +4638,16 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//start locations
|
//start locations
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
|
|
||||||
|
if(supportFBOs == true && renderToTexture != NULL) {
|
||||||
|
glLineWidth(14);
|
||||||
|
playerCrossSize = 24;
|
||||||
|
}
|
||||||
|
else {
|
||||||
// force playerCrossSize to be at least of size 4
|
// force playerCrossSize to be at least of size 4
|
||||||
if(cellSize < 4) {
|
if(cellSize < 4) {
|
||||||
playerCrossSize = 4;
|
playerCrossSize = 4;
|
||||||
@@ -4640,17 +4655,34 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
else {
|
else {
|
||||||
playerCrossSize = cellSize;
|
playerCrossSize = cellSize;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < map->getMaxFactions(); i++) {
|
for (int i = 0; i < map->getMaxFactions(); i++) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0: glColor3f(1.f, 0.f, 0.f); break;
|
case 0:
|
||||||
case 1: glColor3f(0.f, 0.f, 1.f); break;
|
glColor3f(1.f, 0.f, 0.f);
|
||||||
case 2: glColor3f(0.f, 1.f, 0.f); break;
|
break;
|
||||||
case 3: glColor3f(1.f, 1.f, 0.f); break;
|
case 1:
|
||||||
case 4: glColor3f(1.f, 1.f, 1.f); break;
|
glColor3f(0.f, 0.f, 1.f);
|
||||||
case 5: glColor3f(0.f, 1.f, 0.8f); break;
|
break;
|
||||||
case 6: glColor3f(1.f, 0.5f, 0.f); break;
|
case 2:
|
||||||
case 7: glColor3f(1.f, 0.5f, 1.f); break;
|
glColor3f(0.f, 1.f, 0.f);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
glColor3f(1.f, 1.f, 0.f);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
glColor3f(1.f, 1.f, 1.f);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
glColor3f(0.f, 1.f, 0.8f);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
glColor3f(1.f, 0.5f, 0.f);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
glColor3f(1.f, 0.5f, 1.f);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex2f((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
|
glVertex2f((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
|
||||||
@@ -4665,29 +4697,15 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
//glDisable( GL_SCISSOR_TEST );
|
if(supportFBOs == true && renderToTexture != NULL) {
|
||||||
//glViewport(0, 0, 0, 0);
|
|
||||||
|
|
||||||
if(renderToTexture != NULL) {
|
|
||||||
|
|
||||||
// *renderToTexture = saveScreenToTexture(screenPosX, screenPosY, metrics.getVirtualW(), metrics.getVirtualH());
|
|
||||||
// *renderToTexture = saveScreenToTexture(0, 0, metrics.getVirtualW(), metrics.getVirtualH());
|
|
||||||
/*
|
|
||||||
Texture2DGl *texture = static_cast<Texture2DGl *>(*renderToTexture);
|
Texture2DGl *texture = static_cast<Texture2DGl *>(*renderToTexture);
|
||||||
if(texture != NULL) {
|
if(texture != NULL) {
|
||||||
// *renderToTexture = saveScreenToTexture(screenPosX, screenPosY, clientW, clientH);
|
|
||||||
texture->dettachFrameBufferFromTexture();
|
texture->dettachFrameBufferFromTexture();
|
||||||
|
|
||||||
// Signal the threads queue to add a screenshot save request
|
|
||||||
// MutexSafeWrapper safeMutex(&saveScreenShotThreadAccessor);
|
|
||||||
// saveScreenQueue.push_back(make_pair("bob.png",texture->getPixmap()));
|
|
||||||
// *renderToTexture=NULL;
|
|
||||||
// safeMutex.ReleaseLock();
|
|
||||||
|
|
||||||
// texture->teardown_FBO_RBO();
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -674,6 +674,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxFogOfWar.mouseClick(x, y)) {
|
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxFogOfWar.mouseClick(x, y)) {
|
||||||
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
|
||||||
|
cleanupMapPreviewTexture();
|
||||||
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
|
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
|
||||||
needToRepublishToMasterserver = true;
|
needToRepublishToMasterserver = true;
|
||||||
}
|
}
|
||||||
@@ -1213,8 +1214,7 @@ void MenuStateCustomGame::render() {
|
|||||||
renderer.renderTextureQuad(800,600,200,150,factionTexture,0.7f);
|
renderer.renderTextureQuad(800,600,200,150,factionTexture,0.7f);
|
||||||
}
|
}
|
||||||
if(mapPreviewTexture != NULL) {
|
if(mapPreviewTexture != NULL) {
|
||||||
//renderer.renderTextureQuad(10,350,-1,-1,mapPreviewTexture,0.7);
|
renderer.renderTextureQuad(5,165,180,180,mapPreviewTexture,1.0f);
|
||||||
renderer.renderTextureQuad(800,300,200,150,mapPreviewTexture,0.7f);
|
|
||||||
//printf("=================> Rendering map preview texture\n");
|
//printf("=================> Rendering map preview texture\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1349,9 +1349,9 @@ void MenuStateCustomGame::render() {
|
|||||||
renderer.renderMapPreview(&mapPreview, renderAll, 10, 350,&mapPreviewTexture);
|
renderer.renderMapPreview(&mapPreview, renderAll, 10, 350,&mapPreviewTexture);
|
||||||
//printf("=================> Rendering map preview into a texture AFTER (%p)\n", mapPreviewTexture);
|
//printf("=================> Rendering map preview into a texture AFTER (%p)\n", mapPreviewTexture);
|
||||||
}
|
}
|
||||||
else {
|
//else {
|
||||||
renderer.renderMapPreview(&mapPreview, renderAll, 10, 350);
|
//renderer.renderMapPreview(&mapPreview, renderAll, 10, 350);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasNetworkGameSettings() == true) {
|
if(hasNetworkGameSettings() == true) {
|
||||||
|
@@ -28,6 +28,10 @@ protected:
|
|||||||
GLuint renderBufferId;
|
GLuint renderBufferId;
|
||||||
GLuint frameBufferId;
|
GLuint frameBufferId;
|
||||||
|
|
||||||
|
void initRenderBuffer();
|
||||||
|
void initFrameBuffer();
|
||||||
|
void attachRenderBuffer();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextureGl();
|
TextureGl();
|
||||||
virtual ~TextureGl();
|
virtual ~TextureGl();
|
||||||
@@ -36,14 +40,11 @@ public:
|
|||||||
GLuint getRenderBufferHandle() const {return renderBufferId;}
|
GLuint getRenderBufferHandle() const {return renderBufferId;}
|
||||||
GLuint getFrameBufferHandle() const {return frameBufferId;}
|
GLuint getFrameBufferHandle() const {return frameBufferId;}
|
||||||
|
|
||||||
void initRenderBuffer();
|
bool supports_FBO_RBO();
|
||||||
void initFrameBuffer();
|
|
||||||
void attachRenderBuffer();
|
|
||||||
void attachFrameBufferToTexture();
|
|
||||||
bool checkFrameBufferStatus();
|
|
||||||
void dettachFrameBufferFromTexture();
|
|
||||||
|
|
||||||
void setup_FBO_RBO();
|
void setup_FBO_RBO();
|
||||||
|
void attachFrameBufferToTexture();
|
||||||
|
void dettachFrameBufferFromTexture();
|
||||||
|
bool checkFrameBufferStatus();
|
||||||
void teardown_FBO_RBO();
|
void teardown_FBO_RBO();
|
||||||
|
|
||||||
virtual int getTextureWidth() const = 0;
|
virtual int getTextureWidth() const = 0;
|
||||||
|
@@ -21,11 +21,39 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// Define FBO's (Frame Buffer Objects) for win32
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT;
|
||||||
|
PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT;
|
||||||
|
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT;
|
||||||
|
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT;
|
||||||
|
PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Shared { namespace Graphics { namespace Gl {
|
namespace Shared { namespace Graphics { namespace Gl {
|
||||||
|
|
||||||
using namespace Platform;
|
using namespace Platform;
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
|
|
||||||
|
void setupGLExtensionMethods() {
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
static bool setupExtensions=true;
|
||||||
|
if(setupExtensions == true) {
|
||||||
|
setupExtensions = false;
|
||||||
|
glGenFramebuffersEXT= (PFNGLGENFRAMEBUFFERSEXTPROC)SDL_GL_GetProcAddress("glGenFramebuffersEXT");
|
||||||
|
glBindFramebufferEXT= (PFNGLBINDFRAMEBUFFEREXTPROC)SDL_GL_GetProcAddress("glBindFramebufferEXT");
|
||||||
|
glFramebufferTexture2DEXT= (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)SDL_GL_GetProcAddress("glFramebufferTexture2DEXT");
|
||||||
|
glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)SDL_GL_GetProcAddress("glDeleteFramebuffersEXT");
|
||||||
|
glCheckFramebufferStatusEXT= (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)SDL_GL_GetProcAddress("glCheckFramebufferStatusEXT");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
const uint64 MIN_BYTES_TO_COMPRESS = 12;
|
const uint64 MIN_BYTES_TO_COMPRESS = 12;
|
||||||
|
|
||||||
static std::string getSupportCompressedTextureFormatString(int format) {
|
static std::string getSupportCompressedTextureFormatString(int format) {
|
||||||
@@ -425,6 +453,11 @@ TextureGl::TextureGl() {
|
|||||||
handle = 0;
|
handle = 0;
|
||||||
renderBufferId = 0;
|
renderBufferId = 0;
|
||||||
frameBufferId = 0;
|
frameBufferId = 0;
|
||||||
|
setupGLExtensionMethods();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextureGl::supports_FBO_RBO() {
|
||||||
|
return (glGenFramebuffersEXT != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureGl::setup_FBO_RBO() {
|
void TextureGl::setup_FBO_RBO() {
|
||||||
@@ -432,17 +465,17 @@ void TextureGl::setup_FBO_RBO() {
|
|||||||
throw runtime_error("getTextureWidth() < 0 || getTextureHeight() < 0");
|
throw runtime_error("getTextureWidth() < 0 || getTextureHeight() < 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"getTextureWidth() = %d, getTextureHeight() = %d\n",getTextureWidth(),getTextureHeight());
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"getTextureWidth() = %d, getTextureHeight() = %d\n",getTextureWidth(),getTextureHeight());
|
||||||
|
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
|
||||||
#ifndef WIN32
|
|
||||||
|
|
||||||
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
|
// Did we successfully setup FBO's?
|
||||||
|
if(glGenFramebuffersEXT) {
|
||||||
GLint width=0;
|
GLint width=0;
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&width);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&width);
|
||||||
GLint height=0;
|
GLint height=0;
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&height);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&height);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"width = %d, height = %d\n",width,height);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"width = %d, height = %d\n",width,height);
|
||||||
|
|
||||||
//RGBA8 2D texture, 24 bit depth texture, 256x256
|
//RGBA8 2D texture, 24 bit depth texture, 256x256
|
||||||
//glGenTextures(1, &color_tex);
|
//glGenTextures(1, &color_tex);
|
||||||
@@ -472,10 +505,10 @@ void TextureGl::setup_FBO_RBO() {
|
|||||||
switch(status)
|
switch(status)
|
||||||
{
|
{
|
||||||
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"FBO attachment OK!\n");
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"FBO attachment OK!\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"FBO attachment BAD!\n");
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"FBO attachment BAD!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -483,14 +516,12 @@ void TextureGl::setup_FBO_RBO() {
|
|||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferId);
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferId);
|
||||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureGl::teardown_FBO_RBO() {
|
void TextureGl::teardown_FBO_RBO() {
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
#ifndef WIN32
|
if(glGenFramebuffersEXT) {
|
||||||
|
|
||||||
//----------------
|
//----------------
|
||||||
//Bind 0, which means render to back buffer
|
//Bind 0, which means render to back buffer
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
@@ -501,50 +532,48 @@ void TextureGl::teardown_FBO_RBO() {
|
|||||||
//Bind 0, which means render to back buffer, as a result, fb is unbound
|
//Bind 0, which means render to back buffer, as a result, fb is unbound
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
glDeleteFramebuffersEXT(1, &frameBufferId);
|
glDeleteFramebuffersEXT(1, &frameBufferId);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureGl::initRenderBuffer() {
|
void TextureGl::initRenderBuffer() {
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
#ifndef WIN32
|
if(glGenFramebuffersEXT) {
|
||||||
|
|
||||||
// create a renderbuffer object to store depth info
|
// create a renderbuffer object to store depth info
|
||||||
glGenRenderbuffersEXT(1, &renderBufferId);
|
glGenRenderbuffersEXT(1, &renderBufferId);
|
||||||
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBufferId);
|
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBufferId);
|
||||||
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,getTextureWidth(), getTextureHeight());
|
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,getTextureWidth(), getTextureHeight());
|
||||||
//glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
|
//glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureGl::initFrameBuffer() {
|
void TextureGl::initFrameBuffer() {
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
#ifndef WIN32
|
if(glGenFramebuffersEXT) {
|
||||||
// create a framebuffer object
|
// create a framebuffer object
|
||||||
glGenFramebuffersEXT(1, &frameBufferId);
|
glGenFramebuffersEXT(1, &frameBufferId);
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferId);
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferId);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureGl::attachRenderBuffer() {
|
void TextureGl::attachRenderBuffer() {
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
#ifndef WIN32
|
if(glGenFramebuffersEXT) {
|
||||||
// attach the renderbuffer to depth attachment point
|
// attach the renderbuffer to depth attachment point
|
||||||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, renderBufferId);
|
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, renderBufferId);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureGl::attachFrameBufferToTexture() {
|
void TextureGl::attachFrameBufferToTexture() {
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
#ifndef WIN32
|
if(glGenFramebuffersEXT) {
|
||||||
// attach the texture to FBO color attachment point
|
// attach the texture to FBO color attachment point
|
||||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, handle, 0);
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, handle, 0);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureGl::checkFrameBufferStatus() {
|
bool TextureGl::checkFrameBufferStatus() {
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
#ifndef WIN32
|
if(glGenFramebuffersEXT) {
|
||||||
|
|
||||||
// check FBO status
|
// check FBO status
|
||||||
// Does the GPU support current FBO configuration?
|
// Does the GPU support current FBO configuration?
|
||||||
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
||||||
@@ -553,25 +582,22 @@ bool TextureGl::checkFrameBufferStatus() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
return false;
|
return false;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureGl::dettachFrameBufferFromTexture() {
|
void TextureGl::dettachFrameBufferFromTexture() {
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
#ifndef WIN32
|
if(glGenFramebuffersEXT) {
|
||||||
|
|
||||||
// switch back to window-system-provided framebuffer
|
// switch back to window-system-provided framebuffer
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureGl::~TextureGl() {
|
TextureGl::~TextureGl() {
|
||||||
// Need some work to get extensions properly working in Windows (use Glew lib)
|
// Need some work to get extensions properly working in Windows (use Glew lib)
|
||||||
#ifndef WIN32
|
if(glGenFramebuffersEXT) {
|
||||||
|
|
||||||
if(renderBufferId != 0) {
|
if(renderBufferId != 0) {
|
||||||
glDeleteRenderbuffersEXT(1, &renderBufferId);
|
glDeleteRenderbuffersEXT(1, &renderBufferId);
|
||||||
renderBufferId = 0;
|
renderBufferId = 0;
|
||||||
@@ -580,10 +606,8 @@ TextureGl::~TextureGl() {
|
|||||||
glDeleteFramebuffersEXT(1, &frameBufferId);
|
glDeleteFramebuffersEXT(1, &frameBufferId);
|
||||||
frameBufferId = 0;
|
frameBufferId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
Reference in New Issue
Block a user