2008-12-07 22:25:12 -07:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-02-18 23:52:01 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Include
|
|
|
|
// --------------------------
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "Globals.h"
|
|
|
|
|
2009-01-11 06:37:13 -07:00
|
|
|
#include <cstdarg>
|
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "OS/Win32.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
#include "GUI/ConfigDlg.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Config.h"
|
|
|
|
#include "LookUpTables.h"
|
|
|
|
#include "ImageWrite.h"
|
|
|
|
#include "Render.h"
|
|
|
|
#include "GLUtil.h"
|
|
|
|
#include "Fifo.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
|
|
|
#include "TextureMngr.h"
|
|
|
|
#include "BPStructs.h"
|
|
|
|
#include "VertexLoader.h"
|
|
|
|
#include "VertexLoaderManager.h"
|
|
|
|
#include "VertexManager.h"
|
2008-12-26 04:23:59 -07:00
|
|
|
#include "PixelShaderCache.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "PixelShaderManager.h"
|
2008-12-26 04:23:59 -07:00
|
|
|
#include "VertexShaderCache.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "VertexShaderManager.h"
|
|
|
|
#include "XFB.h"
|
|
|
|
#include "XFBConvert.h"
|
|
|
|
#include "TextureConverter.h"
|
2009-02-21 05:53:10 -07:00
|
|
|
#include "OnScreenDisplay.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
|
|
|
|
#include "VideoState.h"
|
2009-02-18 23:52:01 -07:00
|
|
|
///////////////////////////////////////////////
|
2008-12-14 16:52:01 -07:00
|
|
|
|
2009-02-18 23:52:01 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Definitions
|
|
|
|
// --------------------------
|
2008-12-07 22:25:12 -07:00
|
|
|
SVideoInitialize g_VideoInitialize;
|
2009-01-08 16:42:18 -07:00
|
|
|
PLUGIN_GLOBALS* globals;
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2009-02-18 23:52:01 -07:00
|
|
|
// Logging
|
|
|
|
int GLScissorX, GLScissorY, GLScissorW, GLScissorH;
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
void DllDebugger(HWND _hParent, bool Show)
|
|
|
|
{
|
2009-02-20 19:42:35 -07:00
|
|
|
// TODO: Debugger needs recoding, right now its useless
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-02-04 10:48:40 -07:00
|
|
|
void DoDllDebugger(){}
|
2008-12-07 22:25:12 -07:00
|
|
|
#else
|
2009-01-05 15:11:08 -07:00
|
|
|
void DllDebugger(HWND _hParent, bool Show) { }
|
2008-12-07 22:25:12 -07:00
|
|
|
void DoDllDebugger() { }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void GetDllInfo (PLUGIN_INFO* _PluginInfo)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_VIDEO;
|
2009-01-14 23:48:15 -07:00
|
|
|
#ifdef DEBUGFAST
|
2008-12-07 22:25:12 -07:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL (DebugFast)");
|
|
|
|
#else
|
|
|
|
#ifndef _DEBUG
|
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL");
|
|
|
|
#else
|
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL (Debug)");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-21 05:25:43 -07:00
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
|
|
|
{
|
2009-01-08 05:12:15 -07:00
|
|
|
}
|
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
void DllConfig(HWND _hParent)
|
|
|
|
{
|
|
|
|
#if defined(_WIN32)
|
2009-02-21 05:25:43 -07:00
|
|
|
wxWindow *win = new wxWindow();
|
2009-01-14 09:36:43 -07:00
|
|
|
win->SetHWND((WXHWND)_hParent);
|
|
|
|
win->AdoptAttributesFromHWND();
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2009-02-21 05:25:43 -07:00
|
|
|
ConfigDialog *config_dialog = new ConfigDialog(win);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
|
|
|
DWORD iModeNum = 0;
|
|
|
|
DEVMODE dmi;
|
|
|
|
ZeroMemory(&dmi, sizeof(dmi));
|
|
|
|
dmi.dmSize = sizeof(dmi);
|
2009-02-21 05:25:43 -07:00
|
|
|
std::vector<std::string> resos;
|
|
|
|
resos.reserve(20);
|
2008-12-07 22:25:12 -07:00
|
|
|
int i = 0;
|
2009-01-14 23:48:15 -07:00
|
|
|
|
2009-02-19 03:29:53 -07:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// Search for avaliable resolutions
|
|
|
|
// ---------------------
|
2008-12-07 22:25:12 -07:00
|
|
|
while (EnumDisplaySettings(NULL, iModeNum++, &dmi) != 0)
|
2009-01-14 23:48:15 -07:00
|
|
|
{
|
2008-12-07 22:25:12 -07:00
|
|
|
char szBuffer[100];
|
2009-02-21 05:25:43 -07:00
|
|
|
sprintf(szBuffer, "%dx%d", dmi.dmPelsWidth, dmi.dmPelsHeight);
|
2008-12-07 22:25:12 -07:00
|
|
|
std::string strBuffer(szBuffer);
|
2009-02-19 04:28:55 -07:00
|
|
|
// Create a check loop to check every pointer of resolutions to see if the res is added or not
|
2008-12-07 22:25:12 -07:00
|
|
|
int b = 0;
|
|
|
|
bool resFound = false;
|
|
|
|
while (b < i && !resFound)
|
|
|
|
{
|
2009-01-14 09:36:43 -07:00
|
|
|
// Is the res already added?
|
2008-12-07 22:25:12 -07:00
|
|
|
resFound = (resos[b] == strBuffer);
|
|
|
|
b++;
|
|
|
|
}
|
2009-02-19 04:28:55 -07:00
|
|
|
// Add the resolution
|
2009-02-21 05:25:43 -07:00
|
|
|
if (!resFound && i < 100) // don't want to overflow resos array. not likely to happen, but you never know.
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-02-21 05:25:43 -07:00
|
|
|
resos.push_back(strBuffer);
|
2008-12-07 22:25:12 -07:00
|
|
|
i++;
|
2009-02-21 05:25:43 -07:00
|
|
|
config_dialog->AddFSReso(szBuffer);
|
|
|
|
config_dialog->AddWindowReso(szBuffer);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
ZeroMemory(&dmi, sizeof(dmi));
|
|
|
|
}
|
2009-02-19 04:28:55 -07:00
|
|
|
|
|
|
|
// Check if at least one resolution was found. If we don't and the resolution array is empty
|
|
|
|
// CreateGUIControls() will crash because the array is empty.
|
2009-02-21 05:25:43 -07:00
|
|
|
if (config_dialog->arrayStringFor_FullscreenCB.size() == 0)
|
2009-02-19 04:28:55 -07:00
|
|
|
{
|
2009-02-21 05:25:43 -07:00
|
|
|
config_dialog->AddFSReso("<No resolutions found>");
|
|
|
|
config_dialog->AddWindowReso("<No resolutions found>");
|
2009-02-19 04:28:55 -07:00
|
|
|
}
|
2009-02-19 03:29:53 -07:00
|
|
|
|
|
|
|
// Create the controls and show the window
|
2009-02-21 05:25:43 -07:00
|
|
|
config_dialog->CreateGUIControls();
|
|
|
|
config_dialog->Show();
|
2009-02-19 03:29:53 -07:00
|
|
|
|
2008-12-13 15:40:10 -07:00
|
|
|
#elif defined(USE_WX) && USE_WX
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2009-02-21 05:25:43 -07:00
|
|
|
// Hm, why does this code show it modally?
|
|
|
|
config_dialog = new ConfigDialog(NULL);
|
|
|
|
g_Config.Load();
|
|
|
|
config_dialog->ShowModal();
|
|
|
|
delete config_dialog;
|
|
|
|
config_dialog = NULL;
|
2008-12-17 16:49:35 -07:00
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
#elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_XXF86VM) &&\
|
2008-12-14 16:52:01 -07:00
|
|
|
HAVE_XXF86VM && defined(HAVE_WX) && HAVE_WX
|
2009-01-14 23:48:15 -07:00
|
|
|
|
2009-02-21 05:25:43 -07:00
|
|
|
ConfigDialog config_dialog(NULL);
|
2008-12-07 22:25:12 -07:00
|
|
|
g_Config.Load();
|
|
|
|
int glxMajorVersion, glxMinorVersion;
|
|
|
|
int vidModeMajorVersion, vidModeMinorVersion;
|
|
|
|
GLWin.dpy = XOpenDisplay(0);
|
|
|
|
glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion);
|
|
|
|
XF86VidModeQueryVersion(GLWin.dpy, &vidModeMajorVersion, &vidModeMinorVersion);
|
|
|
|
//Get all full screen resos for the config dialog
|
|
|
|
XF86VidModeModeInfo **modes = NULL;
|
|
|
|
int modeNum = 0;
|
|
|
|
int bestMode = 0;
|
|
|
|
|
|
|
|
//set best mode to current
|
|
|
|
bestMode = 0;
|
|
|
|
XF86VidModeGetAllModeLines(GLWin.dpy, GLWin.screen, &modeNum, &modes);
|
|
|
|
int px = 0, py = 0;
|
2009-01-14 23:48:15 -07:00
|
|
|
if (modeNum > 0 && modes != NULL)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-01-14 23:48:15 -07:00
|
|
|
for (int i = 0; i < modeNum; i++)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
if(px != modes[i]->hdisplay && py != modes[i]->vdisplay)
|
|
|
|
{
|
|
|
|
char temp[32];
|
|
|
|
sprintf(temp,"%dx%d", modes[i]->hdisplay, modes[i]->vdisplay);
|
2009-02-21 05:25:43 -07:00
|
|
|
config_dialog.AddFSReso(temp);
|
|
|
|
config_dialog.AddWindowReso(temp);//Add same to Window ones, since they should be nearly all that's needed
|
2008-12-07 22:25:12 -07:00
|
|
|
px = modes[i]->hdisplay;//Used to remove repeating from different screen depths
|
|
|
|
py = modes[i]->vdisplay;
|
|
|
|
}
|
|
|
|
}
|
2009-02-21 05:25:43 -07:00
|
|
|
}
|
2008-12-07 22:25:12 -07:00
|
|
|
XFree(modes);
|
2009-02-21 05:25:43 -07:00
|
|
|
|
|
|
|
// Hm, why does this code show it modally?
|
|
|
|
config_dialog.ShowModal();
|
2008-12-10 16:23:05 -07:00
|
|
|
#endif
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void Initialize(void *init)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
frameCount = 0;
|
2009-01-14 23:48:15 -07:00
|
|
|
SVideoInitialize *_pVideoInitialize = (SVideoInitialize*)init;
|
|
|
|
g_VideoInitialize = *(_pVideoInitialize); // Create a shortcut to _pVideoInitialize that can also update it
|
2008-12-07 22:25:12 -07:00
|
|
|
InitLUTs();
|
|
|
|
InitXFBConvTables();
|
|
|
|
g_Config.Load();
|
|
|
|
|
2009-01-04 14:53:41 -07:00
|
|
|
if (!OpenGL_Create(g_VideoInitialize, 640, 480)) // 640x480 will be the default if all else fails
|
|
|
|
{
|
2008-12-07 22:25:12 -07:00
|
|
|
g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2009-02-21 05:25:43 -07:00
|
|
|
|
|
|
|
_pVideoInitialize->pPeekMessages = g_VideoInitialize.pPeekMessages;
|
2008-12-07 22:25:12 -07:00
|
|
|
_pVideoInitialize->pUpdateFPSDisplay = g_VideoInitialize.pUpdateFPSDisplay;
|
2009-01-04 14:53:41 -07:00
|
|
|
|
|
|
|
// Now the window handle is written
|
2008-12-07 22:25:12 -07:00
|
|
|
_pVideoInitialize->pWindowHandle = g_VideoInitialize.pWindowHandle;
|
|
|
|
|
2009-02-21 05:53:10 -07:00
|
|
|
OSD::AddMessage("Dolphin OpenGL Video Plugin" ,5000);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void DoState(unsigned char **ptr, int mode) {
|
2008-12-15 17:44:50 -07:00
|
|
|
#ifndef _WIN32
|
|
|
|
// WHY is this here??
|
|
|
|
OpenGL_MakeCurrent();
|
|
|
|
#endif
|
2008-12-07 22:25:12 -07:00
|
|
|
// Clear all caches that touch RAM
|
|
|
|
TextureMngr::Invalidate();
|
|
|
|
// DisplayListManager::Invalidate();
|
|
|
|
|
|
|
|
VertexLoaderManager::MarkAllDirty();
|
|
|
|
|
|
|
|
PointerWrap p(ptr, mode);
|
|
|
|
VideoCommon_DoState(p);
|
|
|
|
|
|
|
|
// Refresh state.
|
2009-02-09 13:35:30 -07:00
|
|
|
if (mode == PointerWrap::MODE_READ)
|
|
|
|
{
|
2008-12-07 22:25:12 -07:00
|
|
|
BPReload();
|
2009-02-09 13:35:30 -07:00
|
|
|
RecomputeCachedArraybases();
|
|
|
|
}
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is called after Video_Initialize() from the Core
|
|
|
|
void Video_Prepare(void)
|
|
|
|
{
|
|
|
|
OpenGL_MakeCurrent();
|
2008-12-25 08:56:36 -07:00
|
|
|
if (!Renderer::Init()) {
|
|
|
|
g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE);
|
2008-12-07 22:25:12 -07:00
|
|
|
PanicAlert("Can't create opengl renderer. You might be missing some required opengl extensions, check the logs for more info");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureMngr::Init();
|
|
|
|
|
|
|
|
BPInit();
|
|
|
|
VertexManager::Init();
|
|
|
|
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
|
|
|
OpcodeDecoder_Init();
|
2008-12-26 03:43:18 -07:00
|
|
|
VertexShaderCache::Init();
|
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderCache::Init();
|
|
|
|
PixelShaderManager::Init();
|
2008-12-07 22:25:12 -07:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
VertexLoaderManager::Init();
|
|
|
|
TextureConverter::Init();
|
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void Shutdown(void)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-02-20 15:04:52 -07:00
|
|
|
Fifo_Shutdown();
|
2008-12-07 22:25:12 -07:00
|
|
|
TextureConverter::Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
2008-12-26 03:43:18 -07:00
|
|
|
VertexShaderCache::Shutdown();
|
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
PixelShaderCache::Shutdown();
|
2008-12-07 22:25:12 -07:00
|
|
|
VertexManager::Shutdown();
|
|
|
|
TextureMngr::Shutdown();
|
|
|
|
OpcodeDecoder_Shutdown();
|
|
|
|
Renderer::Shutdown();
|
|
|
|
OpenGL_Shutdown();
|
|
|
|
}
|
|
|
|
|
2009-02-20 15:04:52 -07:00
|
|
|
void Video_EnterLoop()
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-02-20 15:04:52 -07:00
|
|
|
Fifo_EnterLoop(g_VideoInitialize);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-02-20 15:04:52 -07:00
|
|
|
void Video_ExitLoop()
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-02-20 15:04:52 -07:00
|
|
|
Fifo_ExitLoop();
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugLog(const char* _fmt, ...)
|
|
|
|
{
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
|
|
|
|
|
|
|
char* Msg = (char*)alloca(strlen(_fmt)+512);
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start( ap, _fmt );
|
|
|
|
vsnprintf( Msg, strlen(_fmt)+512, _fmt, ap );
|
|
|
|
va_end( ap );
|
|
|
|
|
|
|
|
g_VideoInitialize.pLog(Msg, FALSE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Video_Screenshot(TCHAR* _szFilename)
|
|
|
|
{
|
2009-02-21 05:25:43 -07:00
|
|
|
char str[64];
|
|
|
|
int left = 200, top = 15;
|
|
|
|
sprintf(str, "Dolphin OpenGL");
|
|
|
|
|
|
|
|
Renderer::ResetGLState();
|
|
|
|
Renderer::RenderText(str, left+1, top+1, 0xff000000);
|
|
|
|
Renderer::RenderText(str, left, top, 0xffc0ffff);
|
|
|
|
Renderer::RestoreGLState();
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2009-02-21 05:25:43 -07:00
|
|
|
if (Renderer::SaveRenderTarget(_szFilename, 0))
|
|
|
|
{
|
|
|
|
char msg[255];
|
|
|
|
sprintf(msg, "saved %s\n", _szFilename);
|
2009-02-21 05:53:10 -07:00
|
|
|
OSD::AddMessage(msg, 500);
|
2009-02-21 05:25:43 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-01-24 15:02:27 -07:00
|
|
|
void Video_UpdateXFB(u8* _pXFB, u32 _dwWidth, u32 _dwHeight, s32 _dwYOffset, bool scheduling)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-02-21 05:25:43 -07:00
|
|
|
if (g_Config.bUseXFB && XFB_isInit())
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-01-27 13:59:27 -07:00
|
|
|
if (scheduling) // from CPU in DC without fifo&CP (some 2D homebrews)
|
2009-01-24 07:43:17 -07:00
|
|
|
{
|
|
|
|
XFB_SetUpdateArgs(_pXFB, _dwWidth, _dwHeight, _dwYOffset);
|
|
|
|
g_XFBUpdateRequested = TRUE;
|
|
|
|
}
|
2009-01-27 13:59:27 -07:00
|
|
|
else
|
2009-01-24 07:43:17 -07:00
|
|
|
{
|
2009-01-27 13:59:27 -07:00
|
|
|
if (_pXFB) // from CPU in SC mode
|
2009-01-24 07:43:17 -07:00
|
|
|
XFB_Draw(_pXFB, _dwWidth, _dwHeight, _dwYOffset);
|
2009-01-27 13:59:27 -07:00
|
|
|
else // from GP in DC without fifo&CP (some 2D homebrews)
|
|
|
|
{
|
2009-01-24 07:43:17 -07:00
|
|
|
XFB_Draw();
|
2009-01-27 13:59:27 -07:00
|
|
|
g_XFBUpdateRequested = FALSE;
|
|
|
|
}
|
2009-01-24 07:43:17 -07:00
|
|
|
}
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Video_AddMessage(const char* pstr, u32 milliseconds)
|
|
|
|
{
|
2009-02-21 05:53:10 -07:00
|
|
|
OSD::AddMessage(pstr, milliseconds);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|