⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r_d3d_old.cpp

📁 The source code of Doom legacy for windows
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if (!lpDDSPrimary)
                return;

    // show fps?
    // draw software view ?
    // page flip

    D3D_BufferClear ();

    if ( FAILED( lpD3DDevice->BeginScene() ) )
                return;

    lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
                                pvTriangleVertices, 6, NULL );

    // End the scene.
    lpD3DDevice->EndScene();

    // We are in windowed mode, so perform a blit from the backbuffer to the
        // correct position on the primary surface
    if (fullScreen)
    {
    }
    else
    {
        hr = lpDDSPrimary->Blt( &rcScreenRect, lpDDSBackBuffer, 
                                &rcViewportRect, DDBLT_WAIT, NULL );
        if (hr == DDERR_SURFACELOST)
            RestoreSurfaces ();
    }
}


// --------------------------------------------------------------------------
// Moves the screen rect for windowed renderers
// --------------------------------------------------------------------------
void OnWindowMove( int x, int y )
{
        DWORD dwWidth  = rcScreenRect.right - rcScreenRect.left;
        DWORD dwHeight = rcScreenRect.bottom - rcScreenRect.top;
    SetRect( &rcScreenRect, x, y, x + dwWidth, y + dwHeight );
}


// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------
//TODO: do the chroma key stuff out of here
EXPORT void HWRAPI( SetPalette ) (PALETTEENTRY* pal, RGBA_t *gamma)
{
    int i;

    if (!d3d_display)
        return;

    // create the palette in the format used for downloading to 3Dfx card
    for (i=0; i<256; i++)
        myPaletteData[i] =  (0xFF << 24) |          //alpha
                            (pal[i].peRed<<16) |
                            (pal[i].peGreen<<8) |
                             pal[i].peBlue;

    // make sure the chromakey color is always the same value
    myPaletteData[HWR_PATCHES_CHROMAKEY_COLORINDEX] = HWR_PATCHES_CHROMAKEY_COLORVALUE;

    // download palette
}


// **************************************************************************
//
// **************************************************************************


// --------------------------------------------------------------------------
// Do a full buffer clear including color / alpha / and Z buffers
// --------------------------------------------------------------------------
static void D3D_BufferClear (void)
{
    // clear color/alpha and depth buffers
    if (lpD3DViewport)
        lpD3DViewport->Clear2( 1UL, (D3DRECT*)&rcViewportRect, D3DCLEAR_TARGET, 0x000000ff,
                                       0L, 0L );
}


// --------------------------------------------------------------------------
// Set initial state of 3d card settings
// --------------------------------------------------------------------------
static BOOL D3D_InitStates (LPDIRECT3DDEVICE3 pd3dDevice,
                           LPDIRECT3DVIEWPORT3 pvViewport)
{
    DBG_Printf ("InitD3DStates()...\r\n");

    // Get a ptr to the ID3D object to create materials and/or lights.
    LPDIRECT3D3 pD3D;
    if( FAILED( pd3dDevice->GetDirect3D( &pD3D ) ) )
        return FALSE;
    pD3D->Release();
    

        // Data for the geometry of the triangle. Note that this tutorial only
        // uses ambient lighting, so the vertices' normals are not actually used.
        D3DVECTOR p1( 0.0f, 3.0f, 0.0f );
        D3DVECTOR p2( 3.0f,-3.0f, 0.0f );
        D3DVECTOR p3(-3.0f,-3.0f, 0.0f );
        D3DVECTOR vNormal( 0.0f, 0.0f, 1.0f );
    // Initialize the 3 vertices for the front of the triangle
        pvTriangleVertices[0] = D3DVERTEX( p1, vNormal, 0, 0 );
        pvTriangleVertices[1] = D3DVERTEX( p2, vNormal, 0, 0 );
        pvTriangleVertices[2] = D3DVERTEX( p3, vNormal, 0, 0 );
        // Initialize the 3 vertices for the back of the triangle
        pvTriangleVertices[3] = D3DVERTEX( p1, -vNormal, 0, 0 );
        pvTriangleVertices[4] = D3DVERTEX( p3, -vNormal, 0, 0 );
        pvTriangleVertices[5] = D3DVERTEX( p2, -vNormal, 0, 0 );

    
    // get min/max w buffer range values

    // set my vertex format (the one of wallVert2D hwr_data.h)

    // set coord space
    
    // set W buffer

    // depth buffer func cmp_less

    // enable depth buffer

    // Ambient lighting on to full white.
    pd3dDevice->SetLightState(  D3DLIGHTSTATE_AMBIENT,  0xffffffff );

    D3D_BufferClear();

    return TRUE;
}


// **************************************************************************
//                                                   TEXTURE CACHE MANAGEMENT
// **************************************************************************

static  DWORD           gr_cachemin;
static  DWORD           gr_cachemax;

static  DWORD           gr_cachetailpos;    // manage a cycling cache for mipmaps
static  DWORD           gr_cachepos;        
static  GlideMipmap_t*  gr_cachetail;
static  GlideMipmap_t*  gr_cachehead;


// --------------------------------------------------------------------------
// This must be done once only for all program execution
// --------------------------------------------------------------------------
static void D3D_ClearMipmapCache (void)
{
    DBG_Printf ("ClearMipmapCache() \r\n");
    while (gr_cachetail)
    {
        gr_cachetail->downloaded = false;
        gr_cachetail = gr_cachetail->next;
    }
    
    gr_cachetail = NULL;
    gr_cachehead = NULL;
    gr_cachetailpos = gr_cachepos = gr_cachemin;
}


static void D3D_InitMipmapCache (void)
{
    DBG_Printf ("InitMipmapCache() \r\n");
    /*
    gr_cachemin = grTexMinAddress(GR_TMU0);
    gr_cachemax = grTexMaxAddress(GR_TMU0);
    */

    //testing..
    //gr_cachemax = gr_cachemin + (1024<<10);

    gr_cachetail = NULL;
    D3D_ClearMipmapCache();

    //CONS_Printf ("HWR_InitMipmapCache() : %d kb\n", (gr_cachemax-gr_cachemin)>>10);
}


static void D3D_FlushMipmap (GlideMipmap_t* mipmap)
{
    mipmap->downloaded = false;
    gr_cachetail = mipmap->next;
    // should never happen
    if (!mipmap->next)
    //    I_Error ("This just CAN'T HAPPEN!!! So you think you're different eh ?");
        D3D_ClearMipmapCache ();
    else
        gr_cachetailpos = mipmap->next->cachepos;
}


// --------------------------------------------------------------------------
// Download a 'surface' into the graphics card memory
// --------------------------------------------------------------------------
void D3D_DownloadMipmap (GlideMipmap_t* grMipmap)
{
    DWORD   mipmapSize;
    DWORD   freespace;

    if (grMipmap->downloaded)
        return;

    DBG_Printf ("Downloading mipmap\r\n");

    return;
/*
    //if (grMipmap->grInfo.data == NULL)
    //    I_Error ("info.data is NULL\n");

    // (re-)download the texture data
    //mipmapSize = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, &grMipmap->grInfo);

    //CONS_Printf ("DOWNLOAD\n");

    // flush out older mipmaps to make space
    //CONS_Printf ("HWR_DownloadTexture: texture too big for TMU0\n");
    if (gr_cachehead)
    {
        while (1)
        {
            if (gr_cachetailpos >= gr_cachepos)
                freespace = gr_cachetailpos - gr_cachepos;
            else
                freespace = gr_cachemax - gr_cachepos;
    
            if (freespace >= mipmapSize)
                break;

            //CONS_Printf ("        tail: %#07d   pos: %#07d\n"
            //             "        size: %#07d  free: %#07d\n",
            //                      gr_cachetailpos, gr_cachepos, mipmapSize, freespace);

            // not enough space in the end of the buffer
            if (gr_cachepos > gr_cachetailpos) {
                gr_cachepos = gr_cachemin;
                //CONS_Printf ("        cycle over\n");
            }
            else{
                FlushMipmap (gr_cachetail);
            }
        }
    }

    grMipmap->startAddress = gr_cachepos;
    //gr_cachepos += mipmapSize;
    grMipmap->mipmapSize = mipmapSize;
    //grTexDownloadMipMap (GR_TMU0, grMipmap->startAddress, GR_MIPMAPLEVELMASK_BOTH, &grMipmap->grInfo);
    grMipmap->downloaded = true;

    // store pointer to downloaded mipmap
    if (gr_cachehead)
        gr_cachehead->next = grMipmap;
    else {
        gr_cachetail = gr_cachehead = grMipmap;
    }
    grMipmap->cachepos = gr_cachepos;
    grMipmap->next = NULL;  //debug (not used)
    gr_cachepos += mipmapSize;
    gr_cachehead = grMipmap;
*/
}

void D3D_DownloadCorona(void)
{
    RGBA_t tex[128][128];
    int i, j;    

    for (i=0; i<128; i++)
        for (j=0; j<128; j++) {
            int pos = ((i-64)*(i-64))+((j-64)*(j-64));
            if (pos <= 63*63) {
                tex[i][j].red   = 0xff;
                tex[i][j].green = 0xff;
                tex[i][j].blue  = 0xff;
                tex[i][j].alpha = 255-(unsigned char)(4*sqrt(pos));
            } else {
                tex[i][j].red   = 0x00;
                tex[i][j].green = 0x00;
                tex[i][j].blue  = 0x00;
                tex[i][j].alpha = 0x00;
            }
        }
    // load Texture in D3D Memory
}

// ==========================================================================
// The mipmap becomes the current texture source
// ==========================================================================
EXPORT void HWRAPI( SetTexture ) (GlideMipmap_t* grMipmap)
{
    if (!grMipmap->downloaded)
        D3D_DownloadMipmap (grMipmap);
    
    //grTexSource (GR_TMU0, grMipmap->startAddress, GR_MIPMAPLEVELMASK_BOTH, &grMipmap->grInfo);
}


// ==========================================================================
//
// ==========================================================================
EXPORT void HWRAPI( SetState ) (hwdstate_t IdState, int Value)
{
/*
    switch (IdState)
    {
        // set depth buffer on/off
        case HWD_SET_DEPTHMASK:
            grDepthMask (Value);
            break;

        case HWD_SET_COLORMASK:
            grColorMask (Value, FXTRUE);    //! alpha buffer true
            break;

        case HWD_SET_CULLMODE:
            grCullMode (Value ? GR_CULL_POSITIVE : GR_CULL_DISABLE);
            break;

        case HWD_SET_CONSTANTCOLOR:
            grConstantColorValue (Value);
            break;

        case HWD_SET_COLORSOURCE:
            if (Value == HWD_COLORSOURCE_CONSTANT)
            {
                grColorCombine( GR_COMBINE_FUNCTION_ZERO,
                                GR_COMBINE_FACTOR_ZERO,
                                GR_COMBINE_LOCAL_CONSTANT,
                                GR_COMBINE_OTHER_NONE,
                                FXFALSE );
            }
            else if (Value == HWD_COLORSOURCE_ITERATED)
            {
                    grColorCombine(GR_COMBINE_FUNCTION_LOCAL,
                                               GR_COMBINE_FACTOR_NONE,
                                               GR_COMBINE_LOCAL_ITERATED,
                                               GR_COMBINE_OTHER_NONE,
                                               FXFALSE );
            }
            else if (Value == HWD_COLORSOURCE_TEXTURE)
            {
                grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
                                GR_COMBINE_FACTOR_ONE,
                                GR_COMBINE_LOCAL_NONE,
                                GR_COMBINE_OTHER_TEXTURE,
                                FXFALSE );
            }
            else if (Value == HWD_COLORSOURCE_CONSTANTALPHA_SCALE_TEXTURE)
            {
                grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,        // factor * Color other
                                GR_COMBINE_FACTOR_LOCAL_ALPHA,
                                GR_COMBINE_LOCAL_CONSTANT, //ITERATED    // local is constant color
                                GR_COMBINE_OTHER_TEXTURE,               // color from texture map
                                FXFALSE );
            }
            break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -