~ubuntu-branches/ubuntu/trusty/mupen64plus-video-rice/trusty

« back to all changes in this revision

Viewing changes to src/OGLGraphicsContext.cpp

  • Committer: Package Import Robot
  • Author(s): Sven Eckelmann
  • Date: 2013-07-05 22:53:25 UTC
  • mfrom: (1.2.2) (3.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130705225325-k0fbb2m44xnrju66
Tags: 2.0-1
* New Upstream Version
* Upload to unstable
* debian/control:
  - Build-Depend on debhelper 9.20130604 for support of parameters when
    detecting targets in dh_auto_*
* debian/rules:
  - Work around new debhelper 9.20130624 dh_auto_{clean,test} behavior
    which is causing a FTBFS by adding an explicit
    override_dh_auto_{clean,test} rule
* debian/watch:
  - Verify new upstream versions using GPG key 954F81B094AA5BB226F5

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
17
*/
18
18
 
19
 
#include <SDL_opengl.h>
 
19
#include "osal_opengl.h"
20
20
 
21
21
#define M64P_PLUGIN_PROTOTYPES 1
22
22
#include "m64p_plugin.h"
23
23
#include "Config.h"
24
24
#include "Debugger.h"
 
25
#if SDL_VIDEO_OPENGL
25
26
#include "OGLExtensions.h"
 
27
#endif
26
28
#include "OGLDebug.h"
27
29
#include "OGLGraphicsContext.h"
28
30
#include "TextureManager.h"
29
31
#include "Video.h"
30
32
#include "version.h"
31
33
 
32
 
#include "liblinux/BMGLibPNG.h"
33
 
 
34
34
COGLGraphicsContext::COGLGraphicsContext() :
35
35
    m_bSupportMultiTexture(false),
36
36
    m_bSupportTextureEnvCombine(false),
109
109
        else
110
110
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 16);
111
111
    }
112
 
   
 
112
 
113
113
    /* Set the video mode */
114
114
    m64p_video_mode ScreenMode = bWindowed ? M64VIDEO_WINDOWED : M64VIDEO_FULLSCREEN;
115
 
    if (CoreVideo_SetVideoMode(windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, colorBufferDepth, ScreenMode) != M64ERR_SUCCESS)
 
115
    m64p_video_flags flags = M64VIDEOFLAG_SUPPORT_RESIZING;
 
116
    if (CoreVideo_SetVideoMode(windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, colorBufferDepth, ScreenMode, flags) != M64ERR_SUCCESS)
116
117
    {
117
118
        DebugMessage(M64MSG_ERROR, "Failed to set %i-bit video mode: %ix%i", colorBufferDepth, (int)windowSetting.uDisplayWidth, (int)windowSetting.uDisplayHeight);
118
119
        CoreVideo_Quit();
134
135
        if (iActual != depthBufferDepth)
135
136
            DebugMessage(M64MSG_WARNING, "Failed to set GL_DEPTH_SIZE to %i. (it's %i)", depthBufferDepth, iActual);
136
137
 
 
138
#if SDL_VIDEO_OPENGL
137
139
    /* Get function pointers to OpenGL extensions (blame Microsoft Windows for this) */
138
140
    OGLExtensions_Init();
 
141
#endif
139
142
 
140
143
    char caption[500];
141
144
    sprintf(caption, "%s v%i.%i.%i", PLUGIN_NAME, VERSION_PRINTF_SPLIT(PLUGIN_VERSION));
161
164
    return true;
162
165
}
163
166
 
 
167
bool COGLGraphicsContext::ResizeInitialize(uint32 dwWidth, uint32 dwHeight, BOOL bWindowed )
 
168
{
 
169
    Lock();
 
170
 
 
171
    CGraphicsContext::Initialize(dwWidth, dwHeight, bWindowed );
 
172
 
 
173
    int  depthBufferDepth = options.OpenglDepthBufferSetting;
 
174
    int  colorBufferDepth = 32;
 
175
    int bVerticalSync = windowSetting.bVerticalSync;
 
176
    if( options.colorQuality == TEXTURE_FMT_A4R4G4B4 ) colorBufferDepth = 16;
 
177
 
 
178
    /* hard-coded attribute values */
 
179
    const int iDOUBLEBUFFER = 1;
 
180
 
 
181
    /* set opengl attributes */
 
182
    CoreVideo_GL_SetAttribute(M64P_GL_DOUBLEBUFFER, iDOUBLEBUFFER);
 
183
    CoreVideo_GL_SetAttribute(M64P_GL_SWAP_CONTROL, bVerticalSync);
 
184
    CoreVideo_GL_SetAttribute(M64P_GL_BUFFER_SIZE, colorBufferDepth);
 
185
    CoreVideo_GL_SetAttribute(M64P_GL_DEPTH_SIZE, depthBufferDepth);
 
186
 
 
187
    /* set multisampling */
 
188
    if (options.multiSampling > 0)
 
189
    {
 
190
        CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLEBUFFERS, 1);
 
191
        if (options.multiSampling <= 2)
 
192
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 2);
 
193
        else if (options.multiSampling <= 4)
 
194
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 4);
 
195
        else if (options.multiSampling <= 8)
 
196
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 8);
 
197
        else
 
198
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 16);
 
199
    }
 
200
 
 
201
    /* Call Mupen64plus core Video Extension to resize the window, which will create a new OpenGL Context under SDL */
 
202
    if (CoreVideo_ResizeWindow(windowSetting.uDisplayWidth, windowSetting.uDisplayHeight) != M64ERR_SUCCESS)
 
203
    {
 
204
        DebugMessage(M64MSG_ERROR, "Failed to set %i-bit video mode: %ix%i", colorBufferDepth, (int)windowSetting.uDisplayWidth, (int)windowSetting.uDisplayHeight);
 
205
        CoreVideo_Quit();
 
206
        return false;
 
207
    }
 
208
 
 
209
    InitState();
 
210
    Unlock();
 
211
 
 
212
    Clear(CLEAR_COLOR_AND_DEPTH_BUFFER);    // Clear buffers
 
213
    UpdateFrame();
 
214
    Clear(CLEAR_COLOR_AND_DEPTH_BUFFER);
 
215
    UpdateFrame();
 
216
    
 
217
    return true;
 
218
}
 
219
 
164
220
void COGLGraphicsContext::InitState(void)
165
221
{
166
222
    m_pRenderStr = glGetString(GL_RENDERER);
177
233
    glClearDepth(1.0f);
178
234
    OPENGL_CHECK_ERRORS;
179
235
 
 
236
#if SDL_VIDEO_OPENGL
180
237
    glShadeModel(GL_SMOOTH);
181
238
    OPENGL_CHECK_ERRORS;
182
239
 
186
243
 
187
244
    glDisable(GL_ALPHA_TEST);
188
245
    OPENGL_CHECK_ERRORS;
 
246
#endif
189
247
 
190
248
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
191
249
    OPENGL_CHECK_ERRORS;
196
254
    OPENGL_CHECK_ERRORS;
197
255
    glDisable(GL_CULL_FACE);
198
256
    OPENGL_CHECK_ERRORS;
 
257
#if SDL_VIDEO_OPENGL
199
258
    glDisable(GL_NORMALIZE);
200
259
    OPENGL_CHECK_ERRORS;
 
260
#endif
201
261
 
202
262
    glDepthFunc(GL_LEQUAL);
203
263
    OPENGL_CHECK_ERRORS;
204
264
    glEnable(GL_DEPTH_TEST);
205
265
    OPENGL_CHECK_ERRORS;
206
266
 
 
267
#if SDL_VIDEO_OPENGL
207
268
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
208
269
    OPENGL_CHECK_ERRORS;
 
270
#endif
209
271
 
210
272
    glEnable(GL_BLEND);
211
273
    OPENGL_CHECK_ERRORS;
 
274
#if SDL_VIDEO_OPENGL
212
275
    glEnable(GL_ALPHA_TEST);
213
276
    OPENGL_CHECK_ERRORS;
214
277
 
218
281
    OPENGL_CHECK_ERRORS;
219
282
    
220
283
    glDepthRange(-1, 1);
 
284
 
 
285
#elif SDL_VIDEO_OPENGL_ES2
 
286
    glDepthRangef(0.0f, 1.0f);
 
287
#endif
221
288
    OPENGL_CHECK_ERRORS;
222
289
}
223
290
 
224
291
void COGLGraphicsContext::InitOGLExtension(void)
225
292
{
226
293
    // important extension features, it is very bad not to have these feature
227
 
    m_bSupportMultiTexture = IsExtensionSupported("GL_ARB_multitexture");
 
294
    m_bSupportMultiTexture = IsExtensionSupported(OSAL_GL_ARB_MULTITEXTURE);
228
295
    m_bSupportTextureEnvCombine = IsExtensionSupported("GL_EXT_texture_env_combine");
229
296
    
230
297
    m_bSupportSeparateSpecularColor = IsExtensionSupported("GL_EXT_separate_specular_color");
401
468
 
402
469
    glDepthMask(GL_TRUE);
403
470
    OPENGL_CHECK_ERRORS;
404
 
    glClearDepth(1.0);
 
471
    glClearDepth(1.0f);
405
472
    OPENGL_CHECK_ERRORS;
406
 
    if( !g_curRomInfo.bForceScreenClear ) 
 
473
    if( !g_curRomInfo.bForceScreenClear )
407
474
    {
408
475
        glClear(GL_DEPTH_BUFFER_BIT);
409
476
        OPENGL_CHECK_ERRORS;