2009-04-03 08:35:49 -06:00
|
|
|
// Copyright (C) 2003-2009 Dolphin Project.
|
2008-12-07 22:25:12 -07: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 07:36:33 -06:00
|
|
|
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-06-06 07:36:33 -06:00
|
|
|
// OpenGL Plugin Documentation
|
2009-06-15 00:39:26 -06:00
|
|
|
/*
|
2009-06-06 07:36:33 -06:00
|
|
|
|
|
|
|
1.1 Display settings
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-06-06 07:36:33 -06: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.
|
|
|
|
|
2009-06-08 14:07:20 -06:00
|
|
|
Todo: Make the internal resolution option apply instantly, currently only the native and 2x option
|
|
|
|
applies instantly. To do this we need to enumerate all avaliable display resolutions before
|
|
|
|
Renderer:Init().
|
2009-06-06 07:36:33 -06:00
|
|
|
|
2009-06-07 05:51:53 -06:00
|
|
|
1.2 Screenshots
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-06-07 05:51:53 -06: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.
|
|
|
|
|
|
|
|
Todo: Render AA and wireframe to a separate picture used for the screenshot in addition to the one
|
|
|
|
for display.
|
|
|
|
|
|
|
|
1.3 AA
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-06-07 05:51:53 -06:00
|
|
|
|
|
|
|
Make AA apply instantly during gameplay if possible
|
|
|
|
|
2009-06-15 00:39:26 -06:00
|
|
|
*/
|
2009-06-06 07:36:33 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "Globals.h"
|
2009-07-12 15:58:32 -06:00
|
|
|
#include "LogManager.h"
|
|
|
|
#include "Thread.h"
|
2009-07-12 23:38:34 -06:00
|
|
|
#include "Atomic.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
|
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"
|
2009-07-02 11:11:27 -06:00
|
|
|
GFXConfigDialogOGL *m_ConfigFrame = NULL;
|
|
|
|
#include "Debugger/Debugger.h"
|
|
|
|
GFXDebuggerOGL *m_DebuggerFrame = NULL;
|
2008-12-07 22:25:12 -07:00
|
|
|
#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"
|
2009-06-22 03:31:30 -06:00
|
|
|
#include "BPStructs.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
#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-06-08 13:42:25 -06:00
|
|
|
#include "PostProcessing.h"
|
2009-02-21 05:53:10 -07:00
|
|
|
#include "OnScreenDisplay.h"
|
2009-02-21 21:24:53 -07:00
|
|
|
#include "Setup.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
|
|
|
|
#include "VideoState.h"
|
2008-12-14 16:52:01 -07:00
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
SVideoInitialize g_VideoInitialize;
|
2009-03-18 11:17:58 -06:00
|
|
|
PLUGIN_GLOBALS* globals = NULL;
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2009-02-18 23:52:01 -07:00
|
|
|
// Logging
|
|
|
|
int GLScissorX, GLScissorY, GLScissorW, GLScissorH;
|
|
|
|
|
2009-06-26 02:57:53 -06:00
|
|
|
static bool s_PluginInitialized = false;
|
|
|
|
|
2009-07-12 23:38:34 -06:00
|
|
|
static volatile u32 s_swapRequested = false;
|
2009-07-10 20:34:16 -06:00
|
|
|
static Common::Event s_swapResponseEvent;
|
|
|
|
|
2009-07-12 23:38:34 -06:00
|
|
|
static volatile u32 s_efbAccessRequested = false;
|
2009-07-11 10:52:34 -06:00
|
|
|
static Common::Event s_efbResponseEvent;
|
2009-07-02 04:16:06 -06:00
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
|
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-03-18 11:17:58 -06:00
|
|
|
globals = _pPluginGlobals;
|
|
|
|
LogManager::SetInstance((LogManager *)globals->logManager);
|
2009-01-08 05:12:15 -07:00
|
|
|
}
|
|
|
|
|
2009-07-02 11:11:27 -06:00
|
|
|
// This is used for the functions right below here which use wxwidgets
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
#ifdef _WIN32
|
2009-02-21 21:24:53 -07:00
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
|
|
|
extern HINSTANCE g_hInstance;
|
|
|
|
#endif
|
|
|
|
|
2009-07-02 11:11:27 -06:00
|
|
|
wxWindow* GetParentedWxWindow(HWND Parent)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-02-22 15:57:56 -07:00
|
|
|
#ifdef _WIN32
|
2009-07-02 11:11:27 -06:00
|
|
|
wxSetInstance((HINSTANCE)g_hInstance);
|
2009-02-22 15:04:31 -07:00
|
|
|
#endif
|
2009-07-02 11:11:27 -06:00
|
|
|
wxWindow *win = new wxWindow();
|
2009-02-23 14:38:06 -07:00
|
|
|
#ifdef _WIN32
|
2009-07-02 11:11:27 -06:00
|
|
|
win->SetHWND((WXHWND)Parent);
|
|
|
|
win->AdoptAttributesFromHWND();
|
|
|
|
#endif
|
|
|
|
return win;
|
|
|
|
}
|
2009-02-22 15:04:31 -07:00
|
|
|
#endif
|
2009-02-23 14:38:06 -07:00
|
|
|
|
2009-07-02 11:11:27 -06:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
void DllDebugger(HWND _hParent, bool Show)
|
|
|
|
{
|
|
|
|
if (!m_DebuggerFrame)
|
|
|
|
m_DebuggerFrame = new GFXDebuggerOGL(GetParentedWxWindow(_hParent));
|
2009-02-22 15:57:56 -07:00
|
|
|
|
2009-07-02 11:11:27 -06:00
|
|
|
if (Show)
|
|
|
|
m_DebuggerFrame->ShowModal();
|
|
|
|
else
|
|
|
|
m_DebuggerFrame->Hide();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void DllDebugger(HWND _hParent, bool Show) { }
|
2009-02-23 14:38:06 -07:00
|
|
|
#endif
|
2009-02-21 21:24:53 -07:00
|
|
|
|
2009-07-02 11:11:27 -06:00
|
|
|
void DllConfig(HWND _hParent)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
if (!m_ConfigFrame)
|
|
|
|
m_ConfigFrame = new GFXConfigDialogOGL(GetParentedWxWindow(_hParent));
|
2009-07-02 21:01:58 -06:00
|
|
|
else if (!m_ConfigFrame->GetParent()->IsShown())
|
|
|
|
m_ConfigFrame->Close(true);
|
2009-07-02 11:11:27 -06:00
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
2009-02-21 22:21:54 -07:00
|
|
|
// Search for avaliable resolutions
|
2009-06-15 00:39:26 -06:00
|
|
|
|
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
|
|
|
|
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-07-02 11:11:27 -06:00
|
|
|
m_ConfigFrame->AddFSReso(szBuffer);
|
|
|
|
m_ConfigFrame->AddWindowReso(szBuffer);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
ZeroMemory(&dmi, sizeof(dmi));
|
|
|
|
}
|
2009-02-19 04:28:55 -07:00
|
|
|
|
2009-07-02 11:11:27 -06:00
|
|
|
#elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_XXF86VM) && HAVE_XXF86VM
|
2009-01-14 23:48:15 -07:00
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
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
|
|
|
{
|
2009-03-05 16:11:13 -07:00
|
|
|
if (px != modes[i]->hdisplay && py != modes[i]->vdisplay)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
char temp[32];
|
|
|
|
sprintf(temp,"%dx%d", modes[i]->hdisplay, modes[i]->vdisplay);
|
2009-07-02 11:11:27 -06:00
|
|
|
m_ConfigFrame->AddFSReso(temp);
|
|
|
|
m_ConfigFrame->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-07-02 11:11:27 -06:00
|
|
|
|
|
|
|
#elif defined(HAVE_COCOA) && HAVE_COCOA
|
2009-05-15 02:55:46 -06:00
|
|
|
|
|
|
|
CFArrayRef modes;
|
|
|
|
CFRange range;
|
|
|
|
CFDictionaryRef modesDict;
|
|
|
|
CFNumberRef modeValue;
|
|
|
|
|
|
|
|
int modeWidth;
|
|
|
|
int modeHeight;
|
|
|
|
int modeBpp;
|
|
|
|
int modeIndex;
|
|
|
|
int px = 0, py = 0;
|
|
|
|
|
|
|
|
|
|
|
|
modes = CGDisplayAvailableModes(CGMainDisplayID());
|
|
|
|
|
|
|
|
range.location = 0;
|
|
|
|
range.length = CFArrayGetCount(modes);
|
|
|
|
|
|
|
|
for (modeIndex=0; modeIndex<range.length; modeIndex++)
|
|
|
|
{
|
|
|
|
modesDict = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, modeIndex);
|
|
|
|
modeValue = (CFNumberRef) CFDictionaryGetValue(modesDict, kCGDisplayWidth);
|
|
|
|
CFNumberGetValue(modeValue, kCFNumberLongType, &modeWidth);
|
|
|
|
modeValue = (CFNumberRef) CFDictionaryGetValue(modesDict, kCGDisplayHeight);
|
|
|
|
CFNumberGetValue(modeValue, kCFNumberLongType, &modeHeight);
|
|
|
|
modeValue = (CFNumberRef) CFDictionaryGetValue(modesDict, kCGDisplayBitsPerPixel);
|
|
|
|
CFNumberGetValue(modeValue, kCFNumberLongType, &modeBpp);
|
|
|
|
|
|
|
|
if (px != modeWidth && py != modeHeight)
|
|
|
|
{
|
|
|
|
char temp[32];
|
|
|
|
sprintf(temp,"%dx%d", modeWidth, modeHeight);
|
2009-07-02 11:11:27 -06:00
|
|
|
m_ConfigFrame->AddFSReso(temp);
|
|
|
|
m_ConfigFrame->AddWindowReso(temp);//Add same to Window ones, since they should be nearly all that's needed
|
2009-05-15 02:55:46 -06:00
|
|
|
px = modeWidth;
|
|
|
|
py = modeHeight;
|
|
|
|
}
|
|
|
|
}
|
2009-02-23 14:38:06 -07:00
|
|
|
#endif
|
2009-07-02 11:11:27 -06:00
|
|
|
|
2009-02-23 14:38:06 -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-07-02 11:11:27 -06:00
|
|
|
if (m_ConfigFrame->arrayStringFor_FullscreenCB.size() == 0)
|
2009-02-23 14:38:06 -07:00
|
|
|
{
|
2009-07-02 11:11:27 -06:00
|
|
|
m_ConfigFrame->AddFSReso("<No resolutions found>");
|
|
|
|
m_ConfigFrame->AddWindowReso("<No resolutions found>");
|
2009-02-23 14:38:06 -07:00
|
|
|
}
|
|
|
|
|
2009-07-02 11:11:27 -06:00
|
|
|
// Only allow one open at a time
|
|
|
|
if (!m_ConfigFrame->IsShown())
|
|
|
|
{
|
|
|
|
m_ConfigFrame->CreateGUIControls();
|
|
|
|
m_ConfigFrame->ShowModal();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_ConfigFrame->Hide();
|
|
|
|
#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-03-20 05:51:22 -06:00
|
|
|
g_Config.GameIniLoad();
|
2009-06-03 17:38:31 -06:00
|
|
|
g_Config.UpdateProjectionHack();
|
2009-03-20 05:51:22 -06:00
|
|
|
|
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
|
2009-02-22 13:21:56 -07:00
|
|
|
TextureMngr::Invalidate(false);
|
2008-12-07 22:25:12 -07:00
|
|
|
VertexLoaderManager::MarkAllDirty();
|
|
|
|
|
|
|
|
PointerWrap p(ptr, mode);
|
|
|
|
VideoCommon_DoState(p);
|
|
|
|
|
|
|
|
// Refresh state.
|
2009-02-09 13:35:30 -07:00
|
|
|
if (mode == PointerWrap::MODE_READ)
|
|
|
|
{
|
2009-06-22 03:31:30 -06: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();
|
|
|
|
|
2009-06-22 03:31:30 -06:00
|
|
|
BPInit();
|
2008-12-07 22:25:12 -07:00
|
|
|
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();
|
2009-06-08 13:42:25 -06:00
|
|
|
PostProcessing::Init();
|
2008-12-07 22:25:12 -07:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
VertexLoaderManager::Init();
|
|
|
|
TextureConverter::Init();
|
2009-06-26 02:57:53 -06:00
|
|
|
|
2009-07-10 20:34:16 -06:00
|
|
|
s_swapRequested = false;
|
|
|
|
s_swapResponseEvent.Init();
|
|
|
|
s_swapResponseEvent.Set();
|
|
|
|
|
2009-07-11 10:52:34 -06:00
|
|
|
s_efbAccessRequested = false;
|
|
|
|
s_efbResponseEvent.Init();
|
|
|
|
|
2009-06-26 02:57:53 -06:00
|
|
|
s_PluginInitialized = true;
|
2009-03-10 16:51:17 -06:00
|
|
|
INFO_LOG(VIDEO, "Video plugin initialized.");
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void Shutdown(void)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-06-26 02:57:53 -06:00
|
|
|
s_PluginInitialized = false;
|
|
|
|
|
2009-07-12 23:38:34 -06:00
|
|
|
s_efbAccessRequested = FALSE;
|
2009-07-11 10:52:34 -06:00
|
|
|
s_efbResponseEvent.Shutdown();
|
|
|
|
|
2009-07-12 23:38:34 -06:00
|
|
|
s_swapRequested = FALSE;
|
2009-07-10 20:34:16 -06:00
|
|
|
s_swapResponseEvent.Shutdown();
|
|
|
|
|
2009-02-21 21:24:53 -07:00
|
|
|
Fifo_Shutdown();
|
2009-06-08 13:42:25 -06:00
|
|
|
PostProcessing::Shutdown();
|
2009-02-22 15:57:56 -07:00
|
|
|
TextureConverter::Shutdown();
|
2009-02-21 21:24:53 -07:00
|
|
|
VertexLoaderManager::Shutdown();
|
|
|
|
VertexShaderCache::Shutdown();
|
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
PixelShaderCache::Shutdown();
|
|
|
|
VertexManager::Shutdown();
|
2009-02-22 13:21:56 -07:00
|
|
|
TextureMngr::Shutdown();
|
2009-02-21 21:24:53 -07:00
|
|
|
OpcodeDecoder_Shutdown();
|
2009-02-22 15:57:56 -07:00
|
|
|
Renderer::Shutdown();
|
2009-02-21 21:24:53 -07:00
|
|
|
OpenGL_Shutdown();
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-06-14 22:30:02 -06:00
|
|
|
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-02-21 21:24:53 -07:00
|
|
|
// Enter and exit the video loop
|
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
|
|
|
}
|
2009-04-03 08:35:49 -06:00
|
|
|
|
2009-02-21 21:24:53 -07:00
|
|
|
|
2009-06-15 00:39:26 -06:00
|
|
|
|
|
|
|
|
2009-06-14 22:30:02 -06:00
|
|
|
// Screenshot and screen message
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-02-26 20:56:34 -07:00
|
|
|
void Video_Screenshot(const char *_szFilename)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-02-26 20:56:34 -07:00
|
|
|
Renderer::SetScreenshot(_szFilename);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-06-14 22:30:02 -06:00
|
|
|
void Video_AddMessage(const char* pstr, u32 milliseconds)
|
|
|
|
{
|
|
|
|
OSD::AddMessage(pstr, milliseconds);
|
|
|
|
}
|
|
|
|
|
2009-07-10 20:34:16 -06:00
|
|
|
static volatile struct
|
|
|
|
{
|
2009-06-29 01:30:48 -06:00
|
|
|
u32 xfbAddr;
|
2009-07-10 20:34:16 -06:00
|
|
|
FieldType field;
|
|
|
|
u32 fbWidth;
|
|
|
|
u32 fbHeight;
|
2009-07-11 10:52:34 -06:00
|
|
|
} s_beginFieldArgs;
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-07-10 20:34:16 -06:00
|
|
|
// Run from the graphics thread (from Fifo.cpp)
|
|
|
|
void VideoFifo_CheckSwapRequest()
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-07-12 23:38:34 -06:00
|
|
|
if (Common::AtomicLoadAcquire(s_swapRequested))
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-07-12 23:38:34 -06:00
|
|
|
s_swapRequested = FALSE;
|
2009-06-26 02:57:53 -06:00
|
|
|
|
2009-07-10 20:34:16 -06:00
|
|
|
Renderer::Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.field, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight);
|
2009-06-26 02:57:53 -06:00
|
|
|
|
2009-07-10 20:34:16 -06:00
|
|
|
// TODO: Find better name for this because I don't know if it means what it says.
|
|
|
|
g_VideoInitialize.pCopiedToXFB();
|
2009-06-26 02:57:53 -06:00
|
|
|
|
2009-07-10 20:34:16 -06:00
|
|
|
s_swapResponseEvent.Set();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool addrRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(aLower >= bLower && aLower < bUpper) ||
|
|
|
|
(aUpper >= bLower && aUpper < bUpper) ||
|
|
|
|
(bLower >= aLower && bLower < aUpper) ||
|
|
|
|
(bUpper >= aLower && bUpper < aUpper)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the graphics thread (from Fifo.cpp)
|
|
|
|
void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
|
|
|
|
{
|
2009-07-12 23:38:34 -06:00
|
|
|
if (Common::AtomicLoadAcquire(s_swapRequested))
|
2009-07-10 20:34:16 -06:00
|
|
|
{
|
|
|
|
u32 aLower = xfbAddr;
|
|
|
|
u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight;
|
|
|
|
u32 bLower = s_beginFieldArgs.xfbAddr;
|
|
|
|
u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight;
|
|
|
|
|
|
|
|
if (addrRangesOverlap(aLower, aUpper, bLower, bUpper))
|
|
|
|
VideoFifo_CheckSwapRequest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
|
|
|
void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
|
|
|
{
|
|
|
|
if (s_PluginInitialized)
|
|
|
|
{
|
2009-07-11 10:52:34 -06:00
|
|
|
if (g_VideoInitialize.bUseDualCore)
|
|
|
|
s_swapResponseEvent.MsgWait();
|
|
|
|
else
|
|
|
|
VideoFifo_CheckSwapRequest();
|
2009-07-10 20:34:16 -06:00
|
|
|
|
|
|
|
s_beginFieldArgs.xfbAddr = xfbAddr;
|
|
|
|
s_beginFieldArgs.field = field;
|
|
|
|
s_beginFieldArgs.fbWidth = fbWidth;
|
|
|
|
s_beginFieldArgs.fbHeight = fbHeight;
|
|
|
|
|
2009-07-12 23:38:34 -06:00
|
|
|
Common::AtomicStoreRelease(s_swapRequested, TRUE);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
}
|
2009-06-15 00:39:26 -06:00
|
|
|
|
2009-07-11 10:52:34 -06:00
|
|
|
static volatile struct
|
|
|
|
{
|
|
|
|
EFBAccessType type;
|
|
|
|
u32 x;
|
|
|
|
u32 y;
|
|
|
|
} s_accessEFBArgs;
|
|
|
|
|
|
|
|
static volatile u32 s_AccessEFBResult = 0;
|
|
|
|
|
|
|
|
void VideoFifo_CheckEFBAccess()
|
2009-07-01 07:49:49 -06:00
|
|
|
{
|
2009-07-12 23:38:34 -06:00
|
|
|
if (Common::AtomicLoadAcquire(s_efbAccessRequested))
|
2009-07-12 16:22:48 -06:00
|
|
|
{
|
2009-07-12 23:38:34 -06:00
|
|
|
s_efbAccessRequested = FALSE;
|
2009-07-02 04:16:06 -06:00
|
|
|
|
2009-07-12 16:22:48 -06:00
|
|
|
switch (s_accessEFBArgs.type)
|
2009-07-01 07:49:49 -06:00
|
|
|
{
|
2009-07-12 16:22:48 -06:00
|
|
|
case PEEK_Z:
|
2009-07-01 07:49:49 -06:00
|
|
|
{
|
2009-07-12 16:22:48 -06:00
|
|
|
u32 z = 0;
|
|
|
|
float xScale = Renderer::GetTargetScaleX();
|
|
|
|
float yScale = Renderer::GetTargetScaleY();
|
|
|
|
|
|
|
|
if (g_Config.iMultisampleMode != MULTISAMPLE_OFF)
|
|
|
|
{
|
|
|
|
// Find the proper dimensions
|
|
|
|
TRectangle source, scaledTargetSource;
|
|
|
|
ComputeBackbufferRectangle(&source);
|
|
|
|
source.Scale(xScale, yScale, &scaledTargetSource);
|
|
|
|
// This will resolve and bind to the depth buffer
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Renderer::ResolveAndGetDepthTarget(scaledTargetSource));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the z value! Also adjust the pixel to read to the upscaled EFB resolution
|
|
|
|
// Plus we need to flip the y value as the OGL image is upside down
|
|
|
|
glReadPixels(s_accessEFBArgs.x*xScale, Renderer::GetTargetHeight() - s_accessEFBArgs.y*yScale, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &z);
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
|
|
|
// Clamp the 32bits value returned by glReadPixels to a 24bits value (GC uses a 24bits Z-Buffer)
|
|
|
|
s_AccessEFBResult = z / 0x100;
|
|
|
|
|
|
|
|
// We should probably re-bind the old fbo here.
|
|
|
|
if (g_Config.iMultisampleMode != MULTISAMPLE_OFF) {
|
|
|
|
Renderer::SetFramebuffer(0);
|
|
|
|
}
|
2009-07-02 14:06:39 -06:00
|
|
|
}
|
2009-07-12 16:22:48 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POKE_Z:
|
|
|
|
// TODO: Implement
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PEEK_COLOR:
|
|
|
|
// TODO: Implement
|
|
|
|
s_AccessEFBResult = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POKE_COLOR:
|
|
|
|
// TODO: Implement. One way is to draw a tiny pixel-sized rectangle at
|
|
|
|
// the exact location. Note: EFB pokes are susceptible to Z-buffering
|
|
|
|
// and perhaps blending.
|
|
|
|
//WARN_LOG(VIDEOINTERFACE, "This is probably some kind of software rendering");
|
|
|
|
break;
|
2009-07-01 07:49:49 -06:00
|
|
|
}
|
2009-07-03 09:35:31 -06:00
|
|
|
|
2009-07-12 16:22:48 -06:00
|
|
|
s_efbResponseEvent.Set();
|
|
|
|
}
|
2009-07-02 04:16:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 Video_AccessEFB(EFBAccessType type, u32 x, u32 y)
|
|
|
|
{
|
2009-07-11 14:39:28 -06:00
|
|
|
if (s_PluginInitialized)
|
|
|
|
{
|
|
|
|
s_accessEFBArgs.type = type;
|
|
|
|
s_accessEFBArgs.x = x;
|
|
|
|
s_accessEFBArgs.y = y;
|
2009-07-02 04:16:06 -06:00
|
|
|
|
2009-07-12 23:38:34 -06:00
|
|
|
Common::AtomicStoreRelease(s_efbAccessRequested, TRUE);
|
2009-07-02 04:16:06 -06:00
|
|
|
|
2009-07-11 14:39:28 -06:00
|
|
|
if (g_VideoInitialize.bUseDualCore)
|
|
|
|
s_efbResponseEvent.MsgWait();
|
|
|
|
else
|
|
|
|
VideoFifo_CheckEFBAccess();
|
2009-07-02 04:16:06 -06:00
|
|
|
|
2009-07-11 14:39:28 -06:00
|
|
|
return s_AccessEFBResult;
|
|
|
|
}
|
2009-07-03 04:00:09 -06:00
|
|
|
|
2009-07-11 14:39:28 -06:00
|
|
|
return 0;
|
2009-07-01 07:49:49 -06:00
|
|
|
}
|
|
|
|
|