#5979: Cubemap support for opengl2.
This commit is contained in:
parent
68a616c7f1
commit
7e875c6941
23 changed files with 1268 additions and 516 deletions
|
@ -36,13 +36,13 @@ static float s_flipMatrix[16] = {
|
|||
|
||||
|
||||
/*
|
||||
** GL_Bind2
|
||||
** GL_Bind
|
||||
*/
|
||||
void GL_Bind2( image_t *image, GLenum type ) {
|
||||
void GL_Bind( image_t *image ) {
|
||||
int texnum;
|
||||
|
||||
if ( !image ) {
|
||||
ri.Printf( PRINT_WARNING, "GL_Bind2: NULL image\n" );
|
||||
ri.Printf( PRINT_WARNING, "GL_Bind: NULL image\n" );
|
||||
texnum = tr.defaultImage->texnum;
|
||||
} else {
|
||||
texnum = image->texnum;
|
||||
|
@ -57,26 +57,13 @@ void GL_Bind2( image_t *image, GLenum type ) {
|
|||
image->frameUsed = tr.frameCount;
|
||||
}
|
||||
glState.currenttextures[glState.currenttmu] = texnum;
|
||||
qglBindTexture (type, texnum);
|
||||
if (image && image->flags & IMGFLAG_CUBEMAP)
|
||||
qglBindTexture( GL_TEXTURE_CUBE_MAP, texnum );
|
||||
else
|
||||
qglBindTexture( GL_TEXTURE_2D, texnum );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** GL_Bind2
|
||||
*/
|
||||
void GL_Bind( image_t *image )
|
||||
{
|
||||
GL_Bind2( image, GL_TEXTURE_2D );
|
||||
}
|
||||
|
||||
/*
|
||||
** GL_BindCubemap
|
||||
*/
|
||||
void GL_BindCubemap( image_t *image )
|
||||
{
|
||||
GL_Bind2( image, GL_TEXTURE_CUBE_MAP );
|
||||
}
|
||||
|
||||
/*
|
||||
** GL_SelectTexture
|
||||
*/
|
||||
|
@ -95,34 +82,6 @@ void GL_SelectTexture( int unit )
|
|||
glState.currenttmu = unit;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** GL_BindMultitexture
|
||||
*/
|
||||
void GL_BindMultitexture( image_t *image0, GLuint env0, image_t *image1, GLuint env1 ) {
|
||||
int texnum0, texnum1;
|
||||
|
||||
texnum0 = image0->texnum;
|
||||
texnum1 = image1->texnum;
|
||||
|
||||
if ( r_nobind->integer && tr.dlightImage ) { // performance evaluation option
|
||||
texnum0 = texnum1 = tr.dlightImage->texnum;
|
||||
}
|
||||
|
||||
if ( glState.currenttextures[1] != texnum1 ) {
|
||||
GL_SelectTexture( 1 );
|
||||
image1->frameUsed = tr.frameCount;
|
||||
glState.currenttextures[1] = texnum1;
|
||||
qglBindTexture( GL_TEXTURE_2D, texnum1 );
|
||||
}
|
||||
if ( glState.currenttextures[0] != texnum0 ) {
|
||||
GL_SelectTexture( 0 );
|
||||
image0->frameUsed = tr.frameCount;
|
||||
glState.currenttextures[0] = texnum0;
|
||||
qglBindTexture( GL_TEXTURE_2D, texnum0 );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** GL_BindToTMU
|
||||
*/
|
||||
|
@ -141,7 +100,11 @@ void GL_BindToTMU( image_t *image, int tmu )
|
|||
if (image)
|
||||
image->frameUsed = tr.frameCount;
|
||||
glState.currenttextures[tmu] = texnum;
|
||||
qglBindTexture( GL_TEXTURE_2D, texnum );
|
||||
|
||||
if (image && (image->flags & IMGFLAG_CUBEMAP))
|
||||
qglBindTexture( GL_TEXTURE_CUBE_MAP, texnum );
|
||||
else
|
||||
qglBindTexture( GL_TEXTURE_2D, texnum );
|
||||
GL_SelectTexture( oldtmu );
|
||||
}
|
||||
}
|
||||
|
@ -496,6 +459,13 @@ void RB_BeginDrawingView (void) {
|
|||
else
|
||||
{
|
||||
FBO_Bind(backEnd.viewParms.targetFbo);
|
||||
|
||||
// FIXME: hack for cubemap testing
|
||||
if (backEnd.viewParms.targetFbo == tr.renderCubeFbo)
|
||||
{
|
||||
//qglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + backEnd.viewParms.targetFboLayer, backEnd.viewParms.targetFbo->colorImage[0]->texnum, 0);
|
||||
qglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + backEnd.viewParms.targetFboLayer, tr.cubemaps[backEnd.viewParms.targetFboCubemapIndex]->texnum, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,6 +500,13 @@ void RB_BeginDrawingView (void) {
|
|||
qglClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
}
|
||||
|
||||
// clear to black for cube maps
|
||||
if (backEnd.viewParms.targetFbo == tr.renderCubeFbo)
|
||||
{
|
||||
clearBits |= GL_COLOR_BUFFER_BIT;
|
||||
qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
qglClear( clearBits );
|
||||
|
||||
if ( ( backEnd.refdef.rdflags & RDF_HYPERSPACE ) )
|
||||
|
@ -581,6 +558,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
|
|||
int entityNum, oldEntityNum;
|
||||
int dlighted, oldDlighted;
|
||||
int pshadowed, oldPshadowed;
|
||||
int cubemapIndex, oldCubemapIndex;
|
||||
qboolean depthRange, oldDepthRange, isCrosshair, wasCrosshair;
|
||||
int i;
|
||||
drawSurf_t *drawSurf;
|
||||
|
@ -606,6 +584,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
|
|||
wasCrosshair = qfalse;
|
||||
oldDlighted = qfalse;
|
||||
oldPshadowed = qfalse;
|
||||
oldCubemapIndex = -1;
|
||||
oldSort = -1;
|
||||
|
||||
depth[0] = 0.f;
|
||||
|
@ -614,7 +593,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
|
|||
backEnd.pc.c_surfaces += numDrawSurfs;
|
||||
|
||||
for (i = 0, drawSurf = drawSurfs ; i < numDrawSurfs ; i++, drawSurf++) {
|
||||
if ( drawSurf->sort == oldSort ) {
|
||||
if ( drawSurf->sort == oldSort && drawSurf->cubemapIndex == oldCubemapIndex) {
|
||||
if (backEnd.depthFill && shader && shader->sort != SS_OPAQUE)
|
||||
continue;
|
||||
|
||||
|
@ -624,22 +603,24 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
|
|||
}
|
||||
oldSort = drawSurf->sort;
|
||||
R_DecomposeSort( drawSurf->sort, &entityNum, &shader, &fogNum, &dlighted, &pshadowed );
|
||||
cubemapIndex = drawSurf->cubemapIndex;
|
||||
|
||||
//
|
||||
// change the tess parameters if needed
|
||||
// a "entityMergable" shader is a shader that can have surfaces from seperate
|
||||
// entities merged into a single batch, like smoke and blood puff sprites
|
||||
if ( shader != NULL && ( shader != oldShader || fogNum != oldFogNum || dlighted != oldDlighted || pshadowed != oldPshadowed
|
||||
if ( shader != NULL && ( shader != oldShader || fogNum != oldFogNum || dlighted != oldDlighted || pshadowed != oldPshadowed || cubemapIndex != oldCubemapIndex
|
||||
|| ( entityNum != oldEntityNum && !shader->entityMergable ) ) ) {
|
||||
if (oldShader != NULL) {
|
||||
RB_EndSurface();
|
||||
}
|
||||
RB_BeginSurface( shader, fogNum );
|
||||
RB_BeginSurface( shader, fogNum, cubemapIndex );
|
||||
backEnd.pc.c_surfBatches++;
|
||||
oldShader = shader;
|
||||
oldFogNum = fogNum;
|
||||
oldDlighted = dlighted;
|
||||
oldPshadowed = pshadowed;
|
||||
oldCubemapIndex = cubemapIndex;
|
||||
}
|
||||
|
||||
if (backEnd.depthFill && shader && shader->sort != SS_OPAQUE)
|
||||
|
@ -981,7 +962,7 @@ const void *RB_StretchPic ( const void *data ) {
|
|||
RB_EndSurface();
|
||||
}
|
||||
backEnd.currentEntity = &backEnd.entity2D;
|
||||
RB_BeginSurface( shader, 0 );
|
||||
RB_BeginSurface( shader, 0, 0 );
|
||||
}
|
||||
|
||||
RB_CHECKOVERFLOW( 4, 6 );
|
||||
|
@ -1311,8 +1292,14 @@ const void *RB_DrawSurfs( const void *data ) {
|
|||
RB_RenderFlares();
|
||||
}
|
||||
|
||||
//if (glRefConfig.framebufferObject)
|
||||
//FBO_Bind(NULL);
|
||||
if (glRefConfig.framebufferObject && backEnd.viewParms.targetFbo == tr.renderCubeFbo)
|
||||
{
|
||||
FBO_Bind(NULL);
|
||||
GL_SelectTexture(TB_CUBEMAP);
|
||||
GL_BindToTMU(tr.cubemaps[backEnd.viewParms.targetFboCubemapIndex], TB_CUBEMAP);
|
||||
qglGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP);
|
||||
GL_SelectTexture(0);
|
||||
}
|
||||
|
||||
return (const void *)(cmd + 1);
|
||||
}
|
||||
|
@ -1586,7 +1573,7 @@ const void *RB_CapShadowMap(const void *data)
|
|||
GL_SelectTexture(0);
|
||||
if (cmd->cubeSide != -1)
|
||||
{
|
||||
GL_BindCubemap(tr.shadowCubemaps[cmd->map]);
|
||||
GL_Bind(tr.shadowCubemaps[cmd->map]);
|
||||
qglCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + cmd->cubeSide, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0);
|
||||
}
|
||||
else
|
||||
|
@ -1682,7 +1669,7 @@ const void *RB_PostProcess(const void *data)
|
|||
color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value);
|
||||
color[3] = 1.0f;
|
||||
|
||||
FBO_Blit(srcFbo, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, color, 0);
|
||||
FBO_Blit(srcFbo, srcBox, NULL, tr.screenScratchFbo, dstBox, NULL, color, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1721,6 +1708,21 @@ const void *RB_PostProcess(const void *data)
|
|||
FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (r_cubeMapping->integer && tr.numCubemaps)
|
||||
{
|
||||
vec4i_t dstBox;
|
||||
int cubemapIndex = R_CubemapForPoint( backEnd.viewParms.or.origin );
|
||||
|
||||
if (cubemapIndex)
|
||||
{
|
||||
VectorSet4(dstBox, 0, glConfig.vidHeight - 256, 256, 256);
|
||||
//FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, tr.screenScratchFbo, dstBox, &tr.testcubeShader, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1], NULL, NULL, tr.screenScratchFbo, dstBox, &tr.testcubeShader, NULL, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
backEnd.framePostProcessed = qtrue;
|
||||
|
||||
return (const void *)(cmd + 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue