~ubuntu-branches/ubuntu/wily/mupen64plus/wily

« back to all changes in this revision

Viewing changes to .pc/rice-ati-symbols.patch/rice_video/OGLGraphicsContext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sven Eckelmann
  • Date: 2011-07-24 14:23:26 UTC
  • mfrom: (10.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110724142326-x9z5qu8j9jecrmod
Tags: 1.99.4+2
* Upload to unstable
* Remove overrides for lintian warning about change to native package
* Update Vcs-* fields to new anonscm.debian.org URLs in debian/control
* Fix spelling of "Flexible" in debian/control (Closes: #633693)
* Mark all targets in debian/rules as phony
* Add some information about the mupen64plus 2.0 vision in debian/NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright (C) 2003 Rice1964
3
 
 
4
 
This program is free software; you can redistribute it and/or
5
 
modify it under the terms of the GNU General Public License
6
 
as published by the Free Software Foundation; either version 2
7
 
of the License, or (at your option) any later version.
8
 
 
9
 
This program is distributed in the hope that it will be useful,
10
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
GNU General Public License for more details.
13
 
 
14
 
You should have received a copy of the GNU General Public License
15
 
along with this program; if not, write to the Free Software
16
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 
*/
18
 
 
19
 
#include <SDL_opengl.h>
20
 
 
21
 
#include "stdafx.h"
22
 
 
23
 
#include "liblinux/BMGLibPNG.h"
24
 
 
25
 
#include "../main/version.h"
26
 
 
27
 
COGLGraphicsContext::COGLGraphicsContext() :
28
 
    m_pScreen(0),
29
 
    m_bSupportMultiTexture(false),
30
 
    m_bSupportTextureEnvCombine(false),
31
 
    m_bSupportSeparateSpecularColor(false),
32
 
    m_bSupportSecondColor(false),
33
 
    m_bSupportFogCoord(false),
34
 
    m_bSupportTextureObject(false),
35
 
    m_bSupportRescaleNormal(false),
36
 
    m_bSupportLODBias(false),
37
 
    m_bSupportTextureMirrorRepeat(false),
38
 
    m_bSupportTextureLOD(false),
39
 
    m_bSupportNVRegisterCombiner(false),
40
 
    m_bSupportBlendColor(false),
41
 
    m_bSupportBlendSubtract(false),
42
 
    m_bSupportNVTextureEnvCombine4(false),
43
 
    m_pVendorStr(NULL),
44
 
    m_pRenderStr(NULL),
45
 
    m_pExtensionStr(NULL),
46
 
    m_pVersionStr(NULL)
47
 
{
48
 
}
49
 
 
50
 
 
51
 
COGLGraphicsContext::~COGLGraphicsContext()
52
 
{
53
 
}
54
 
 
55
 
bool COGLGraphicsContext::Initialize(HWND hWnd, HWND hWndStatus, uint32 dwWidth, uint32 dwHeight, BOOL bWindowed )
56
 
{
57
 
    printf("Initializing OpenGL Device Context\n");
58
 
    Lock();
59
 
 
60
 
    CGraphicsContext::Get()->m_supportTextureMirror = false;
61
 
    CGraphicsContext::Initialize(hWnd, hWndStatus, dwWidth, dwHeight, bWindowed );
62
 
 
63
 
    if( bWindowed )
64
 
    {
65
 
        windowSetting.statusBarHeightToUse = windowSetting.statusBarHeight;
66
 
        windowSetting.toolbarHeightToUse = windowSetting.toolbarHeight;
67
 
    }
68
 
    else
69
 
    {
70
 
        windowSetting.statusBarHeightToUse = 0;
71
 
        windowSetting.toolbarHeightToUse = 0;
72
 
    }
73
 
 
74
 
    int  depthBufferDepth = options.OpenglDepthBufferSetting;
75
 
    int  colorBufferDepth = 32;
76
 
    if( options.colorQuality == TEXTURE_FMT_A4R4G4B4 ) colorBufferDepth = 16;
77
 
 
78
 
   // init sdl & gl
79
 
   const SDL_VideoInfo *videoInfo;
80
 
   Uint32 videoFlags = 0;
81
 
   
82
 
   /* Initialize SDL */
83
 
   printf("(II) Initializing SDL video subsystem...\n");
84
 
   if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
85
 
     {
86
 
    printf("(EE) Error initializing SDL video subsystem: %s\n", SDL_GetError());
87
 
    return false;
88
 
     }
89
 
   
90
 
   /* Video Info */
91
 
   printf("(II) Getting video info...\n");
92
 
   if(!(videoInfo = SDL_GetVideoInfo()))
93
 
     {
94
 
    printf("(EE) Video query failed: %s\n", SDL_GetError());
95
 
    SDL_QuitSubSystem(SDL_INIT_VIDEO);
96
 
    return false;
97
 
     }
98
 
   /* Setting the video mode */
99
 
   videoFlags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE;
100
 
   
101
 
   if(videoInfo->hw_available)
102
 
     videoFlags |= SDL_HWSURFACE;
103
 
   else
104
 
     videoFlags |= SDL_SWSURFACE;
105
 
   
106
 
   if(videoInfo->blit_hw)
107
 
     videoFlags |= SDL_HWACCEL;
108
 
   
109
 
   if(!bWindowed)
110
 
     videoFlags |= SDL_FULLSCREEN;
111
 
   
112
 
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
113
 
   SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, colorBufferDepth);
114
 
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depthBufferDepth);
115
 
   
116
 
   printf("(II) Setting video mode %dx%d...\n", (int)windowSetting.uDisplayWidth, (int)windowSetting.uDisplayHeight);
117
 
   if(!(m_pScreen = SDL_SetVideoMode(windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, colorBufferDepth, videoFlags)))
118
 
     {
119
 
    printf("(EE) Error setting video mode %dx%d: %s\n", (int)windowSetting.uDisplayWidth, (int)windowSetting.uDisplayHeight, SDL_GetError());
120
 
    SDL_QuitSubSystem(SDL_INIT_VIDEO);
121
 
    return false;
122
 
     }
123
 
   
124
 
   char caption[500];
125
 
   sprintf(caption, "RiceVideoLinux N64 Plugin %s", MUPEN_VERSION);
126
 
   SDL_WM_SetCaption(caption, caption);
127
 
   SetWindowMode();
128
 
 
129
 
    InitState();
130
 
    InitOGLExtension();
131
 
    sprintf(m_strDeviceStats, "%.60s - %.128s : %.60s", m_pVendorStr, m_pRenderStr, m_pVersionStr);
132
 
    TRACE0(m_strDeviceStats);
133
 
    printf("%s\n", m_strDeviceStats);
134
 
 
135
 
    Unlock();
136
 
 
137
 
    Clear(CLEAR_COLOR_AND_DEPTH_BUFFER);    // Clear buffers
138
 
    UpdateFrame();
139
 
    Clear(CLEAR_COLOR_AND_DEPTH_BUFFER);
140
 
    UpdateFrame();
141
 
    
142
 
    m_bReady = true;
143
 
    status.isVertexShaderEnabled = false;
144
 
 
145
 
    return true;
146
 
}
147
 
 
148
 
void COGLGraphicsContext::InitState(void)
149
 
{
150
 
    m_pRenderStr = glGetString(GL_RENDERER);;
151
 
    m_pExtensionStr = glGetString(GL_EXTENSIONS);;
152
 
    m_pVersionStr = glGetString(GL_VERSION);;
153
 
    m_pVendorStr = glGetString(GL_VENDOR);
154
 
    glMatrixMode(GL_PROJECTION);
155
 
    glLoadIdentity();
156
 
 
157
 
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
158
 
    glClearDepth(1.0f);
159
 
 
160
 
    glShadeModel(GL_SMOOTH);
161
 
 
162
 
    //position viewer 
163
 
    //glMatrixMode(GL_MODELVIEW);
164
 
    //glLoadIdentity();
165
 
 
166
 
    glDisable(GL_ALPHA_TEST);
167
 
 
168
 
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
169
 
    glDisable(GL_BLEND);
170
 
 
171
 
    glFrontFace(GL_CCW);
172
 
    glDisable(GL_CULL_FACE);
173
 
    glDisable(GL_NORMALIZE);
174
 
 
175
 
    glDepthFunc(GL_LEQUAL);
176
 
    glEnable(GL_DEPTH_TEST);
177
 
 
178
 
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
179
 
 
180
 
    glEnable(GL_BLEND);
181
 
    glEnable(GL_ALPHA_TEST);
182
 
 
183
 
    glMatrixMode(GL_PROJECTION);
184
 
    glLoadIdentity();
185
 
    
186
 
    glDepthRange(-1, 1);
187
 
}
188
 
 
189
 
void COGLGraphicsContext::InitOGLExtension(void)
190
 
{
191
 
    // important extension features, it is very bad not to have these feature
192
 
    m_bSupportMultiTexture = IsExtensionSupported("GL_ARB_multitexture");
193
 
    m_bSupportTextureEnvCombine = IsExtensionSupported("GL_EXT_texture_env_combine");
194
 
    
195
 
    m_bSupportSeparateSpecularColor = IsExtensionSupported("GL_EXT_separate_specular_color");
196
 
    m_bSupportSecondColor = IsExtensionSupported("GL_EXT_secondary_color");
197
 
    m_bSupportFogCoord = IsExtensionSupported("GL_EXT_fog_coord");
198
 
    m_bSupportTextureObject = IsExtensionSupported("GL_EXT_texture_object");
199
 
 
200
 
    // Optional extension features
201
 
    m_bSupportRescaleNormal = IsExtensionSupported("GL_EXT_rescale_normal");
202
 
    m_bSupportLODBias = IsExtensionSupported("GL_EXT_texture_lod_bias");
203
 
 
204
 
    // Nvidia only extension features (optional)
205
 
    m_bSupportNVRegisterCombiner = IsExtensionSupported("GL_NV_register_combiners");
206
 
    m_bSupportTextureMirrorRepeat = IsExtensionSupported("GL_IBM_texture_mirrored_repeat") || IsExtensionSupported("ARB_texture_mirrored_repeat");
207
 
    m_supportTextureMirror = m_bSupportTextureMirrorRepeat;
208
 
    m_bSupportTextureLOD = IsExtensionSupported("GL_EXT_texture_lod");
209
 
    m_bSupportBlendColor = IsExtensionSupported("GL_EXT_blend_color");
210
 
    m_bSupportBlendSubtract = IsExtensionSupported("GL_EXT_blend_subtract");
211
 
    m_bSupportNVTextureEnvCombine4 = IsExtensionSupported("GL_NV_texture_env_combine4");
212
 
 
213
 
}
214
 
 
215
 
bool COGLGraphicsContext::IsExtensionSupported(const char* pExtName)
216
 
{
217
 
    if( strstr((const char*)m_pExtensionStr, pExtName) != NULL )
218
 
        return true;
219
 
    else
220
 
        return false;
221
 
}
222
 
 
223
 
bool COGLGraphicsContext::IsWglExtensionSupported(const char* pExtName)
224
 
{
225
 
    if( m_pWglExtensionStr == NULL )
226
 
        return false;
227
 
 
228
 
    if( strstr((const char*)m_pWglExtensionStr, pExtName) != NULL )
229
 
        return true;
230
 
    else
231
 
        return false;
232
 
}
233
 
 
234
 
 
235
 
void COGLGraphicsContext::CleanUp()
236
 
{
237
 
    SDL_QuitSubSystem(SDL_INIT_VIDEO);
238
 
    m_pScreen = NULL;
239
 
    m_bReady = false;
240
 
}
241
 
 
242
 
 
243
 
void COGLGraphicsContext::Clear(ClearFlag dwFlags, uint32 color, float depth)
244
 
{
245
 
    uint32 flag=0;
246
 
    if( dwFlags&CLEAR_COLOR_BUFFER )    flag |= GL_COLOR_BUFFER_BIT;
247
 
    if( dwFlags&CLEAR_DEPTH_BUFFER )    flag |= GL_DEPTH_BUFFER_BIT;
248
 
 
249
 
    float r = ((color>>16)&0xFF)/255.0f;
250
 
    float g = ((color>> 8)&0xFF)/255.0f;
251
 
    float b = ((color    )&0xFF)/255.0f;
252
 
    float a = ((color>>24)&0xFF)/255.0f;
253
 
    glClearColor(r, g, b, a);
254
 
    glClearDepth(depth);
255
 
    glClear(flag);  //Clear color buffer and depth buffer
256
 
}
257
 
 
258
 
void COGLGraphicsContext::UpdateFrame(bool swaponly)
259
 
{
260
 
    status.gFrameCount++;
261
 
 
262
 
    glFlush();
263
 
    //glFinish();
264
 
    //wglSwapIntervalEXT(0);
265
 
 
266
 
    /*
267
 
    if (debuggerPauseCount == countToPause)
268
 
    {
269
 
        static int iShotNum = 0;
270
 
        // get width, height, allocate buffer to store image
271
 
        int width = windowSetting.uDisplayWidth;
272
 
        int height = windowSetting.uDisplayHeight;
273
 
        printf("Saving debug images: width=%i  height=%i\n", width, height);
274
 
        short *buffer = (short *) malloc(((width+3)&~3)*(height+1)*4);
275
 
        glReadBuffer( GL_FRONT );
276
 
        // set up a BMGImage struct
277
 
        struct BMGImageStruct img;
278
 
        memset(&img, 0, sizeof(BMGImageStruct));
279
 
        InitBMGImage(&img);
280
 
        img.bits = (unsigned char *) buffer;
281
 
        img.bits_per_pixel = 32;
282
 
        img.height = height;
283
 
        img.width = width;
284
 
        img.scan_width = width * 4;
285
 
        // store the RGB color image
286
 
        char chFilename[64];
287
 
        sprintf(chFilename, "dbg_rgb_%03i.png", iShotNum);
288
 
        glReadPixels(0,0,width,height, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
289
 
        WritePNG(chFilename, img);
290
 
        // store the Z buffer
291
 
        sprintf(chFilename, "dbg_Z_%03i.png", iShotNum);
292
 
        glReadPixels(0,0,width,height, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, buffer);
293
 
        //img.bits_per_pixel = 16;
294
 
        //img.scan_width = width * 2;
295
 
        WritePNG(chFilename, img);
296
 
        // dump a subset of the Z data
297
 
        for (int y = 0; y < 480; y += 16)
298
 
        {
299
 
            for (int x = 0; x < 640; x+= 16)
300
 
                printf("%4hx ", buffer[y*640 + x]);
301
 
            printf("\n");
302
 
        }
303
 
        printf("\n");
304
 
        // free memory and get out of here
305
 
        free(buffer);
306
 
        iShotNum++;
307
 
        }
308
 
    */
309
 
 
310
 
   
311
 
   // if emulator defined a render callback function, call it before buffer swap
312
 
   if(renderCallback)
313
 
       (*renderCallback)();
314
 
 
315
 
   SDL_GL_SwapBuffers();
316
 
   
317
 
   /*if(options.bShowFPS)
318
 
     {
319
 
    static unsigned int lastTick=0;
320
 
    static int frames=0;
321
 
    unsigned int nowTick = SDL_GetTicks();
322
 
    frames++;
323
 
    if(lastTick + 5000 <= nowTick)
324
 
      {
325
 
         char caption[200];
326
 
         sprintf(caption, "RiceVideoLinux N64 Plugin %s - %.3f VI/S", MUPEN_VERSION, frames/5.0);
327
 
         SDL_WM_SetCaption(caption, caption);
328
 
         frames = 0;
329
 
         lastTick = nowTick;
330
 
      }
331
 
     }*/
332
 
 
333
 
    glDepthMask(GL_TRUE);
334
 
    glClearDepth(1.0);
335
 
    if( !g_curRomInfo.bForceScreenClear ) 
336
 
        glClear(GL_DEPTH_BUFFER_BIT);
337
 
    else
338
 
        needCleanScene = true;
339
 
 
340
 
    status.bScreenIsDrawn = false;
341
 
}
342
 
 
343
 
bool COGLGraphicsContext::SetFullscreenMode()
344
 
{
345
 
    windowSetting.uDisplayWidth = windowSetting.uFullScreenDisplayWidth;
346
 
    windowSetting.uDisplayHeight = windowSetting.uFullScreenDisplayHeight;
347
 
    windowSetting.statusBarHeightToUse = 0;
348
 
    windowSetting.toolbarHeightToUse = 0;
349
 
    return true;
350
 
}
351
 
 
352
 
bool COGLGraphicsContext::SetWindowMode()
353
 
{
354
 
    windowSetting.uDisplayWidth = windowSetting.uWindowDisplayWidth;
355
 
    windowSetting.uDisplayHeight = windowSetting.uWindowDisplayHeight;
356
 
    windowSetting.statusBarHeightToUse = windowSetting.statusBarHeight;
357
 
    windowSetting.toolbarHeightToUse = windowSetting.toolbarHeight;
358
 
    return true;
359
 
}
360
 
int COGLGraphicsContext::ToggleFullscreen()
361
 
{
362
 
   if(SDL_WM_ToggleFullScreen(m_pScreen) == 1)
363
 
     {
364
 
    m_bWindowed = 1 - m_bWindowed;
365
 
    if(m_bWindowed)
366
 
      SetWindowMode();
367
 
    else
368
 
      SetFullscreenMode();
369
 
     }
370
 
 
371
 
    return m_bWindowed?0:1;
372
 
}
373
 
 
374
 
// This is a static function, will be called when the plugin DLL is initialized
375
 
void COGLGraphicsContext::InitDeviceParameters()
376
 
{
377
 
    status.isVertexShaderEnabled = false;   // Disable it for now
378
 
}
379