So I made it grabbing the 1024768 screen in a 10241024 texture. But this is sloooooow, I want to grab directly in the correct mip map level (256256), and not first in 1024, and then sampling all mip maps down to 11, and then using GL_TEXTURE_LOD_BIAS_EXT. Actually, I’d like to generate a 256*256 mip map level directly from the screen, there must be a way to do this … which one ?
If this first method is slow, it may come from my implementation of the grabbing code, here it is :
Texture creation :
glGenTextures(1, &ScreenRenderTexture) ;
glBindTexture(GL_TEXTURE_2D, ScreenRenderTexture) ;
// w and h are 1024 for the working version, Data is an array of 102410244 unsigned byte
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, &Data[0]) ;
// Trilinear to adjust LOD Bias precisely
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) ; glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) ;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) ;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) ;
Rendering :
// Grab screen
glBindTexture(GL_TEXTURE_2D, ScreenRenderTexture) ;
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1024, 1024) ;
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE) ;
// Texture LOD bias
float MaxBias ;
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxBias) ;
GLfloat RealLODBias = 0.18f * MaxBias ;
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, RealLODBias) ;
// Render ortho poly
glBegin(GL_QUADS) ;
glTexCoord2f(1.0f, 768.0f / 1024.0f) ;
glVertex2i(1, 1) ;
glTexCoord2f(0.0f, 768.0f / 1024.0f) ;
glVertex2i(-1, 1) ;
glTexCoord2f(0.0f, 0.0f) ;
glVertex2i(-1, -1) ;
glTexCoord2f(1.0f, 0.0f) ;
glVertex2i(1, -1) ;
glEnd() ;
Pixel format :
// Pixel format descriptor
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), 1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
BpP,
(BpP == 32) ? 8 : 5, 0, // Red Bits
(BpP == 32) ? 8 : 6, 0, // Green Bits
(BpP == 32) ? 8 : 5, 0, // Blue Bits
8, 0, // Alpha Bits
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
24, // Z-Buffer
8, // Stencil Buffer
0, // Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
} ;
It gives really really neat effects, but frame rates goes from 60-90 down to 20-35
SeskaPeel.