📄 r_opengl.c
字号:
if( PolyFlags & PF_NoAlphaTest) glDisable( GL_ALPHA_TEST ); else glEnable( GL_ALPHA_TEST ); // discard 0 alpha pixels (holes in texture) } if( Xor & PF_Decal ) { if( PolyFlags & PF_Decal ) glEnable(GL_POLYGON_OFFSET_FILL); else glDisable(GL_POLYGON_OFFSET_FILL); } if( Xor&PF_NoDepthTest ) { if( PolyFlags & PF_NoDepthTest ) { glDepthFunc(GL_ALWAYS); //glDisable( GL_DEPTH_TEST ); } else glDepthFunc(GL_LEQUAL); //glEnable( GL_DEPTH_TEST ); } if( Xor&PF_Modulated ) {#ifdef LINUX if (oglflags & GLF_NOTEXENV) { if ( !(PolyFlags & PF_Modulated) ) glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } else#endif if( PolyFlags & PF_Modulated ) { // mix texture colour with Surface->FlatColor glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); } else { // colour from texture is unchanged before blending glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); } } if( Xor & PF_Occlude ) // depth test but (no) depth write { if (PolyFlags&PF_Occlude) { glDepthMask( 1 ); } else glDepthMask( 0 ); } ////Hurdler: not used if we don't define POLYSKY if( Xor & PF_Invisible ) { // glColorMask( (PolyFlags&PF_Invisible)==0, (PolyFlags&PF_Invisible)==0,// (PolyFlags&PF_Invisible)==0, (PolyFlags&PF_Invisible)==0 ); if (PolyFlags&PF_Invisible) glBlendFunc( GL_ZERO, GL_ONE ); // transparent blending else { // big hack: (TODO: manage that better) // we test only for PF_Masked because PF_Invisible is only used // (for now) with it (yeah, that's crappy, sorry) if ((PolyFlags&PF_Blending)==PF_Masked) glBlendFunc( GL_SRC_ALPHA, GL_ZERO ); } } if( PolyFlags & PF_NoTexture ) { SetNoTexture(); } } CurrentPolyFlags = PolyFlags;}// -----------------+// SetTexture : The mipmap becomes the current texture source// -----------------+EXPORT void HWRAPI( SetTexture ) ( FTextureInfo *pTexInfo ){ if( pTexInfo->downloaded ) { if (pTexInfo->downloaded != tex_downloaded) { glBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); tex_downloaded = pTexInfo->downloaded; } } else { // Download a mipmap static RGBA_t tex[256*256]; RGBA_t *ptex = tex; int w, h; //DBG_Printf ("DownloadMipmap %d %x\n",NextTexAvail,pTexInfo->grInfo.data); w = pTexInfo->width; h = pTexInfo->height;#ifdef USE_PALETTED_TEXTURE if( usePalettedTexture && (pTexInfo->grInfo.format==GR_TEXFMT_P_8) && !(pTexInfo->flags & TF_CHROMAKEYED) ) { // do nothing here. // Not a problem with MiniGL since we don't use paletted texture } else#endif if( (pTexInfo->grInfo.format==GR_TEXFMT_P_8) || (pTexInfo->grInfo.format==GR_TEXFMT_AP_88) ) { GLubyte *pImgData; int i, j; pImgData = (GLubyte *)pTexInfo->grInfo.data; for( j=0; j<h; j++ ) { for( i=0; i<w; i++) { if ( (*pImgData==HWR_PATCHES_CHROMAKEY_COLORINDEX) && (pTexInfo->flags & TF_CHROMAKEYED) ) { tex[w*j+i].s.red = 0; tex[w*j+i].s.green = 0; tex[w*j+i].s.blue = 0; tex[w*j+i].s.alpha = 0; } else { tex[w*j+i].s.red = myPaletteData[*pImgData].s.red; tex[w*j+i].s.green = myPaletteData[*pImgData].s.green; tex[w*j+i].s.blue = myPaletteData[*pImgData].s.blue; tex[w*j+i].s.alpha = myPaletteData[*pImgData].s.alpha; } pImgData++; if( pTexInfo->grInfo.format == GR_TEXFMT_AP_88 ) { if( !(pTexInfo->flags & TF_CHROMAKEYED) ) tex[w*j+i].s.alpha = *pImgData; pImgData++; } } } } else if (pTexInfo->grInfo.format==GR_RGBA) { // corona test : passed as ARGB 8888, which is not in glide formats // Hurdler: not used for coronas anymore, just for dynamic lighting ptex = (RGBA_t *) pTexInfo->grInfo.data; } else if (pTexInfo->grInfo.format==GR_TEXFMT_ALPHA_INTENSITY_88) { GLubyte *pImgData; int i, j; pImgData = (GLubyte *)pTexInfo->grInfo.data; for( j=0; j<h; j++ ) { for( i=0; i<w; i++) { tex[w*j+i].s.red = *pImgData; tex[w*j+i].s.green = *pImgData; tex[w*j+i].s.blue = *pImgData; pImgData++; tex[w*j+i].s.alpha = *pImgData; pImgData++; } } } else DBG_Printf ("SetTexture(bad format) %d\n", pTexInfo->grInfo.format); pTexInfo->downloaded = NextTexAvail++; tex_downloaded = pTexInfo->downloaded; glBindTexture( GL_TEXTURE_2D, pTexInfo->downloaded );#ifdef MINI_GL_COMPATIBILITY //if (pTexInfo->grInfo.format==GR_TEXFMT_ALPHA_INTENSITY_88) // glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex ); //else if (min_filter & MIPMAP_MASK) gluBuild2DMipmaps( GL_TEXTURE_2D, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex ); else glTexImage2D( GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex );#else#ifdef USE_PALETTED_TEXTURE //Hurdler: not really supported and not tested recently if( usePalettedTexture && (pTexInfo->grInfo.format==GR_TEXFMT_P_8) && !(pTexInfo->flags & TF_CHROMAKEYED) ) { glColorTableEXT(GL_TEXTURE_2D, GL_RGB8, 256, GL_RGB, GL_UNSIGNED_BYTE, palette_tex); glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, w, h, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, pTexInfo->grInfo.data ); } else#endif if (pTexInfo->grInfo.format==GR_TEXFMT_ALPHA_INTENSITY_88) { //glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex ); if (min_filter & MIPMAP_MASK) gluBuild2DMipmaps( GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex ); else glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex ); } else { if (min_filter & MIPMAP_MASK) gluBuild2DMipmaps( GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex ); else glTexImage2D( GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex ); }#endif if( pTexInfo->flags & TF_WRAPX ) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); else glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); if( pTexInfo->flags & TF_WRAPY ) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); else glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); pTexInfo->nextmipmap = NULL; if (gr_cachetail) { // insertion en fin de liste gr_cachetail->nextmipmap = pTexInfo; gr_cachetail = pTexInfo; } else // initialisation de la liste gr_cachetail = gr_cachehead = pTexInfo; }#ifdef MINI_GL_COMPATIBILITY switch(pTexInfo->flags) { case 0 : glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); break; default: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); break; }#endif}// -----------------+// DrawPolygon : Render a polygon, set the texture, set render mode// -----------------+EXPORT void HWRAPI( DrawPolygon ) ( FSurfaceInfo *pSurf, //FTextureInfo *pTexInfo, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags ){ FUINT i, j; FRGBAFloat c;#ifdef MINI_GL_COMPATIBILITY if (PolyFlags & PF_Corona) PolyFlags &= ~PF_NoDepthTest;#else if( (PolyFlags & PF_Corona) && (oglflags & GLF_NOZBUFREAD) ) PolyFlags &= ~(PF_NoDepthTest|PF_Corona);#endif SetBlend( PolyFlags ); //TODO: inline (#pragma..) // If Modulated, mix the surface colour to the texture if( (CurrentPolyFlags & PF_Modulated) && pSurf) { if (pal_col) { // hack for non-palettized mode c.red = (const_pal_col.red +byte2float[pSurf->FlatColor.s.red]) /2.0f; c.green = (const_pal_col.green+byte2float[pSurf->FlatColor.s.green])/2.0f; c.blue = (const_pal_col.blue +byte2float[pSurf->FlatColor.s.blue]) /2.0f; c.alpha = byte2float[pSurf->FlatColor.s.alpha]; } else { c.red = byte2float[pSurf->FlatColor.s.red]; c.green = byte2float[pSurf->FlatColor.s.green]; c.blue = byte2float[pSurf->FlatColor.s.blue]; c.alpha = byte2float[pSurf->FlatColor.s.alpha]; }#ifdef MINI_GL_COMPATIBILITY glColor4f(c.red, c.green, c.blue, c.alpha);#else glColor4fv( (float *)&c ); // is in RGBA float format#endif } // this test is added for new coronas' code (without depth buffer) // I think I should do a separate function for drawing coronas, so it will be a little faster#ifndef MINI_GL_COMPATIBILITY if (PolyFlags & PF_Corona) // check to see if we need to draw the corona { //rem: all 8 (or 8.0f) values are hard coded: it can be changed to a higher value GLfloat buf[8][8]; GLdouble cx, cy, cz; GLdouble px, py, pz; GLfloat scalef = 0; cx = (pOutVerts[0].x + pOutVerts[2].x) / 2.0f; // we should change the coronas' ... cy = (pOutVerts[0].y + pOutVerts[2].y) / 2.0f; // ... code so its only done once. cz = pOutVerts[0].oow; // I dont know if this is slow or not gluProject(cx, cy, cz, modelMatrix, projMatrix, viewport, &px, &py, &pz); //DBG_Printf("Projection: (%f, %f, %f)\n", px, py, pz); if ( (pz < 0.0) || (px < -8.0) || (py < viewport[1]-8.0) || (px > viewport[2]+8.0) || (py > viewport[1]+viewport[3]+8.0)) return; // the damned slow glReadPixels functions :( glReadPixels( (int)px-4, (int)py, 8, 8, GL_DEPTH_COMPONENT, GL_FLOAT, buf ); //DBG_Printf("DepthBuffer: %f %f\n", buf[0][0], buf[3][3]); for (i=0; i<8; i++) for (j=0; j<8; j++) scalef += (pz > buf[i][j]+0.0001f) ? 0 : 1; // quick test for screen border (not 100% correct, but looks ok) if (px < 4) scalef -= 8*(4-px); if (py < viewport[1]+4) scalef -= 8*(viewport[1]+4-py); if (px > viewport[2]-4) scalef -= 8*(4-(viewport[2]-px)); if (py > viewport[1]+viewport[3]-4) scalef -= 8*(4-(viewport[1]+viewport[3]-py)); scalef /= 64; //DBG_Printf("Scale factor: %f\n", scalef); if (scalef < 0.05f) // 嘺 sert
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -