1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  *   Mupen64plus-core - api/vidext.c                                       *
3  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4  *   Copyright (C) 2009 Richard Goedeken                                   *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
20  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21 
22 /* This file contains the Core video extension functions which will be exported
23  * outside of the core library.
24  */
25 
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include <boolean.h>
30 
31 int retro_return(bool a);
32 
33 #define M64P_CORE_PROTOTYPES 1
34 #include "m64p_types.h"
35 #include "m64p_vidext.h"
36 #include "vidext.h"
37 #include "callbacks.h"
38 
39 #include <libretro.h>
40 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
41 #include <glsm/glsmsym.h>
42 #endif
43 
44 /* local variables */
45 static m64p_video_extension_functions l_ExternalVideoFuncTable = {10, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
46 static int l_VideoExtensionActive = 0;
47 static int l_VideoOutputActive = 0;
48 
49 /* global function for use by frontend.c */
OverrideVideoFunctions(m64p_video_extension_functions * VideoFunctionStruct)50 m64p_error OverrideVideoFunctions(m64p_video_extension_functions *VideoFunctionStruct)
51 {
52     /* check input data */
53     if (VideoFunctionStruct == NULL)
54         return M64ERR_INPUT_ASSERT;
55     if (VideoFunctionStruct->Functions < 11)
56         return M64ERR_INPUT_INVALID;
57 
58     /* disable video extension if any of the function pointers are NULL */
59     if (VideoFunctionStruct->VidExtFuncInit == NULL ||
60         VideoFunctionStruct->VidExtFuncQuit == NULL ||
61         VideoFunctionStruct->VidExtFuncListModes == NULL ||
62         VideoFunctionStruct->VidExtFuncSetMode == NULL ||
63         VideoFunctionStruct->VidExtFuncGLGetProc == NULL ||
64         VideoFunctionStruct->VidExtFuncGLSetAttr == NULL ||
65         VideoFunctionStruct->VidExtFuncGLGetAttr == NULL ||
66         VideoFunctionStruct->VidExtFuncGLSwapBuf == NULL ||
67         VideoFunctionStruct->VidExtFuncSetCaption == NULL ||
68         VideoFunctionStruct->VidExtFuncToggleFS == NULL ||
69         VideoFunctionStruct->VidExtFuncResizeWindow == NULL)
70     {
71         l_ExternalVideoFuncTable.Functions = 11;
72         memset(&l_ExternalVideoFuncTable.VidExtFuncInit, 0, 11 * sizeof(void *));
73         l_VideoExtensionActive = 0;
74         return M64ERR_SUCCESS;
75     }
76 
77     /* otherwise copy in the override function pointers */
78     memcpy(&l_ExternalVideoFuncTable, VideoFunctionStruct, sizeof(m64p_video_extension_functions));
79     l_VideoExtensionActive = 1;
80     return M64ERR_SUCCESS;
81 }
82 
VidExt_InFullscreenMode(void)83 int VidExt_InFullscreenMode(void)
84 {
85     return 1;
86 }
87 
VidExt_VideoRunning(void)88 int VidExt_VideoRunning(void)
89 {
90     return l_VideoOutputActive;
91 }
92 
VidExt_SetCaption(const char * Title)93 EXPORT m64p_error CALL VidExt_SetCaption(const char *Title)
94 {
95    return M64ERR_SUCCESS;
96 }
97 
VidExt_ToggleFullScreen(void)98 EXPORT m64p_error CALL VidExt_ToggleFullScreen(void)
99 {
100    /* TODO/FIXME - should just do a context reset here. */
101    return M64ERR_SUCCESS;
102 }
103 
VidExt_GL_SetAttribute(m64p_GLattr Attr,int Value)104 EXPORT m64p_error CALL VidExt_GL_SetAttribute(m64p_GLattr Attr, int Value)
105 {
106    return M64ERR_SUCCESS;
107 }
108 
VidExt_Init(void)109 EXPORT m64p_error CALL VidExt_Init(void)
110 {
111    /* TODO/FIXME - implement. */
112    return M64ERR_SUCCESS;
113 }
114 
VidExt_Quit(void)115 EXPORT m64p_error CALL VidExt_Quit(void)
116 {
117    /* TODO/FIXME - implement. */
118    return M64ERR_SUCCESS;
119 }
120 
VidExt_SetVideoMode(int Width,int Height,int BitsPerPixel,m64p_video_mode ScreenMode,m64p_video_flags Flags)121 EXPORT m64p_error CALL VidExt_SetVideoMode(int Width, int Height, int BitsPerPixel,
122       m64p_video_mode ScreenMode, m64p_video_flags Flags)
123 {
124    /* TODO/FIXME - implement. */
125    return M64ERR_SUCCESS;
126 }
127 
VidExt_GL_GetProcAddress(const char * Proc)128 EXPORT void * CALL VidExt_GL_GetProcAddress(const char* Proc)
129 {
130 #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
131    glsm_ctx_proc_address_t proc_info;
132    proc_info.addr = NULL;
133    if (!glsm_ctl(GLSM_CTL_PROC_ADDRESS_GET, NULL))
134       return NULL;
135    return proc_info.addr(Proc);
136 #else
137    return NULL;
138 #endif
139 }
140 
VidExt_GL_SwapBuffers(void)141 EXPORT m64p_error CALL VidExt_GL_SwapBuffers(void)
142 {
143    retro_return(true);
144    return M64ERR_SUCCESS;
145 }
146 
VidExt_ListFullscreenModes(m64p_2d_size * SizeArray,int * NumSizes)147 EXPORT m64p_error CALL VidExt_ListFullscreenModes(m64p_2d_size *SizeArray, int *NumSizes)
148 {
149 #if 0
150    /* TODO/FIXME - implement */
151     i = 0;
152     while (i < *NumSizes && modes[i] != NULL)
153     {
154         SizeArray[i].uiWidth  = modes[i]->w;
155         SizeArray[i].uiHeight = modes[i]->h;
156         i++;
157     }
158 
159     *NumSizes = i;
160 #endif
161 
162     return M64ERR_SUCCESS;
163 }
164 
VidExt_ResizeWindow(int Width,int Height)165 EXPORT m64p_error CALL VidExt_ResizeWindow(int Width, int Height)
166 {
167    /* TODO/FIXME - implement? */
168    return M64ERR_SUCCESS;
169 }
170