Changeset 2754


Ignore:
Timestamp:
Jun 20, 2013, 8:40:41 PM (8 years ago)
Author:
sam
Message:

gpu: move more platform-specific code from Video to Render.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/renderer.cpp

    r2753 r2754  
    6060  : m_data(new RendererData())
    6161{
     62#if defined USE_D3D9 || defined _XBOX
     63    /* TODO */
     64#else
     65#   if defined USE_GLEW && !defined __APPLE__
     66    /* Initialise GLEW if necessary */
     67    GLenum glerr = glewInit();
     68    if (glerr != GLEW_OK)
     69    {
     70        Log::Error("cannot initialise GLEW: %s\n", glewGetErrorString(glerr));
     71        exit(EXIT_FAILURE);
     72    }
     73#   endif
     74#endif
     75
     76    /* Initialise rendering states */
    6277    m_data->m_clear_color = vec4(-1.f);
    6378    SetClearColor(vec4(0.1f, 0.2f, 0.3f, 1.0f));
     
    7489    m_data->m_face_culling = false;
    7590    SetFaceCulling(true);
     91
     92    /* Add some rendering states that we don't export to the user */
     93#if defined USE_D3D9 || defined _XBOX
     94    /* TODO */
     95#else
     96#   if defined HAVE_GL_2X && !defined __APPLE__
     97    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     98#   endif
     99#endif
    76100}
    77101
  • trunk/src/gradient.cpp

    r2506 r2754  
    1414
    1515#include "core.h"
    16 #include "lolgl.h"
    1716
    1817using namespace std;
  • trunk/src/tileset.cpp

    r2737 r2754  
    2828
    2929#include "core.h"
    30 #include "lolgl.h"
    3130
    3231using namespace std;
    33 
    34 #if defined USE_D3D9
    35 extern IDirect3DDevice9 *g_d3ddevice;
    36 #elif defined _XBOX
    37 extern D3DDevice *g_d3ddevice;
    38 #endif
    3932
    4033namespace lol
  • trunk/src/video.cpp

    r2753 r2754  
    3535#if defined USE_D3D9
    3636IDirect3DDevice9 *g_d3ddevice;
    37 #   if defined USE_SDL
    3837extern HWND g_hwnd;
    39 #   endif
    4038#elif defined _XBOX
    4139D3DDevice *g_d3ddevice;
     40HWND g_hwnd = 0;
    4241#endif
    4342
     
    5049
    5150private:
    52     static mat4 proj_matrix;
    5351    static ivec2 saved_viewport;
    5452    static DebugRenderMode render_mode;
     
    6462};
    6563
    66 mat4 VideoData::proj_matrix;
    6764ivec2 VideoData::saved_viewport(0, 0);
    6865DebugRenderMode VideoData::render_mode = DebugRenderMode::Default;
     
    9289    }
    9390
    94     HWND window = 0;
     91    /* Choose best viewport size */
     92#   if defined _XBOX
     93    XVIDEO_MODE VideoMode;
     94    XGetVideoMode(&VideoMode);
     95    size = lol::min(size, ivec2(VideoMode.dwDisplayWidth,
     96                                VideoMode.dwDisplayHeight);
     97#   endif
     98    VideoData::saved_viewport = size;
     99
    95100    D3DPRESENT_PARAMETERS d3dpp;
    96101    memset(&d3dpp, 0, sizeof(d3dpp));
    97 
    98 #   if defined USE_SDL
    99     window = g_hwnd;
    100     d3dpp.hDeviceWindow = g_hwnd;
    101     d3dpp.Windowed = TRUE;
    102 #   elif defined _XBOX
    103     XVIDEO_MODE VideoMode;
    104     XGetVideoMode( &VideoMode );
    105     if (size.x > VideoMode.dwDisplayWidth)
    106         size.x = VideoMode.dwDisplayWidth;
    107     if (size.y > VideoMode.dwDisplayHeight)
    108         size.y = VideoMode.dwDisplayHeight;
    109 #   endif
    110     VideoData::saved_viewport = size;
    111 
    112102    d3dpp.BackBufferWidth = size.x;
    113103    d3dpp.BackBufferHeight = size.y;
    114104    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    115105    d3dpp.BackBufferCount = 1;
     106    d3dpp.hDeviceWindow = g_hwnd;
     107#   if defined USE_SDL
     108    d3dpp.Windowed = TRUE;
     109#   endif
    116110    d3dpp.EnableAutoDepthStencil = TRUE;
    117111    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
     
    119113    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    120114
    121     HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, window,
     115    HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, g_hwnd,
    122116                                                  D3DCREATE_HARDWARE_VERTEXPROCESSING,
    123117                                                  &d3dpp, &VideoData::d3d_dev);
     
    129123
    130124    g_d3ddevice = VideoData::d3d_dev;
    131 #else
    132 #   if defined USE_GLEW && !defined __APPLE__
    133     /* Initialise GLEW if necessary */
    134     GLenum glerr = glewInit();
    135     if (glerr != GLEW_OK)
    136     {
    137         Log::Error("cannot initialise GLEW: %s\n", glewGetErrorString(glerr));
    138         exit(EXIT_FAILURE);
    139     }
    140 #   endif
    141 
     125
     126    g_renderer = new Renderer();
     127#else
    142128    /* Initialise OpenGL */
     129    g_renderer = new Renderer();
     130
    143131    glViewport(0, 0, size.x, size.y);
    144132    VideoData::saved_viewport = size;
    145 
    146 #   if defined HAVE_GL_2X && !defined __APPLE__
    147     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    148 #   endif
    149 #endif
    150 
    151     g_renderer = new Renderer();
     133#endif
    152134
    153135    /* Initialise reasonable scene default properties */
     
    185167        glViewport(0, 0, VideoData::saved_viewport.x, VideoData::saved_viewport.y);
    186168#endif
    187 }
    188 
    189 void Video::SetFov(float theta)
    190 {
    191     vec2 size = GetSize();
    192     float near = -size.x - size.y;
    193     float far = size.x + size.y;
    194 
    195 #if defined __ANDROID__
    196     size = vec2(640.0f, 480.0f);
    197 #endif
    198 
    199     /* Set the projection matrix */
    200     if (theta < 1e-4f)
    201     {
    202         /* The easy way: purely orthogonal projection. */
    203         VideoData::proj_matrix = mat4::ortho(0, size.x, 0, size.y, near, far);
    204     }
    205     else
    206     {
    207         /* Compute a view that approximates the glOrtho view when theta
    208          * approaches zero. This view ensures that the z=0 plane fills
    209          * the screen. */
    210         float t1 = tanf(theta / 2);
    211         float t2 = t1 * size.y / size.y;
    212         float dist = size.x / (2.0f * t1);
    213 
    214         near += dist;
    215         far += dist;
    216 
    217         if (near <= 0.0f)
    218         {
    219             far -= (near - 1.0f);
    220             near = 1.0f;
    221         }
    222 
    223         mat4 proj = mat4::frustum(-near * t1, near * t1,
    224                                   -near * t2, near * t2, near, far);
    225         mat4 trans = mat4::translate(-0.5f * size.x, -0.5f * size.y, -dist);
    226         VideoData::proj_matrix = proj * trans;
    227     }
    228169}
    229170
     
    316257    glClear(mask);
    317258#endif
    318 
    319     SetFov(0.0f);
    320259}
    321260
  • trunk/src/video.h

    r2753 r2754  
    7171    static void SetCustomSize(ivec2 size);
    7272    static void RestoreSize();
    73     static void SetFov(float theta);
    7473    static void SetDebugRenderMode(DebugRenderMode d);
    7574    static DebugRenderMode GetDebugRenderMode();
  • trunk/test/xolotl/xolotl.cpp

    r2297 r2754  
    1515
    1616#include "core.h"
    17 #include "lolgl.h"
    1817#include "loldebug.h"
    1918
Note: See TracChangeset for help on using the changeset viewer.