mirror of
https://github.com/libretro/Play-.git
synced 2025-02-13 04:52:32 +00:00
git-svn-id: http://svn.purei.org/purei/trunk@52 b36208d7-6611-0410-8bec-b1987f11c4a2
This commit is contained in:
parent
d8a476c825
commit
a7a7a6ed2a
@ -6,15 +6,9 @@
|
||||
#include "PtrMacro.h"
|
||||
#include "RendererSettingsWnd.h"
|
||||
#include "Config.h"
|
||||
#include "glext.h"
|
||||
|
||||
using namespace Framework;
|
||||
|
||||
PFNGLCOLORTABLEEXTPROC glColorTableEXT;
|
||||
PFNGLBLENDCOLOREXTPROC glBlendColorEXT;
|
||||
PFNGLBLENDEQUATIONEXTPROC glBlendEquationEXT;
|
||||
PFNGLFOGCOORDFEXTPROC glFogCoordfEXT;
|
||||
|
||||
PIXELFORMATDESCRIPTOR CGSH_OpenGL::m_PFD =
|
||||
{
|
||||
sizeof(PIXELFORMATDESCRIPTOR),
|
||||
@ -83,6 +77,8 @@ void CGSH_OpenGL::InitializeRC()
|
||||
m_hRC = wglCreateContext(m_hDC);
|
||||
wglMakeCurrent(m_hDC, m_hRC);
|
||||
|
||||
glewInit();
|
||||
/*
|
||||
glColorTableEXT = (PFNGLCOLORTABLEEXTPROC)wglGetProcAddress("glColorTable");
|
||||
if(glColorTableEXT == NULL)
|
||||
{
|
||||
@ -102,7 +98,7 @@ void CGSH_OpenGL::InitializeRC()
|
||||
}
|
||||
|
||||
glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC)wglGetProcAddress("glFogCoordfEXT");
|
||||
|
||||
*/
|
||||
//Initialize basic stuff
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClearDepth(0.0f);
|
||||
@ -135,6 +131,28 @@ void CGSH_OpenGL::InitializeRC()
|
||||
m_pTexUploader_Psm16 = &CGSH_OpenGL::TexUploader_Psm16_Hw;
|
||||
}
|
||||
|
||||
m_pProgram = NULL;
|
||||
m_pVertShader = m_pFragShader = NULL;
|
||||
|
||||
//Create shaders/program
|
||||
if((glCreateProgram != NULL) && (glCreateShader != NULL))
|
||||
{
|
||||
m_pProgram = new OpenGl::CProgram();
|
||||
m_pVertShader = new OpenGl::CShader(GL_VERTEX_SHADER);
|
||||
m_pFragShader = new OpenGl::CShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
LoadShaderSourceFromResource(m_pVertShader, _X("IDR_VERTSHADER"));
|
||||
LoadShaderSourceFromResource(m_pFragShader, _X("IDR_FRAGSHADER"));
|
||||
|
||||
m_pVertShader->Compile();
|
||||
m_pFragShader->Compile();
|
||||
|
||||
m_pProgram->AttachShader((*m_pVertShader));
|
||||
m_pProgram->AttachShader((*m_pFragShader));
|
||||
|
||||
m_pProgram->Link();
|
||||
}
|
||||
|
||||
m_pCvtBuffer = (uint8*)malloc(CVTBUFFERSIZE);
|
||||
|
||||
m_pCLUT = malloc(0x400);
|
||||
@ -148,6 +166,21 @@ void CGSH_OpenGL::InitializeRC()
|
||||
SwapBuffers(m_hDC);
|
||||
}
|
||||
|
||||
void CGSH_OpenGL::LoadShaderSourceFromResource(OpenGl::CShader* pShader, const xchar* sResourceName)
|
||||
{
|
||||
const char* sSource;
|
||||
HGLOBAL nResourcePtr;
|
||||
HRSRC nResource;
|
||||
DWORD nSize;
|
||||
|
||||
nResource = FindResource(GetModuleHandle(NULL), sResourceName, _X("SHADER"));
|
||||
nResourcePtr = LoadResource(GetModuleHandle(NULL), nResource);
|
||||
sSource = const_cast<char*>(reinterpret_cast<char*>(LockResource(nResourcePtr)));
|
||||
nSize = SizeofResource(GetModuleHandle(NULL), nResource);
|
||||
|
||||
pShader->SetSource(sSource, nSize);
|
||||
}
|
||||
|
||||
void CGSH_OpenGL::VerifyRGBA5551Support()
|
||||
{
|
||||
unsigned int nTexture;
|
||||
|
@ -3,7 +3,9 @@
|
||||
|
||||
#include "GSHandler.h"
|
||||
#include "win32/Window.h"
|
||||
#include <gl/gl.h>
|
||||
#include "opengl/OpenGl.h"
|
||||
#include "opengl/Program.h"
|
||||
#include "opengl/Shader.h"
|
||||
|
||||
#define PREF_CGSH_OPENGL_LINEASQUADS "renderer.opengl.linesasquads"
|
||||
#define PREF_CGSH_OPENGL_FORCEBILINEARTEXTURES "renderer.opengl.forcebilineartextures"
|
||||
@ -77,6 +79,7 @@ private:
|
||||
static CGSHandler* GSHandlerFactory(void*);
|
||||
|
||||
void InitializeRC();
|
||||
void LoadShaderSourceFromResource(Framework::OpenGl::CShader*, const xchar*);
|
||||
void SetViewport(int, int);
|
||||
void SetReadCircuitMatrix(int, int);
|
||||
void LinearZOrtho(double, double, double, double);
|
||||
@ -162,6 +165,10 @@ private:
|
||||
|
||||
Framework::CWindow* m_pOutputWnd;
|
||||
|
||||
Framework::OpenGl::CProgram* m_pProgram;
|
||||
Framework::OpenGl::CShader* m_pVertShader;
|
||||
Framework::OpenGl::CShader* m_pFragShader;
|
||||
|
||||
HGLRC m_hRC;
|
||||
HDC m_hDC;
|
||||
static PIXELFORMATDESCRIPTOR m_PFD;
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
using namespace Framework;
|
||||
|
||||
extern PFNGLCOLORTABLEEXTPROC glColorTableEXT;
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Texture Loading
|
||||
/////////////////////////////////////////////////////////////
|
||||
@ -40,6 +38,25 @@ unsigned int CGSH_OpenGL::LoadTexture(GSTEX0* pReg0, GSTEX1* pReg1, CLAMP* pClam
|
||||
break;
|
||||
}
|
||||
|
||||
if(m_pProgram != NULL)
|
||||
{
|
||||
if((pClamp->nWMS > 1) || (pClamp->nWMT > 1))
|
||||
{
|
||||
//We gotta use the shader
|
||||
|
||||
glUseProgram((*m_pProgram));
|
||||
|
||||
m_pProgram->SetUniformi("g_nClamp", pClamp->nWMS - 1, pClamp->nWMT - 1);
|
||||
m_pProgram->SetUniformi("g_nMin", pClamp->GetMinU(), pClamp->GetMinV());
|
||||
m_pProgram->SetUniformi("g_nMax", pClamp->GetMaxU(), pClamp->GetMaxV());
|
||||
m_pProgram->SetUniformf("g_nSize", (float)nWidth, (float)nHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
glUseProgram(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
nTexture = TexCache_Search(pReg0);
|
||||
if(nTexture != 0) return nTexture;
|
||||
|
||||
|
@ -829,10 +829,10 @@ void CGSHandler::DisassembleWrite(uint8 nRegister, uint64 nData)
|
||||
nRegister == GS_REG_CLAMP_1 ? 1 : 2, \
|
||||
clamp.nWMS, \
|
||||
clamp.nWMT, \
|
||||
clamp.nMINU, \
|
||||
clamp.nMAXU, \
|
||||
clamp.nMINV, \
|
||||
clamp.nMAXV);
|
||||
clamp.GetMinU(), \
|
||||
clamp.GetMaxU(), \
|
||||
clamp.GetMinV(), \
|
||||
clamp.GetMaxV());
|
||||
break;
|
||||
case GS_REG_TEX1_1:
|
||||
case GS_REG_TEX1_2:
|
||||
|
@ -295,9 +295,14 @@ protected:
|
||||
unsigned int nWMT : 2;
|
||||
unsigned int nMINU : 10;
|
||||
unsigned int nMAXU : 10;
|
||||
unsigned int nMINV : 10;
|
||||
unsigned int nReserved0 : 8;
|
||||
unsigned int nReserved1 : 2;
|
||||
unsigned int nMAXV : 10;
|
||||
unsigned int nReserved0 : 22;
|
||||
unsigned int nReserved2 : 22;
|
||||
unsigned int GetMinU() { return nMINU; }
|
||||
unsigned int GetMaxU() { return nMAXU; }
|
||||
unsigned int GetMinV() { return (nReserved0) | (nReserved1 << 8); }
|
||||
unsigned int GetMaxV() { return nMAXV; }
|
||||
};
|
||||
|
||||
//Reg 0x16/0x17
|
||||
|
@ -165,6 +165,15 @@ IDB_EX BITMAP "Images\\ex.bmp"
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_PUREI ICON "Images\\purei.ico"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SHADER
|
||||
//
|
||||
|
||||
IDR_VERTSHADER SHADER "shaders\\TexClamp.vert"
|
||||
IDR_FRAGSHADER SHADER "shaders\\TexClamp.frag"
|
||||
|
||||
#endif // French (Canada) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
#define IDB_EX 108
|
||||
#define IDR_MAINWINDOW 109
|
||||
#define IDI_PUREI 110
|
||||
#define IDR_SHADER1 113
|
||||
#define IDR_SHADER2 114
|
||||
#define ID_FILE_EXIT 40002
|
||||
#define ID_FILE_OPENELF 40003
|
||||
#define ID_Menu 40005
|
||||
@ -124,7 +126,7 @@
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 113
|
||||
#define _APS_NEXT_RESOURCE_VALUE 115
|
||||
#define _APS_NEXT_COMMAND_VALUE 40124
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
|
84
Source/shaders/TexClamp.frag
Normal file
84
Source/shaders/TexClamp.frag
Normal file
@ -0,0 +1,84 @@
|
||||
uniform sampler2D g_nTexture;
|
||||
uniform vec2 g_nSize;
|
||||
uniform ivec2 g_nMin;
|
||||
uniform ivec2 g_nMax;
|
||||
uniform ivec2 g_nClamp;
|
||||
|
||||
float and(int a, int b)
|
||||
{
|
||||
int m;
|
||||
int r = 0;
|
||||
int ha, hb;
|
||||
|
||||
m = int(min(float(a), float(b)));
|
||||
|
||||
for(int k = 1; k <= m; k *= 2)
|
||||
{
|
||||
ha = a / 2;
|
||||
hb = b / 2;
|
||||
if(((a - ha * 2) != 0) && ((b - hb * 2) != 0))
|
||||
{
|
||||
r += k;
|
||||
}
|
||||
a = ha;
|
||||
b = hb;
|
||||
}
|
||||
|
||||
return float(r);
|
||||
}
|
||||
|
||||
float or(int a, int b)
|
||||
{
|
||||
int m;
|
||||
int r = 0;
|
||||
int ha, hb;
|
||||
|
||||
m = int(max(float(a), float(b)));
|
||||
|
||||
for(int k = 1; k <= m; k *= 2)
|
||||
{
|
||||
ha = a / 2;
|
||||
hb = b / 2;
|
||||
if(((a - ha * 2) != 0) || ((b - hb * 2) != 0))
|
||||
{
|
||||
r += k;
|
||||
}
|
||||
a = ha;
|
||||
b = hb;
|
||||
}
|
||||
|
||||
return float(r);
|
||||
}
|
||||
|
||||
float Clamp(int nClampMode, float nCoord, int nMin, int nMax)
|
||||
{
|
||||
if(nClampMode == 1)
|
||||
{
|
||||
//Region Clamp
|
||||
nCoord = max(float(nMin), nCoord);
|
||||
nCoord = min(float(nMax), nCoord);
|
||||
}
|
||||
else if(nClampMode == 2)
|
||||
{
|
||||
//Repeat Clamp
|
||||
nCoord = or(int(and(int(nCoord), nMin)), nMax);
|
||||
}
|
||||
|
||||
return nCoord;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 nTexCoord;
|
||||
|
||||
nTexCoord = gl_TexCoord[0];
|
||||
|
||||
nTexCoord.st *= g_nSize.st;
|
||||
|
||||
nTexCoord.s = Clamp(g_nClamp.s, nTexCoord.s, g_nMin.s, g_nMax.s);
|
||||
nTexCoord.t = Clamp(g_nClamp.t, nTexCoord.t, g_nMin.t, g_nMax.t);
|
||||
|
||||
nTexCoord.st /= g_nSize.st;
|
||||
|
||||
gl_FragColor = texture2D(g_nTexture, nTexCoord.st);
|
||||
}
|
5
Source/shaders/TexClamp.vert
Normal file
5
Source/shaders/TexClamp.vert
Normal file
@ -0,0 +1,5 @@
|
||||
void main()
|
||||
{
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_Position = ftransform();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user