2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// 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-06-06 13:36:33 +00:00
|
|
|
|
2009-06-15 06:39:26 +00:00
|
|
|
|
2009-06-06 13:36:33 +00:00
|
|
|
// OpenGL Plugin Documentation
|
2009-06-15 06:39:26 +00:00
|
|
|
/*
|
2009-06-06 13:36:33 +00:00
|
|
|
|
|
|
|
1.1 Display settings
|
2009-06-15 06:39:26 +00:00
|
|
|
|
2009-09-09 19:52:45 +00:00
|
|
|
Internal and fullscreen resolution: Since the only internal resolutions allowed
|
|
|
|
are also fullscreen resolution allowed by the system there is only need for one
|
|
|
|
resolution setting that applies to both the internal resolution and the
|
|
|
|
fullscreen resolution. - Apparently no, someone else doesn't agree
|
2009-06-06 13:36:33 +00:00
|
|
|
|
2009-09-09 19:52:45 +00:00
|
|
|
Todo: Make the internal resolution option apply instantly, currently only the
|
|
|
|
native and 2x option applies instantly. To do this we need to be able to change
|
|
|
|
the reinitialize FramebufferManager:Init() while a game is running.
|
2009-06-06 13:36:33 +00:00
|
|
|
|
2009-06-07 11:51:53 +00:00
|
|
|
1.2 Screenshots
|
2009-06-15 06:39:26 +00:00
|
|
|
|
2009-06-07 11:51:53 +00:00
|
|
|
|
2009-09-09 19:52:45 +00:00
|
|
|
The screenshots should be taken from the internal representation of the picture
|
|
|
|
regardless of what the current window size is. Since AA and wireframe is
|
|
|
|
applied together with the picture resizing this rule is not currently applied
|
|
|
|
to AA or wireframe pictures, they are instead taken from whatever the window
|
|
|
|
size is.
|
2009-06-07 11:51:53 +00:00
|
|
|
|
2009-09-09 19:52:45 +00:00
|
|
|
Todo: Render AA and wireframe to a separate picture used for the screenshot in
|
|
|
|
addition to the one for display.
|
2009-06-07 11:51:53 +00:00
|
|
|
|
|
|
|
1.3 AA
|
2009-06-15 06:39:26 +00:00
|
|
|
|
2009-06-07 11:51:53 +00:00
|
|
|
Make AA apply instantly during gameplay if possible
|
|
|
|
|
2009-06-15 06:39:26 +00:00
|
|
|
*/
|
2009-06-06 13:36:33 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "Globals.h"
|
2009-07-13 05:38:34 +00:00
|
|
|
#include "Atomic.h"
|
2010-09-30 15:24:34 +00:00
|
|
|
#include "Thread.h"
|
|
|
|
#include "LogManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-01-11 13:37:13 +00:00
|
|
|
#include <cstdarg>
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
#ifdef _WIN32
|
2010-12-19 19:43:18 +00:00
|
|
|
#include "EmuWindow.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-11-15 09:54:07 +00:00
|
|
|
#include "VideoConfigDiag.h"
|
2010-12-05 14:15:36 +00:00
|
|
|
#include "DebuggerPanel.h"
|
2009-07-26 09:52:35 +00:00
|
|
|
#endif // HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
#include "MainBase.h"
|
2009-09-13 09:23:30 +00:00
|
|
|
#include "VideoConfig.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "LookUpTables.h"
|
|
|
|
#include "ImageWrite.h"
|
|
|
|
#include "Render.h"
|
|
|
|
#include "GLUtil.h"
|
|
|
|
#include "Fifo.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
2010-09-28 02:15:02 +00:00
|
|
|
#include "TextureCache.h"
|
2009-06-22 09:31:30 +00:00
|
|
|
#include "BPStructs.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "VertexLoader.h"
|
|
|
|
#include "VertexLoaderManager.h"
|
|
|
|
#include "VertexManager.h"
|
2008-12-26 11:23:59 +00:00
|
|
|
#include "PixelShaderCache.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "PixelShaderManager.h"
|
2008-12-26 11:23:59 +00:00
|
|
|
#include "VertexShaderCache.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "VertexShaderManager.h"
|
|
|
|
#include "XFBConvert.h"
|
2009-10-10 21:19:39 +00:00
|
|
|
#include "CommandProcessor.h"
|
|
|
|
#include "PixelEngine.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "TextureConverter.h"
|
2009-06-08 19:42:25 +00:00
|
|
|
#include "PostProcessing.h"
|
2009-02-21 12:53:10 +00:00
|
|
|
#include "OnScreenDisplay.h"
|
2009-02-22 04:24:53 +00:00
|
|
|
#include "Setup.h"
|
2009-08-09 11:03:58 +00:00
|
|
|
#include "DLCache.h"
|
2010-11-18 02:21:26 +00:00
|
|
|
#include "FramebufferManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "VideoState.h"
|
2008-12-14 23:52:01 +00:00
|
|
|
|
2009-02-19 06:52:01 +00:00
|
|
|
// Logging
|
|
|
|
int GLScissorX, GLScissorY, GLScissorW, GLScissorH;
|
|
|
|
|
2010-12-19 19:43:18 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
class wxDLLApp : public wxApp
|
|
|
|
{
|
|
|
|
bool OnInit()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
2010-08-04 21:02:32 +00:00
|
|
|
#endif
|
2010-12-19 19:43:18 +00:00
|
|
|
// ------------------
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2010-12-19 19:43:18 +00:00
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
|
|
|
|
DWORD dwReason, // reason called
|
|
|
|
LPVOID lpvReserved) // reserved
|
|
|
|
{
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
{
|
2010-09-30 15:24:34 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-12-19 19:43:18 +00:00
|
|
|
wxSetInstance((HINSTANCE)hinstDLL);
|
|
|
|
wxInitialize();
|
2010-09-30 15:24:34 +00:00
|
|
|
#endif
|
2010-12-19 19:43:18 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
wxUninitialize();
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif // _WIN32
|
|
|
|
|
2010-09-30 15:24:34 +00:00
|
|
|
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-02-25 06:12:35 +00:00
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_VIDEO;
|
2009-01-15 06:48:15 +00:00
|
|
|
#ifdef DEBUGFAST
|
2010-02-25 12:35:31 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL (DebugFast)");
|
2009-09-09 19:52:45 +00:00
|
|
|
#elif defined _DEBUG
|
2010-02-25 12:35:31 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL (Debug)");
|
2008-12-08 05:25:12 +00:00
|
|
|
#else
|
2010-02-25 12:35:31 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin OpenGL");
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-21 12:25:43 +00:00
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
globals = _pPluginGlobals;
|
2010-06-16 10:12:57 +00:00
|
|
|
LogManager::SetInstance((LogManager*)globals->logManager);
|
2009-01-08 12:12:15 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 02:05:28 +00:00
|
|
|
void *DllDebugger(void *_hParent, bool Show)
|
2009-07-02 17:11:27 +00:00
|
|
|
{
|
2009-09-09 19:52:45 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-12-05 14:15:36 +00:00
|
|
|
return new GFXDebuggerPanel((wxWindow *)_hParent);
|
2010-07-22 02:05:28 +00:00
|
|
|
#else
|
|
|
|
return NULL;
|
2009-02-23 21:38:06 +00:00
|
|
|
#endif
|
2009-09-09 19:52:45 +00:00
|
|
|
}
|
2009-02-22 04:24:53 +00:00
|
|
|
|
2010-11-15 09:54:07 +00:00
|
|
|
void GetShaders(std::vector<std::string> &shaders)
|
|
|
|
{
|
|
|
|
shaders.clear();
|
|
|
|
if (File::IsDirectory(File::GetUserPath(D_SHADERS_IDX)))
|
|
|
|
{
|
|
|
|
File::FSTEntry entry;
|
|
|
|
File::ScanDirectoryTree(File::GetUserPath(D_SHADERS_IDX), entry);
|
|
|
|
for (u32 i = 0; i < entry.children.size(); i++)
|
|
|
|
{
|
|
|
|
std::string name = entry.children[i].virtualName.c_str();
|
|
|
|
if (!strcasecmp(name.substr(name.size() - 4).c_str(), ".txt"))
|
|
|
|
name = name.substr(0, name.size() - 4);
|
|
|
|
shaders.push_back(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
File::CreateDir(File::GetUserPath(D_SHADERS_IDX));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-22 22:17:35 +00:00
|
|
|
void InitBackendInfo()
|
2009-09-09 19:52:45 +00:00
|
|
|
{
|
2010-11-21 14:47:28 +00:00
|
|
|
g_Config.backend_info.APIType = API_OPENGL;
|
|
|
|
g_Config.backend_info.bUseRGBATextures = false;
|
|
|
|
g_Config.backend_info.bSupportsEFBToRAM = true;
|
|
|
|
g_Config.backend_info.bSupportsRealXFB = true;
|
2010-11-24 17:13:12 +00:00
|
|
|
g_Config.backend_info.bSupports3DVision = false;
|
2010-11-21 14:47:28 +00:00
|
|
|
g_Config.backend_info.bAllowSignedBytes = true;
|
2010-12-05 14:15:36 +00:00
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = false; // supported, but broken
|
2010-11-22 22:17:35 +00:00
|
|
|
}
|
2009-09-09 19:52:45 +00:00
|
|
|
|
2010-11-22 22:17:35 +00:00
|
|
|
void DllConfig(void *_hParent)
|
|
|
|
{
|
2010-11-21 14:47:28 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-11-22 22:17:35 +00:00
|
|
|
InitBackendInfo();
|
|
|
|
|
|
|
|
// aamodes
|
|
|
|
const char* caamodes[] = {"None", "2x", "4x", "8x", "8x CSAA", "8xQ CSAA", "16x CSAA", "16xQ CSAA"};
|
|
|
|
g_Config.backend_info.AAModes.assign(caamodes, caamodes + sizeof(caamodes)/sizeof(*caamodes));
|
|
|
|
|
|
|
|
// pp shaders
|
|
|
|
GetShaders(g_Config.backend_info.PPShaders);
|
|
|
|
|
|
|
|
VideoConfigDiag *const diag = new VideoConfigDiag((wxWindow*)_hParent, "OpenGL", "gfx_opengl");
|
2010-11-15 09:54:07 +00:00
|
|
|
diag->ShowModal();
|
|
|
|
diag->Destroy();
|
2009-07-02 17:11:27 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
void Initialize(void *init)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-11-22 22:17:35 +00:00
|
|
|
InitBackendInfo();
|
|
|
|
|
2010-02-25 06:12:35 +00:00
|
|
|
frameCount = 0;
|
|
|
|
SVideoInitialize *_pVideoInitialize = (SVideoInitialize*)init;
|
2009-09-09 19:52:45 +00:00
|
|
|
// Create a shortcut to _pVideoInitialize that can also update it
|
2010-09-28 21:28:49 +00:00
|
|
|
g_VideoInitialize = *(_pVideoInitialize);
|
2008-12-08 05:25:12 +00:00
|
|
|
InitXFBConvTables();
|
2009-09-09 19:52:45 +00:00
|
|
|
|
2010-02-25 06:12:35 +00:00
|
|
|
g_Config.Load((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_opengl.ini").c_str());
|
2009-09-13 08:54:46 +00:00
|
|
|
g_Config.GameIniLoad(globals->game_ini);
|
2009-03-20 11:51:22 +00:00
|
|
|
|
2009-08-01 18:31:25 +00:00
|
|
|
g_Config.UpdateProjectionHack();
|
2010-11-20 03:24:51 +00:00
|
|
|
#if defined _WIN32
|
|
|
|
// Enable support for PNG screenshots.
|
|
|
|
wxImage::AddHandler( new wxPNGHandler );
|
|
|
|
#endif
|
2009-09-13 08:21:35 +00:00
|
|
|
UpdateActiveConfig();
|
2009-07-31 01:55:26 +00:00
|
|
|
|
2010-02-25 06:12:35 +00:00
|
|
|
if (!OpenGL_Create(g_VideoInitialize, 640, 480))
|
2010-01-20 19:51:13 +00:00
|
|
|
{
|
2010-02-25 06:12:35 +00:00
|
|
|
g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2009-02-21 12:25:43 +00:00
|
|
|
|
|
|
|
_pVideoInitialize->pPeekMessages = g_VideoInitialize.pPeekMessages;
|
2010-02-25 06:12:35 +00:00
|
|
|
_pVideoInitialize->pUpdateFPSDisplay = g_VideoInitialize.pUpdateFPSDisplay;
|
2009-01-04 21:53:41 +00:00
|
|
|
|
|
|
|
// Now the window handle is written
|
2010-02-25 06:12:35 +00:00
|
|
|
_pVideoInitialize->pWindowHandle = g_VideoInitialize.pWindowHandle;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-09-28 21:28:49 +00:00
|
|
|
OSD::AddMessage("Dolphin OpenGL Video Plugin.", 5000);
|
2010-09-28 02:15:02 +00:00
|
|
|
s_PluginInitialized = true;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2010-09-30 15:24:34 +00:00
|
|
|
// This is called after Initialize() from the Core
|
|
|
|
// Run from the graphics thread
|
|
|
|
void Video_Prepare()
|
|
|
|
{
|
|
|
|
OpenGL_MakeCurrent();
|
2010-11-18 02:21:26 +00:00
|
|
|
//if (!Renderer::Init()) {
|
|
|
|
// g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE);
|
|
|
|
// PanicAlert("Can't create opengl renderer. You might be missing some required opengl extensions, check the logs for more info");
|
|
|
|
// exit(1);
|
|
|
|
//}
|
|
|
|
|
|
|
|
g_renderer = new OGL::Renderer;
|
2010-09-30 15:24:34 +00:00
|
|
|
|
|
|
|
s_efbAccessRequested = FALSE;
|
|
|
|
s_FifoShuttingDown = FALSE;
|
|
|
|
s_swapRequested = FALSE;
|
|
|
|
|
2010-09-30 16:11:31 +00:00
|
|
|
CommandProcessor::Init();
|
|
|
|
PixelEngine::Init();
|
|
|
|
|
2010-10-19 22:24:27 +00:00
|
|
|
g_texture_cache = new OGL::TextureCache;
|
2010-09-30 16:11:31 +00:00
|
|
|
|
2010-09-30 15:24:34 +00:00
|
|
|
BPInit();
|
2010-10-03 00:41:06 +00:00
|
|
|
g_vertex_manager = new OGL::VertexManager;
|
2010-09-30 16:11:31 +00:00
|
|
|
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
2010-09-30 15:24:34 +00:00
|
|
|
OpcodeDecoder_Init();
|
|
|
|
VertexShaderCache::Init();
|
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderCache::Init();
|
|
|
|
PixelShaderManager::Init();
|
|
|
|
PostProcessing::Init();
|
2010-09-30 16:11:31 +00:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
VertexLoaderManager::Init();
|
2010-09-30 15:24:34 +00:00
|
|
|
TextureConverter::Init();
|
|
|
|
DLCache::Init();
|
|
|
|
|
|
|
|
// Notify the core that the video plugin is ready
|
|
|
|
g_VideoInitialize.pCoreMessage(WM_USER_CREATE);
|
|
|
|
|
|
|
|
s_PluginInitialized = true;
|
|
|
|
INFO_LOG(VIDEO, "Video plugin initialized.");
|
2010-09-30 16:11:31 +00:00
|
|
|
|
2010-09-30 15:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
|
|
|
s_PluginInitialized = false;
|
|
|
|
|
|
|
|
s_efbAccessRequested = FALSE;
|
|
|
|
s_FifoShuttingDown = FALSE;
|
|
|
|
s_swapRequested = FALSE;
|
|
|
|
DLCache::Shutdown();
|
|
|
|
Fifo_Shutdown();
|
|
|
|
PostProcessing::Shutdown();
|
2010-09-30 16:11:31 +00:00
|
|
|
|
|
|
|
// The following calls are NOT Thread Safe
|
|
|
|
// And need to be called from the video thread
|
2010-09-30 15:24:34 +00:00
|
|
|
TextureConverter::Shutdown();
|
2010-09-30 16:11:31 +00:00
|
|
|
VertexLoaderManager::Shutdown();
|
2010-09-30 15:24:34 +00:00
|
|
|
VertexShaderCache::Shutdown();
|
2010-09-30 16:11:31 +00:00
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
PixelShaderCache::Shutdown();
|
2010-10-03 00:41:06 +00:00
|
|
|
delete g_vertex_manager;
|
2010-10-19 22:24:27 +00:00
|
|
|
delete g_texture_cache;
|
2010-09-30 16:11:31 +00:00
|
|
|
OpcodeDecoder_Shutdown();
|
2010-11-18 02:21:26 +00:00
|
|
|
delete g_renderer;
|
2010-09-30 15:24:34 +00:00
|
|
|
OpenGL_Shutdown();
|
|
|
|
}
|