2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-02-23 07:23:34 +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/
|
|
|
|
|
|
|
|
#include "Globals.h"
|
2009-07-12 21:58:32 +00:00
|
|
|
#include "Thread.h"
|
2010-01-26 14:56:51 +00:00
|
|
|
#include "Atomic.h"
|
2009-03-05 23:11:13 +00:00
|
|
|
|
2009-02-23 07:23:34 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <cmath>
|
2009-03-28 21:07:16 +00:00
|
|
|
#include <cstdio>
|
2009-02-23 07:23:34 +00:00
|
|
|
|
|
|
|
#include "GLUtil.h"
|
|
|
|
|
2010-02-02 21:56:29 +00:00
|
|
|
#include "FileUtil.h"
|
|
|
|
|
2009-02-23 07:23:34 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#endif
|
|
|
|
|
2009-03-28 21:07:16 +00:00
|
|
|
#include "CommonPaths.h"
|
2009-09-13 09:23:30 +00:00
|
|
|
#include "VideoConfig.h"
|
2009-02-23 07:23:34 +00:00
|
|
|
#include "Statistics.h"
|
|
|
|
#include "ImageWrite.h"
|
2010-10-24 19:52:52 +00:00
|
|
|
#include "PixelEngine.h"
|
2009-02-23 07:23:34 +00:00
|
|
|
#include "Render.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
2009-06-22 09:31:30 +00:00
|
|
|
#include "BPStructs.h"
|
2010-09-28 02:15:02 +00:00
|
|
|
#include "TextureCache.h"
|
2009-10-13 06:12:58 +00:00
|
|
|
#include "RasterFont.h"
|
2009-02-23 07:23:34 +00:00
|
|
|
#include "VertexShaderGen.h"
|
2009-08-09 11:03:58 +00:00
|
|
|
#include "DLCache.h"
|
2009-02-23 07:23:34 +00:00
|
|
|
#include "PixelShaderCache.h"
|
|
|
|
#include "PixelShaderManager.h"
|
2009-02-28 16:33:59 +00:00
|
|
|
#include "VertexShaderCache.h"
|
|
|
|
#include "VertexShaderManager.h"
|
2009-02-23 07:23:34 +00:00
|
|
|
#include "VertexLoaderManager.h"
|
|
|
|
#include "VertexLoader.h"
|
2009-06-08 19:42:25 +00:00
|
|
|
#include "PostProcessing.h"
|
2009-06-26 08:57:53 +00:00
|
|
|
#include "TextureConverter.h"
|
2009-02-23 07:23:34 +00:00
|
|
|
#include "OnScreenDisplay.h"
|
|
|
|
#include "Timer.h"
|
2009-06-06 13:36:33 +00:00
|
|
|
#include "StringUtil.h"
|
2009-06-28 23:35:08 +00:00
|
|
|
#include "FramebufferManager.h"
|
2009-07-11 02:34:16 +00:00
|
|
|
#include "Fifo.h"
|
2010-12-05 14:15:36 +00:00
|
|
|
#include "Debugger.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "Core.h"
|
2011-06-24 06:50:50 +00:00
|
|
|
#include "Movie.h"
|
2011-03-15 23:09:12 +00:00
|
|
|
#include "Host.h"
|
2011-09-05 20:04:28 +00:00
|
|
|
#include "BPFunctions.h"
|
2012-10-04 03:41:02 +00:00
|
|
|
#include "FPSCounter.h"
|
2012-11-11 22:57:06 +00:00
|
|
|
#include "ConfigManager.h"
|
2009-02-23 07:23:34 +00:00
|
|
|
|
|
|
|
#include "main.h" // Local
|
|
|
|
#ifdef _WIN32
|
2010-12-19 19:43:18 +00:00
|
|
|
#include "EmuWindow.h"
|
2010-11-14 21:14:26 +00:00
|
|
|
#endif
|
2011-02-11 21:30:53 +00:00
|
|
|
#if defined _WIN32 || defined HAVE_LIBAV
|
2009-03-28 21:07:16 +00:00
|
|
|
#include "AVIDump.h"
|
2011-02-11 21:30:53 +00:00
|
|
|
#endif
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2009-02-27 03:56:34 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
#include <wx/image.h>
|
|
|
|
#endif
|
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
void VideoConfig::UpdateProjectionHack()
|
|
|
|
{
|
2011-01-29 21:13:56 +00:00
|
|
|
::UpdateProjectionHack(g_Config.iPhackvalue, g_Config.sPhackvalue);
|
2011-01-29 20:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
// Screenshot thread struct
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int W, H;
|
|
|
|
std::string filename;
|
|
|
|
wxImage *img;
|
|
|
|
} ScrStrct;
|
|
|
|
#endif
|
2010-02-20 04:18:19 +00:00
|
|
|
|
2010-07-24 10:24:16 +00:00
|
|
|
#if defined HAVE_CG && HAVE_CG
|
2009-02-23 07:23:34 +00:00
|
|
|
CGcontext g_cgcontext;
|
|
|
|
CGprofile g_cgvProf;
|
|
|
|
CGprofile g_cgfProf;
|
2010-07-24 10:24:16 +00:00
|
|
|
#endif
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2011-01-31 03:02:23 +00:00
|
|
|
int OSDInternalW, OSDInternalH;
|
2011-01-29 20:16:51 +00:00
|
|
|
|
|
|
|
namespace OGL
|
|
|
|
{
|
|
|
|
|
|
|
|
// Declarations and definitions
|
|
|
|
// ----------------------------
|
2012-12-07 22:34:38 +00:00
|
|
|
static int s_fps = 0;
|
|
|
|
static GLuint s_ShowEFBCopyRegions_VBO = 0;
|
2012-12-09 21:49:58 +00:00
|
|
|
static GLuint s_ShowEFBCopyRegions_VAO = 0;
|
2012-12-08 01:01:35 +00:00
|
|
|
static GLuint s_Swap_VBO = 0;
|
2012-12-09 21:49:58 +00:00
|
|
|
static GLuint s_Swap_VAO[2];
|
2012-12-09 19:30:29 +00:00
|
|
|
static TargetRectangle s_cached_targetRc;
|
2011-01-29 20:16:51 +00:00
|
|
|
|
2012-12-07 22:34:38 +00:00
|
|
|
static RasterFont* s_pfont = NULL;
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2009-03-08 19:19:51 +00:00
|
|
|
// 1 for no MSAA. Use s_MSAASamples > 1 to check for MSAA.
|
|
|
|
static int s_MSAASamples = 1;
|
2009-03-08 20:04:40 +00:00
|
|
|
static int s_MSAACoverageSamples = 0;
|
2011-05-07 22:00:05 +00:00
|
|
|
static int s_LastMultisampleMode = 0;
|
2009-03-05 23:11:13 +00:00
|
|
|
|
2009-06-29 21:54:42 +00:00
|
|
|
bool s_bHaveFramebufferBlit = false; // export to FramebufferManager.cpp
|
2009-03-08 20:04:40 +00:00
|
|
|
static bool s_bHaveCoverageMSAA = false;
|
2009-03-08 19:19:51 +00:00
|
|
|
static u32 s_blendMode;
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-05-26 20:46:28 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2011-01-27 20:47:58 +00:00
|
|
|
static std::thread scrshotThread;
|
2010-05-26 20:46:28 +00:00
|
|
|
#endif
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2011-08-22 04:15:02 +00:00
|
|
|
// EFB cache related
|
2012-12-07 22:34:38 +00:00
|
|
|
static const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks.
|
|
|
|
static const u32 EFB_CACHE_WIDTH = (EFB_WIDTH + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; // round up
|
|
|
|
static const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE;
|
2011-08-22 04:15:02 +00:00
|
|
|
static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT];
|
|
|
|
static std::vector<u32> s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR
|
2009-07-29 03:11:35 +00:00
|
|
|
|
2009-02-23 07:23:34 +00:00
|
|
|
static const GLenum glSrcFactors[8] =
|
|
|
|
{
|
2010-06-05 01:38:22 +00:00
|
|
|
GL_ZERO,
|
|
|
|
GL_ONE,
|
|
|
|
GL_DST_COLOR,
|
|
|
|
GL_ONE_MINUS_DST_COLOR,
|
|
|
|
GL_SRC_ALPHA,
|
2010-10-23 19:55:19 +00:00
|
|
|
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
2010-06-05 01:38:22 +00:00
|
|
|
GL_DST_ALPHA,
|
|
|
|
GL_ONE_MINUS_DST_ALPHA
|
2009-02-23 07:23:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const GLenum glDestFactors[8] = {
|
2010-08-10 01:08:22 +00:00
|
|
|
GL_ZERO,
|
|
|
|
GL_ONE,
|
|
|
|
GL_SRC_COLOR,
|
2009-10-25 02:35:21 +00:00
|
|
|
GL_ONE_MINUS_SRC_COLOR,
|
2010-08-10 01:08:22 +00:00
|
|
|
GL_SRC_ALPHA,
|
2010-10-23 19:55:19 +00:00
|
|
|
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
2010-08-10 01:08:22 +00:00
|
|
|
GL_DST_ALPHA,
|
2009-10-25 02:35:21 +00:00
|
|
|
GL_ONE_MINUS_DST_ALPHA
|
2009-02-23 07:23:34 +00:00
|
|
|
};
|
|
|
|
|
2009-11-27 19:42:27 +00:00
|
|
|
static const GLenum glCmpFuncs[8] = {
|
2010-05-19 03:15:36 +00:00
|
|
|
GL_NEVER,
|
|
|
|
GL_LESS,
|
|
|
|
GL_EQUAL,
|
|
|
|
GL_LEQUAL,
|
|
|
|
GL_GREATER,
|
|
|
|
GL_NOTEQUAL,
|
|
|
|
GL_GEQUAL,
|
|
|
|
GL_ALWAYS
|
2009-11-27 19:42:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const GLenum glLogicOpCodes[16] = {
|
2010-06-05 01:38:22 +00:00
|
|
|
GL_CLEAR,
|
2010-05-19 03:15:36 +00:00
|
|
|
GL_AND,
|
|
|
|
GL_AND_REVERSE,
|
|
|
|
GL_COPY,
|
|
|
|
GL_AND_INVERTED,
|
|
|
|
GL_NOOP,
|
2010-08-10 01:08:22 +00:00
|
|
|
GL_XOR,
|
2010-05-19 03:15:36 +00:00
|
|
|
GL_OR,
|
|
|
|
GL_NOR,
|
|
|
|
GL_EQUIV,
|
|
|
|
GL_INVERT,
|
|
|
|
GL_OR_REVERSE,
|
|
|
|
GL_COPY_INVERTED,
|
|
|
|
GL_OR_INVERTED,
|
|
|
|
GL_NAND,
|
|
|
|
GL_SET
|
2009-11-27 19:42:27 +00:00
|
|
|
};
|
|
|
|
|
2010-07-24 10:24:16 +00:00
|
|
|
#if defined HAVE_CG && HAVE_CG
|
2009-04-08 17:58:58 +00:00
|
|
|
void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
|
|
|
|
{
|
2009-06-09 19:40:47 +00:00
|
|
|
DEBUG_LOG(VIDEO, "Cg error: %s", cgGetErrorString(err));
|
2009-04-08 17:58:58 +00:00
|
|
|
const char* listing = cgGetLastListing(g_cgcontext);
|
2010-08-10 01:08:22 +00:00
|
|
|
if (listing != NULL)
|
2009-06-09 19:40:47 +00:00
|
|
|
DEBUG_LOG(VIDEO, " last listing: %s", listing);
|
2009-04-08 17:58:58 +00:00
|
|
|
}
|
2010-07-24 10:24:16 +00:00
|
|
|
#endif
|
2009-03-05 23:11:13 +00:00
|
|
|
|
2011-05-07 22:00:05 +00:00
|
|
|
int GetNumMSAASamples(int MSAAMode)
|
2009-02-23 07:23:34 +00:00
|
|
|
{
|
2011-05-07 22:00:05 +00:00
|
|
|
// required for MSAA
|
|
|
|
if (!s_bHaveFramebufferBlit)
|
|
|
|
return 1;
|
2010-07-24 10:24:16 +00:00
|
|
|
|
2011-05-07 22:00:05 +00:00
|
|
|
switch (MSAAMode)
|
2009-03-08 20:04:40 +00:00
|
|
|
{
|
2010-11-18 02:21:26 +00:00
|
|
|
case MULTISAMPLE_OFF:
|
2011-05-07 22:00:05 +00:00
|
|
|
return 1;
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
case MULTISAMPLE_2X:
|
2011-05-07 22:00:05 +00:00
|
|
|
return 2;
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
case MULTISAMPLE_4X:
|
2011-05-07 22:00:05 +00:00
|
|
|
case MULTISAMPLE_CSAA_8X:
|
|
|
|
case MULTISAMPLE_CSAA_16X:
|
|
|
|
return 4;
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
case MULTISAMPLE_8X:
|
2011-05-07 22:00:05 +00:00
|
|
|
case MULTISAMPLE_CSAA_8XQ:
|
|
|
|
case MULTISAMPLE_CSAA_16XQ:
|
|
|
|
return 8;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetNumMSAACoverageSamples(int MSAAMode)
|
|
|
|
{
|
|
|
|
if (!s_bHaveCoverageMSAA)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (g_ActiveConfig.iMultisampleMode)
|
|
|
|
{
|
2010-08-10 01:08:22 +00:00
|
|
|
case MULTISAMPLE_CSAA_8X:
|
|
|
|
case MULTISAMPLE_CSAA_8XQ:
|
2011-05-07 22:00:05 +00:00
|
|
|
return 8;
|
|
|
|
|
2010-08-10 01:08:22 +00:00
|
|
|
case MULTISAMPLE_CSAA_16X:
|
|
|
|
case MULTISAMPLE_CSAA_16XQ:
|
2011-05-07 22:00:05 +00:00
|
|
|
return 16;
|
|
|
|
|
2010-05-19 03:15:36 +00:00
|
|
|
default:
|
2011-05-07 22:00:05 +00:00
|
|
|
return 0;
|
2009-03-08 20:04:40 +00:00
|
|
|
}
|
2011-05-07 22:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init functions
|
|
|
|
Renderer::Renderer()
|
|
|
|
{
|
|
|
|
OSDInternalW = 0;
|
|
|
|
OSDInternalH = 0;
|
|
|
|
|
|
|
|
s_fps=0;
|
2012-12-07 22:34:38 +00:00
|
|
|
s_ShowEFBCopyRegions_VBO = 0;
|
2012-12-08 01:01:35 +00:00
|
|
|
s_Swap_VBO = 0;
|
2011-05-07 22:00:05 +00:00
|
|
|
s_blendMode = 0;
|
2012-12-09 18:22:21 +00:00
|
|
|
|
|
|
|
// should be invalid, so there will be an upload on the first call
|
2012-12-09 19:30:29 +00:00
|
|
|
s_cached_targetRc.bottom = -1;
|
|
|
|
s_cached_targetRc.top = -1;
|
|
|
|
s_cached_targetRc.left = -1;
|
|
|
|
s_cached_targetRc.right = -1;
|
2012-12-09 18:22:21 +00:00
|
|
|
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2012-10-04 03:41:02 +00:00
|
|
|
InitFPSCounter();
|
|
|
|
|
2010-07-24 10:24:16 +00:00
|
|
|
#if defined HAVE_CG && HAVE_CG
|
|
|
|
g_cgcontext = cgCreateContext();
|
2010-06-05 01:38:22 +00:00
|
|
|
cgGetError();
|
2009-03-08 19:19:51 +00:00
|
|
|
cgSetErrorHandler(HandleCgError, NULL);
|
2010-07-24 10:24:16 +00:00
|
|
|
#endif
|
2009-03-05 23:11:13 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
// Look for required extensions.
|
|
|
|
const char *ptoken = (const char*)glGetString(GL_EXTENSIONS);
|
2009-02-28 16:33:59 +00:00
|
|
|
if (!ptoken)
|
|
|
|
{
|
2009-04-03 21:32:10 +00:00
|
|
|
PanicAlert("Your OpenGL Driver seems to be not working.\n"
|
2010-08-10 01:08:22 +00:00
|
|
|
"Please make sure your drivers are up-to-date and\n"
|
|
|
|
"that your video hardware is OpenGL 2.x compatible.");
|
2010-11-18 02:21:26 +00:00
|
|
|
return; // TODO: fail
|
2009-02-28 16:33:59 +00:00
|
|
|
}
|
2009-07-31 01:55:26 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
INFO_LOG(VIDEO, "Supported OpenGL Extensions:");
|
2010-12-05 09:04:34 +00:00
|
|
|
INFO_LOG(VIDEO, "%s", ptoken); // write to the log file
|
|
|
|
INFO_LOG(VIDEO, "\n");
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-08-10 01:08:22 +00:00
|
|
|
OSD::AddMessage(StringFromFormat("Video Info: %s, %s, %s",
|
|
|
|
glGetString(GL_VENDOR),
|
|
|
|
glGetString(GL_RENDERER),
|
|
|
|
glGetString(GL_VERSION)).c_str(), 5000);
|
2009-04-03 20:22:45 +00:00
|
|
|
|
2011-05-07 22:00:05 +00:00
|
|
|
bool bSuccess = true;
|
|
|
|
GLint numvertexattribs = 0;
|
2009-02-28 16:33:59 +00:00
|
|
|
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &numvertexattribs);
|
2010-08-10 01:08:22 +00:00
|
|
|
if (numvertexattribs < 11)
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "GPU: OGL ERROR: Number of attributes %d not enough.\n"
|
|
|
|
"GPU: Does your video card support OpenGL 2.x?",
|
|
|
|
numvertexattribs);
|
2010-06-05 01:38:22 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
2009-02-28 16:33:59 +00:00
|
|
|
|
|
|
|
// Init extension support.
|
2010-08-10 01:08:22 +00:00
|
|
|
if (glewInit() != GLEW_OK)
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "glewInit() failed! Does your video card support OpenGL 2.x?");
|
2010-11-18 02:21:26 +00:00
|
|
|
return; // TODO: fail
|
2010-06-05 01:38:22 +00:00
|
|
|
}
|
2010-08-10 01:08:22 +00:00
|
|
|
|
|
|
|
if (!GLEW_EXT_framebuffer_object)
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "GPU: ERROR: Need GL_EXT_framebufer_object for multiple render targets.\n"
|
|
|
|
"GPU: Does your video card support OpenGL 2.x?");
|
2010-06-05 01:38:22 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
2010-08-10 01:08:22 +00:00
|
|
|
|
|
|
|
if (!GLEW_EXT_secondary_color)
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "GPU: OGL ERROR: Need GL_EXT_secondary_color.\n"
|
|
|
|
"GPU: Does your video card support OpenGL 2.x?");
|
2010-06-05 01:38:22 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2012-12-09 21:49:58 +00:00
|
|
|
if (!GLEW_ARB_vertex_array_object)
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "GPU: OGL ERROR: Need GL_ARB_vertex_array_object.\n"
|
|
|
|
"GPU: Does your video card support OpenGL 3.0?");
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
2009-03-08 19:19:51 +00:00
|
|
|
s_bHaveFramebufferBlit = strstr(ptoken, "GL_EXT_framebuffer_blit") != NULL;
|
2009-03-08 20:04:40 +00:00
|
|
|
s_bHaveCoverageMSAA = strstr(ptoken, "GL_NV_framebuffer_multisample_coverage") != NULL;
|
2011-05-07 22:00:05 +00:00
|
|
|
|
|
|
|
s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode;
|
|
|
|
s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode);
|
|
|
|
s_MSAACoverageSamples = GetNumMSAACoverageSamples(s_LastMultisampleMode);
|
2009-03-08 20:04:40 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
if (!bSuccess)
|
2010-11-18 02:21:26 +00:00
|
|
|
return; // TODO: fail
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Decide frambuffer size
|
2012-12-17 20:54:20 +00:00
|
|
|
s_backbuffer_width = (int)GLInterface->GetBackBufferWidth();
|
|
|
|
s_backbuffer_height = (int)GLInterface->GetBackBufferHeight();
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2009-03-05 23:11:13 +00:00
|
|
|
// Handle VSync on/off
|
2011-01-28 09:39:28 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
int swapInterval = g_ActiveConfig.bVSync ? 1 : 0;
|
2009-09-09 20:47:11 +00:00
|
|
|
#if defined USE_WX && USE_WX
|
2011-01-28 09:39:28 +00:00
|
|
|
NSOpenGLContext *ctx = GLWin.glCtxt->GetWXGLContext();
|
|
|
|
#else
|
|
|
|
NSOpenGLContext *ctx = GLWin.cocoaCtx;
|
|
|
|
#endif
|
|
|
|
[ctx setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
|
2009-09-09 20:47:11 +00:00
|
|
|
#elif defined _WIN32
|
2009-02-28 16:33:59 +00:00
|
|
|
if (WGLEW_EXT_swap_control)
|
2009-09-13 08:21:35 +00:00
|
|
|
wglSwapIntervalEXT(g_ActiveConfig.bVSync ? 1 : 0);
|
2009-02-28 16:33:59 +00:00
|
|
|
else
|
2010-08-10 01:08:22 +00:00
|
|
|
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
|
2009-02-23 07:23:34 +00:00
|
|
|
#elif defined(HAVE_X11) && HAVE_X11
|
2009-02-28 16:33:59 +00:00
|
|
|
if (glXSwapIntervalSGI)
|
2009-09-13 08:21:35 +00:00
|
|
|
glXSwapIntervalSGI(g_ActiveConfig.bVSync ? 1 : 0);
|
2009-02-28 16:33:59 +00:00
|
|
|
else
|
2010-08-10 01:08:22 +00:00
|
|
|
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
|
2009-02-23 07:23:34 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
// check the max texture width and height
|
2009-02-23 07:23:34 +00:00
|
|
|
GLint max_texture_size;
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&max_texture_size);
|
2010-08-10 01:08:22 +00:00
|
|
|
if (max_texture_size < 1024)
|
|
|
|
ERROR_LOG(VIDEO, "GL_MAX_TEXTURE_SIZE too small at %i - must be at least 1024.",
|
|
|
|
max_texture_size);
|
2009-03-22 11:21:44 +00:00
|
|
|
|
|
|
|
if (GL_REPORT_ERROR() != GL_NO_ERROR)
|
|
|
|
bSuccess = false;
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
if (glDrawBuffers == NULL && !GLEW_ARB_draw_buffers)
|
|
|
|
glDrawBuffers = glDrawBuffersARB;
|
2010-08-10 01:08:22 +00:00
|
|
|
|
|
|
|
if (!GLEW_ARB_texture_non_power_of_two)
|
2010-01-18 21:11:50 +00:00
|
|
|
WARN_LOG(VIDEO, "ARB_texture_non_power_of_two not supported.");
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2012-09-28 21:48:18 +00:00
|
|
|
// TODO: Move these somewhere else?
|
|
|
|
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
|
|
|
|
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
|
2010-05-19 03:15:36 +00:00
|
|
|
|
2012-09-28 22:04:55 +00:00
|
|
|
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-09-30 15:24:34 +00:00
|
|
|
s_LastEFBScale = g_ActiveConfig.iEFBScale;
|
2012-09-28 22:19:28 +00:00
|
|
|
CalculateTargetSize(s_backbuffer_width, s_backbuffer_height);
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2010-08-10 01:08:22 +00:00
|
|
|
// Because of the fixed framebuffer size we need to disable the resolution
|
|
|
|
// options while running
|
2009-10-22 20:22:50 +00:00
|
|
|
g_Config.bRunning = true;
|
2009-02-28 16:33:59 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
if (GL_REPORT_ERROR() != GL_NO_ERROR)
|
2009-03-22 11:21:44 +00:00
|
|
|
bSuccess = false;
|
|
|
|
|
2009-06-28 23:35:08 +00:00
|
|
|
// Initialize the FramebufferManager
|
2010-11-14 23:31:53 +00:00
|
|
|
g_framebuffer_manager = new FramebufferManager(s_target_width, s_target_height,
|
2010-08-10 01:08:22 +00:00
|
|
|
s_MSAASamples, s_MSAACoverageSamples);
|
2009-09-06 13:36:05 +00:00
|
|
|
|
2009-03-08 19:19:51 +00:00
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
if (GL_REPORT_ERROR() != GL_NO_ERROR)
|
2009-02-23 07:23:34 +00:00
|
|
|
bSuccess = false;
|
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
s_pfont = new RasterFont();
|
|
|
|
|
2010-07-24 10:24:16 +00:00
|
|
|
#if defined HAVE_CG && HAVE_CG
|
2010-06-05 01:38:22 +00:00
|
|
|
// load the effect, find the best profiles (if any)
|
2010-08-10 01:08:22 +00:00
|
|
|
if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1) != CG_TRUE)
|
|
|
|
{
|
2010-06-05 01:38:22 +00:00
|
|
|
ERROR_LOG(VIDEO, "arbvp1 not supported");
|
2010-11-18 02:21:26 +00:00
|
|
|
return; // TODO: fail
|
2010-06-05 01:38:22 +00:00
|
|
|
}
|
|
|
|
|
2010-08-10 01:08:22 +00:00
|
|
|
if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) != CG_TRUE)
|
|
|
|
{
|
2010-06-05 01:38:22 +00:00
|
|
|
ERROR_LOG(VIDEO, "arbfp1 not supported");
|
2010-11-18 02:21:26 +00:00
|
|
|
return; // TODO: fail
|
2010-06-05 01:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_cgvProf = cgGLGetLatestProfile(CG_GL_VERTEX);
|
|
|
|
g_cgfProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);
|
2010-10-06 18:03:31 +00:00
|
|
|
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") == NULL)
|
|
|
|
{
|
2010-07-03 21:21:28 +00:00
|
|
|
#if CG_VERSION_NUM == 2100
|
2010-07-03 19:10:23 +00:00
|
|
|
// A bug was introduced in Cg2.1's handling of very large profile option values
|
|
|
|
// so this will not work on ATI. ATI returns MAXINT = 2147483647 (0x7fffffff)
|
|
|
|
// which is correct in OpenGL but Cg fails to handle it properly. As a result
|
|
|
|
// -1 is used by Cg resulting (signedness incorrect) and compilation fails.
|
2010-10-06 18:03:31 +00:00
|
|
|
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") == NULL)
|
2010-08-10 01:08:22 +00:00
|
|
|
#endif
|
2010-10-06 18:03:31 +00:00
|
|
|
{
|
|
|
|
cgGLSetOptimalOptions(g_cgvProf);
|
|
|
|
cgGLSetOptimalOptions(g_cgfProf);
|
|
|
|
}
|
2010-07-03 19:10:23 +00:00
|
|
|
}
|
2010-07-24 10:24:16 +00:00
|
|
|
#endif // HAVE_CG
|
2010-06-05 01:38:22 +00:00
|
|
|
|
|
|
|
int nenvvertparams, nenvfragparams, naddrregisters[2];
|
2010-08-10 01:08:22 +00:00
|
|
|
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB,
|
|
|
|
GL_MAX_PROGRAM_ENV_PARAMETERS_ARB,
|
|
|
|
(GLint *)&nenvvertparams);
|
|
|
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
GL_MAX_PROGRAM_ENV_PARAMETERS_ARB,
|
|
|
|
(GLint *)&nenvfragparams);
|
|
|
|
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB,
|
|
|
|
GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB,
|
|
|
|
(GLint *)&naddrregisters[0]);
|
|
|
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB,
|
|
|
|
(GLint *)&naddrregisters[1]);
|
|
|
|
DEBUG_LOG(VIDEO, "Max program env parameters: vert=%d, frag=%d",
|
|
|
|
nenvvertparams, nenvfragparams);
|
|
|
|
DEBUG_LOG(VIDEO, "Max program address register parameters: vert=%d, frag=%d",
|
|
|
|
naddrregisters[0], naddrregisters[1]);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
|
|
|
if (nenvvertparams < 238)
|
2010-06-05 01:38:22 +00:00
|
|
|
ERROR_LOG(VIDEO, "Not enough vertex shader environment constants!!");
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-07-24 10:24:16 +00:00
|
|
|
#if defined HAVE_CG && HAVE_CG
|
|
|
|
INFO_LOG(VIDEO, "Max buffer sizes: %d %d",
|
|
|
|
cgGetProgramBufferMaxSize(g_cgvProf),
|
|
|
|
cgGetProgramBufferMaxSize(g_cgfProf));
|
2009-02-23 07:23:34 +00:00
|
|
|
#ifndef _DEBUG
|
2010-06-05 01:38:22 +00:00
|
|
|
cgGLSetDebugMode(GL_FALSE);
|
2010-07-24 10:24:16 +00:00
|
|
|
#endif
|
2009-02-23 07:23:34 +00:00
|
|
|
#endif
|
2012-12-07 22:34:38 +00:00
|
|
|
|
|
|
|
// creating buffers
|
|
|
|
glGenBuffers(1, &s_ShowEFBCopyRegions_VBO);
|
2012-12-09 21:49:58 +00:00
|
|
|
glGenVertexArrays(1, &s_ShowEFBCopyRegions_VAO);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, s_ShowEFBCopyRegions_VBO);
|
|
|
|
glBindVertexArray( s_ShowEFBCopyRegions_VAO );
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glColorPointer (3, GL_FLOAT, sizeof(GLfloat)*5, (GLfloat*)NULL+2);
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(GLfloat)*5, NULL);
|
|
|
|
|
2012-12-08 01:01:35 +00:00
|
|
|
glGenBuffers(1, &s_Swap_VBO);
|
2012-12-09 21:49:58 +00:00
|
|
|
glGenVertexArrays(2, s_Swap_VAO);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO);
|
|
|
|
glBindVertexArray(s_Swap_VAO[0]);
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glVertexPointer(3, GL_FLOAT, 7*sizeof(GLfloat), NULL);
|
|
|
|
glClientActiveTexture(GL_TEXTURE0);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+3);
|
|
|
|
|
|
|
|
glBindVertexArray(s_Swap_VAO[1]);
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glVertexPointer(3, GL_FLOAT, 7*sizeof(GLfloat), NULL);
|
|
|
|
glClientActiveTexture(GL_TEXTURE0);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+3);
|
|
|
|
glClientActiveTexture(GL_TEXTURE1);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 7*sizeof(GLfloat), (GLfloat*)NULL+5);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2012-12-13 14:48:42 +00:00
|
|
|
// TODO: this after merging with graphic_update
|
|
|
|
glBindVertexArray(0);
|
2012-12-29 11:50:42 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2012-12-13 14:48:42 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
glStencilFunc(GL_ALWAYS, 0, 0);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE);
|
|
|
|
|
|
|
|
glViewport(0, 0, GetTargetWidth(), GetTargetHeight()); // Reset The Current Viewport
|
|
|
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
2010-12-27 03:18:01 +00:00
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
2010-06-05 01:38:22 +00:00
|
|
|
glClearDepth(1.0f);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
glScissor(0, 0, GetTargetWidth(), GetTargetHeight());
|
|
|
|
glBlendColorEXT(0, 0, 0, 0.5f);
|
|
|
|
glClearDepth(1.0f);
|
|
|
|
|
|
|
|
// legacy multitexturing: select texture channel only.
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glClientActiveTexture(GL_TEXTURE0);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
UpdateActiveConfig();
|
2010-11-18 02:21:26 +00:00
|
|
|
|
|
|
|
//return GL_REPORT_ERROR() == GL_NO_ERROR && bSuccess;
|
|
|
|
return;
|
2009-02-23 07:23:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
Renderer::~Renderer()
|
2010-06-05 01:38:22 +00:00
|
|
|
{
|
2009-09-06 15:11:21 +00:00
|
|
|
g_Config.bRunning = false;
|
2009-09-13 08:21:35 +00:00
|
|
|
UpdateActiveConfig();
|
2012-12-07 22:34:38 +00:00
|
|
|
|
|
|
|
glDeleteBuffers(1, &s_ShowEFBCopyRegions_VBO);
|
2012-12-09 21:49:58 +00:00
|
|
|
glDeleteVertexArrays(1, &s_ShowEFBCopyRegions_VAO);
|
2012-12-08 01:01:35 +00:00
|
|
|
glDeleteBuffers(1, &s_Swap_VBO);
|
2012-12-09 21:49:58 +00:00
|
|
|
glDeleteVertexArrays(2, s_Swap_VAO);
|
2012-12-07 22:34:38 +00:00
|
|
|
s_ShowEFBCopyRegions_VBO = 0;
|
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
delete s_pfont;
|
2009-09-03 19:24:16 +00:00
|
|
|
s_pfont = 0;
|
|
|
|
|
2010-07-24 10:24:16 +00:00
|
|
|
#if defined HAVE_CG && HAVE_CG
|
2010-08-10 01:08:22 +00:00
|
|
|
if (g_cgcontext)
|
|
|
|
{
|
2010-06-05 01:38:22 +00:00
|
|
|
cgDestroyContext(g_cgcontext);
|
|
|
|
g_cgcontext = 0;
|
2009-09-03 19:24:16 +00:00
|
|
|
}
|
2010-07-24 10:24:16 +00:00
|
|
|
#endif
|
2009-09-03 19:24:16 +00:00
|
|
|
|
2010-08-08 00:13:05 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2011-01-27 20:47:58 +00:00
|
|
|
if (scrshotThread.joinable())
|
|
|
|
scrshotThread.join();
|
2010-08-08 00:13:05 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-14 23:31:53 +00:00
|
|
|
delete g_framebuffer_manager;
|
2009-09-03 19:24:16 +00:00
|
|
|
}
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Create On-Screen-Messages
|
2010-11-18 02:21:26 +00:00
|
|
|
void Renderer::DrawDebugInfo()
|
2009-02-23 07:23:34 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
// Reset viewport for drawing text
|
2012-12-17 20:54:20 +00:00
|
|
|
glViewport(0, 0, GLInterface->GetBackBufferWidth(), GLInterface->GetBackBufferHeight());
|
2010-09-28 02:15:02 +00:00
|
|
|
// Draw various messages on the screen, like FPS, statistics, etc.
|
|
|
|
char debugtext_buffer[8192];
|
|
|
|
char *p = debugtext_buffer;
|
|
|
|
p[0] = 0;
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (g_ActiveConfig.bShowFPS)
|
|
|
|
p+=sprintf(p, "FPS: %d\n", s_fps);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2012-11-14 21:21:54 +00:00
|
|
|
if (SConfig::GetInstance().m_ShowLag)
|
2012-12-07 01:25:07 +00:00
|
|
|
p+=sprintf(p, "Lag: %llu\n", Movie::g_currentLagCount);
|
2012-11-11 22:57:06 +00:00
|
|
|
|
2011-02-17 09:12:36 +00:00
|
|
|
if (g_ActiveConfig.bShowInputDisplay)
|
2011-06-24 06:50:50 +00:00
|
|
|
p+=sprintf(p, "%s", Movie::GetInputDisplay().c_str());
|
2011-02-17 09:12:36 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (g_ActiveConfig.bShowEFBCopyRegions)
|
|
|
|
{
|
|
|
|
// Store Line Size
|
|
|
|
GLfloat lSize;
|
|
|
|
glGetFloatv(GL_LINE_WIDTH, &lSize);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Set Line Size
|
|
|
|
glLineWidth(3.0f);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2012-12-07 21:49:18 +00:00
|
|
|
// 2*Coords + 3*Color
|
2012-12-07 22:34:38 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, s_ShowEFBCopyRegions_VBO);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, stats.efb_regions.size() * sizeof(GLfloat) * (2+3)*2*6, NULL, GL_STREAM_DRAW);
|
|
|
|
GLfloat *Vertices = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Draw EFB copy regions rectangles
|
2012-10-27 23:10:31 +00:00
|
|
|
int a = 0;
|
2012-12-07 21:49:18 +00:00
|
|
|
GLfloat color[3] = {0.0f, 1.0f, 1.0f};
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
for (std::vector<EFBRectangle>::const_iterator it = stats.efb_regions.begin();
|
|
|
|
it != stats.efb_regions.end(); ++it)
|
|
|
|
{
|
|
|
|
GLfloat halfWidth = EFB_WIDTH / 2.0f;
|
|
|
|
GLfloat halfHeight = EFB_HEIGHT / 2.0f;
|
|
|
|
GLfloat x = (GLfloat) -1.0f + ((GLfloat)it->left / halfWidth);
|
|
|
|
GLfloat y = (GLfloat) 1.0f - ((GLfloat)it->top / halfHeight);
|
|
|
|
GLfloat x2 = (GLfloat) -1.0f + ((GLfloat)it->right / halfWidth);
|
|
|
|
GLfloat y2 = (GLfloat) 1.0f - ((GLfloat)it->bottom / halfHeight);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2012-12-07 21:49:18 +00:00
|
|
|
Vertices[a++] = x;
|
|
|
|
Vertices[a++] = y;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
2012-10-27 23:10:31 +00:00
|
|
|
|
2012-12-07 21:49:18 +00:00
|
|
|
Vertices[a++] = x2;
|
|
|
|
Vertices[a++] = y;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
2012-10-27 23:10:31 +00:00
|
|
|
|
2012-12-07 21:49:18 +00:00
|
|
|
|
|
|
|
Vertices[a++] = x2;
|
|
|
|
Vertices[a++] = y;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
Vertices[a++] = x2;
|
|
|
|
Vertices[a++] = y2;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
|
|
|
|
Vertices[a++] = x2;
|
|
|
|
Vertices[a++] = y2;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
Vertices[a++] = x;
|
|
|
|
Vertices[a++] = y2;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
|
|
|
|
Vertices[a++] = x;
|
|
|
|
Vertices[a++] = y2;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
Vertices[a++] = x;
|
|
|
|
Vertices[a++] = y;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
|
|
|
|
Vertices[a++] = x;
|
|
|
|
Vertices[a++] = y;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
Vertices[a++] = x2;
|
|
|
|
Vertices[a++] = y2;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
|
|
|
|
Vertices[a++] = x2;
|
|
|
|
Vertices[a++] = y;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
Vertices[a++] = x;
|
|
|
|
Vertices[a++] = y2;
|
|
|
|
Vertices[a++] = color[0];
|
|
|
|
Vertices[a++] = color[1];
|
|
|
|
Vertices[a++] = color[2];
|
|
|
|
|
|
|
|
// TO DO: build something nicer here
|
|
|
|
GLfloat temp = color[0];
|
|
|
|
color[0] = color[1];
|
|
|
|
color[1] = color[2];
|
|
|
|
color[2] = temp;
|
2010-09-28 02:15:02 +00:00
|
|
|
}
|
2012-12-07 22:34:38 +00:00
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
2012-10-27 23:10:31 +00:00
|
|
|
|
2012-12-09 21:49:58 +00:00
|
|
|
glBindVertexArray( s_ShowEFBCopyRegions_VAO );
|
2012-12-07 21:49:18 +00:00
|
|
|
glDrawArrays(GL_LINES, 0, stats.efb_regions.size() * 2*6);
|
2012-12-13 14:48:42 +00:00
|
|
|
|
|
|
|
// TODO: this after merging with graphic_update
|
|
|
|
glBindVertexArray(0);
|
2012-12-29 11:50:42 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Restore Line Size
|
|
|
|
glLineWidth(lSize);
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Clear stored regions
|
|
|
|
stats.efb_regions.clear();
|
|
|
|
}
|
2010-01-07 20:01:41 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (g_ActiveConfig.bOverlayStats)
|
|
|
|
p = Statistics::ToString(p);
|
2009-07-15 00:51:24 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (g_ActiveConfig.bOverlayProjStats)
|
|
|
|
p = Statistics::ToStringProj(p);
|
2009-07-15 00:51:24 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Render a shadow, and then the text.
|
|
|
|
if (p != debugtext_buffer)
|
2009-07-15 00:51:24 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
Renderer::RenderText(debugtext_buffer, 21, 21, 0xDD000000);
|
|
|
|
Renderer::RenderText(debugtext_buffer, 20, 20, 0xFF00FFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::RenderText(const char *text, int left, int top, u32 color)
|
|
|
|
{
|
2012-12-17 20:54:20 +00:00
|
|
|
const int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
|
|
|
|
const int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight();
|
2011-11-30 03:50:31 +00:00
|
|
|
|
2012-12-21 23:03:58 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
s_pfont->printMultilineText(text,
|
|
|
|
left * 2.0f / (float)nBackbufferWidth - 1,
|
|
|
|
1 - top * 2.0f / (float)nBackbufferHeight,
|
2012-12-11 11:37:08 +00:00
|
|
|
0, nBackbufferWidth, nBackbufferHeight, color);
|
2010-11-18 02:21:26 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
GL_REPORT_ERRORD();
|
2012-12-21 23:03:58 +00:00
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
2010-09-28 02:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
|
|
|
{
|
2010-09-30 15:24:34 +00:00
|
|
|
TargetRectangle result;
|
2011-05-12 02:14:45 +00:00
|
|
|
result.left = EFBToScaledX(rc.left);
|
|
|
|
result.top = EFBToScaledY(EFB_HEIGHT - rc.top);
|
|
|
|
result.right = EFBToScaledX(rc.right);
|
|
|
|
result.bottom = EFBToScaledY(EFB_HEIGHT - rc.bottom);
|
2010-09-30 15:24:34 +00:00
|
|
|
return result;
|
2010-09-28 02:15:02 +00:00
|
|
|
}
|
|
|
|
|
2009-06-07 12:06:15 +00:00
|
|
|
// Function: This function handles the OpenGL glScissor() function
|
2009-09-08 16:07:13 +00:00
|
|
|
// ----------------------------
|
2009-02-23 07:23:34 +00:00
|
|
|
// Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg()
|
|
|
|
// case 0x52 > SetScissorRect()
|
2009-09-08 16:07:13 +00:00
|
|
|
// ----------------------------
|
2009-06-22 09:31:30 +00:00
|
|
|
// bpmem.scissorTL.x, y = 342x342
|
|
|
|
// bpmem.scissorBR.x, y = 981x821
|
2009-02-23 07:23:34 +00:00
|
|
|
// Renderer::GetTargetHeight() = the fixed ini file setting
|
|
|
|
// donkopunchstania - it appears scissorBR is the bottom right pixel inside the scissor box
|
|
|
|
// therefore the width and height are (scissorBR + 1) - scissorTL
|
2011-09-05 20:04:28 +00:00
|
|
|
void Renderer::SetScissorRect(const TargetRectangle& rc)
|
2009-02-23 07:23:34 +00:00
|
|
|
{
|
2011-09-05 20:04:28 +00:00
|
|
|
glScissor(rc.left, rc.bottom, rc.GetWidth(), rc.GetHeight());
|
2009-02-23 07:23:34 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetColorMask()
|
|
|
|
{
|
2010-12-20 16:57:29 +00:00
|
|
|
// Only enable alpha channel if it's supported by the current EFB format
|
2010-12-21 22:18:40 +00:00
|
|
|
GLenum ColorMask = GL_FALSE, AlphaMask = GL_FALSE;
|
2010-12-27 18:09:03 +00:00
|
|
|
if (bpmem.blendmode.colorupdate)
|
2010-12-21 22:18:40 +00:00
|
|
|
ColorMask = GL_TRUE;
|
2010-12-27 18:09:03 +00:00
|
|
|
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
2010-12-21 22:49:35 +00:00
|
|
|
AlphaMask = GL_TRUE;
|
2010-09-28 02:15:02 +00:00
|
|
|
glColorMask(ColorMask, ColorMask, ColorMask, AlphaMask);
|
|
|
|
}
|
|
|
|
|
2011-08-22 04:15:02 +00:00
|
|
|
void ClearEFBCache()
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT; ++i)
|
|
|
|
s_efbCacheValid[0][i] = false;
|
|
|
|
|
|
|
|
for (u32 i = 0; i < EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT; ++i)
|
|
|
|
s_efbCacheValid[1][i] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc, const TargetRectangle& targetPixelRc, const u32* data)
|
|
|
|
{
|
|
|
|
u32 cacheType = (type == PEEK_Z ? 0 : 1);
|
|
|
|
|
|
|
|
if (!s_efbCache[cacheType][cacheRectIdx].size())
|
|
|
|
s_efbCache[cacheType][cacheRectIdx].resize(EFB_CACHE_RECT_SIZE * EFB_CACHE_RECT_SIZE);
|
|
|
|
|
|
|
|
u32 targetPixelRcWidth = targetPixelRc.right - targetPixelRc.left;
|
2012-07-23 17:56:57 +00:00
|
|
|
u32 efbPixelRcHeight = efbPixelRc.bottom - efbPixelRc.top;
|
|
|
|
u32 efbPixelRcWidth = efbPixelRc.right - efbPixelRc.left;
|
2011-08-22 04:15:02 +00:00
|
|
|
|
2012-07-23 17:56:57 +00:00
|
|
|
for (u32 yCache = 0; yCache < efbPixelRcHeight; ++yCache)
|
2011-08-22 04:15:02 +00:00
|
|
|
{
|
|
|
|
u32 yEFB = efbPixelRc.top + yCache;
|
|
|
|
u32 yPixel = (EFBToScaledY(EFB_HEIGHT - yEFB) + EFBToScaledY(EFB_HEIGHT - yEFB - 1)) / 2;
|
|
|
|
u32 yData = yPixel - targetPixelRc.bottom;
|
|
|
|
|
2012-07-23 17:56:57 +00:00
|
|
|
for (u32 xCache = 0; xCache < efbPixelRcWidth; ++xCache)
|
2011-08-22 04:15:02 +00:00
|
|
|
{
|
|
|
|
u32 xEFB = efbPixelRc.left + xCache;
|
|
|
|
u32 xPixel = (EFBToScaledX(xEFB) + EFBToScaledX(xEFB + 1)) / 2;
|
|
|
|
u32 xData = xPixel - targetPixelRc.left;
|
|
|
|
s_efbCache[cacheType][cacheRectIdx][yCache * EFB_CACHE_RECT_SIZE + xCache] = data[yData * targetPixelRcWidth + xData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s_efbCacheValid[cacheType][cacheRectIdx] = true;
|
|
|
|
}
|
|
|
|
|
2010-10-24 19:52:52 +00:00
|
|
|
// This function allows the CPU to directly access the EFB.
|
|
|
|
// There are EFB peeks (which will read the color or depth of a pixel)
|
|
|
|
// and EFB pokes (which will change the color or depth of a pixel).
|
|
|
|
//
|
|
|
|
// The behavior of EFB peeks can only be modified by:
|
|
|
|
// - GX_PokeAlphaRead
|
|
|
|
// The behavior of EFB pokes can be modified by:
|
|
|
|
// - GX_PokeAlphaMode (TODO)
|
|
|
|
// - GX_PokeAlphaUpdate (TODO)
|
|
|
|
// - GX_PokeBlendMode (TODO)
|
|
|
|
// - GX_PokeColorUpdate (TODO)
|
|
|
|
// - GX_PokeDither (TODO)
|
|
|
|
// - GX_PokeDstAlpha (TODO)
|
|
|
|
// - GX_PokeZMode (TODO)
|
2010-10-22 19:40:05 +00:00
|
|
|
u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
|
2010-09-28 02:15:02 +00:00
|
|
|
{
|
2010-09-30 15:24:34 +00:00
|
|
|
if (!g_ActiveConfig.bEFBAccessEnable)
|
2010-09-28 02:15:02 +00:00
|
|
|
return 0;
|
|
|
|
|
2011-12-01 01:40:58 +00:00
|
|
|
u32 cacheRectIdx = (y / EFB_CACHE_RECT_SIZE) * EFB_CACHE_WIDTH
|
|
|
|
+ (x / EFB_CACHE_RECT_SIZE);
|
2011-08-22 04:15:02 +00:00
|
|
|
|
|
|
|
// Get the rectangular target region containing the EFB pixel
|
2010-09-28 02:15:02 +00:00
|
|
|
EFBRectangle efbPixelRc;
|
2011-08-22 04:15:02 +00:00
|
|
|
efbPixelRc.left = (x / EFB_CACHE_RECT_SIZE) * EFB_CACHE_RECT_SIZE;
|
|
|
|
efbPixelRc.top = (y / EFB_CACHE_RECT_SIZE) * EFB_CACHE_RECT_SIZE;
|
2012-07-23 17:56:57 +00:00
|
|
|
efbPixelRc.right = std::min(efbPixelRc.left + EFB_CACHE_RECT_SIZE, (u32)EFB_WIDTH);
|
|
|
|
efbPixelRc.bottom = std::min(efbPixelRc.top + EFB_CACHE_RECT_SIZE, (u32)EFB_HEIGHT);
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2010-09-30 15:24:34 +00:00
|
|
|
TargetRectangle targetPixelRc = ConvertEFBRectangle(efbPixelRc);
|
2011-08-22 04:15:02 +00:00
|
|
|
u32 targetPixelRcWidth = targetPixelRc.right - targetPixelRc.left;
|
|
|
|
u32 targetPixelRcHeight = targetPixelRc.top - targetPixelRc.bottom;
|
2010-09-28 02:15:02 +00:00
|
|
|
|
|
|
|
// TODO (FIX) : currently, AA path is broken/offset and doesn't return the correct pixel
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case PEEK_Z:
|
|
|
|
{
|
2011-08-22 04:15:02 +00:00
|
|
|
u32 z;
|
|
|
|
|
|
|
|
if (!s_efbCacheValid[0][cacheRectIdx])
|
2010-09-28 02:15:02 +00:00
|
|
|
{
|
2011-08-22 04:15:02 +00:00
|
|
|
if (s_MSAASamples > 1)
|
|
|
|
{
|
|
|
|
// Resolve our rectangle.
|
|
|
|
FramebufferManager::GetEFBDepthTexture(efbPixelRc);
|
|
|
|
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, FramebufferManager::GetResolvedFramebuffer());
|
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2011-08-22 04:15:02 +00:00
|
|
|
u32* depthMap = new u32[targetPixelRcWidth * targetPixelRcHeight];
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2011-08-22 04:15:02 +00:00
|
|
|
glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth, targetPixelRcHeight,
|
|
|
|
GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, depthMap);
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
|
|
|
UpdateEFBCache(type, cacheRectIdx, efbPixelRc, targetPixelRc, depthMap);
|
|
|
|
|
|
|
|
delete[] depthMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 xRect = x % EFB_CACHE_RECT_SIZE;
|
|
|
|
u32 yRect = y % EFB_CACHE_RECT_SIZE;
|
|
|
|
z = s_efbCache[0][cacheRectIdx][yRect * EFB_CACHE_RECT_SIZE + xRect];
|
2010-09-28 02:15:02 +00:00
|
|
|
|
|
|
|
// Scale the 32-bit value returned by glReadPixels to a 24-bit
|
|
|
|
// value (GC uses a 24-bit Z-buffer).
|
|
|
|
// TODO: in RE0 this value is often off by one, which causes lighting to disappear
|
2010-12-27 03:18:01 +00:00
|
|
|
if(bpmem.zcontrol.pixel_format == PIXELFMT_RGB565_Z16)
|
|
|
|
{
|
2010-12-27 18:09:03 +00:00
|
|
|
// if Z is in 16 bit format you must return a 16 bit integer
|
2010-12-27 03:18:01 +00:00
|
|
|
z = z >> 16;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
z = z >> 8;
|
|
|
|
}
|
|
|
|
return z;
|
2010-09-28 02:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PEEK_COLOR: // GXPeekARGB
|
|
|
|
{
|
|
|
|
// Although it may sound strange, this really is A8R8G8B8 and not RGBA or 24-bit...
|
|
|
|
|
|
|
|
// Tested in Killer 7, the first 8bits represent the alpha value which is used to
|
|
|
|
// determine if we're aiming at an enemy (0x80 / 0x88) or not (0x70)
|
|
|
|
// Wind Waker is also using it for the pictograph to determine the color of each pixel
|
|
|
|
|
2011-08-22 04:15:02 +00:00
|
|
|
u32 color;
|
|
|
|
|
|
|
|
if (!s_efbCacheValid[1][cacheRectIdx])
|
2010-09-28 02:15:02 +00:00
|
|
|
{
|
2011-08-22 04:15:02 +00:00
|
|
|
if (s_MSAASamples > 1)
|
|
|
|
{
|
|
|
|
// Resolve our rectangle.
|
|
|
|
FramebufferManager::GetEFBColorTexture(efbPixelRc);
|
|
|
|
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, FramebufferManager::GetResolvedFramebuffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
u32* colorMap = new u32[targetPixelRcWidth * targetPixelRcHeight];
|
|
|
|
|
|
|
|
glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth, targetPixelRcHeight,
|
|
|
|
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, colorMap);
|
|
|
|
GL_REPORT_ERRORD();
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2011-08-22 04:15:02 +00:00
|
|
|
UpdateEFBCache(type, cacheRectIdx, efbPixelRc, targetPixelRc, colorMap);
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2011-08-22 04:15:02 +00:00
|
|
|
delete[] colorMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 xRect = x % EFB_CACHE_RECT_SIZE;
|
|
|
|
u32 yRect = y % EFB_CACHE_RECT_SIZE;
|
|
|
|
color = s_efbCache[1][cacheRectIdx][yRect * EFB_CACHE_RECT_SIZE + xRect];
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2010-10-24 19:52:52 +00:00
|
|
|
// check what to do with the alpha channel (GX_PokeAlphaRead)
|
|
|
|
PixelEngine::UPEAlphaReadReg alpha_read_mode;
|
2011-01-07 19:51:28 +00:00
|
|
|
PixelEngine::Read16((u16&)alpha_read_mode, PE_ALPHAREAD);
|
2010-12-27 03:18:01 +00:00
|
|
|
|
|
|
|
if (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24)
|
|
|
|
{
|
|
|
|
color = RGBA8ToRGBA6ToRGBA8(color);
|
|
|
|
}
|
|
|
|
else if (bpmem.zcontrol.pixel_format == PIXELFMT_RGB565_Z16)
|
|
|
|
{
|
2010-12-27 18:09:03 +00:00
|
|
|
color = RGBA8ToRGB565ToRGBA8(color);
|
|
|
|
}
|
2010-12-27 03:18:01 +00:00
|
|
|
if(bpmem.zcontrol.pixel_format != PIXELFMT_RGBA6_Z24)
|
|
|
|
{
|
|
|
|
color |= 0xFF000000;
|
|
|
|
}
|
2010-10-24 19:52:52 +00:00
|
|
|
if(alpha_read_mode.ReadMode == 2) return color; // GX_READ_NONE
|
|
|
|
else if(alpha_read_mode.ReadMode == 1) return (color | 0xFF000000); // GX_READ_FF
|
|
|
|
else /*if(alpha_read_mode.ReadMode == 0)*/ return (color & 0x00FFFFFF); // GX_READ_00
|
2010-09-28 02:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case POKE_COLOR:
|
2010-12-27 18:09:03 +00:00
|
|
|
case POKE_Z:
|
2010-09-28 02:15:02 +00:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called from VertexShaderManager
|
2011-05-12 02:14:45 +00:00
|
|
|
void Renderer::UpdateViewport(Matrix44& vpCorrection)
|
2010-09-28 02:15:02 +00:00
|
|
|
{
|
|
|
|
// reversed gxsetviewport(xorig, yorig, width, height, nearz, farz)
|
|
|
|
// [0] = width/2
|
|
|
|
// [1] = height/2
|
|
|
|
// [2] = 16777215 * (farz - nearz)
|
|
|
|
// [3] = xorig + width/2 + 342
|
|
|
|
// [4] = yorig + height/2 + 342
|
|
|
|
// [5] = 16777215 * farz
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2011-05-12 02:14:45 +00:00
|
|
|
int scissorXOff = bpmem.scissorOffset.x * 2;
|
|
|
|
int scissorYOff = bpmem.scissorOffset.y * 2;
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2010-12-10 15:54:14 +00:00
|
|
|
// TODO: ceil, floor or just cast to int?
|
2011-04-11 01:49:32 +00:00
|
|
|
int X = EFBToScaledX((int)ceil(xfregs.viewport.xOrig - xfregs.viewport.wd - (float)scissorXOff));
|
|
|
|
int Y = EFBToScaledY((int)ceil((float)EFB_HEIGHT - xfregs.viewport.yOrig + xfregs.viewport.ht + (float)scissorYOff));
|
|
|
|
int Width = EFBToScaledX((int)ceil(2.0f * xfregs.viewport.wd));
|
|
|
|
int Height = EFBToScaledY((int)ceil(-2.0f * xfregs.viewport.ht));
|
|
|
|
double GLNear = (xfregs.viewport.farZ - xfregs.viewport.zRange) / 16777216.0f;
|
|
|
|
double GLFar = xfregs.viewport.farZ / 16777216.0f;
|
2010-09-30 15:24:34 +00:00
|
|
|
if (Width < 0)
|
2010-09-28 02:15:02 +00:00
|
|
|
{
|
2010-09-30 15:24:34 +00:00
|
|
|
X += Width;
|
2010-12-10 15:54:14 +00:00
|
|
|
Width *= -1;
|
2010-09-28 02:15:02 +00:00
|
|
|
}
|
2010-09-30 15:24:34 +00:00
|
|
|
if (Height < 0)
|
2010-09-28 02:15:02 +00:00
|
|
|
{
|
2010-09-30 15:24:34 +00:00
|
|
|
Y += Height;
|
|
|
|
Height *= -1;
|
2010-09-28 02:15:02 +00:00
|
|
|
}
|
2011-05-12 02:14:45 +00:00
|
|
|
|
|
|
|
// OpenGL does not require any viewport correct
|
|
|
|
Matrix44::LoadIdentity(vpCorrection);
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Update the view port
|
2010-09-30 15:24:34 +00:00
|
|
|
glViewport(X, Y, Width, Height);
|
2010-09-28 02:15:02 +00:00
|
|
|
glDepthRange(GLNear, GLFar);
|
|
|
|
}
|
|
|
|
|
2010-12-19 22:00:25 +00:00
|
|
|
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z)
|
2009-07-15 00:51:24 +00:00
|
|
|
{
|
2010-12-28 16:16:27 +00:00
|
|
|
ResetAPIState();
|
2009-07-15 00:51:24 +00:00
|
|
|
|
2011-11-30 03:50:31 +00:00
|
|
|
// color
|
|
|
|
GLboolean const
|
|
|
|
color_mask = colorEnable ? GL_TRUE : GL_FALSE,
|
|
|
|
alpha_mask = alphaEnable ? GL_TRUE : GL_FALSE;
|
|
|
|
glColorMask(color_mask, color_mask, color_mask, alpha_mask);
|
2009-07-15 00:51:24 +00:00
|
|
|
|
2011-11-30 03:50:31 +00:00
|
|
|
glClearColor(
|
|
|
|
float((color >> 16) & 0xFF) / 255.0f,
|
|
|
|
float((color >> 8) & 0xFF) / 255.0f,
|
|
|
|
float((color >> 0) & 0xFF) / 255.0f,
|
|
|
|
float((color >> 24) & 0xFF) / 255.0f);
|
|
|
|
|
|
|
|
// depth
|
|
|
|
glDepthMask(zEnable ? GL_TRUE : GL_FALSE);
|
2009-07-15 00:51:24 +00:00
|
|
|
|
2011-11-30 03:50:31 +00:00
|
|
|
glClearDepth(float(z & 0xFFFFFF) / float(0xFFFFFF));
|
|
|
|
|
|
|
|
// Update rect for clearing the picture
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
TargetRectangle const targetRc = ConvertEFBRectangle(rc);
|
|
|
|
glScissor(targetRc.left, targetRc.bottom, targetRc.GetWidth(), targetRc.GetHeight());
|
2009-07-15 00:51:24 +00:00
|
|
|
|
2011-11-30 03:50:31 +00:00
|
|
|
// glColorMask/glDepthMask/glScissor affect glClear (glViewport does not)
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2010-12-28 16:16:27 +00:00
|
|
|
|
|
|
|
RestoreAPIState();
|
2011-08-22 04:15:02 +00:00
|
|
|
|
|
|
|
ClearEFBCache();
|
2009-07-15 00:51:24 +00:00
|
|
|
}
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-12-27 21:56:20 +00:00
|
|
|
void Renderer::ReinterpretPixelData(unsigned int convtype)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetBlendMode(bool forceUpdate)
|
2009-06-26 08:57:53 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
// blend mode bit mask
|
|
|
|
// 0 - blend enable
|
|
|
|
// 2 - reverse subtract enable (else add)
|
|
|
|
// 3-5 - srcRGB function
|
|
|
|
// 6-8 - dstRGB function
|
|
|
|
|
|
|
|
u32 newval = bpmem.blendmode.subtract << 2;
|
|
|
|
|
|
|
|
if (bpmem.blendmode.subtract)
|
|
|
|
newval |= 0x0049; // enable blending src 1 dst 1
|
|
|
|
else if (bpmem.blendmode.blendenable)
|
2010-07-02 17:09:53 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
newval |= 1; // enable blending
|
|
|
|
newval |= bpmem.blendmode.srcfactor << 3;
|
|
|
|
newval |= bpmem.blendmode.dstfactor << 6;
|
2009-08-31 17:47:17 +00:00
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
|
|
|
|
u32 changes = forceUpdate ? 0xFFFFFFFF : newval ^ s_blendMode;
|
|
|
|
|
2010-10-24 18:26:28 +00:00
|
|
|
#ifdef USE_DUAL_SOURCE_BLEND
|
2010-10-23 19:55:19 +00:00
|
|
|
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate
|
|
|
|
&& bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
2010-10-24 18:26:28 +00:00
|
|
|
bool useDualSource = useDstAlpha && GLEW_ARB_blend_func_extended;
|
|
|
|
#endif
|
2010-10-23 19:55:19 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (changes & 1)
|
|
|
|
// blend enable change
|
|
|
|
(newval & 1) ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
if (changes & 4)
|
2010-10-23 19:55:19 +00:00
|
|
|
{
|
2010-10-24 18:26:28 +00:00
|
|
|
#ifdef USE_DUAL_SOURCE_BLEND
|
2010-09-28 02:15:02 +00:00
|
|
|
// subtract enable change
|
2010-10-23 19:55:19 +00:00
|
|
|
GLenum equation = newval & 4 ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD;
|
|
|
|
GLenum equationAlpha = useDualSource ? GL_FUNC_ADD : equation;
|
|
|
|
glBlendEquationSeparate(equation, equationAlpha);
|
2010-10-24 18:26:28 +00:00
|
|
|
#else
|
|
|
|
glBlendEquation(newval & 4 ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD);
|
|
|
|
#endif
|
2010-10-23 19:55:19 +00:00
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
|
|
|
|
if (changes & 0x1F8)
|
2010-10-23 19:55:19 +00:00
|
|
|
{
|
2010-10-24 18:26:28 +00:00
|
|
|
#ifdef USE_DUAL_SOURCE_BLEND
|
2010-10-23 19:55:19 +00:00
|
|
|
GLenum srcFactor = glSrcFactors[(newval >> 3) & 7];
|
|
|
|
GLenum srcFactorAlpha = srcFactor;
|
|
|
|
GLenum dstFactor = glDestFactors[(newval >> 6) & 7];
|
|
|
|
GLenum dstFactorAlpha = dstFactor;
|
|
|
|
if (useDualSource)
|
|
|
|
{
|
|
|
|
srcFactorAlpha = GL_ONE;
|
|
|
|
dstFactorAlpha = GL_ZERO;
|
|
|
|
|
|
|
|
if (srcFactor == GL_SRC_ALPHA)
|
|
|
|
srcFactor = GL_SRC1_ALPHA;
|
|
|
|
else if (srcFactor == GL_ONE_MINUS_SRC_ALPHA)
|
|
|
|
srcFactor = GL_ONE_MINUS_SRC1_ALPHA;
|
|
|
|
|
|
|
|
if (dstFactor == GL_SRC_ALPHA)
|
|
|
|
dstFactor = GL_SRC1_ALPHA;
|
|
|
|
else if (dstFactor == GL_ONE_MINUS_SRC_ALPHA)
|
|
|
|
dstFactor = GL_ONE_MINUS_SRC1_ALPHA;
|
|
|
|
}
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// blend RGB change
|
2010-10-23 19:55:19 +00:00
|
|
|
glBlendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
|
2010-10-24 18:26:28 +00:00
|
|
|
#else
|
|
|
|
glBlendFunc(glSrcFactors[(newval >> 3) & 7], glDestFactors[(newval >> 6) & 7]);
|
|
|
|
#endif
|
2010-10-23 19:55:19 +00:00
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
|
|
|
|
s_blendMode = newval;
|
2009-06-26 08:57:53 +00:00
|
|
|
}
|
|
|
|
|
2009-06-29 07:30:48 +00:00
|
|
|
// This function has the final picture. We adjust the aspect ratio here.
|
2010-12-27 03:18:01 +00:00
|
|
|
void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma)
|
2009-02-28 16:33:59 +00:00
|
|
|
{
|
2011-02-11 18:59:42 +00:00
|
|
|
static int w = 0, h = 0;
|
2012-09-28 21:19:50 +00:00
|
|
|
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
|
2010-01-28 14:37:03 +00:00
|
|
|
{
|
2011-09-08 15:09:24 +00:00
|
|
|
if (g_ActiveConfig.bDumpFrames && frame_data)
|
2012-08-28 10:27:58 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2011-09-08 15:09:24 +00:00
|
|
|
AVIDump::AddFrame(frame_data);
|
2012-08-28 10:27:58 +00:00
|
|
|
#elif defined HAVE_LIBAV
|
2011-09-09 03:24:11 +00:00
|
|
|
AVIDump::AddFrame((u8*)frame_data, w, h);
|
2012-08-28 10:27:58 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-01-31 01:28:32 +00:00
|
|
|
Core::Callback_VideoCopiedToXFB(false);
|
2009-08-08 01:39:56 +00:00
|
|
|
return;
|
2010-06-05 01:38:22 +00:00
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
// this function is called after the XFB field is changed, not after
|
|
|
|
// EFB is copied to XFB. In this way, flickering is reduced in games
|
|
|
|
// and seems to also give more FPS in ZTP
|
|
|
|
|
2010-04-14 13:57:16 +00:00
|
|
|
if (field == FIELD_LOWER) xfbAddr -= fbWidth * 2;
|
2010-03-10 06:45:13 +00:00
|
|
|
u32 xfbCount = 0;
|
2010-11-14 23:31:53 +00:00
|
|
|
const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
|
2012-09-28 21:19:50 +00:00
|
|
|
if (g_ActiveConfig.VirtualXFBEnabled() && (!xfbSourceList || xfbCount == 0))
|
2009-06-29 07:30:48 +00:00
|
|
|
{
|
2011-09-08 15:09:24 +00:00
|
|
|
if (g_ActiveConfig.bDumpFrames && frame_data)
|
2011-09-08 13:39:03 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2011-09-08 15:09:24 +00:00
|
|
|
AVIDump::AddFrame(frame_data);
|
2011-09-08 13:39:03 +00:00
|
|
|
#elif defined HAVE_LIBAV
|
2011-09-09 03:24:11 +00:00
|
|
|
AVIDump::AddFrame((u8*)frame_data, w, h);
|
2011-09-08 13:39:03 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-01-31 01:28:32 +00:00
|
|
|
Core::Callback_VideoCopiedToXFB(false);
|
2009-06-29 07:30:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
ResetAPIState();
|
2010-11-18 02:21:26 +00:00
|
|
|
|
2012-09-28 22:04:55 +00:00
|
|
|
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
|
|
|
TargetRectangle flipped_trc = GetTargetRectangle();
|
|
|
|
|
|
|
|
// Flip top and bottom for some reason; TODO: Fix the code to suck less?
|
|
|
|
int tmp = flipped_trc.top;
|
|
|
|
flipped_trc.top = flipped_trc.bottom;
|
|
|
|
flipped_trc.bottom = tmp;
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2009-06-26 08:57:53 +00:00
|
|
|
// Textured triangles are necessary because of post-processing shaders
|
2009-02-28 19:02:37 +00:00
|
|
|
|
2009-06-26 08:57:53 +00:00
|
|
|
// Disable all other stages
|
|
|
|
for (int i = 1; i < 8; ++i)
|
2010-10-19 22:24:27 +00:00
|
|
|
OGL::TextureCache::DisableStage(i);
|
2009-03-08 19:19:51 +00:00
|
|
|
|
2009-06-26 08:57:53 +00:00
|
|
|
// Update GLViewPort
|
2012-09-28 22:04:55 +00:00
|
|
|
glViewport(flipped_trc.left, flipped_trc.bottom, flipped_trc.GetWidth(), flipped_trc.GetHeight());
|
2009-03-08 19:19:51 +00:00
|
|
|
|
2009-06-26 08:57:53 +00:00
|
|
|
GL_REPORT_ERRORD();
|
2009-03-08 19:19:51 +00:00
|
|
|
|
2009-06-26 08:57:53 +00:00
|
|
|
// Copy the framebuffer to screen.
|
|
|
|
|
|
|
|
// Texture map s_xfbTexture onto the main buffer
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
// Use linear filtering.
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
// We must call ApplyShader here even if no post proc is selected - it takes
|
2009-06-26 08:57:53 +00:00
|
|
|
// care of disabling it in that case. It returns false in case of no post processing.
|
2010-03-10 06:45:13 +00:00
|
|
|
bool applyShader = PostProcessing::ApplyShader();
|
|
|
|
|
2010-11-14 23:31:53 +00:00
|
|
|
const XFBSourceBase* xfbSource = NULL;
|
2010-03-10 06:45:13 +00:00
|
|
|
|
2010-07-02 17:09:53 +00:00
|
|
|
if(g_ActiveConfig.bUseXFB)
|
2009-06-26 08:57:53 +00:00
|
|
|
{
|
2010-07-02 17:09:53 +00:00
|
|
|
// draw each xfb source
|
2010-07-12 19:30:25 +00:00
|
|
|
// Render to the real buffer now.
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the window backbuffer
|
|
|
|
|
2010-07-02 17:09:53 +00:00
|
|
|
for (u32 i = 0; i < xfbCount; ++i)
|
2010-03-10 06:45:13 +00:00
|
|
|
{
|
2010-07-02 17:09:53 +00:00
|
|
|
xfbSource = xfbSourceList[i];
|
2010-03-10 06:45:13 +00:00
|
|
|
|
2010-07-02 17:09:53 +00:00
|
|
|
MathUtil::Rectangle<float> drawRc;
|
2010-03-10 06:45:13 +00:00
|
|
|
|
2012-09-28 21:21:09 +00:00
|
|
|
if (g_ActiveConfig.bUseRealXFB)
|
|
|
|
{
|
|
|
|
drawRc.top = 1;
|
|
|
|
drawRc.bottom = -1;
|
|
|
|
drawRc.left = -1;
|
|
|
|
drawRc.right = 1;
|
|
|
|
}
|
|
|
|
else
|
2010-03-10 06:45:13 +00:00
|
|
|
{
|
2010-07-02 17:09:53 +00:00
|
|
|
// use virtual xfb with offset
|
|
|
|
int xfbHeight = xfbSource->srcHeight;
|
|
|
|
int xfbWidth = xfbSource->srcWidth;
|
|
|
|
int hOffset = ((s32)xfbSource->srcAddr - (s32)xfbAddr) / ((s32)fbWidth * 2);
|
|
|
|
|
|
|
|
drawRc.top = 1.0f - (2.0f * (hOffset) / (float)fbHeight);
|
|
|
|
drawRc.bottom = 1.0f - (2.0f * (hOffset + xfbHeight) / (float)fbHeight);
|
|
|
|
drawRc.left = -(xfbWidth / (float)fbWidth);
|
|
|
|
drawRc.right = (xfbWidth / (float)fbWidth);
|
|
|
|
|
2010-09-30 15:24:34 +00:00
|
|
|
// The following code disables auto stretch. Kept for reference.
|
|
|
|
// scale draw area for a 1 to 1 pixel mapping with the draw target
|
2012-09-28 22:04:55 +00:00
|
|
|
//float vScale = (float)fbHeight / (float)flipped_trc.GetHeight();
|
|
|
|
//float hScale = (float)fbWidth / (float)flipped_trc.GetWidth();
|
2010-09-30 15:24:34 +00:00
|
|
|
//drawRc.top *= vScale;
|
|
|
|
//drawRc.bottom *= vScale;
|
|
|
|
//drawRc.left *= hScale;
|
|
|
|
//drawRc.right *= hScale;
|
2010-03-10 06:45:13 +00:00
|
|
|
}
|
2010-07-02 17:09:53 +00:00
|
|
|
// Tell the OSD Menu about the current internal resolution
|
|
|
|
OSDInternalW = xfbSource->sourceRc.GetWidth(); OSDInternalH = xfbSource->sourceRc.GetHeight();
|
2010-03-10 06:45:13 +00:00
|
|
|
|
2010-11-14 23:31:53 +00:00
|
|
|
MathUtil::Rectangle<float> sourceRc;
|
|
|
|
sourceRc.left = xfbSource->sourceRc.left;
|
|
|
|
sourceRc.right = xfbSource->sourceRc.right;
|
|
|
|
sourceRc.top = xfbSource->sourceRc.top;
|
|
|
|
sourceRc.bottom = xfbSource->sourceRc.bottom;
|
|
|
|
|
|
|
|
xfbSource->Draw(sourceRc, drawRc, 0, 0);
|
2010-03-10 06:45:13 +00:00
|
|
|
|
2010-08-10 01:08:22 +00:00
|
|
|
// We must call ApplyShader here even if no post proc is selected.
|
|
|
|
// It takes care of disabling it in that case. It returns false in
|
|
|
|
// case of no post processing.
|
2010-07-02 17:09:53 +00:00
|
|
|
if (applyShader)
|
|
|
|
PixelShaderCache::DisableShader();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-30 15:24:34 +00:00
|
|
|
TargetRectangle targetRc = ConvertEFBRectangle(rc);
|
2010-11-14 23:31:53 +00:00
|
|
|
GLuint read_texture = FramebufferManager::ResolveAndGetRenderTarget(rc);
|
2010-07-12 19:30:25 +00:00
|
|
|
// Render to the real buffer now.
|
2010-07-07 22:09:52 +00:00
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the window backbuffer
|
2010-07-02 17:09:53 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2012-12-09 19:30:29 +00:00
|
|
|
if(!( s_cached_targetRc == targetRc)) {
|
2012-12-09 18:22:21 +00:00
|
|
|
GLfloat vertices[] = {
|
|
|
|
-1.0f, -1.0f, 1.0f,
|
|
|
|
(GLfloat)targetRc.left, (GLfloat)targetRc.bottom,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
|
|
|
|
-1.0f, 1.0f, 1.0f,
|
|
|
|
(GLfloat)targetRc.left, (GLfloat)targetRc.top,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
|
|
|
|
1.0f, 1.0f, 1.0f,
|
|
|
|
(GLfloat)targetRc.right, (GLfloat)targetRc.top,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
|
|
|
|
1.0f, -1.0f, 1.0f,
|
|
|
|
(GLfloat)targetRc.right, (GLfloat)targetRc.bottom,
|
|
|
|
1.0f, 0.0f
|
|
|
|
};
|
2012-12-08 01:01:35 +00:00
|
|
|
|
2012-12-09 18:22:21 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, s_Swap_VBO);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, 4*7*sizeof(GLfloat), vertices, GL_STREAM_DRAW);
|
2012-12-13 14:48:42 +00:00
|
|
|
|
2012-12-09 19:30:29 +00:00
|
|
|
s_cached_targetRc = targetRc;
|
2012-12-09 21:49:58 +00:00
|
|
|
}
|
2012-12-08 01:01:35 +00:00
|
|
|
|
2012-12-09 21:49:58 +00:00
|
|
|
glBindVertexArray(s_Swap_VAO[applyShader]);
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
2012-10-28 03:50:06 +00:00
|
|
|
|
2012-12-13 14:48:42 +00:00
|
|
|
|
|
|
|
// TODO: this after merging with graphic_update
|
|
|
|
glBindVertexArray(0);
|
2012-12-29 11:50:42 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2012-12-13 14:48:42 +00:00
|
|
|
|
2011-08-25 10:20:41 +00:00
|
|
|
if(applyShader)
|
|
|
|
PixelShaderCache::DisableShader();
|
2009-06-26 08:57:53 +00:00
|
|
|
}
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2009-06-26 08:57:53 +00:00
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
2010-10-19 22:24:27 +00:00
|
|
|
OGL::TextureCache::DisableStage(0);
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2009-06-08 00:44:48 +00:00
|
|
|
// Save screenshot
|
|
|
|
if (s_bScreenshot)
|
2009-06-07 11:51:53 +00:00
|
|
|
{
|
2011-03-05 06:11:26 +00:00
|
|
|
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
2012-09-28 22:04:55 +00:00
|
|
|
SaveScreenshot(s_sScreenshotName, flipped_trc);
|
2009-06-07 11:51:53 +00:00
|
|
|
// Reset settings
|
2010-11-18 02:21:26 +00:00
|
|
|
s_sScreenshotName.clear();
|
2009-06-07 11:51:53 +00:00
|
|
|
s_bScreenshot = false;
|
|
|
|
}
|
|
|
|
|
2009-03-28 21:07:16 +00:00
|
|
|
// Frame dumps are handled a little differently in Windows
|
2011-03-11 12:56:26 +00:00
|
|
|
#if defined _WIN32 || defined HAVE_LIBAV
|
2009-09-13 08:21:35 +00:00
|
|
|
if (g_ActiveConfig.bDumpFrames)
|
2009-06-08 10:16:08 +00:00
|
|
|
{
|
2011-03-05 06:11:26 +00:00
|
|
|
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
2012-09-28 22:04:55 +00:00
|
|
|
if (!frame_data || w != flipped_trc.GetWidth() ||
|
|
|
|
h != flipped_trc.GetHeight())
|
2011-02-11 18:59:42 +00:00
|
|
|
{
|
2011-09-08 15:09:24 +00:00
|
|
|
if (frame_data) delete[] frame_data;
|
2012-09-28 22:04:55 +00:00
|
|
|
w = flipped_trc.GetWidth();
|
|
|
|
h = flipped_trc.GetHeight();
|
2011-09-08 15:09:24 +00:00
|
|
|
frame_data = new char[3 * w * h];
|
2011-02-11 18:59:42 +00:00
|
|
|
}
|
2009-03-28 21:07:16 +00:00
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
2012-09-28 22:04:55 +00:00
|
|
|
glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data);
|
2010-08-03 10:48:49 +00:00
|
|
|
if (GL_REPORT_ERROR() == GL_NO_ERROR && w > 0 && h > 0)
|
2009-04-03 14:35:49 +00:00
|
|
|
{
|
2011-09-08 13:39:03 +00:00
|
|
|
if (!bLastFrameDumped)
|
2009-04-03 14:35:49 +00:00
|
|
|
{
|
2010-11-14 21:14:26 +00:00
|
|
|
#ifdef _WIN32
|
2011-09-08 15:09:24 +00:00
|
|
|
bAVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), w, h);
|
2010-11-14 21:14:26 +00:00
|
|
|
#else
|
2011-09-08 15:09:24 +00:00
|
|
|
bAVIDumping = AVIDump::Start(w, h);
|
2010-11-14 21:14:26 +00:00
|
|
|
#endif
|
2011-09-08 15:09:24 +00:00
|
|
|
if (!bAVIDumping)
|
2009-06-08 10:16:08 +00:00
|
|
|
OSD::AddMessage("AVIDump Start failed", 2000);
|
2010-06-05 01:38:22 +00:00
|
|
|
else
|
2009-04-03 14:35:49 +00:00
|
|
|
{
|
2009-06-08 10:16:08 +00:00
|
|
|
OSD::AddMessage(StringFromFormat(
|
2010-11-18 16:46:17 +00:00
|
|
|
"Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)",
|
2011-02-28 20:40:15 +00:00
|
|
|
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h).c_str(), 2000);
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-08 15:09:24 +00:00
|
|
|
if (bAVIDumping)
|
2010-11-14 21:14:26 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2011-09-08 15:09:24 +00:00
|
|
|
AVIDump::AddFrame(frame_data);
|
2010-11-14 21:14:26 +00:00
|
|
|
#else
|
2011-09-09 03:24:11 +00:00
|
|
|
FlipImageData((u8*)frame_data, w, h);
|
|
|
|
AVIDump::AddFrame((u8*)frame_data, w, h);
|
2010-11-14 21:14:26 +00:00
|
|
|
#endif
|
|
|
|
}
|
2009-04-03 14:35:49 +00:00
|
|
|
|
2011-09-08 13:39:03 +00:00
|
|
|
bLastFrameDumped = true;
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
2009-06-08 10:16:08 +00:00
|
|
|
else
|
|
|
|
NOTICE_LOG(VIDEO, "Error reading framebuffer");
|
2010-06-05 01:38:22 +00:00
|
|
|
}
|
|
|
|
else
|
2009-04-03 14:35:49 +00:00
|
|
|
{
|
2011-09-08 15:09:24 +00:00
|
|
|
if (bLastFrameDumped && bAVIDumping)
|
2009-04-03 14:35:49 +00:00
|
|
|
{
|
2011-09-08 15:09:24 +00:00
|
|
|
if (frame_data)
|
2011-02-11 18:59:42 +00:00
|
|
|
{
|
2011-09-08 15:09:24 +00:00
|
|
|
delete[] frame_data;
|
|
|
|
frame_data = NULL;
|
2011-02-11 18:59:42 +00:00
|
|
|
w = h = 0;
|
|
|
|
}
|
2009-03-28 21:07:16 +00:00
|
|
|
AVIDump::Stop();
|
2011-09-08 15:09:24 +00:00
|
|
|
bAVIDumping = false;
|
2010-11-14 21:14:26 +00:00
|
|
|
OSD::AddMessage("Stop dumping frames", 2000);
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
2011-09-08 13:39:03 +00:00
|
|
|
bLastFrameDumped = false;
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
|
|
|
#else
|
2010-08-10 01:08:22 +00:00
|
|
|
if (g_ActiveConfig.bDumpFrames)
|
|
|
|
{
|
2011-03-05 12:05:58 +00:00
|
|
|
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
2011-02-28 20:40:15 +00:00
|
|
|
std::string movie_file_name;
|
2012-09-28 22:04:55 +00:00
|
|
|
w = GetTargetRectangle().GetWidth();
|
|
|
|
h = GetTargetRectangle().GetHeight();
|
2011-09-12 15:58:05 +00:00
|
|
|
frame_data = new char[3 * w * h];
|
2009-03-28 21:07:16 +00:00
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
2012-09-28 22:04:55 +00:00
|
|
|
glReadPixels(GetTargetRectangle().left, GetTargetRectangle().bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data);
|
2010-08-10 01:08:22 +00:00
|
|
|
if (GL_REPORT_ERROR() == GL_NO_ERROR)
|
|
|
|
{
|
2011-09-08 15:09:24 +00:00
|
|
|
if (!bLastFrameDumped)
|
2010-08-10 01:08:22 +00:00
|
|
|
{
|
2011-02-28 20:40:15 +00:00
|
|
|
movie_file_name = File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump.raw";
|
2011-09-08 15:09:24 +00:00
|
|
|
pFrameDump.Open(movie_file_name, "wb");
|
|
|
|
if (!pFrameDump)
|
2010-08-10 01:08:22 +00:00
|
|
|
OSD::AddMessage("Error opening framedump.raw for writing.", 2000);
|
|
|
|
else
|
|
|
|
{
|
2009-03-28 21:07:16 +00:00
|
|
|
char msg [255];
|
2011-02-28 20:40:15 +00:00
|
|
|
sprintf(msg, "Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h);
|
2009-03-28 21:07:16 +00:00
|
|
|
OSD::AddMessage(msg, 2000);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 15:09:24 +00:00
|
|
|
if (pFrameDump)
|
2010-08-10 01:08:22 +00:00
|
|
|
{
|
2011-09-12 15:58:05 +00:00
|
|
|
FlipImageData((u8*)frame_data, w, h);
|
2011-09-08 15:09:24 +00:00
|
|
|
pFrameDump.WriteBytes(frame_data, w * 3 * h);
|
|
|
|
pFrameDump.Flush();
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
2011-09-08 15:09:24 +00:00
|
|
|
bLastFrameDumped = true;
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2011-09-08 15:09:24 +00:00
|
|
|
delete[] frame_data;
|
2010-08-10 01:08:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-08 15:09:24 +00:00
|
|
|
if (bLastFrameDumped)
|
|
|
|
pFrameDump.Close();
|
|
|
|
bLastFrameDumped = false;
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-09-30 15:24:34 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Finish up the current frame, print some stats
|
2011-01-07 04:57:59 +00:00
|
|
|
|
2011-01-25 03:30:12 +00:00
|
|
|
SetWindowSize(fbWidth, fbHeight);
|
2011-01-07 04:57:59 +00:00
|
|
|
|
2012-12-17 20:54:20 +00:00
|
|
|
GLInterface->Update(); // just updates the render window position and the backbuffer size
|
2011-05-07 22:00:05 +00:00
|
|
|
|
2010-05-19 03:15:36 +00:00
|
|
|
bool xfbchanged = false;
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2012-09-28 21:48:18 +00:00
|
|
|
if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight)
|
2010-05-19 03:15:36 +00:00
|
|
|
{
|
|
|
|
xfbchanged = true;
|
2012-09-28 21:48:18 +00:00
|
|
|
unsigned int w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth;
|
|
|
|
unsigned int h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight;
|
|
|
|
FramebufferManagerBase::SetLastXfbWidth(w);
|
|
|
|
FramebufferManagerBase::SetLastXfbHeight(h);
|
2010-05-19 03:15:36 +00:00
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2010-05-19 03:15:36 +00:00
|
|
|
bool WindowResized = false;
|
2012-12-17 20:54:20 +00:00
|
|
|
int W = (int)GLInterface->GetBackBufferWidth();
|
|
|
|
int H = (int)GLInterface->GetBackBufferHeight();
|
2010-09-30 15:24:34 +00:00
|
|
|
if (W != s_backbuffer_width || H != s_backbuffer_height || s_LastEFBScale != g_ActiveConfig.iEFBScale)
|
2010-05-19 03:15:36 +00:00
|
|
|
{
|
|
|
|
WindowResized = true;
|
2010-09-28 02:15:02 +00:00
|
|
|
s_backbuffer_width = W;
|
|
|
|
s_backbuffer_height = H;
|
2010-09-30 15:24:34 +00:00
|
|
|
s_LastEFBScale = g_ActiveConfig.iEFBScale;
|
2010-05-19 03:15:36 +00:00
|
|
|
}
|
|
|
|
|
2011-05-07 22:00:05 +00:00
|
|
|
if (xfbchanged || WindowResized || (s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode))
|
2010-06-05 01:38:22 +00:00
|
|
|
{
|
2012-09-28 22:04:55 +00:00
|
|
|
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2012-09-28 22:19:28 +00:00
|
|
|
if (CalculateTargetSize(s_backbuffer_width, s_backbuffer_height) || s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode)
|
2010-05-19 03:15:36 +00:00
|
|
|
{
|
2011-05-07 22:00:05 +00:00
|
|
|
s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode;
|
|
|
|
s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode);
|
|
|
|
s_MSAACoverageSamples = GetNumMSAACoverageSamples(s_LastMultisampleMode);
|
|
|
|
|
2010-11-14 23:31:53 +00:00
|
|
|
delete g_framebuffer_manager;
|
|
|
|
g_framebuffer_manager = new FramebufferManager(s_target_width, s_target_height,
|
2010-09-28 02:15:02 +00:00
|
|
|
s_MSAASamples, s_MSAACoverageSamples);
|
2010-05-19 03:15:36 +00:00
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (XFBWrited)
|
2012-10-04 03:41:02 +00:00
|
|
|
s_fps = UpdateFPSCounter();
|
2009-06-07 12:06:15 +00:00
|
|
|
// ---------------------------------------------------------------------
|
2010-06-05 01:38:22 +00:00
|
|
|
GL_REPORT_ERRORD();
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-06-07 12:06:15 +00:00
|
|
|
DrawDebugText();
|
2010-11-21 21:45:38 +00:00
|
|
|
DrawDebugInfo();
|
2009-06-07 12:06:15 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
GL_REPORT_ERRORD();
|
2009-06-13 22:08:01 +00:00
|
|
|
|
2009-09-03 20:37:35 +00:00
|
|
|
// Get the status of the Blend mode
|
|
|
|
GLboolean blend_enabled = glIsEnabled(GL_BLEND);
|
|
|
|
glDisable(GL_BLEND);
|
2009-06-07 12:06:15 +00:00
|
|
|
OSD::DrawMessages();
|
2009-09-03 20:37:35 +00:00
|
|
|
if (blend_enabled)
|
|
|
|
glEnable(GL_BLEND);
|
2010-06-05 01:38:22 +00:00
|
|
|
GL_REPORT_ERRORD();
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
// Copy the rendered frame to the real window
|
2012-12-26 06:34:09 +00:00
|
|
|
GLInterface->Swap();
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-06-13 22:08:01 +00:00
|
|
|
GL_REPORT_ERRORD();
|
2009-08-08 01:39:56 +00:00
|
|
|
|
2009-06-08 20:07:20 +00:00
|
|
|
// Clear framebuffer
|
2010-09-23 02:17:48 +00:00
|
|
|
if(!g_ActiveConfig.bAnaglyphStereo)
|
|
|
|
{
|
|
|
|
glClearColor(0, 0, 0, 0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
2009-06-07 12:06:15 +00:00
|
|
|
|
2009-08-08 01:39:56 +00:00
|
|
|
GL_REPORT_ERRORD();
|
2009-06-07 12:06:15 +00:00
|
|
|
|
2010-01-17 17:44:09 +00:00
|
|
|
// Clean out old stuff from caches. It's not worth it to clean out the shader caches.
|
2009-08-09 11:03:58 +00:00
|
|
|
DLCache::ProgressiveCleanup();
|
2010-09-28 02:15:02 +00:00
|
|
|
TextureCache::Cleanup();
|
2009-06-07 12:06:15 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
frameCount++;
|
2009-06-07 12:06:15 +00:00
|
|
|
|
2010-12-05 14:15:36 +00:00
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true);
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Begin new frame
|
|
|
|
// Set default viewport and scissor, for the clear to work correctly
|
2010-06-05 01:38:22 +00:00
|
|
|
// New frame
|
|
|
|
stats.ResetFrame();
|
2009-06-07 12:06:15 +00:00
|
|
|
|
|
|
|
// Render to the framebuffer.
|
2010-11-14 23:31:53 +00:00
|
|
|
FramebufferManager::SetFramebuffer(0);
|
2009-06-07 12:06:15 +00:00
|
|
|
|
|
|
|
GL_REPORT_ERRORD();
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
RestoreAPIState();
|
2009-09-13 17:46:33 +00:00
|
|
|
|
|
|
|
GL_REPORT_ERRORD();
|
2010-06-05 01:38:22 +00:00
|
|
|
g_Config.iSaveTargetId = 0;
|
2009-09-13 17:46:33 +00:00
|
|
|
|
2010-12-28 12:46:00 +00:00
|
|
|
UpdateActiveConfig();
|
2012-05-28 09:31:37 +00:00
|
|
|
TextureCache::OnConfigChanged(g_ActiveConfig);
|
2010-12-28 12:46:00 +00:00
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
// For testing zbuffer targets.
|
2010-06-05 01:38:22 +00:00
|
|
|
// Renderer::SetZBufferRender();
|
2010-08-10 01:08:22 +00:00
|
|
|
// SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, s_FakeZTarget,
|
2010-11-18 02:21:26 +00:00
|
|
|
// GetTargetWidth(), GetTargetHeight());
|
2011-01-31 01:28:32 +00:00
|
|
|
Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB));
|
2010-03-25 22:01:33 +00:00
|
|
|
XFBWrited = false;
|
2011-08-22 04:15:02 +00:00
|
|
|
|
|
|
|
// Invalidate EFB cache
|
|
|
|
ClearEFBCache();
|
2009-09-13 17:46:33 +00:00
|
|
|
}
|
2009-06-07 12:06:15 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// ALWAYS call RestoreAPIState for each ResetAPIState call you're doing
|
|
|
|
void Renderer::ResetAPIState()
|
2009-02-23 07:23:34 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
// Gets us to a reasonably sane state where it's possible to do things like
|
|
|
|
// image copies with textured quads, etc.
|
|
|
|
VertexShaderCache::DisableShader();
|
|
|
|
PixelShaderCache::DisableShader();
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
}
|
2009-02-23 07:23:34 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::RestoreAPIState()
|
|
|
|
{
|
|
|
|
// Gets us back into a more game-like state.
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2010-12-28 16:16:27 +00:00
|
|
|
SetGenerationMode();
|
2011-09-05 20:04:28 +00:00
|
|
|
BPFunctions::SetScissor();
|
2010-09-28 02:15:02 +00:00
|
|
|
SetColorMask();
|
2010-12-28 16:16:27 +00:00
|
|
|
SetDepthMode();
|
2010-09-28 02:15:02 +00:00
|
|
|
SetBlendMode(true);
|
2011-05-12 02:14:45 +00:00
|
|
|
VertexShaderManager::SetViewportChanged();
|
2009-03-16 07:54:44 +00:00
|
|
|
|
2011-11-30 04:21:43 +00:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, g_ActiveConfig.bWireFrame ? GL_LINE : GL_FILL);
|
2011-02-06 18:43:56 +00:00
|
|
|
|
2010-11-18 15:12:12 +00:00
|
|
|
VertexShaderCache::SetCurrentShader(0);
|
2010-09-28 02:15:02 +00:00
|
|
|
PixelShaderCache::SetCurrentShader(0);
|
|
|
|
}
|
2009-03-16 07:54:44 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetGenerationMode()
|
|
|
|
{
|
|
|
|
// none, ccw, cw, ccw
|
|
|
|
if (bpmem.genMode.cullmode > 0)
|
|
|
|
{
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW);
|
2009-03-16 07:54:44 +00:00
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
else
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
}
|
2009-03-16 07:54:44 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetDepthMode()
|
|
|
|
{
|
|
|
|
if (bpmem.zmode.testenable)
|
2009-09-13 08:21:35 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(bpmem.zmode.updateenable ? GL_TRUE : GL_FALSE);
|
|
|
|
glDepthFunc(glCmpFuncs[bpmem.zmode.func]);
|
2009-09-13 08:21:35 +00:00
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
else
|
2009-06-08 02:48:38 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
// if the test is disabled write is disabled too
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2009-10-22 20:22:50 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetLogicOpMode()
|
|
|
|
{
|
|
|
|
if (bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != 3)
|
|
|
|
{
|
|
|
|
glEnable(GL_COLOR_LOGIC_OP);
|
|
|
|
glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_COLOR_LOGIC_OP);
|
|
|
|
}
|
|
|
|
}
|
2009-10-22 20:22:50 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetDitherMode()
|
|
|
|
{
|
|
|
|
if (bpmem.blendmode.dither)
|
|
|
|
glEnable(GL_DITHER);
|
|
|
|
else
|
|
|
|
glDisable(GL_DITHER);
|
|
|
|
}
|
2009-10-22 20:22:50 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetLineWidth()
|
|
|
|
{
|
2011-04-11 01:49:32 +00:00
|
|
|
float fratio = xfregs.viewport.wd != 0 ?
|
2010-09-28 02:15:02 +00:00
|
|
|
((float)Renderer::GetTargetWidth() / EFB_WIDTH) : 1.0f;
|
|
|
|
if (bpmem.lineptwidth.linesize > 0)
|
|
|
|
// scale by ratio of widths
|
|
|
|
glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f);
|
|
|
|
if (bpmem.lineptwidth.pointsize > 0)
|
|
|
|
glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f);
|
|
|
|
}
|
2009-10-22 20:22:50 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetSamplerState(int stage, int texindex)
|
|
|
|
{
|
|
|
|
// TODO
|
2009-02-28 16:33:59 +00:00
|
|
|
}
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::SetInterlacingMode()
|
2009-02-23 07:23:34 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
// TODO
|
2009-02-23 07:23:34 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
void Renderer::FlipImageData(u8 *data, int w, int h)
|
|
|
|
{
|
|
|
|
// Flip image upside down. Damn OpenGL.
|
|
|
|
for (int y = 0; y < h / 2; y++)
|
|
|
|
{
|
|
|
|
for(int x = 0; x < w; x++)
|
|
|
|
{
|
|
|
|
std::swap(data[(y * w + x) * 3], data[((h - 1 - y) * w + x) * 3]);
|
|
|
|
std::swap(data[(y * w + x) * 3 + 1], data[((h - 1 - y) * w + x) * 3 + 1]);
|
|
|
|
std::swap(data[(y * w + x) * 3 + 2], data[((h - 1 - y) * w + x) * 3 + 2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
// TODO: remove
|
|
|
|
extern bool g_aspect_wide;
|
|
|
|
|
2009-07-31 01:55:26 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2011-01-27 20:47:58 +00:00
|
|
|
void TakeScreenshot(ScrStrct* threadStruct)
|
2009-07-29 03:11:35 +00:00
|
|
|
{
|
|
|
|
// These will contain the final image size
|
|
|
|
float FloatW = (float)threadStruct->W;
|
|
|
|
float FloatH = (float)threadStruct->H;
|
|
|
|
|
|
|
|
// Handle aspect ratio for the final ScrStrct to look exactly like what's on screen.
|
2010-01-13 21:11:02 +00:00
|
|
|
if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH)
|
2009-07-29 03:11:35 +00:00
|
|
|
{
|
2011-01-31 01:28:32 +00:00
|
|
|
bool use16_9 = g_aspect_wide;
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-01-13 21:11:02 +00:00
|
|
|
// Check for force-settings and override.
|
|
|
|
if (g_ActiveConfig.iAspectRatio == ASPECT_FORCE_16_9)
|
|
|
|
use16_9 = true;
|
|
|
|
else if (g_ActiveConfig.iAspectRatio == ASPECT_FORCE_4_3)
|
|
|
|
use16_9 = false;
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-01-13 21:11:02 +00:00
|
|
|
float Ratio = (FloatW / FloatH) / (!use16_9 ? (4.0f / 3.0f) : (16.0f / 9.0f));
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-07-29 03:11:35 +00:00
|
|
|
// If ratio > 1 the picture is too wide and we have to limit the width.
|
|
|
|
if (Ratio > 1)
|
|
|
|
FloatW /= Ratio;
|
|
|
|
// ratio == 1 or the image is too high, we have to limit the height.
|
|
|
|
else
|
|
|
|
FloatH *= Ratio;
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-07-31 01:55:26 +00:00
|
|
|
// This is a bit expensive on high resolutions
|
2009-07-29 03:11:35 +00:00
|
|
|
threadStruct->img->Rescale((int)FloatW, (int)FloatH, wxIMAGE_QUALITY_HIGH);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the screenshot and finally kill the wxImage object
|
2009-07-31 01:55:26 +00:00
|
|
|
// This is really expensive when saving to PNG, but not at all when using BMP
|
2010-08-10 01:08:22 +00:00
|
|
|
threadStruct->img->SaveFile(wxString::FromAscii(threadStruct->filename.c_str()),
|
2010-09-28 02:15:02 +00:00
|
|
|
wxBITMAP_TYPE_PNG);
|
2009-07-29 03:11:35 +00:00
|
|
|
threadStruct->img->Destroy();
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-07-29 03:11:35 +00:00
|
|
|
// Show success messages
|
2010-08-10 01:08:22 +00:00
|
|
|
OSD::AddMessage(StringFromFormat("Saved %i x %i %s", (int)FloatW, (int)FloatH,
|
2010-09-28 02:15:02 +00:00
|
|
|
threadStruct->filename.c_str()).c_str(), 2000);
|
2009-07-31 01:55:26 +00:00
|
|
|
delete threadStruct;
|
2009-07-29 03:11:35 +00:00
|
|
|
}
|
2009-07-31 01:55:26 +00:00
|
|
|
#endif
|
2009-07-29 03:11:35 +00:00
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
namespace OGL
|
|
|
|
{
|
|
|
|
|
|
|
|
bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle &back_rc)
|
2009-02-27 03:56:34 +00:00
|
|
|
{
|
2010-07-09 20:56:16 +00:00
|
|
|
u32 W = back_rc.GetWidth();
|
|
|
|
u32 H = back_rc.GetHeight();
|
2011-03-23 02:06:40 +00:00
|
|
|
u8 *data = (u8 *)malloc((sizeof(u8) * 3 * W * H));
|
2009-02-27 03:56:34 +00:00
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2010-07-09 20:56:16 +00:00
|
|
|
glReadPixels(back_rc.left, back_rc.bottom, W, H, GL_RGB, GL_UNSIGNED_BYTE, data);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-06-06 17:34:54 +00:00
|
|
|
// Show failure message
|
2010-08-03 10:48:49 +00:00
|
|
|
if (GL_REPORT_ERROR() != GL_NO_ERROR)
|
2009-06-06 17:34:54 +00:00
|
|
|
{
|
2011-03-23 02:06:40 +00:00
|
|
|
free(data);
|
2009-06-06 13:36:33 +00:00
|
|
|
OSD::AddMessage("Error capturing or saving screenshot.", 2000);
|
2009-06-06 17:34:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-06-06 13:36:33 +00:00
|
|
|
// Turn image upside down
|
|
|
|
FlipImageData(data, W, H);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-03-28 21:07:16 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-06-06 13:36:33 +00:00
|
|
|
// Create wxImage
|
2009-07-29 03:11:35 +00:00
|
|
|
wxImage *a = new wxImage(W, H, data);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2011-01-27 20:47:58 +00:00
|
|
|
if (scrshotThread.joinable())
|
|
|
|
scrshotThread.join();
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-07-29 03:11:35 +00:00
|
|
|
ScrStrct *threadStruct = new ScrStrct;
|
2010-11-18 02:21:26 +00:00
|
|
|
threadStruct->filename = filename;
|
2009-07-29 03:11:35 +00:00
|
|
|
threadStruct->img = a;
|
|
|
|
threadStruct->H = H; threadStruct->W = W;
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2011-01-27 20:47:58 +00:00
|
|
|
scrshotThread = std::thread(TakeScreenshot, threadStruct);
|
2009-07-31 01:55:26 +00:00
|
|
|
#ifdef _WIN32
|
2011-01-27 20:47:58 +00:00
|
|
|
SetThreadPriority(scrshotThread.native_handle(), THREAD_PRIORITY_BELOW_NORMAL);
|
2009-07-31 01:55:26 +00:00
|
|
|
#endif
|
2009-03-28 21:07:16 +00:00
|
|
|
bool result = true;
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-07-29 03:11:35 +00:00
|
|
|
OSD::AddMessage("Saving Screenshot... ", 2000);
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-03-28 21:07:16 +00:00
|
|
|
#else
|
2010-11-18 02:21:26 +00:00
|
|
|
bool result = SaveTGA(filename.c_str(), W, H, data);
|
2011-03-23 02:06:40 +00:00
|
|
|
free(data);
|
2009-07-29 00:49:12 +00:00
|
|
|
#endif
|
2010-08-10 01:08:22 +00:00
|
|
|
|
2009-03-28 21:07:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
2010-11-18 02:21:26 +00:00
|
|
|
|
2010-12-20 17:06:39 +00:00
|
|
|
}
|