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-08-25 19:44:11 +00:00
|
|
|
#if defined(__APPLE__)
|
2008-08-26 23:32:54 +00:00
|
|
|
#include <SDL.h>
|
2008-08-12 23:17:29 +00:00
|
|
|
#endif
|
|
|
|
|
2008-07-23 15:20:36 +00:00
|
|
|
#include "GUI/ConfigDlg.h"
|
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-10-15 14:07:03 +00:00
|
|
|
|
2008-08-26 23:40:18 +00:00
|
|
|
#include "VideoState.h"
|
2008-10-09 18:47:53 +00:00
|
|
|
#include "Debugger/Debugger.h" // for the CDebugger class
|
2008-08-26 23:40:18 +00:00
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
SVideoInitialize g_VideoInitialize;
|
|
|
|
#define VERSION_STRING "0.1"
|
|
|
|
|
2008-10-09 18:47:53 +00:00
|
|
|
// Create debugging window. We can't use Show() here as usual because then DLL_PROCESS_DETACH will
|
|
|
|
// be called immediately. And if we use ShowModal() we block the main video window from appearing.
|
|
|
|
// So I've made a separate function called DoDllDebugger() that creates the window.
|
|
|
|
CDebugger* m_frame;
|
|
|
|
void DllDebugger(HWND _hParent)
|
|
|
|
{
|
|
|
|
if(m_frame) // if we have created it, let us show it again
|
|
|
|
{
|
|
|
|
m_frame->Show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox(_T("The debugging window will open after you start a game."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoDllDebugger()
|
|
|
|
{
|
|
|
|
m_frame = new CDebugger(NULL);
|
|
|
|
m_frame->Show();
|
|
|
|
}
|
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
void GetDllInfo (PLUGIN_INFO* _PluginInfo)
|
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_VIDEO;
|
|
|
|
#ifdef DEBUGFAST
|
2008-07-16 12:17:20 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OGL (DebugFast) " VERSION_STRING);
|
2008-07-12 17:40:22 +00:00
|
|
|
#else
|
|
|
|
#ifndef _DEBUG
|
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OGL " VERSION_STRING);
|
|
|
|
#else
|
2008-07-16 12:17:20 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OGL (Debug) " VERSION_STRING);
|
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-07-23 15:20:36 +00:00
|
|
|
wxWindow win;
|
2008-08-05 08:49:27 +00:00
|
|
|
win.SetHWND(_hParent);
|
2008-08-06 09:48:54 +00:00
|
|
|
ConfigDialog frame(&win);
|
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++;
|
|
|
|
frame.AddFSReso(szBuffer);
|
|
|
|
frame.AddWindowReso(szBuffer);
|
|
|
|
}
|
2008-08-06 09:48:54 +00:00
|
|
|
ZeroMemory(&dmi, sizeof(dmi));
|
|
|
|
}
|
2008-07-23 15:20:36 +00:00
|
|
|
frame.ShowModal();
|
2008-08-05 08:49:27 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Renderer::AddMessage("Dolphin OpenGL Video Plugin v" VERSION_STRING ,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-08-28 07:58:04 +00:00
|
|
|
//PanicAlert("Saving/Loading state from OpenGL");
|
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-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-10-25 13:27:28 +00:00
|
|
|
VertexLoaderManager::Shutdown();
|
2008-07-12 17:40:22 +00:00
|
|
|
VertexShaderMngr::Shutdown();
|
|
|
|
PixelShaderMngr::Shutdown();
|
|
|
|
Fifo_Shutdown();
|
|
|
|
VertexManager::Destroy();
|
|
|
|
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;
|
|
|
|
sprintf(str, "Dolphin OGL " VERSION_STRING);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL Video_Screenshot(TCHAR* _szFilename)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|