Ignore:
Timestamp:
Mar 26, 2012, 8:18:40 PM (8 years ago)
Author:
sam
Message:

xbox: start working on an Xbox/Direct3D port.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/video.cpp

    r1108 r1173  
    22// Lol Engine
    33//
    4 // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    1515#include <cmath>
    1616
    17 #if defined _WIN32 && !defined _XBOX
     17#if _XBOX
     18#   include <xtl.h>
     19#   undef near /* Fuck Microsoft */
     20#   undef far /* Fuck Microsoft again */
     21#elif defined _WIN32
    1822#   define WIN32_LEAN_AND_MEAN
    1923#   include <windows.h>
     
    3741    static mat4 proj_matrix, view_matrix;
    3842    static ivec2 saved_viewport;
     43#if defined _XBOX
     44    static Direct3D *d3d_ctx;
     45    static D3DDevice *d3d_dev;
     46#endif
    3947};
    4048
    4149mat4 VideoData::proj_matrix;
    4250mat4 VideoData::view_matrix;
    43 
    4451ivec2 VideoData::saved_viewport(0, 0);
     52
     53#if defined _XBOX
     54Direct3D *VideoData::d3d_ctx;
     55D3DDevice *VideoData::d3d_dev;
     56#endif
    4557
    4658/*
     
    5062void Video::Setup(ivec2 size)
    5163{
    52 #if defined USE_GLEW && !defined __APPLE__
     64#if defined _XBOX
     65    VideoData::d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION);
     66    if (!VideoData::d3d_ctx)
     67    {
     68        Log::Error("cannot initialise D3D\n");
     69        exit(EXIT_FAILURE);
     70    }
     71
     72    D3DPRESENT_PARAMETERS d3dpp;
     73    memset(&d3dpp, 0, sizeof(d3dpp));
     74
     75    XVIDEO_MODE VideoMode;
     76    XGetVideoMode( &VideoMode );
     77    if (size.x > VideoMode.dwDisplayWidth)
     78        size.x = VideoMode.dwDisplayWidth;
     79    if (size.y > VideoMode.dwDisplayHeight)
     80        size.y = VideoMode.dwDisplayHeight;
     81    VideoData::saved_viewport = size;
     82
     83    d3dpp.BackBufferWidth = size.x;
     84    d3dpp.BackBufferHeight = size.y;
     85    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
     86    d3dpp.BackBufferCount = 1;
     87    d3dpp.EnableAutoDepthStencil = TRUE;
     88    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
     89    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
     90    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
     91
     92    if (!VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, NULL,
     93                                          D3DCREATE_HARDWARE_VERTEXPROCESSING,
     94                                          &d3dpp, &VideoData::d3d_dev))
     95    {
     96        Log::Error("cannot create D3D device\n");
     97        exit(EXIT_FAILURE);
     98    }
     99#else
     100#   if defined USE_GLEW && !defined __APPLE__
    53101    /* Initialise GLEW if necessary */
    54102    GLenum glerr = glewInit();
     
    58106        exit(EXIT_FAILURE);
    59107    }
    60 #endif
     108#   endif
    61109
    62110    /* Initialise OpenGL */
     
    67115    glClearDepth(1.0);
    68116
    69 #if defined HAVE_GL_2X && !defined __APPLE__
     117#   if defined HAVE_GL_2X && !defined __APPLE__
    70118    glShadeModel(GL_SMOOTH);
    71119    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     120#   endif
    72121#endif
    73122}
     
    127176{
    128177    ivec2 size = GetSize();
     178#if defined _XBOX
     179    VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER
     180                                        | D3DCLEAR_STENCIL,
     181                              D3DCOLOR_XRGB(26, 51, 77), 1.0f, 0);
     182#else
    129183    glViewport(0, 0, size.x, size.y);
    130184    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     185#endif
    131186
    132187    SetFov(0.0f);
     
    140195void Video::Capture(uint32_t *buffer)
    141196{
     197#if _XBOX
     198    /* TODO */
     199#else
    142200    GLint v[4];
    143 #if defined __CELLOS_LV2__
     201#   if defined __CELLOS_LV2__
    144202    // FIXME: use psglCreateDeviceAuto && psglGetDeviceDimensions
    145203    v[2] = 1920;
    146204    v[3] = 1080;
    147 #else
     205#   else
    148206    glGetIntegerv(GL_VIEWPORT, v);
    149 #endif
     207#   endif
    150208    int width = v[2], height = v[3];
    151209
    152 #if defined HAVE_GL_2X
     210#   if defined HAVE_GL_2X
    153211    glPixelStorei(GL_PACK_ROW_LENGTH, 0);
    154 #endif
     212#   endif
    155213    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    156214
    157 #if defined GL_BGRA
     215#   if defined GL_BGRA
    158216    glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
    159 #else
     217#   else
    160218    glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    161 #endif
     219#   endif
    162220
    163221    for (int j = 0; j < height / 2; j++)
     
    168226            buffer[(height - j - 1) * width + i] = tmp;
    169227        }
     228#endif
    170229}
    171230
    172231ivec2 Video::GetSize()
    173232{
     233#if _XBOX
     234    return VideoData::saved_viewport;
     235#elif 1
    174236    /* GetSize() is called too often on the game thread; we cannot rely on
    175237     * the GL context at this point */
    176 #if 1
    177238    return VideoData::saved_viewport;
    178239#elif defined __CELLOS_LV2__
Note: See TracChangeset for help on using the changeset viewer.