2010-03-19 00:31:15 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
2010-07-10 08:20:50 +00:00
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-03-19 00:31:15 +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; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-19 00:31:15 +00:00
|
|
|
*/
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// Create and Destroy function. They would be called once per session.
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
//------------------ Includes
|
|
|
|
#include "GS.h"
|
|
|
|
#include "Mem.h"
|
|
|
|
#include "zerogs.h"
|
|
|
|
|
|
|
|
#include "ZeroGSShaders/zerogsshaders.h"
|
|
|
|
#include "targets.h"
|
|
|
|
// This include for windows resource file with Shaders
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include "Win32.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------ Defines
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define GL_LOADFN(name) { \
|
|
|
|
if( (*(void**)&name = (void*)wglGetProcAddress(#name)) == NULL ) { \
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Failed to find %s, exiting.", #name); \
|
2010-03-19 00:31:15 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// let GLEW take care of it
|
|
|
|
#define GL_LOADFN(name)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GL_BLEND_RGB(src, dst) { \
|
|
|
|
s_srcrgb = src; \
|
|
|
|
s_dstrgb = dst; \
|
|
|
|
zgsBlendFuncSeparateEXT(s_srcrgb, s_dstrgb, s_srcalpha, s_dstalpha); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GL_BLEND_ALPHA(src, dst) { \
|
|
|
|
s_srcalpha = src; \
|
|
|
|
s_dstalpha = dst; \
|
|
|
|
zgsBlendFuncSeparateEXT(s_srcrgb, s_dstrgb, s_srcalpha, s_dstalpha); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GL_BLEND_ALL(srcrgb, dstrgb, srcalpha, dstalpha) { \
|
|
|
|
s_srcrgb = srcrgb; \
|
|
|
|
s_dstrgb = dstrgb; \
|
|
|
|
s_srcalpha = srcalpha; \
|
|
|
|
s_dstalpha = dstalpha; \
|
|
|
|
zgsBlendFuncSeparateEXT(s_srcrgb, s_dstrgb, s_srcalpha, s_dstalpha); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GL_BLEND_SET() zgsBlendFuncSeparateEXT(s_srcrgb, s_dstrgb, s_srcalpha, s_dstalpha)
|
|
|
|
|
|
|
|
#define GL_STENCILFUNC(func, ref, mask) { \
|
|
|
|
s_stencilfunc = func; \
|
|
|
|
s_stencilref = ref; \
|
|
|
|
s_stencilmask = mask; \
|
|
|
|
glStencilFunc(func, ref, mask); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GL_STENCILFUNC_SET() glStencilFunc(s_stencilfunc, s_stencilref, s_stencilmask)
|
|
|
|
|
|
|
|
#define VB_BUFFERSIZE 0x400
|
|
|
|
#define VB_NUMBUFFERS 512
|
|
|
|
|
|
|
|
// ----------------- Types
|
2010-05-01 20:33:53 +00:00
|
|
|
typedef void (APIENTRYP _PFNSWAPINTERVAL)(int);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
map<string, GLbyte> mapGLExtensions;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
namespace ZeroGS
|
|
|
|
{
|
|
|
|
RenderFormatType g_RenderFormatType = RFT_float16;
|
|
|
|
|
|
|
|
extern void KickPoint();
|
|
|
|
extern void KickLine();
|
|
|
|
extern void KickTriangle();
|
|
|
|
extern void KickTriangleFan();
|
|
|
|
extern void KickSprite();
|
|
|
|
extern void KickDummy();
|
|
|
|
extern bool LoadEffects();
|
|
|
|
extern bool LoadExtraEffects();
|
|
|
|
extern FRAGMENTSHADER* LoadShadeEffect(int type, int texfilter, int fog, int testaem, int exactcolor, const clampInfo& clamp, int context, bool* pbFailed);
|
|
|
|
VERTEXSHADER pvsBitBlt;
|
|
|
|
|
|
|
|
GLuint vboRect = 0;
|
|
|
|
vector<GLuint> g_vboBuffers; // VBOs for all drawing commands
|
|
|
|
int g_nCurVBOIndex = 0;
|
|
|
|
|
|
|
|
inline bool CreateImportantCheck();
|
|
|
|
inline void CreateOtherCheck();
|
|
|
|
inline bool CreateOpenShadersFile();
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------ Dummies
|
|
|
|
#ifdef _WIN32
|
2010-05-01 20:33:53 +00:00
|
|
|
void __stdcall glBlendFuncSeparateDummy(GLenum e1, GLenum e2, GLenum e3, GLenum e4)
|
2010-03-19 00:31:15 +00:00
|
|
|
#else
|
2010-05-01 20:33:53 +00:00
|
|
|
void APIENTRY glBlendFuncSeparateDummy(GLenum e1, GLenum e2, GLenum e3, GLenum e4)
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
|
|
|
glBlendFunc(e1, e2);
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2010-05-01 20:33:53 +00:00
|
|
|
void __stdcall glBlendEquationSeparateDummy(GLenum e1, GLenum e2)
|
2010-03-19 00:31:15 +00:00
|
|
|
#else
|
2010-05-01 20:33:53 +00:00
|
|
|
void APIENTRY glBlendEquationSeparateDummy(GLenum e1, GLenum e2)
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
|
|
|
glBlendEquation(e1);
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2010-05-01 20:33:53 +00:00
|
|
|
extern HINSTANCE hInst;
|
|
|
|
void (__stdcall *zgsBlendEquationSeparateEXT)(GLenum, GLenum) = NULL;
|
|
|
|
void (__stdcall *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum) = NULL;
|
2010-03-19 00:31:15 +00:00
|
|
|
#else
|
2010-05-01 20:33:53 +00:00
|
|
|
void (APIENTRY *zgsBlendEquationSeparateEXT)(GLenum, GLenum) = NULL;
|
|
|
|
void (APIENTRY *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum) = NULL;
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------ variables
|
|
|
|
////////////////////////////
|
|
|
|
// State parameters
|
2010-04-25 00:31:27 +00:00
|
|
|
float fiRendWidth, fiRendHeight;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-07-03 07:57:56 +00:00
|
|
|
extern u8* s_lpShaderResources;
|
2010-03-19 00:31:15 +00:00
|
|
|
CGprogram pvs[16] = {NULL};
|
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
// String's for shader file in developer mode
|
2010-03-19 00:31:15 +00:00
|
|
|
#ifdef DEVBUILD
|
2010-05-01 20:33:53 +00:00
|
|
|
char* EFFECT_NAME = "";
|
|
|
|
char* EFFECT_DIR = "";
|
2010-04-25 00:31:27 +00:00
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
/////////////////////
|
|
|
|
// graphics resources
|
|
|
|
FRAGMENTSHADER ppsRegular[4], ppsTexture[NUM_SHADERS];
|
|
|
|
FRAGMENTSHADER ppsCRTC[2], ppsCRTC24[2], ppsCRTCTarg[2];
|
|
|
|
GLenum s_srcrgb, s_dstrgb, s_srcalpha, s_dstalpha; // set by zgsBlendFuncSeparateEXT
|
|
|
|
u32 s_stencilfunc, s_stencilref, s_stencilmask;
|
|
|
|
GLenum s_drawbuffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT };
|
|
|
|
|
|
|
|
GLenum g_internalFloatFmt = GL_ALPHA_FLOAT32_ATI;
|
|
|
|
GLenum g_internalRGBAFloatFmt = GL_RGBA_FLOAT32_ATI;
|
|
|
|
GLenum g_internalRGBAFloat16Fmt = GL_RGBA_FLOAT16_ATI;
|
|
|
|
|
|
|
|
u32 ptexLogo = 0;
|
|
|
|
int nLogoWidth, nLogoHeight;
|
|
|
|
u32 s_ptexInterlace = 0; // holds interlace fields
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
//------------------ Global Variables
|
2010-03-19 00:31:15 +00:00
|
|
|
int g_MaxTexWidth = 4096, g_MaxTexHeight = 4096;
|
|
|
|
u32 s_uFramebuffer = 0;
|
|
|
|
CGprofile cgvProf, cgfProf;
|
|
|
|
int g_nPixelShaderVer = 0; // default
|
|
|
|
|
|
|
|
RasterFont* font_p = NULL;
|
|
|
|
float g_fBlockMult = 1;
|
2010-07-03 07:57:56 +00:00
|
|
|
//int s_nFullscreen = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
u32 ptexBlocks = 0, ptexConv16to32 = 0; // holds information on block tiling
|
|
|
|
u32 ptexBilinearBlocks = 0;
|
|
|
|
u32 ptexConv32to16 = 0;
|
2010-05-01 23:34:44 +00:00
|
|
|
bool g_bDisplayMsg = 1;
|
2010-03-19 00:31:15 +00:00
|
|
|
int g_nDepthBias = 0;
|
2010-07-04 03:53:01 +00:00
|
|
|
//u32 g_bSaveFlushedFrame = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
//------------------ Code
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
bool ZeroGS::IsGLExt(const char* szTargetExtension)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
return mapGLExtensions.find(string(szTargetExtension)) != mapGLExtensions.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-05-01 20:33:53 +00:00
|
|
|
ZeroGS::Create_Window(int _width, int _height)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
nBackbufferWidth = _width;
|
|
|
|
nBackbufferHeight = _height;
|
|
|
|
fiRendWidth = 1.0f / nBackbufferWidth;
|
|
|
|
fiRendHeight = 1.0f / nBackbufferHeight;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
if (!GLWin.DisplayWindow(_width, _height)) return false;
|
2010-03-19 02:04:55 +00:00
|
|
|
|
2010-07-03 07:57:56 +00:00
|
|
|
//s_nFullscreen = (conf.fullscreen()) ? 1 : 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.mrtdepth = 0; // for now
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
// Function asks about different OGL extensions, that are required to setup accordingly. Return false if checks failed
|
2010-05-01 20:33:53 +00:00
|
|
|
inline bool ZeroGS::CreateImportantCheck()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
bool bSuccess = true;
|
|
|
|
#ifndef _WIN32
|
|
|
|
int const glew_ok = glewInit();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (glew_ok != GLEW_OK)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("glewInit() is not ok!");
|
2010-03-19 00:31:15 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!IsGLExt("GL_EXT_framebuffer_object"))
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("*********\nZZogl: ERROR: Need GL_EXT_framebufer_object for multiple render targets\nZZogl: *********");
|
2010-03-19 00:31:15 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!IsGLExt("GL_EXT_secondary_color"))
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("*********\nZZogl: OGL WARNING: Need GL_EXT_secondary_color\nZZogl: *********");
|
2010-03-19 00:31:15 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
// load the effect & find the best profiles (if any)
|
2010-05-01 20:33:53 +00:00
|
|
|
if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1) != CG_TRUE)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("arbvp1 not supported.");
|
2010-03-19 00:31:15 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) != CG_TRUE)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("arbfp1 not supported.");
|
2010-03-19 00:31:15 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
// This is a check for less important open gl extensions.
|
2010-05-01 20:33:53 +00:00
|
|
|
inline void ZeroGS::CreateOtherCheck()
|
|
|
|
{
|
|
|
|
if (!IsGLExt("GL_EXT_blend_equation_separate") || glBlendEquationSeparateEXT == NULL)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("*********\nZZogl: OGL WARNING: Need GL_EXT_blend_equation_separate\nZZogl: *********");
|
2010-03-19 00:31:15 +00:00
|
|
|
zgsBlendEquationSeparateEXT = glBlendEquationSeparateDummy;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2010-03-19 00:31:15 +00:00
|
|
|
zgsBlendEquationSeparateEXT = glBlendEquationSeparateEXT;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!IsGLExt("GL_EXT_blend_func_separate") || glBlendFuncSeparateEXT == NULL)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("*********\nZZogl: OGL WARNING: Need GL_EXT_blend_func_separate\nZZogl: *********");
|
2010-03-19 00:31:15 +00:00
|
|
|
zgsBlendFuncSeparateEXT = glBlendFuncSeparateDummy;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2010-03-19 00:31:15 +00:00
|
|
|
zgsBlendFuncSeparateEXT = glBlendFuncSeparateEXT;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!IsGLExt("GL_ARB_draw_buffers") && !IsGLExt("GL_ATI_draw_buffers"))
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("*********\nZZogl: OGL WARNING: multiple render targets not supported, some effects might look bad\nZZogl: *********");
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.mrtdepth = 0;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (IsGLExt("GL_ARB_draw_buffers"))
|
2010-03-19 00:31:15 +00:00
|
|
|
glDrawBuffers = (PFNGLDRAWBUFFERSPROC)wglGetProcAddress("glDrawBuffers");
|
2010-05-01 20:33:53 +00:00
|
|
|
else if (IsGLExt("GL_ATI_draw_buffers"))
|
2010-03-19 00:31:15 +00:00
|
|
|
glDrawBuffers = (PFNGLDRAWBUFFERSPROC)wglGetProcAddress("glDrawBuffersATI");
|
|
|
|
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!IsGLExt("GL_ARB_multitexture"))
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("No multitexturing.");
|
2010-03-19 00:31:15 +00:00
|
|
|
else
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Using multitexturing.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
GLint Max_Texture_Size_NV = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
GLint Max_Texture_Size_2d = 0;
|
|
|
|
|
|
|
|
glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, &Max_Texture_Size_NV);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Max_Texture_Size_2d);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Maximum texture size is %d for Tex_2d and %d for Tex_NV.", Max_Texture_Size_2d, Max_Texture_Size_NV);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
if (Max_Texture_Size_NV < 1024)
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Could not properly make bitmasks, so some textures will be missed.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
/* Zeydlitz: we don't support 128-bit targets yet. they are slow and weirdo
|
2010-06-19 08:46:40 +00:00
|
|
|
if( conf.settings() & GAME_32BITTARGS ) {
|
2010-03-19 00:31:15 +00:00
|
|
|
g_RenderFormatType = RFT_byte8;
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Setting 32 bit render target.");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if( !IsGLExt("GL_NV_float_buffer") && !IsGLExt("GL_ARB_color_buffer_float") && !IsGLExt("ATI_pixel_format_float") ) {
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("******\nZZogl: GS WARNING: Floating point render targets not supported, switching to 32bit\nZZogl: *********");
|
2010-03-19 00:31:15 +00:00
|
|
|
g_RenderFormatType = RFT_byte8;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
g_RenderFormatType = RFT_byte8;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2010-05-01 20:33:53 +00:00
|
|
|
if (IsGLExt("WGL_EXT_swap_control") || IsGLExt("EXT_swap_control"))
|
2010-03-19 00:31:15 +00:00
|
|
|
wglSwapIntervalEXT(0);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#else
|
2010-05-01 20:33:53 +00:00
|
|
|
if (IsGLExt("GLX_SGI_swap_control"))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
_PFNSWAPINTERVAL swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapInterval");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (!swapinterval)
|
2010-03-19 00:31:15 +00:00
|
|
|
swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapIntervalSGI");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (!swapinterval)
|
2010-03-19 00:31:15 +00:00
|
|
|
swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapIntervalEXT");
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (swapinterval)
|
2010-03-19 00:31:15 +00:00
|
|
|
swapinterval(0);
|
|
|
|
else
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("No support for SwapInterval (framerate clamped to monitor refresh rate),");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// open shader file according to build target
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
inline bool ZeroGS::CreateOpenShadersFile()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
#ifndef DEVBUILD
|
|
|
|
# ifdef _WIN32
|
|
|
|
HRSRC hShaderSrc = FindResource(hInst, MAKEINTRESOURCE(IDR_SHADERS), RT_RCDATA);
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(hShaderSrc != NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
HGLOBAL hShaderGlob = LoadResource(hInst, hShaderSrc);
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(hShaderGlob != NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
s_lpShaderResources = (u8*)LockResource(hShaderGlob);
|
|
|
|
# else // not _WIN32
|
|
|
|
FILE* fres = fopen("ps2hw.dat", "rb");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (fres == NULL)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
fres = fopen("plugins/ps2hw.dat", "rb");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (fres == NULL)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Cannot find ps2hw.dat in working directory. Exiting.");
|
2010-03-19 00:31:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
fseek(fres, 0, SEEK_END);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
size_t s = ftell(fres);
|
|
|
|
s_lpShaderResources = new u8[s+1];
|
|
|
|
fseek(fres, 0, SEEK_SET);
|
|
|
|
fread(s_lpShaderResources, s, 1, fres);
|
|
|
|
s_lpShaderResources[s] = 0;
|
|
|
|
# endif // _WIN32
|
2010-04-25 09:02:36 +00:00
|
|
|
#else // defined(ZEROGS_DEVBUILD)
|
2010-03-19 00:31:15 +00:00
|
|
|
# ifndef _WIN32 // NOT WINDOWS
|
|
|
|
// test if ps2hw.fx exists
|
|
|
|
char tempstr[255];
|
|
|
|
char curwd[255];
|
|
|
|
getcwd(curwd, ARRAY_SIZE(curwd));
|
|
|
|
|
|
|
|
strcpy(tempstr, "/plugins/");
|
|
|
|
sprintf(EFFECT_NAME, "%sps2hw.fx", tempstr);
|
|
|
|
FILE* f = fopen(EFFECT_NAME, "r");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (f == NULL)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-03-19 01:00:53 +00:00
|
|
|
strcpy(tempstr, "../../plugins/zzogl-pg/opengl/");
|
2010-03-19 00:31:15 +00:00
|
|
|
sprintf(EFFECT_NAME, "%sps2hw.fx", tempstr);
|
|
|
|
f = fopen(EFFECT_NAME, "r");
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (f == NULL)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Failed to find %s, try compiling a non-devbuild.", EFFECT_NAME);
|
2010-03-19 00:31:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
sprintf(EFFECT_DIR, "%s/%s", curwd, tempstr);
|
|
|
|
sprintf(EFFECT_NAME, "%sps2hw.fx", EFFECT_DIR);
|
2010-05-01 20:33:53 +00:00
|
|
|
#endif
|
2010-04-25 09:02:36 +00:00
|
|
|
#endif // !defined(ZEROGS_DEVBUILD)
|
2010-03-19 00:31:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read all extensions name and fill mapGLExtensions
|
2010-05-01 20:33:53 +00:00
|
|
|
inline bool CreateFillExtensionsMap()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// fill the opengl extension map
|
2010-05-01 20:33:53 +00:00
|
|
|
const char* ptoken = (const char*)glGetString(GL_EXTENSIONS);
|
|
|
|
|
|
|
|
if (ptoken == NULL) return false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
int prevlog = conf.log;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.log = 1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
ZZLog::GS_Log("Supported OpenGL Extensions:\n%s\n", ptoken); // write to the log file
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
// Probably a better way to do it, but seems to crash.
|
|
|
|
/*int n;
|
|
|
|
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
|
|
|
|
ZZLog::GS_Log("Supported OpenGL Extensions:\n");
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = 0; i < n; i++)
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
|
|
|
ZZLog::GS_Log("%s/n", (const char*)glGetStringi(GL_EXTENSIONS, i));
|
|
|
|
}*/
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.log = prevlog;
|
|
|
|
|
|
|
|
// insert all exts into mapGLExtensions
|
|
|
|
|
|
|
|
const char* pend = NULL;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
while (ptoken != NULL)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
pend = strchr(ptoken, ' ');
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (pend != NULL)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
mapGLExtensions[string(ptoken, pend-ptoken)];
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
mapGLExtensions[string(ptoken)];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptoken = pend;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
while (*ptoken == ' ') ++ptoken;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-19 06:38:44 +00:00
|
|
|
|
|
|
|
const static char* g_pShaders[] = { "full", "reduced", "accurate", "accurate-reduced" };
|
|
|
|
|
2010-06-19 05:41:06 +00:00
|
|
|
void LoadglFunctions()
|
|
|
|
{
|
|
|
|
GL_LOADFN(glIsRenderbufferEXT);
|
|
|
|
GL_LOADFN(glBindRenderbufferEXT);
|
|
|
|
GL_LOADFN(glDeleteRenderbuffersEXT);
|
|
|
|
GL_LOADFN(glGenRenderbuffersEXT);
|
|
|
|
GL_LOADFN(glRenderbufferStorageEXT);
|
|
|
|
GL_LOADFN(glGetRenderbufferParameterivEXT);
|
|
|
|
GL_LOADFN(glIsFramebufferEXT);
|
|
|
|
GL_LOADFN(glBindFramebufferEXT);
|
|
|
|
GL_LOADFN(glDeleteFramebuffersEXT);
|
|
|
|
GL_LOADFN(glGenFramebuffersEXT);
|
|
|
|
GL_LOADFN(glCheckFramebufferStatusEXT);
|
|
|
|
GL_LOADFN(glFramebufferTexture1DEXT);
|
|
|
|
GL_LOADFN(glFramebufferTexture2DEXT);
|
|
|
|
GL_LOADFN(glFramebufferTexture3DEXT);
|
|
|
|
GL_LOADFN(glFramebufferRenderbufferEXT);
|
|
|
|
GL_LOADFN(glGetFramebufferAttachmentParameterivEXT);
|
|
|
|
GL_LOADFN(glGenerateMipmapEXT);
|
|
|
|
}
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
bool ZeroGS::Create(int _width, int _height)
|
|
|
|
{
|
|
|
|
GLenum err = GL_NO_ERROR;
|
|
|
|
bool bSuccess = true;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Destroy(1);
|
2010-04-25 00:31:27 +00:00
|
|
|
GSStateReset();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
cgSetErrorHandler(HandleCgError, NULL);
|
|
|
|
g_RenderFormatType = RFT_float16;
|
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
if (!Create_Window(_width, _height)) return false;
|
|
|
|
if (!CreateFillExtensionsMap()) return false;
|
|
|
|
if (!CreateImportantCheck()) return false;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ZeroGS::CreateOtherCheck();
|
|
|
|
|
|
|
|
// check the max texture width and height
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &g_MaxTexWidth);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
g_MaxTexHeight = g_MaxTexWidth / 4;
|
|
|
|
GPU_TEXWIDTH = g_MaxTexWidth / 8;
|
2010-03-19 00:31:15 +00:00
|
|
|
g_fiGPU_TEXWIDTH = 1.0f / GPU_TEXWIDTH;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!CreateOpenShadersFile()) return false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
s_srcrgb = s_dstrgb = s_srcalpha = s_dstalpha = GL_ONE;
|
|
|
|
|
2010-06-19 05:41:06 +00:00
|
|
|
LoadglFunctions();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2010-03-19 00:31:15 +00:00
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
|
|
|
|
|
|
|
glGenFramebuffersEXT(1, &s_uFramebuffer);
|
|
|
|
|
|
|
|
if (s_uFramebuffer == 0)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Failed to create the renderbuffer.");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 11:20:52 +00:00
|
|
|
GL_REPORT_ERRORD();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, s_uFramebuffer);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-06-19 05:41:06 +00:00
|
|
|
DrawBuffers(s_drawbuffers);
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
font_p = new RasterFont();
|
2010-03-19 00:31:15 +00:00
|
|
|
GL_REPORT_ERROR();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// init draw fns
|
|
|
|
drawfn[0] = KickPoint;
|
|
|
|
drawfn[1] = KickLine;
|
|
|
|
drawfn[2] = KickLine;
|
|
|
|
drawfn[3] = KickTriangle;
|
|
|
|
drawfn[4] = KickTriangle;
|
|
|
|
drawfn[5] = KickTriangleFan;
|
|
|
|
drawfn[6] = KickSprite;
|
|
|
|
drawfn[7] = KickDummy;
|
|
|
|
|
|
|
|
SetAA(conf.aa);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 08:46:40 +00:00
|
|
|
GSsetGameCRC(g_LastCRC, conf.settings()._u32);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
GL_STENCILFUNC(GL_ALWAYS, 0, 0);
|
|
|
|
|
2010-05-01 23:34:44 +00:00
|
|
|
//s_bWriteDepth = true;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
GL_BLEND_ALL(GL_ONE, GL_ONE, GL_ONE, GL_ONE);
|
2010-05-01 20:33:53 +00:00
|
|
|
glViewport(0, 0, nBackbufferWidth, nBackbufferHeight); // Reset The Current Viewport
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
glClearDepth(1.0f);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_LIGHTING);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
|
|
|
|
glGenTextures(1, &ptexLogo);
|
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexLogo);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
HRSRC hBitmapSrc = FindResource(hInst, MAKEINTRESOURCE(IDB_ZEROGSLOGO), RT_BITMAP);
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(hBitmapSrc != NULL);
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
HGLOBAL hBitmapGlob = LoadResource(hInst, hBitmapSrc);
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(hBitmapGlob != NULL);
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
PBITMAPINFO pinfo = (PBITMAPINFO)LockResource(hBitmapGlob);
|
|
|
|
|
2010-06-20 07:33:47 +00:00
|
|
|
GLenum tempFmt = (pinfo->bmiHeader.biBitCount == 32) ? GL_RGBA : GL_RGB;
|
2010-06-19 12:59:51 +00:00
|
|
|
TextureRect(4, pinfo->bmiHeader.biWidth, pinfo->bmiHeader.biHeight, tempFmt, GL_UNSIGNED_BYTE, (u8*)pinfo + pinfo->bmiHeader.biSize);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
nLogoWidth = pinfo->bmiHeader.biWidth;
|
|
|
|
nLogoHeight = pinfo->bmiHeader.biHeight;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
setRectFilters(GL_LINEAR);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
|
|
|
g_nCurVBOIndex = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_vboBuffers.resize(VB_NUMBUFFERS);
|
|
|
|
glGenBuffers((GLsizei)g_vboBuffers.size(), &g_vboBuffers[0]);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < (int)g_vboBuffers.size(); ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_vboBuffers[i]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, 0x100*sizeof(VertexGPU), NULL, GL_STREAM_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
2010-05-01 20:33:53 +00:00
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// create the blocks texture
|
|
|
|
g_fBlockMult = 1;
|
|
|
|
|
|
|
|
vector<char> vBlockData, vBilinearData;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
BLOCK::FillBlocks(vBlockData, vBilinearData, 1);
|
|
|
|
|
|
|
|
glGenTextures(1, &ptexBlocks);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ptexBlocks);
|
|
|
|
|
|
|
|
g_internalFloatFmt = GL_ALPHA_FLOAT32_ATI;
|
|
|
|
g_internalRGBAFloatFmt = GL_RGBA_FLOAT32_ATI;
|
|
|
|
g_internalRGBAFloat16Fmt = GL_RGBA_FLOAT16_ATI;
|
2010-06-19 05:41:06 +00:00
|
|
|
|
|
|
|
Texture2D(g_internalFloatFmt, GL_ALPHA, GL_FLOAT, &vBlockData[0]);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (glGetError() != GL_NO_ERROR)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// try different internal format
|
|
|
|
g_internalFloatFmt = GL_FLOAT_R32_NV;
|
2010-06-19 05:41:06 +00:00
|
|
|
Texture2D(g_internalFloatFmt, GL_RED, GL_FLOAT, &vBlockData[0]);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-06-19 12:59:51 +00:00
|
|
|
setTex2DFilters(GL_NEAREST);
|
|
|
|
setTex2DWrap(GL_REPEAT);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (glGetError() != GL_NO_ERROR)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// error, resort to 16bit
|
2010-05-01 20:33:53 +00:00
|
|
|
g_fBlockMult = 65535.0f * (float)g_fiGPU_TEXWIDTH / 32.0f;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
BLOCK::FillBlocks(vBlockData, vBilinearData, 0);
|
2010-06-19 05:41:06 +00:00
|
|
|
Texture2D(2, GL_R, GL_UNSIGNED_SHORT, &vBlockData[0]);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (glGetError() != GL_NO_ERROR)
|
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Could not fill blocks.");
|
2010-03-19 00:31:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::GS_Log("Using non-bilinear fill.");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
// fill in the bilinear blocks
|
|
|
|
glGenTextures(1, &ptexBilinearBlocks);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ptexBilinearBlocks);
|
2010-06-19 05:41:06 +00:00
|
|
|
Texture2D(g_internalRGBAFloatFmt, GL_RGBA, GL_FLOAT, &vBilinearData[0]);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (glGetError() != GL_NO_ERROR)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_internalRGBAFloatFmt = GL_FLOAT_RGBA32_NV;
|
|
|
|
g_internalRGBAFloat16Fmt = GL_FLOAT_RGBA16_NV;
|
2010-06-19 05:41:06 +00:00
|
|
|
Texture2D(g_internalRGBAFloatFmt, GL_RGBA, GL_FLOAT, &vBilinearData[0]);
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::Debug_Log("ZZogl Fill bilinear blocks. ");
|
2010-03-19 00:31:15 +00:00
|
|
|
B_G(glGetError() == GL_NO_ERROR, return false);
|
|
|
|
}
|
|
|
|
else
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
// No, they failed on the first clause of the if statement, not the second.
|
|
|
|
//ZZLog::Error_Log("Fill bilinear blocks failed!");
|
2010-04-25 08:33:05 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
setTex2DFilters(GL_NEAREST);
|
|
|
|
setTex2DWrap(GL_REPEAT);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float fpri = 1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glPrioritizeTextures(1, &ptexBlocks, &fpri);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (ptexBilinearBlocks != 0) glPrioritizeTextures(1, &ptexBilinearBlocks, &fpri);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
|
|
|
// fill a simple rect
|
|
|
|
glGenBuffers(1, &vboRect);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vboRect);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
vector<VertexGPU> verts(4);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
VertexGPU* pvert = &verts[0];
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
pvert->x = -0x7fff;
|
|
|
|
pvert->y = 0x7fff;
|
|
|
|
pvert->z = 0;
|
|
|
|
pvert->s = 0;
|
|
|
|
pvert->t = 0;
|
|
|
|
pvert++;
|
|
|
|
|
|
|
|
pvert->x = 0x7fff;
|
|
|
|
pvert->y = 0x7fff;
|
|
|
|
pvert->z = 0;
|
|
|
|
pvert->s = 1;
|
|
|
|
pvert->t = 0;
|
|
|
|
pvert++;
|
|
|
|
|
|
|
|
pvert->x = -0x7fff;
|
|
|
|
pvert->y = -0x7fff;
|
|
|
|
pvert->z = 0;
|
|
|
|
pvert->s = 0;
|
|
|
|
pvert->t = 1;
|
|
|
|
pvert++;
|
|
|
|
|
|
|
|
pvert->x = 0x7fff;
|
|
|
|
pvert->y = -0x7fff;
|
|
|
|
pvert->z = 0;
|
|
|
|
pvert->s = 1;
|
|
|
|
pvert->t = 1;
|
|
|
|
pvert++;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glBufferDataARB(GL_ARRAY_BUFFER, 4*sizeof(VertexGPU), &verts[0], GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
// setup the default vertex declaration
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glClientActiveTexture(GL_TEXTURE0);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
GL_REPORT_ERROR();
|
|
|
|
|
|
|
|
// some cards don't support this
|
|
|
|
// glClientActiveTexture(GL_TEXTURE0);
|
|
|
|
// glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
// glTexCoordPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)12);
|
|
|
|
|
|
|
|
// create the conversion textures
|
|
|
|
glGenTextures(1, &ptexConv16to32);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, ptexConv16to32);
|
|
|
|
|
|
|
|
vector<u32> conv16to32data(256*256);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 256*256; ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
u32 tempcol = RGBA16to32(i);
|
|
|
|
// have to flip r and b
|
2010-05-01 20:33:53 +00:00
|
|
|
conv16to32data[i] = (tempcol & 0xff00ff00) | ((tempcol & 0xff) << 16) | ((tempcol & 0xff0000) >> 16);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
Texture2D(4, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, &conv16to32data[0]);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
setTex2DFilters(GL_NEAREST);
|
|
|
|
setTex2DWrap(GL_CLAMP);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
vector<u32> conv32to16data(32*32*32);
|
|
|
|
|
|
|
|
glGenTextures(1, &ptexConv32to16);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glBindTexture(GL_TEXTURE_3D, ptexConv32to16);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
u32* dst = &conv32to16data[0];
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 32; ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 32; ++j)
|
|
|
|
{
|
|
|
|
for (int k = 0; k < 32; ++k)
|
|
|
|
{
|
|
|
|
u32 col = (i << 10) | (j << 5) | k;
|
|
|
|
*dst++ = ((col & 0xff) << 16) | (col & 0xff00);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 12:59:51 +00:00
|
|
|
Texture3D(4, 32, 32, 32, GL_RGBA, GL_UNSIGNED_BYTE, &conv32to16data[0]);
|
|
|
|
setTex3DFilters(GL_NEAREST);
|
|
|
|
setTex3DWrap(GL_CLAMP);
|
2010-03-19 00:31:15 +00:00
|
|
|
GL_REPORT_ERROR();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
g_cgcontext = cgCreateContext();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
cgvProf = CG_PROFILE_ARBVP1;
|
|
|
|
cgfProf = CG_PROFILE_ARBFP1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
cgGLEnableProfile(cgvProf);
|
|
|
|
cgGLEnableProfile(cgfProf);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
cgGLSetOptimalOptions(cgvProf);
|
|
|
|
cgGLSetOptimalOptions(cgfProf);
|
|
|
|
|
|
|
|
cgGLSetManageTextureParameters(g_cgcontext, CG_FALSE);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
//cgSetAutoCompile(g_cgcontext, CG_COMPILE_IMMEDIATE);
|
|
|
|
|
|
|
|
g_fparamFogColor = cgCreateParameter(g_cgcontext, CG_FLOAT4);
|
|
|
|
g_vparamPosXY[0] = cgCreateParameter(g_cgcontext, CG_FLOAT4);
|
|
|
|
g_vparamPosXY[1] = cgCreateParameter(g_cgcontext, CG_FLOAT4);
|
|
|
|
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::GS_Log("Creating effects.");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
B_G(LoadEffects(), return false);
|
|
|
|
|
|
|
|
g_bDisplayMsg = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// create a sample shader
|
|
|
|
clampInfo temp;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
memset(&temp, 0, sizeof(temp));
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
temp.wms = 3;
|
|
|
|
temp.wmt = 3;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
g_nPixelShaderVer = 0;//SHADER_ACCURATE;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// test
|
|
|
|
bool bFailed;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
FRAGMENTSHADER* pfrag = LoadShadeEffect(0, 1, 1, 1, 1, temp, 0, &bFailed);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (bFailed || pfrag == NULL)
|
|
|
|
{
|
|
|
|
g_nPixelShaderVer = SHADER_ACCURATE | SHADER_REDUCED;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
pfrag = LoadShadeEffect(0, 0, 1, 1, 0, temp, 0, &bFailed);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (pfrag != NULL)
|
2010-03-19 00:31:15 +00:00
|
|
|
cgGLLoadProgram(pfrag->prog);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (bFailed || pfrag == NULL || cgGetError() != CG_NO_ERROR)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nPixelShaderVer = SHADER_REDUCED;
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Basic shader test failed.");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_bDisplayMsg = 1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (g_nPixelShaderVer & SHADER_REDUCED) conf.bilinear = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::GS_Log("Creating extra effects.");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
B_G(LoadExtraEffects(), return false);
|
|
|
|
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::GS_Log("Using %s shaders.", g_pShaders[g_nPixelShaderVer]);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
GL_REPORT_ERROR();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (err != GL_NO_ERROR) bSuccess = false;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
GL_BLEND_ALPHA(GL_ONE, GL_ZERO);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glBlendColorEXT(0, 0, 0, 0.5f);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
|
|
|
|
// points
|
|
|
|
// This was changed in SetAA - should we be changing it back?
|
|
|
|
glPointSize(1.0f);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nDepthBias = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glEnable(GL_POLYGON_OFFSET_LINE);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
glPolygonOffset(0, 1);
|
|
|
|
|
|
|
|
vb[0].Init(VB_BUFFERSIZE);
|
|
|
|
vb[1].Init(VB_BUFFERSIZE);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-07-04 03:53:01 +00:00
|
|
|
// g_bSaveFlushedFrame = 1;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
g_vsprog = g_psprog = 0;
|
|
|
|
|
|
|
|
if (glGetError() == GL_NO_ERROR)
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return bSuccess;
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::Debug_Log("In final init!");
|
2010-03-19 00:31:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 23:34:44 +00:00
|
|
|
void ZeroGS::Destroy(bool bD3D)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
2010-07-03 07:57:56 +00:00
|
|
|
Delete_Avi_Capture();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
g_MemTargs.Destroy();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
s_RTs.Destroy();
|
|
|
|
s_DepthRTs.Destroy();
|
|
|
|
s_BitwiseTextures.Destroy();
|
|
|
|
|
|
|
|
SAFE_RELEASE_TEX(s_ptexInterlace);
|
|
|
|
SAFE_RELEASE_TEX(ptexBlocks);
|
|
|
|
SAFE_RELEASE_TEX(ptexBilinearBlocks);
|
|
|
|
SAFE_RELEASE_TEX(ptexConv16to32);
|
|
|
|
SAFE_RELEASE_TEX(ptexConv32to16);
|
|
|
|
|
|
|
|
vb[0].Destroy();
|
|
|
|
vb[1].Destroy();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_vboBuffers.size() > 0)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
glDeleteBuffers((GLsizei)g_vboBuffers.size(), &g_vboBuffers[0]);
|
|
|
|
g_vboBuffers.clear();
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nCurVBOIndex = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = 0; i < ARRAY_SIZE(pvs); ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SAFE_RELEASE_PROG(pvs[i]);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(ppsRegular); ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SAFE_RELEASE_PROG(ppsRegular[i].prog);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(ppsTexture); ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SAFE_RELEASE_PROG(ppsTexture[i].prog);
|
|
|
|
}
|
|
|
|
|
|
|
|
SAFE_RELEASE_PROG(pvsBitBlt.prog);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
SAFE_RELEASE_PROG(ppsBitBlt[0].prog);
|
|
|
|
SAFE_RELEASE_PROG(ppsBitBlt[1].prog);
|
2010-03-19 00:31:15 +00:00
|
|
|
SAFE_RELEASE_PROG(ppsBitBltDepth.prog);
|
2010-05-01 20:33:53 +00:00
|
|
|
SAFE_RELEASE_PROG(ppsCRTCTarg[0].prog);
|
|
|
|
SAFE_RELEASE_PROG(ppsCRTCTarg[1].prog);
|
|
|
|
SAFE_RELEASE_PROG(ppsCRTC[0].prog);
|
|
|
|
SAFE_RELEASE_PROG(ppsCRTC[1].prog);
|
|
|
|
SAFE_RELEASE_PROG(ppsCRTC24[0].prog);
|
|
|
|
SAFE_RELEASE_PROG(ppsCRTC24[1].prog);
|
2010-03-19 00:31:15 +00:00
|
|
|
SAFE_RELEASE_PROG(ppsOne.prog);
|
|
|
|
|
|
|
|
SAFE_DELETE(font_p);
|
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
GLWin.ReleaseWindow();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
mapGLExtensions.clear();
|
|
|
|
}
|
|
|
|
|