2008-07-12 17:40:22 +00: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/
|
2008-09-07 10:29:46 +00:00
|
|
|
|
2008-07-23 16:04:58 +00:00
|
|
|
#include "Globals.h"
|
2008-07-23 15:20:36 +00:00
|
|
|
|
2008-07-23 16:32:38 +00:00
|
|
|
#ifdef _WIN32
|
2008-08-26 23:32:54 +00:00
|
|
|
#include "OS/Win32.h"
|
2008-07-23 16:32:38 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-25 17:47:46 +00:00
|
|
|
#if defined(__APPLE__) && !defined(OSX64)
|
2008-08-26 23:32:54 +00:00
|
|
|
#include <SDL.h>
|
2008-08-12 23:17:29 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-25 17:47:46 +00:00
|
|
|
#if !defined(OSX64)
|
2008-07-23 15:20:36 +00:00
|
|
|
#include "GUI/ConfigDlg.h"
|
2008-10-25 17:47:46 +00:00
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-22 21:23:40 +00:00
|
|
|
#include "Config.h"
|
2008-10-17 11:30:14 +00:00
|
|
|
#include "LookUpTables.h"
|
|
|
|
#include "ImageWrite.h"
|
2008-07-12 17:40:22 +00:00
|
|
|
#include "Render.h"
|
2008-10-22 21:02:37 +00:00
|
|
|
#include "GLUtil.h"
|
2008-07-12 17:40:22 +00:00
|
|
|
#include "Fifo.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
|
|
|
#include "TextureMngr.h"
|
|
|
|
#include "BPStructs.h"
|
|
|
|
#include "VertexLoader.h"
|
2008-10-25 13:27:28 +00:00
|
|
|
#include "VertexLoaderManager.h"
|
2008-10-17 11:30:14 +00:00
|
|
|
#include "VertexManager.h"
|
2008-07-17 21:09:18 +00:00
|
|
|
#include "PixelShaderManager.h"
|
|
|
|
#include "VertexShaderManager.h"
|
2008-10-15 14:07:03 +00:00
|
|
|
#include "XFB.h"
|
2008-10-15 21:29:44 +00:00
|
|
|
#include "XFBConvert.h"
|
2008-11-10 07:12:14 +00:00
|
|
|
#include "TextureConverter.h"
|
2008-10-15 14:07:03 +00:00
|
|
|
|
2008-08-26 23:40:18 +00:00
|
|
|
#include "VideoState.h"
|
2008-10-25 17:47:46 +00:00
|
|
|
#if !defined(OSX64)
|
2008-10-09 18:47:53 +00:00
|
|
|
#include "Debugger/Debugger.h" // for the CDebugger class
|
2008-10-25 17:47:46 +00:00
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
SVideoInitialize g_VideoInitialize;
|
|
|
|
|
2008-11-16 20:09:13 +00:00
|
|
|
|
|
|
|
/* Create debugging window. There's currently a strange crash that occurs whe a game is loaded
|
|
|
|
if the OpenGL plugin was loaded before. I'll try to fix that. Currently you may have to
|
|
|
|
clsoe the window if it has auto started, and then restart it after the dll has loaded
|
|
|
|
for the purpose of the game. At that point there is no need to use the same dll instance
|
|
|
|
as the one that is rendering the game. However, that could be done. */
|
2008-10-25 17:47:46 +00:00
|
|
|
#if defined(OSX64)
|
|
|
|
void DllDebugger(HWND _hParent) { }
|
|
|
|
void DoDllDebugger() { }
|
|
|
|
#else
|
2008-10-09 18:47:53 +00:00
|
|
|
CDebugger* m_frame;
|
2008-11-16 20:09:13 +00:00
|
|
|
void DllDebugger(HWND _hParent, bool Show)
|
2008-10-09 18:47:53 +00:00
|
|
|
{
|
2008-11-16 20:09:13 +00:00
|
|
|
if(m_frame && Show) // if we have created it, let us show it again
|
2008-10-09 18:47:53 +00:00
|
|
|
{
|
2008-11-21 01:28:00 +00:00
|
|
|
m_frame->DoShow();
|
2008-10-09 18:47:53 +00:00
|
|
|
}
|
2008-11-16 20:09:13 +00:00
|
|
|
else if(!m_frame && Show)
|
|
|
|
{
|
|
|
|
m_frame = new CDebugger(NULL);
|
|
|
|
m_frame->Show();
|
|
|
|
}
|
|
|
|
else if(m_frame && !Show)
|
2008-10-09 18:47:53 +00:00
|
|
|
{
|
2008-11-21 01:28:00 +00:00
|
|
|
m_frame->DoHide();
|
2008-10-09 18:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoDllDebugger()
|
|
|
|
{
|
2008-11-16 20:09:13 +00:00
|
|
|
//m_frame = new CDebugger(NULL);
|
|
|
|
//m_frame->Show();
|
2008-10-09 18:47:53 +00:00
|
|
|
}
|
2008-10-25 17:47:46 +00:00
|
|
|
#endif
|
2008-10-09 18:47:53 +00:00
|
|
|
|
2008-11-16 20:09:13 +00:00
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
void GetDllInfo (PLUGIN_INFO* _PluginInfo)
|
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_VIDEO;
|
|
|
|
#ifdef DEBUGFAST
|
2008-11-23 21:26:47 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL (DebugFast)");
|
2008-07-12 17:40:22 +00:00
|
|
|
#else
|
|
|
|
#ifndef _DEBUG
|
2008-11-23 21:26:47 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL");
|
2008-07-12 17:40:22 +00:00
|
|
|
#else
|
2008-11-23 21:26:47 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL (Debug)");
|
2008-07-12 17:40:22 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void DllConfig(HWND _hParent)
|
|
|
|
{
|
2008-08-13 00:00:39 +00:00
|
|
|
#if defined(_WIN32)
|
2008-11-16 20:09:13 +00:00
|
|
|
//wxWindow win;
|
|
|
|
//win.SetHWND(_hParent);
|
|
|
|
//ConfigDialog frame(&win);
|
|
|
|
//ConfigDialog frame(NULL);
|
|
|
|
|
|
|
|
ConfigDialog *frame;
|
|
|
|
frame = new ConfigDialog(NULL);
|
2008-08-05 08:49:27 +00:00
|
|
|
|
2008-08-06 09:48:54 +00:00
|
|
|
DWORD iModeNum = 0;
|
|
|
|
DEVMODE dmi;
|
|
|
|
ZeroMemory(&dmi, sizeof(dmi));
|
|
|
|
dmi.dmSize = sizeof(dmi);
|
2008-08-26 13:15:25 +00:00
|
|
|
std::string resos[100];
|
|
|
|
int i = 0;
|
2008-08-06 09:48:54 +00:00
|
|
|
|
2008-10-17 11:30:14 +00:00
|
|
|
while (EnumDisplaySettings(NULL, iModeNum++, &dmi) != 0)
|
2008-08-06 09:48:54 +00:00
|
|
|
{
|
2008-08-27 11:45:51 +00:00
|
|
|
char szBuffer[100];
|
|
|
|
sprintf(szBuffer,"%dx%d", dmi.dmPelsWidth, dmi.dmPelsHeight);
|
|
|
|
//making a string cause char*[] to char was a baaad idea
|
|
|
|
std::string strBuffer(szBuffer);
|
|
|
|
//create a check loop to check every pointer of resos to see if the res is added or not
|
|
|
|
int b = 0;
|
|
|
|
bool resFound = false;
|
2008-10-17 11:30:14 +00:00
|
|
|
while (b < i && !resFound)
|
2008-08-27 11:45:51 +00:00
|
|
|
{
|
|
|
|
//is the res already added?
|
|
|
|
resFound = (resos[b] == strBuffer);
|
|
|
|
b++;
|
|
|
|
}
|
2008-10-25 15:53:43 +00:00
|
|
|
if (!resFound)
|
2008-08-27 11:45:51 +00:00
|
|
|
//and add the res
|
|
|
|
{
|
|
|
|
resos[i] = strBuffer;
|
|
|
|
i++;
|
2008-11-16 20:09:13 +00:00
|
|
|
//frame.AddFSReso(szBuffer);
|
|
|
|
//frame.AddWindowReso(szBuffer);
|
|
|
|
frame->AddFSReso(szBuffer);
|
|
|
|
frame->AddWindowReso(szBuffer);
|
2008-08-27 11:45:51 +00:00
|
|
|
}
|
2008-08-06 09:48:54 +00:00
|
|
|
ZeroMemory(&dmi, sizeof(dmi));
|
|
|
|
}
|
2008-11-16 20:09:13 +00:00
|
|
|
//frame.ShowModal();
|
|
|
|
frame->ShowModal();
|
|
|
|
//win.SetHWND(0);
|
2008-07-23 15:20:36 +00:00
|
|
|
|
2008-08-13 00:00:39 +00:00
|
|
|
#elif defined(__linux__)
|
2008-07-23 16:32:38 +00:00
|
|
|
ConfigDialog frame(NULL);
|
2008-07-30 04:23:43 +00: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
|
2008-09-13 04:32:28 +00:00
|
|
|
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;
|
|
|
|
if (modeNum > 0 && modes != NULL)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < modeNum; i++)
|
|
|
|
{
|
|
|
|
if(px != modes[i]->hdisplay && py != modes[i]->vdisplay)
|
|
|
|
{
|
|
|
|
char temp[32];
|
|
|
|
sprintf(temp,"%dx%d", modes[i]->hdisplay, modes[i]->vdisplay);
|
|
|
|
frame.AddFSReso(temp);
|
|
|
|
frame.AddWindowReso(temp);//Add same to Window ones, since they should be nearly all that's needed
|
|
|
|
px = modes[i]->hdisplay;//Used to remove repeating from different screen depths
|
|
|
|
py = modes[i]->vdisplay;
|
|
|
|
}
|
|
|
|
}
|
2008-07-30 04:23:43 +00:00
|
|
|
}
|
2008-09-13 04:32:28 +00:00
|
|
|
XFree(modes);
|
2008-07-23 15:20:36 +00:00
|
|
|
frame.ShowModal();
|
2008-08-12 23:17:29 +00:00
|
|
|
#else
|
|
|
|
//TODO
|
2008-07-23 16:32:38 +00:00
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Video_Initialize(SVideoInitialize* _pVideoInitialize)
|
|
|
|
{
|
|
|
|
if (_pVideoInitialize == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
// OpenConsole();
|
|
|
|
#endif
|
2008-11-16 20:09:13 +00:00
|
|
|
|
|
|
|
/* Dolphin currently crashes if the dll is loaded when a game is started so we clsoe the
|
|
|
|
debugger and open it again after loading */
|
|
|
|
/*
|
|
|
|
if(m_frame)
|
|
|
|
{
|
|
|
|
m_frame->EndModal(0); wxEntryCleanup();
|
|
|
|
}//use wxUninitialize() if you don't want GUI
|
|
|
|
*/
|
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
frameCount = 0;
|
|
|
|
g_VideoInitialize = *_pVideoInitialize;
|
|
|
|
InitLUTs();
|
2008-10-15 21:29:44 +00:00
|
|
|
InitXFBConvTables();
|
2008-07-12 17:40:22 +00:00
|
|
|
g_Config.Load();
|
2008-07-30 04:23:43 +00:00
|
|
|
|
|
|
|
if (!OpenGL_Create(g_VideoInitialize, 640, 480)) { //640x480 will be the default if all else fails//
|
2008-07-12 17:40:22 +00:00
|
|
|
g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_pVideoInitialize->pPeekMessages = g_VideoInitialize.pPeekMessages;
|
|
|
|
_pVideoInitialize->pUpdateFPSDisplay = g_VideoInitialize.pUpdateFPSDisplay;
|
|
|
|
_pVideoInitialize->pWindowHandle = g_VideoInitialize.pWindowHandle;
|
2008-08-10 21:06:03 +00:00
|
|
|
|
2008-11-23 21:26:47 +00:00
|
|
|
Renderer::AddMessage("Dolphin OpenGL Video Plugin" ,5000);
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
2008-08-30 12:11:25 +00:00
|
|
|
void Video_DoState(unsigned char **ptr, int mode) {
|
2008-08-30 16:24:45 +00:00
|
|
|
|
2008-10-25 15:53:43 +00:00
|
|
|
// Clear all caches that touch RAM
|
2008-08-30 16:24:45 +00:00
|
|
|
TextureMngr::Invalidate();
|
2008-10-25 15:53:43 +00:00
|
|
|
// DisplayListManager::Invalidate();
|
|
|
|
|
|
|
|
VertexLoaderManager::MarkAllDirty();
|
2008-08-30 16:24:45 +00:00
|
|
|
|
2008-08-30 12:11:25 +00:00
|
|
|
PointerWrap p(ptr, mode);
|
|
|
|
VideoCommon_DoState(p);
|
2008-11-22 20:06:20 +00:00
|
|
|
|
2008-10-25 17:09:06 +00:00
|
|
|
// Refresh state.
|
2008-11-22 20:06:20 +00:00
|
|
|
if (mode == PointerWrap::MODE_READ)
|
2008-10-25 17:09:06 +00:00
|
|
|
BPReload();
|
2008-08-26 23:40:18 +00:00
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-17 11:30:14 +00:00
|
|
|
// This is called after Video_Initialize() from the Core
|
2008-07-12 17:40:22 +00:00
|
|
|
void Video_Prepare(void)
|
|
|
|
{
|
2008-09-22 09:17:28 +00:00
|
|
|
OpenGL_MakeCurrent();
|
|
|
|
if (!Renderer::Create2()) {
|
2008-07-12 17:40:22 +00:00
|
|
|
g_VideoInitialize.pLog("Renderer::Create2 failed\n", TRUE);
|
2008-09-22 09:17:28 +00:00
|
|
|
PanicAlert("Can't create opengl renderer. You might be missing some required opengl extensions, check the logs for more info");
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
TextureMngr::Init();
|
|
|
|
|
|
|
|
BPInit();
|
|
|
|
VertexManager::Init();
|
2008-09-29 17:29:25 +00:00
|
|
|
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
2008-07-12 17:40:22 +00:00
|
|
|
OpcodeDecoder_Init();
|
|
|
|
VertexShaderMngr::Init();
|
|
|
|
PixelShaderMngr::Init();
|
|
|
|
GL_REPORT_ERRORD();
|
2008-10-25 13:27:28 +00:00
|
|
|
VertexLoaderManager::Init();
|
2008-11-10 07:12:14 +00:00
|
|
|
TextureConverter::Init();
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
2008-07-23 16:32:38 +00:00
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
void Video_Shutdown(void)
|
|
|
|
{
|
2008-11-10 07:12:14 +00:00
|
|
|
TextureConverter::Shutdown();
|
2008-10-25 13:27:28 +00:00
|
|
|
VertexLoaderManager::Shutdown();
|
2008-07-12 17:40:22 +00:00
|
|
|
VertexShaderMngr::Shutdown();
|
|
|
|
PixelShaderMngr::Shutdown();
|
|
|
|
Fifo_Shutdown();
|
2008-10-27 21:38:30 +00:00
|
|
|
VertexManager::Shutdown();
|
2008-07-12 17:40:22 +00:00
|
|
|
TextureMngr::Shutdown();
|
|
|
|
OpcodeDecoder_Shutdown();
|
|
|
|
Renderer::Shutdown();
|
2008-10-02 17:03:24 +00:00
|
|
|
OpenGL_Shutdown();
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 17:03:24 +00:00
|
|
|
void Video_Stop(void)
|
|
|
|
{
|
|
|
|
Fifo_Stop();
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-08-21 17:49:06 +00:00
|
|
|
void Video_EnterLoop()
|
|
|
|
{
|
|
|
|
Fifo_EnterLoop(g_VideoInitialize);
|
|
|
|
}
|
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
void DebugLog(const char* _fmt, ...)
|
|
|
|
{
|
2008-10-09 18:47:53 +00:00
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScreenShot(TCHAR *File)
|
|
|
|
{
|
|
|
|
char str[64];
|
|
|
|
int left = 200, top = 15;
|
2008-11-23 21:26:47 +00:00
|
|
|
sprintf(str, "Dolphin OpenGL");
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
Renderer::ResetGLState();
|
2008-08-10 21:06:03 +00:00
|
|
|
Renderer::RenderText(str, left+1, top+1, 0xff000000);
|
|
|
|
Renderer::RenderText(str, left, top, 0xffc0ffff);
|
2008-07-12 17:40:22 +00:00
|
|
|
Renderer::RestoreGLState();
|
|
|
|
|
|
|
|
if (Renderer::SaveRenderTarget(File, 0)) {
|
2008-09-08 06:41:03 +00:00
|
|
|
char msg[255];
|
|
|
|
sprintf(msg, "saved %s\n", File);
|
|
|
|
Renderer::AddMessage(msg, 500);
|
2008-07-12 17:40:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-10-25 17:47:46 +00:00
|
|
|
#if defined(OSX64)
|
|
|
|
unsigned int Video_Screenshot(TCHAR* _szFilename)
|
|
|
|
#else
|
2008-07-12 17:40:22 +00:00
|
|
|
BOOL Video_Screenshot(TCHAR* _szFilename)
|
2008-10-25 17:47:46 +00:00
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
if (ScreenShot(_szFilename))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-15 14:07:03 +00:00
|
|
|
void Video_UpdateXFB(u8* _pXFB, u32 _dwWidth, u32 _dwHeight, s32 _dwYOffset)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2008-10-15 14:07:03 +00:00
|
|
|
if(g_Config.bUseXFB)
|
|
|
|
{
|
|
|
|
XFB_Draw(_pXFB, _dwWidth, _dwHeight, _dwYOffset);
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
2008-08-10 21:34:22 +00:00
|
|
|
|
|
|
|
void Video_AddMessage(const char* pstr, u32 milliseconds)
|
|
|
|
{
|
|
|
|
Renderer::AddMessage(pstr,milliseconds);
|
2008-11-16 20:09:13 +00:00
|
|
|
}
|