Win32: match D3D/OGL cg meta shader capability and update to latest spec

This commit is contained in:
OV2 2011-12-10 15:21:37 +01:00
parent 01bf98aaaf
commit 468275b2f2
11 changed files with 2086 additions and 128 deletions

View File

@ -1,3 +1,179 @@
/***********************************************************************************
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
(c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com),
Jerremy Koot (jkoot@snes9x.com)
(c) Copyright 2002 - 2004 Matthew Kendora
(c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org)
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
(c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net)
(c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca),
Kris Bleakley (codeviolation@hotmail.com)
(c) Copyright 2002 - 2010 Brad Jorsch (anomie@users.sourceforge.net),
Nach (n-a-c-h@users.sourceforge.net),
(c) Copyright 2002 - 2011 zones (kasumitokoduck@yahoo.com)
(c) Copyright 2006 - 2007 nitsuja
(c) Copyright 2009 - 2011 BearOso,
OV2
BS-X C emulator code
(c) Copyright 2005 - 2006 Dreamer Nom,
zones
C4 x86 assembler and some C emulation code
(c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com),
Nach,
zsKnight (zsknight@zsnes.com)
C4 C++ code
(c) Copyright 2003 - 2006 Brad Jorsch,
Nach
DSP-1 emulator code
(c) Copyright 1998 - 2006 _Demo_,
Andreas Naive (andreasnaive@gmail.com),
Gary Henderson,
Ivar (ivar@snes9x.com),
John Weidman,
Kris Bleakley,
Matthew Kendora,
Nach,
neviksti (neviksti@hotmail.com)
DSP-2 emulator code
(c) Copyright 2003 John Weidman,
Kris Bleakley,
Lord Nightmare (lord_nightmare@users.sourceforge.net),
Matthew Kendora,
neviksti
DSP-3 emulator code
(c) Copyright 2003 - 2006 John Weidman,
Kris Bleakley,
Lancer,
z80 gaiden
DSP-4 emulator code
(c) Copyright 2004 - 2006 Dreamer Nom,
John Weidman,
Kris Bleakley,
Nach,
z80 gaiden
OBC1 emulator code
(c) Copyright 2001 - 2004 zsKnight,
pagefault (pagefault@zsnes.com),
Kris Bleakley
Ported from x86 assembler to C by sanmaiwashi
SPC7110 and RTC C++ emulator code used in 1.39-1.51
(c) Copyright 2002 Matthew Kendora with research by
zsKnight,
John Weidman,
Dark Force
SPC7110 and RTC C++ emulator code used in 1.52+
(c) Copyright 2009 byuu,
neviksti
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive,
John Weidman
S-RTC C emulator code
(c) Copyright 2001 - 2006 byuu,
John Weidman
ST010 C++ emulator code
(c) Copyright 2003 Feather,
John Weidman,
Kris Bleakley,
Matthew Kendora
Super FX x86 assembler emulator code
(c) Copyright 1998 - 2003 _Demo_,
pagefault,
zsKnight
Super FX C emulator code
(c) Copyright 1997 - 1999 Ivar,
Gary Henderson,
John Weidman
Sound emulator code used in 1.5-1.51
(c) Copyright 1998 - 2003 Brad Martin
(c) Copyright 1998 - 2006 Charles Bilyue'
Sound emulator code used in 1.52+
(c) Copyright 2004 - 2007 Shay Green (gblargg@gmail.com)
SH assembler code partly based on x86 assembler code
(c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
2xSaI filter
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
HQ2x, HQ3x, HQ4x filters
(c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com)
NTSC filter
(c) Copyright 2006 - 2007 Shay Green
GTK+ GUI code
(c) Copyright 2004 - 2011 BearOso
Win32 GUI code
(c) Copyright 2003 - 2006 blip,
funkyass,
Matthew Kendora,
Nach,
nitsuja
(c) Copyright 2009 - 2011 OV2
Mac OS GUI code
(c) Copyright 1998 - 2001 John Stiles
(c) Copyright 2001 - 2011 zones
Specific ports contains the works of other authors. See headers in
individual files.
Snes9x homepage: http://www.snes9x.com/
Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear
with all copies and any derived work.
This software is provided 'as-is', without any express or implied
warranty. In no event shall the authors be held liable for any damages
arising from the use of this software or it's derivatives.
Snes9x is freeware for PERSONAL USE only. Commercial users should
seek permission of the copyright holders first. Commercial use includes,
but is not limited to, charging money for Snes9x or software derived from
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
using Snes9x as a promotion for your commercial product.
The copyright holders request that bug fixes and improvements to the code
should be forwarded to them so everyone can benefit from the modifications
in future versions.
Super NES and Super Nintendo Entertainment System are trademarks of
Nintendo Co., Limited and its subsidiary companies.
***********************************************************************************/
#include "CCGShader.h"
#include "../conffile.h"
@ -79,11 +255,11 @@ bool CCGShader::LoadShader(const char *path)
const char *scaleFloat = conf.GetString(keyName,"");
int scaleInt = conf.GetInt(keyName,0);
if(!strcasecmp(scaleFloat,"")) {
sprintf(keyName,"::scalex%u",i);
sprintf(keyName,"::scale_x%u",i);
const char *scaleFloatX = conf.GetString(keyName,"1.0");
pass.scaleParams.scaleX = atof(scaleFloatX);
pass.scaleParams.absX = conf.GetInt(keyName,1);
sprintf(keyName,"::scaley%u",i);
sprintf(keyName,"::scale_y%u",i);
const char *scaleFloatY = conf.GetString(keyName,"1.0");
pass.scaleParams.scaleY = atof(scaleFloatY);
pass.scaleParams.absY = conf.GetInt(keyName,1);

View File

@ -1,3 +1,179 @@
/***********************************************************************************
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
(c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com),
Jerremy Koot (jkoot@snes9x.com)
(c) Copyright 2002 - 2004 Matthew Kendora
(c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org)
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
(c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net)
(c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca),
Kris Bleakley (codeviolation@hotmail.com)
(c) Copyright 2002 - 2010 Brad Jorsch (anomie@users.sourceforge.net),
Nach (n-a-c-h@users.sourceforge.net),
(c) Copyright 2002 - 2011 zones (kasumitokoduck@yahoo.com)
(c) Copyright 2006 - 2007 nitsuja
(c) Copyright 2009 - 2011 BearOso,
OV2
BS-X C emulator code
(c) Copyright 2005 - 2006 Dreamer Nom,
zones
C4 x86 assembler and some C emulation code
(c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com),
Nach,
zsKnight (zsknight@zsnes.com)
C4 C++ code
(c) Copyright 2003 - 2006 Brad Jorsch,
Nach
DSP-1 emulator code
(c) Copyright 1998 - 2006 _Demo_,
Andreas Naive (andreasnaive@gmail.com),
Gary Henderson,
Ivar (ivar@snes9x.com),
John Weidman,
Kris Bleakley,
Matthew Kendora,
Nach,
neviksti (neviksti@hotmail.com)
DSP-2 emulator code
(c) Copyright 2003 John Weidman,
Kris Bleakley,
Lord Nightmare (lord_nightmare@users.sourceforge.net),
Matthew Kendora,
neviksti
DSP-3 emulator code
(c) Copyright 2003 - 2006 John Weidman,
Kris Bleakley,
Lancer,
z80 gaiden
DSP-4 emulator code
(c) Copyright 2004 - 2006 Dreamer Nom,
John Weidman,
Kris Bleakley,
Nach,
z80 gaiden
OBC1 emulator code
(c) Copyright 2001 - 2004 zsKnight,
pagefault (pagefault@zsnes.com),
Kris Bleakley
Ported from x86 assembler to C by sanmaiwashi
SPC7110 and RTC C++ emulator code used in 1.39-1.51
(c) Copyright 2002 Matthew Kendora with research by
zsKnight,
John Weidman,
Dark Force
SPC7110 and RTC C++ emulator code used in 1.52+
(c) Copyright 2009 byuu,
neviksti
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive,
John Weidman
S-RTC C emulator code
(c) Copyright 2001 - 2006 byuu,
John Weidman
ST010 C++ emulator code
(c) Copyright 2003 Feather,
John Weidman,
Kris Bleakley,
Matthew Kendora
Super FX x86 assembler emulator code
(c) Copyright 1998 - 2003 _Demo_,
pagefault,
zsKnight
Super FX C emulator code
(c) Copyright 1997 - 1999 Ivar,
Gary Henderson,
John Weidman
Sound emulator code used in 1.5-1.51
(c) Copyright 1998 - 2003 Brad Martin
(c) Copyright 1998 - 2006 Charles Bilyue'
Sound emulator code used in 1.52+
(c) Copyright 2004 - 2007 Shay Green (gblargg@gmail.com)
SH assembler code partly based on x86 assembler code
(c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
2xSaI filter
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
HQ2x, HQ3x, HQ4x filters
(c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com)
NTSC filter
(c) Copyright 2006 - 2007 Shay Green
GTK+ GUI code
(c) Copyright 2004 - 2011 BearOso
Win32 GUI code
(c) Copyright 2003 - 2006 blip,
funkyass,
Matthew Kendora,
Nach,
nitsuja
(c) Copyright 2009 - 2011 OV2
Mac OS GUI code
(c) Copyright 1998 - 2001 John Stiles
(c) Copyright 2001 - 2011 zones
Specific ports contains the works of other authors. See headers in
individual files.
Snes9x homepage: http://www.snes9x.com/
Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear
with all copies and any derived work.
This software is provided 'as-is', without any express or implied
warranty. In no event shall the authors be held liable for any damages
arising from the use of this software or it's derivatives.
Snes9x is freeware for PERSONAL USE only. Commercial users should
seek permission of the copyright holders first. Commercial use includes,
but is not limited to, charging money for Snes9x or software derived from
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
using Snes9x as a promotion for your commercial product.
The copyright holders request that bug fixes and improvements to the code
should be forwarded to them so everyone can benefit from the modifications
in future versions.
Super NES and Super Nintendo Entertainment System are trademarks of
Nintendo Co., Limited and its subsidiary companies.
***********************************************************************************/
#ifndef CCGSHADER_H
#define CCGSHADER_H

836
win32/CD3DCG.cpp Normal file
View File

@ -0,0 +1,836 @@
/***********************************************************************************
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
(c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com),
Jerremy Koot (jkoot@snes9x.com)
(c) Copyright 2002 - 2004 Matthew Kendora
(c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org)
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
(c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net)
(c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca),
Kris Bleakley (codeviolation@hotmail.com)
(c) Copyright 2002 - 2010 Brad Jorsch (anomie@users.sourceforge.net),
Nach (n-a-c-h@users.sourceforge.net),
(c) Copyright 2002 - 2011 zones (kasumitokoduck@yahoo.com)
(c) Copyright 2006 - 2007 nitsuja
(c) Copyright 2009 - 2011 BearOso,
OV2
BS-X C emulator code
(c) Copyright 2005 - 2006 Dreamer Nom,
zones
C4 x86 assembler and some C emulation code
(c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com),
Nach,
zsKnight (zsknight@zsnes.com)
C4 C++ code
(c) Copyright 2003 - 2006 Brad Jorsch,
Nach
DSP-1 emulator code
(c) Copyright 1998 - 2006 _Demo_,
Andreas Naive (andreasnaive@gmail.com),
Gary Henderson,
Ivar (ivar@snes9x.com),
John Weidman,
Kris Bleakley,
Matthew Kendora,
Nach,
neviksti (neviksti@hotmail.com)
DSP-2 emulator code
(c) Copyright 2003 John Weidman,
Kris Bleakley,
Lord Nightmare (lord_nightmare@users.sourceforge.net),
Matthew Kendora,
neviksti
DSP-3 emulator code
(c) Copyright 2003 - 2006 John Weidman,
Kris Bleakley,
Lancer,
z80 gaiden
DSP-4 emulator code
(c) Copyright 2004 - 2006 Dreamer Nom,
John Weidman,
Kris Bleakley,
Nach,
z80 gaiden
OBC1 emulator code
(c) Copyright 2001 - 2004 zsKnight,
pagefault (pagefault@zsnes.com),
Kris Bleakley
Ported from x86 assembler to C by sanmaiwashi
SPC7110 and RTC C++ emulator code used in 1.39-1.51
(c) Copyright 2002 Matthew Kendora with research by
zsKnight,
John Weidman,
Dark Force
SPC7110 and RTC C++ emulator code used in 1.52+
(c) Copyright 2009 byuu,
neviksti
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive,
John Weidman
S-RTC C emulator code
(c) Copyright 2001 - 2006 byuu,
John Weidman
ST010 C++ emulator code
(c) Copyright 2003 Feather,
John Weidman,
Kris Bleakley,
Matthew Kendora
Super FX x86 assembler emulator code
(c) Copyright 1998 - 2003 _Demo_,
pagefault,
zsKnight
Super FX C emulator code
(c) Copyright 1997 - 1999 Ivar,
Gary Henderson,
John Weidman
Sound emulator code used in 1.5-1.51
(c) Copyright 1998 - 2003 Brad Martin
(c) Copyright 1998 - 2006 Charles Bilyue'
Sound emulator code used in 1.52+
(c) Copyright 2004 - 2007 Shay Green (gblargg@gmail.com)
SH assembler code partly based on x86 assembler code
(c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
2xSaI filter
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
HQ2x, HQ3x, HQ4x filters
(c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com)
NTSC filter
(c) Copyright 2006 - 2007 Shay Green
GTK+ GUI code
(c) Copyright 2004 - 2011 BearOso
Win32 GUI code
(c) Copyright 2003 - 2006 blip,
funkyass,
Matthew Kendora,
Nach,
nitsuja
(c) Copyright 2009 - 2011 OV2
Mac OS GUI code
(c) Copyright 1998 - 2001 John Stiles
(c) Copyright 2001 - 2011 zones
Specific ports contains the works of other authors. See headers in
individual files.
Snes9x homepage: http://www.snes9x.com/
Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear
with all copies and any derived work.
This software is provided 'as-is', without any express or implied
warranty. In no event shall the authors be held liable for any damages
arising from the use of this software or it's derivatives.
Snes9x is freeware for PERSONAL USE only. Commercial users should
seek permission of the copyright holders first. Commercial use includes,
but is not limited to, charging money for Snes9x or software derived from
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
using Snes9x as a promotion for your commercial product.
The copyright holders request that bug fixes and improvements to the code
should be forwarded to them so everyone can benefit from the modifications
in future versions.
Super NES and Super Nintendo Entertainment System are trademarks of
Nintendo Co., Limited and its subsidiary companies.
***********************************************************************************/
#include "CD3DCG.h"
#include "wsnes9x.h"
#include "win32_display.h"
#include <Dxerr.h>
#include <png.h>
#include "CDirect3D.h"
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
static float npot(float desired)
{
float out=512.0;
while(out<desired)
out*=2;
return out;
}
CD3DCG::CD3DCG(CGcontext cgContext,LPDIRECT3DDEVICE9 pDevice)
{
this->cgContext = cgContext;
this->pDevice = pDevice;
ClearPasses();
frameCnt=0;
}
CD3DCG::~CD3DCG(void)
{
LoadShader(NULL);
}
void CD3DCG::ClearPasses()
{
/* clean up cg programs, vertex buffers/declarations and textures
from all regular passes. pass 0 is the orignal texture, so ignore that
*/
if(shaderPasses.size()>1) {
for(std::vector<shaderPass>::iterator it=(shaderPasses.begin()+1);it!=shaderPasses.end();it++) {
if(it->cgFragmentProgram)
cgDestroyProgram(it->cgFragmentProgram);
if(it->cgVertexProgram)
cgDestroyProgram(it->cgVertexProgram);
if(it->tex)
it->tex->Release();
if(it->vertexBuffer)
it->vertexBuffer->Release();
if(it->vertexDeclaration)
it->vertexDeclaration->Release();
}
}
for(std::vector<lookupTexture>::iterator it=lookupTextures.begin();it!=lookupTextures.end();it++) {
if(it->tex)
it->tex->Release();
}
for(std::deque<prevPass>::iterator it=prevPasses.begin();it!=prevPasses.end();it++) {
if(it->tex)
it->tex->Release();
if(it->vertexBuffer)
it->vertexBuffer->Release();
}
prevPasses.clear();
shaderPasses.clear();
lookupTextures.clear();
// prevPasses deque is always filled with PREV + PREV1-6 elements
prevPasses.resize(7);
shaderLoaded = false;
}
void CD3DCG::OnLostDevice()
{
/* release all non-managed textures so the device can reset -
will be recreated when required
*/
if(shaderPasses.size()>1) {
for(std::vector<shaderPass>::iterator it=(shaderPasses.begin()+1);it!=shaderPasses.end();it++) {
if(it->tex) {
it->tex->Release();
it->tex = NULL;
}
}
}
}
void CD3DCG::OnResetDevice()
{
}
void CD3DCG::checkForCgError(const char *situation)
{
char buffer[4096];
CGerror error = cgGetError();
const char *string = cgGetErrorString(error);
if (error != CG_NO_ERROR) {
sprintf(buffer,
"Situation: %s\n"
"Error: %s\n\n"
"Cg compiler output...\n", situation, string);
MessageBoxA(0, buffer,
"Cg error", MB_OK|MB_ICONEXCLAMATION);
if (error == CG_COMPILER_ERROR) {
MessageBoxA(0, cgGetLastListing(cgContext),
"Cg compilation error", MB_OK|MB_ICONEXCLAMATION);
}
}
}
#define IS_SLASH(x) ((x) == TEXT('\\') || (x) == TEXT('/'))
bool CD3DCG::LoadShader(const TCHAR *shaderFile)
{
CCGShader cgShader;
TCHAR shaderPath[MAX_PATH];
TCHAR tempPath[MAX_PATH];
HRESULT hr;
GLenum error;
ClearPasses();
if (shaderFile == NULL || *shaderFile==TEXT('\0'))
return true;
lstrcpy(shaderPath,shaderFile);
for(int i=lstrlen(shaderPath); i>=0; i--){
if(IS_SLASH(shaderPath[i])){
shaderPath[i]=TEXT('\0');
break;
}
}
SetCurrentDirectory(shaderPath);
if(!cgShader.LoadShader(_tToChar(shaderFile)))
return false;
CGprofile vertexProfile = cgD3D9GetLatestVertexProfile();
CGprofile pixelProfile = cgD3D9GetLatestPixelProfile();
const char** vertexOptions = cgD3D9GetOptimalOptions(vertexProfile);
const char** pixelOptions = cgD3D9GetOptimalOptions(pixelProfile);
shaderPasses.push_back(shaderPass());
for(CCGShader::passVector::iterator it=cgShader.shaderPasses.begin();
it!=cgShader.shaderPasses.end();it++) {
shaderPass pass;
pass.scaleParams = it->scaleParams;
/* if this is the last pass (the only one that can have CG_SCALE_NONE)
and no filter has been set use the GUI setting
*/
if(pass.scaleParams.scaleTypeX==CG_SCALE_NONE && !it->filterSet) {
pass.linearFilter = GUI.BilinearFilter;
} else {
pass.linearFilter = it->linearFilter;
}
// paths in the meta file can be relative
_tfullpath(tempPath,_tFromChar(it->cgShaderFile),MAX_PATH);
char *fileContents = ReadShaderFileContents(tempPath);
if(!fileContents)
return false;
pass.cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
vertexProfile, "main_vertex", vertexOptions);
checkForCgError("Compiling vertex program");
pass.cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
pixelProfile, "main_fragment", pixelOptions);
checkForCgError("Compiling fragment program");
delete [] fileContents;
if(!pass.cgVertexProgram || !pass.cgFragmentProgram) {
return false;
}
if(pass.cgVertexProgram) {
hr = cgD3D9LoadProgram(pass.cgVertexProgram,false,0);
}
checkForCgError("Loading vertex program");
if(pass.cgFragmentProgram) {
hr = cgD3D9LoadProgram(pass.cgFragmentProgram,false,0);
}
checkForCgError("Loading fragment program");
/* generate vertex buffer
*/
hr = pDevice->CreateVertexBuffer(sizeof(VERTEX)*4,D3DUSAGE_WRITEONLY,0,D3DPOOL_MANAGED,&pass.vertexBuffer,NULL);
if(FAILED(hr)) {
pass.vertexBuffer = NULL;
DXTRACE_ERR_MSGBOX(TEXT("Error creating vertex buffer"), hr);
return false;
}
/* set up vertex declarations for the pass,
this also creates the vertex declaration
*/
setupVertexDeclaration(pass);
shaderPasses.push_back(pass);
}
for(std::vector<CCGShader::lookupTexture>::iterator it=cgShader.lookupTextures.begin();it!=cgShader.lookupTextures.end();it++) {
lookupTexture tex;
strcpy(tex.id,it->id);
tex.linearFilter = it->linearfilter;
_tfullpath(tempPath,_tFromChar(it->texturePath),MAX_PATH);
hr = D3DXCreateTextureFromFileEx(
pDevice,
tempPath,
D3DX_DEFAULT_NONPOW2,
D3DX_DEFAULT_NONPOW2,
0,
0,
D3DFMT_FROM_FILE,
D3DPOOL_MANAGED,
it->linearfilter?D3DX_FILTER_LINEAR:D3DX_FILTER_POINT,
0,
0,
NULL,
NULL,
&tex.tex);
if FAILED(hr){
tex.tex = NULL;
}
lookupTextures.push_back(tex);
}
shaderLoaded = true;
return true;
}
void CD3DCG::ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, D3DXVECTOR2 &texSize,
D3DXVECTOR2 wantedSize,bool renderTarget)
{
HRESULT hr;
if(!tex || texSize != wantedSize) {
if(tex)
tex->Release();
hr = pDevice->CreateTexture(
wantedSize.x, wantedSize.y,
1, // 1 level, no mipmaps
renderTarget?D3DUSAGE_RENDERTARGET:0,
renderTarget?D3DFMT_X8R8G8B8:D3DFMT_R5G6B5,
renderTarget?D3DPOOL_DEFAULT:D3DPOOL_MANAGED, // render targets cannot be managed
&tex,
NULL );
texSize = wantedSize;
if(FAILED(hr)) {
DXTRACE_ERR_MSGBOX(TEXT("Error while creating texture"), hr);
return;
}
}
}
void CD3DCG::setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer,
D3DXVECTOR2 inputSize,D3DXVECTOR2 textureSize,D3DXVECTOR2 outputSize)
{
float tX = inputSize.x / textureSize.x;
float tY = inputSize.y / textureSize.y;
VERTEX vertexStream[4];
/* vertex is POSITION, TEXCOORD, LUT TEXCOORD
*/
vertexStream[0] = VERTEX(0.0f,0.0f,0.0f,
0.0f,tY,
0.0f,1.0f);
vertexStream[1] = VERTEX(0.0f,1.0f,0.0f,
0.0f,0.0f,
0.0f,0.0f);
vertexStream[2] = VERTEX(1.0f,0.0f,0.0f,
tX,tY,
1.0f,1.0f);
vertexStream[3] = VERTEX(1.0f,1.0f,0.0f,
tX,0.0f,
1.0f,0.0f);
// offset coordinates to correct pixel/texture alignment
for(int i=0;i<4;i++) {
vertexStream[i].x -= 0.5f / outputSize.x;
vertexStream[i].y += 0.5f / outputSize.y;
}
void *pLockedVertexBuffer;
HRESULT hr = vertexBuffer->Lock(0,0,&pLockedVertexBuffer,NULL);
memcpy(pLockedVertexBuffer,vertexStream,sizeof(vertexStream));
vertexBuffer->Unlock();
/* set vertex to stream 0-3, for POSITION,TEXCOORD0,TEXCOORD1,COLOR
if stream is used in parameter, this will be set in setShaderVars
*/
pDevice->SetStreamSource(0,vertexBuffer,0,sizeof(VERTEX));
pDevice->SetStreamSource(1,vertexBuffer,0,sizeof(VERTEX));
pDevice->SetStreamSource(2,vertexBuffer,0,sizeof(VERTEX));
pDevice->SetStreamSource(3,vertexBuffer,0,sizeof(VERTEX));
}
void CD3DCG::Render(LPDIRECT3DTEXTURE9 &origTex, D3DXVECTOR2 textureSize,
D3DXVECTOR2 inputSize, D3DXVECTOR2 viewportSize, D3DXVECTOR2 windowSize)
{
LPDIRECT3DSURFACE9 pRenderSurface = NULL,pBackBuffer = NULL;
frameCnt++;
if(!shaderLoaded)
return;
/* save back buffer render target
*/
pDevice->GetRenderTarget(0,&pBackBuffer);
/* pass 0 represents the original texture
*/
shaderPasses[0].tex = origTex;
shaderPasses[0].outputSize = inputSize;
shaderPasses[0].textureSize = textureSize;
calculateMatrix();
for(int i=1;i<shaderPasses.size();i++) {
switch(shaderPasses[i].scaleParams.scaleTypeX) {
case CG_SCALE_ABSOLUTE:
shaderPasses[i].outputSize.x = (double)shaderPasses[i].scaleParams.absX;
break;
case CG_SCALE_SOURCE:
shaderPasses[i].outputSize.x = shaderPasses[i-1].outputSize.x * shaderPasses[i].scaleParams.scaleX;
break;
case CG_SCALE_VIEWPORT:
shaderPasses[i].outputSize.x = viewportSize.x * shaderPasses[i].scaleParams.scaleX;
break;
default:
shaderPasses[i].outputSize.x = viewportSize.x;
}
switch(shaderPasses[i].scaleParams.scaleTypeY) {
case CG_SCALE_ABSOLUTE:
shaderPasses[i].outputSize.y = (double)shaderPasses[i].scaleParams.absY;
break;
case CG_SCALE_SOURCE:
shaderPasses[i].outputSize.y = shaderPasses[i-1].outputSize.y * shaderPasses[i].scaleParams.scaleY;
break;
case CG_SCALE_VIEWPORT:
shaderPasses[i].outputSize.y = viewportSize.y * shaderPasses[i].scaleParams.scaleY;
break;
default:
shaderPasses[i].outputSize.y = viewportSize.y;
}
float texSize = npot(max(shaderPasses[i].outputSize.x,shaderPasses[i].outputSize.y));
/* make sure the render target exists and has an appropriate size,
then set as current render target with last pass as source
*/
ensureTextureSize(shaderPasses[i].tex,shaderPasses[i].textureSize,D3DXVECTOR2(texSize,texSize),true);
shaderPasses[i].tex->GetSurfaceLevel(0,&pRenderSurface);
pDevice->SetTexture(0, shaderPasses[i-1].tex);
pDevice->SetRenderTarget(0,pRenderSurface);
pRenderSurface->Release();
/* set vertex declaration of current pass, update vertex
buffer and set base streams
*/
pDevice->SetVertexDeclaration(shaderPasses[i].vertexDeclaration);
setVertexStream(shaderPasses[i].vertexBuffer,
shaderPasses[i-1].outputSize,shaderPasses[i-1].textureSize,shaderPasses[i].outputSize);
pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, shaderPasses[i].linearFilter?D3DTEXF_LINEAR:D3DTEXF_POINT);
pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, shaderPasses[i].linearFilter?D3DTEXF_LINEAR:D3DTEXF_POINT);
/* shader vars need to be set after the base vertex streams
have been set so they can override them
*/
setShaderVars(i);
cgD3D9BindProgram(shaderPasses[i].cgVertexProgram);
checkForCgError("Binding vertex program");
cgD3D9BindProgram(shaderPasses[i].cgFragmentProgram);
checkForCgError("Binding fragment program");
/* viewport defines output size
*/
setViewport(0,0,shaderPasses[i].outputSize.x,shaderPasses[i].outputSize.y);
pDevice->BeginScene();
pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
pDevice->EndScene();
}
/* take oldes PREV out of deque, make sure it has
the same size as the current texture and
then set it up as new original texture
*/
prevPass &oldestPrev = prevPasses.back();
ensureTextureSize(oldestPrev.tex,oldestPrev.textureSize,textureSize,false);
if(oldestPrev.vertexBuffer)
oldestPrev.vertexBuffer->Release();
origTex = oldestPrev.tex;
prevPasses.pop_back();
/* push current original with corresponding vertex
buffer to front of PREV deque
*/
shaderPasses[0].vertexBuffer = shaderPasses[1].vertexBuffer;
prevPasses.push_front(prevPass(shaderPasses[0]));
/* create new vertex buffer so that next render call
will not overwrite the PREV
*/
pDevice->CreateVertexBuffer(sizeof(VERTEX)*4,D3DUSAGE_WRITEONLY,0,D3DPOOL_MANAGED,&shaderPasses[1].vertexBuffer,NULL);
/* set up last pass texture, backbuffer and viewport
for final display pass without shaders
*/
pDevice->SetTexture(0, shaderPasses.back().tex);
pDevice->SetRenderTarget(0,pBackBuffer);
pBackBuffer->Release();
RECT displayRect=CalculateDisplayRect(shaderPasses.back().outputSize.x,shaderPasses.back().outputSize.y,windowSize.x,windowSize.y);
setViewport(displayRect.left,displayRect.top,displayRect.right - displayRect.left,displayRect.bottom - displayRect.top);
setVertexStream(shaderPasses.back().vertexBuffer,
shaderPasses.back().outputSize,shaderPasses.back().textureSize,
D3DXVECTOR2(displayRect.right - displayRect.left,displayRect.bottom - displayRect.top));
pDevice->SetVertexShader(NULL);
pDevice->SetPixelShader(NULL);
}
void CD3DCG::calculateMatrix()
{
D3DXMATRIX matWorld;
D3DXMATRIX matView;
D3DXMATRIX matProj;
pDevice->GetTransform(D3DTS_WORLD,&matWorld);
pDevice->GetTransform(D3DTS_VIEW,&matView);
pDevice->GetTransform(D3DTS_PROJECTION,&matProj);
mvp = matWorld * matView * matProj;
D3DXMatrixTranspose(&mvp,&mvp);
}
void CD3DCG::setViewport(DWORD x, DWORD y, DWORD width, DWORD height)
{
D3DVIEWPORT9 viewport;
viewport.X = x;
viewport.Y = y;
viewport.Height = height;
viewport.Width = width;
viewport.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
HRESULT hr = pDevice->SetViewport(&viewport);
}
void CD3DCG::setShaderVars(int pass)
{
D3DXVECTOR2 inputSize = shaderPasses[pass-1].outputSize;
D3DXVECTOR2 textureSize = shaderPasses[pass-1].textureSize;
D3DXVECTOR2 outputSize = shaderPasses[pass].outputSize;
/* mvp paramater
*/
CGparameter cgpModelViewProj = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, "modelViewProj");
if(cgpModelViewProj)
cgD3D9SetUniformMatrix(cgpModelViewProj,&mvp);
#define setProgramUniform(pass,varname,floats)\
{\
CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\
CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\
if(cgpf)\
cgD3D9SetUniform(cgpf,floats);\
if(cgpv)\
cgD3D9SetUniform(cgpv,floats);\
}\
#define setTextureParameter(pass,varname,val,linear)\
{\
CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\
if(cgpf) {\
cgD3D9SetTexture(cgpf,val);\
cgD3D9SetSamplerState(cgpf, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);\
cgD3D9SetSamplerState(cgpf, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);\
cgD3D9SetSamplerState(cgpf, D3DSAMP_MINFILTER, linear?D3DTEXF_LINEAR:D3DTEXF_POINT);\
cgD3D9SetSamplerState(cgpf, D3DSAMP_MAGFILTER, linear?D3DTEXF_LINEAR:D3DTEXF_POINT);\
}\
}\
#define setTexCoordsParameter(pass,varname,val)\
{\
CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\
if(cgpv) {\
unsigned long index = cgGetParameterResourceIndex(cgpv);\
pDevice->SetStreamSource(shaderPasses[pass].parameterMap[index].streamNumber,val,0,sizeof(VERTEX));\
}\
}\
/* IN paramater
*/
setProgramUniform(pass,"IN.video_size",&inputSize);
setProgramUniform(pass,"IN.texture_size",&textureSize);
setProgramUniform(pass,"IN.output_size",&outputSize);
setProgramUniform(pass,"IN.frame_count",&frameCnt);
/* ORIG parameter
*/
setProgramUniform(pass,"ORIG.video_size",shaderPasses[0].outputSize);
setProgramUniform(pass,"ORIG.texture_size",shaderPasses[0].textureSize);
setTextureParameter(pass,"ORIG.texture",shaderPasses[0].tex,shaderPasses[1].linearFilter);
setTexCoordsParameter(pass,"ORIG.tex_coord",shaderPasses[1].vertexBuffer);
/* PREV parameter
*/
if(prevPasses[0].tex) {
setProgramUniform(pass,"PREV.video_size",prevPasses[0].imageSize);
setProgramUniform(pass,"PREV.texture_size",prevPasses[0].textureSize);
setTextureParameter(pass,"PREV.texture",prevPasses[0].tex,shaderPasses[1].linearFilter);
setTexCoordsParameter(pass,"PREV.tex_coord",prevPasses[0].vertexBuffer);
}
/* PREV1-6 parameters
*/
for(int i=1;i<prevPasses.size();i++) {
if(!prevPasses[i].tex)
break;
char varname[100];
sprintf(varname,"PREV%d.video_size",i);
setProgramUniform(pass,varname,prevPasses[i].imageSize);
sprintf(varname,"PREV%d.texture_size",i);
setProgramUniform(pass,varname,prevPasses[i].textureSize);
sprintf(varname,"PREV%d.texture",i);
setTextureParameter(pass,varname,prevPasses[i].tex,shaderPasses[1].linearFilter);
sprintf(varname,"PREV%d.tex_coord",i);
setTexCoordsParameter(pass,varname,prevPasses[i].vertexBuffer);
}
/* LUT parameters
*/
for(int i=0;i<lookupTextures.size();i++) {
setTextureParameter(pass,lookupTextures[i].id,lookupTextures[i].tex,lookupTextures[i].linearFilter);
}
/* PASSX parameters, only for third pass and up
*/
if(pass>2) {
for(int i=1;i<pass-1;i++) {
char varname[100];
sprintf(varname,"PASS%d.video_size",i);
setProgramUniform(pass,varname,shaderPasses[i].outputSize);
sprintf(varname,"PASS%d.texture_size",i);
setProgramUniform(pass,varname,shaderPasses[i].textureSize);
sprintf(varname,"PASS%d.texture",i);
setTextureParameter(pass,varname,shaderPasses[i].tex,shaderPasses[i+1].linearFilter);
sprintf(varname,"PASS%d.tex_coord",i);
setTexCoordsParameter(pass,varname,shaderPasses[i+1].vertexBuffer);
}
}
}
/* checks for known cg parameters, to make sure they
get stream offset 12
*/
static bool isKnownParameter(const char *paramName)
{
int len = strlen(paramName);
if(len<3)
return false;
if(!strncmp(paramName,"IN.",3))
return true;
if(len<4)
return false;
if(!strncmp(paramName,"PREV",4) ||
!strncmp(paramName,"PASS",4) ||
!strncmp(paramName,"ORIG",4))
return true;
return false;
}
/* iterate all parameters and record input variyings
with their semantic and resource index
*/
void CD3DCG::fillParameterMap(std::vector<parameterEntry> &map, CGparameter param)
{
parameterEntry mapEntry;
while (param) {
if(cgGetParameterType(param)==CG_STRUCT)
fillParameterMap(map,cgGetFirstStructParameter(param));
else
if (cgGetParameterDirection(param) == CG_IN && cgGetParameterVariability(param) == CG_VARYING) {
mapEntry.rIndex = cgGetParameterResourceIndex(param);
mapEntry.semantic = cgGetParameterSemantic(param);
mapEntry.isKnownParam = isKnownParameter(cgGetParameterName(param));
if(map.size()<mapEntry.rIndex+1)
map.resize(mapEntry.rIndex+1);
map[mapEntry.rIndex] = mapEntry;
}
param = cgGetNextParameter(param);
}
}
void CD3DCG::setupVertexDeclaration(shaderPass &pass)
{
static const D3DVERTEXELEMENT9 end = D3DDECL_END();
CGparameter param = cgGetFirstParameter(pass.cgVertexProgram, CG_PROGRAM);
fillParameterMap(pass.parameterMap,param);
/* set up vertex elements according to parameter map.
all streams use the same vertex buffer layout, with
different offsets.
default (unknown name) parameters with semantics
POSITION0, TEXCOORD0, TEXCOORD1 and COLOR0 get stream
0,1,2 and 3 respectively.
the rest (all texcoords) get stream 4 and up
*/
D3DVERTEXELEMENT9 *vElems = new D3DVERTEXELEMENT9[pass.parameterMap.size()+1];
int streamNum = 4;
for(int i=0;i<pass.parameterMap.size();i++) {
const char* sem = pass.parameterMap[i].semantic;
pass.parameterMap[i].streamNumber = 0;
if(pass.parameterMap[i].isKnownParam==false) {
if(!strcmp(sem,"TEXCOORD0")) {
D3DVERTEXELEMENT9 elem = {1, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0};
vElems[i] = elem;
} else if(!strcmp(sem,"TEXCOORD1")) {
D3DVERTEXELEMENT9 elem = {2, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1};
vElems[i] = elem;
} else if(!strcmp(sem,"COLOR0")) {
D3DVERTEXELEMENT9 elem = {3, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0};
vElems[i] = elem;
} else if(!strcmp(sem,"POSITION0")) {
D3DVERTEXELEMENT9 elem = {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0};
vElems[i] = elem;
}
} else {
int resIndex = atoi(sem + strlen(sem) - 1);
D3DVERTEXELEMENT9 elem = {streamNum, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, resIndex};
vElems[i] = elem;
pass.parameterMap[i].streamNumber = streamNum;
streamNum++;
}
}
vElems[pass.parameterMap.size()] = end;
/* create vertex declaration for vertex elements, then
get rid of the elements
*/
LPDIRECT3DVERTEXDECLARATION9 vertexDeclaration;
HRESULT hr = pDevice->CreateVertexDeclaration(vElems,&vertexDeclaration);
if(FAILED(hr)) {
DXTRACE_ERR_MSGBOX(TEXT("Error creating vertex declaration"), hr);
}
if(pass.vertexDeclaration)
pass.vertexDeclaration->Release();
pass.vertexDeclaration = vertexDeclaration;
delete [] vElems;
}

264
win32/CD3DCG.h Normal file
View File

@ -0,0 +1,264 @@
/***********************************************************************************
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
(c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com),
Jerremy Koot (jkoot@snes9x.com)
(c) Copyright 2002 - 2004 Matthew Kendora
(c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org)
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
(c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net)
(c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca),
Kris Bleakley (codeviolation@hotmail.com)
(c) Copyright 2002 - 2010 Brad Jorsch (anomie@users.sourceforge.net),
Nach (n-a-c-h@users.sourceforge.net),
(c) Copyright 2002 - 2011 zones (kasumitokoduck@yahoo.com)
(c) Copyright 2006 - 2007 nitsuja
(c) Copyright 2009 - 2011 BearOso,
OV2
BS-X C emulator code
(c) Copyright 2005 - 2006 Dreamer Nom,
zones
C4 x86 assembler and some C emulation code
(c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com),
Nach,
zsKnight (zsknight@zsnes.com)
C4 C++ code
(c) Copyright 2003 - 2006 Brad Jorsch,
Nach
DSP-1 emulator code
(c) Copyright 1998 - 2006 _Demo_,
Andreas Naive (andreasnaive@gmail.com),
Gary Henderson,
Ivar (ivar@snes9x.com),
John Weidman,
Kris Bleakley,
Matthew Kendora,
Nach,
neviksti (neviksti@hotmail.com)
DSP-2 emulator code
(c) Copyright 2003 John Weidman,
Kris Bleakley,
Lord Nightmare (lord_nightmare@users.sourceforge.net),
Matthew Kendora,
neviksti
DSP-3 emulator code
(c) Copyright 2003 - 2006 John Weidman,
Kris Bleakley,
Lancer,
z80 gaiden
DSP-4 emulator code
(c) Copyright 2004 - 2006 Dreamer Nom,
John Weidman,
Kris Bleakley,
Nach,
z80 gaiden
OBC1 emulator code
(c) Copyright 2001 - 2004 zsKnight,
pagefault (pagefault@zsnes.com),
Kris Bleakley
Ported from x86 assembler to C by sanmaiwashi
SPC7110 and RTC C++ emulator code used in 1.39-1.51
(c) Copyright 2002 Matthew Kendora with research by
zsKnight,
John Weidman,
Dark Force
SPC7110 and RTC C++ emulator code used in 1.52+
(c) Copyright 2009 byuu,
neviksti
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive,
John Weidman
S-RTC C emulator code
(c) Copyright 2001 - 2006 byuu,
John Weidman
ST010 C++ emulator code
(c) Copyright 2003 Feather,
John Weidman,
Kris Bleakley,
Matthew Kendora
Super FX x86 assembler emulator code
(c) Copyright 1998 - 2003 _Demo_,
pagefault,
zsKnight
Super FX C emulator code
(c) Copyright 1997 - 1999 Ivar,
Gary Henderson,
John Weidman
Sound emulator code used in 1.5-1.51
(c) Copyright 1998 - 2003 Brad Martin
(c) Copyright 1998 - 2006 Charles Bilyue'
Sound emulator code used in 1.52+
(c) Copyright 2004 - 2007 Shay Green (gblargg@gmail.com)
SH assembler code partly based on x86 assembler code
(c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
2xSaI filter
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
HQ2x, HQ3x, HQ4x filters
(c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com)
NTSC filter
(c) Copyright 2006 - 2007 Shay Green
GTK+ GUI code
(c) Copyright 2004 - 2011 BearOso
Win32 GUI code
(c) Copyright 2003 - 2006 blip,
funkyass,
Matthew Kendora,
Nach,
nitsuja
(c) Copyright 2009 - 2011 OV2
Mac OS GUI code
(c) Copyright 1998 - 2001 John Stiles
(c) Copyright 2001 - 2011 zones
Specific ports contains the works of other authors. See headers in
individual files.
Snes9x homepage: http://www.snes9x.com/
Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear
with all copies and any derived work.
This software is provided 'as-is', without any express or implied
warranty. In no event shall the authors be held liable for any damages
arising from the use of this software or it's derivatives.
Snes9x is freeware for PERSONAL USE only. Commercial users should
seek permission of the copyright holders first. Commercial use includes,
but is not limited to, charging money for Snes9x or software derived from
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
using Snes9x as a promotion for your commercial product.
The copyright holders request that bug fixes and improvements to the code
should be forwarded to them so everyone can benefit from the modifications
in future versions.
Super NES and Super Nintendo Entertainment System are trademarks of
Nintendo Co., Limited and its subsidiary companies.
***********************************************************************************/
#ifndef CGD3DCG_H
#define CGD3DCG_H
#include <vector>
#include <d3d9.h>
#include <d3dx9.h>
#include <windows.h>
#include "CCGShader.h"
#include <vector>
#include <deque>
class CD3DCG
{
private:
typedef struct _parameterEntry {
unsigned long rIndex;
const char* semantic;
bool isKnownParam;
UINT streamNumber;
} parameterEntry;
typedef struct _shaderPass {
cgScaleParams scaleParams;
bool linearFilter;
CGprogram cgVertexProgram, cgFragmentProgram;
LPDIRECT3DTEXTURE9 tex;
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
LPDIRECT3DVERTEXDECLARATION9 vertexDeclaration;
std::vector<parameterEntry> parameterMap;
D3DXVECTOR2 outputSize;
D3DXVECTOR2 textureSize;
_shaderPass() {cgVertexProgram=NULL;
cgFragmentProgram=NULL;
tex=NULL;
vertexBuffer=NULL;
vertexDeclaration=NULL;}
} shaderPass;
typedef struct _prevPass {
LPDIRECT3DTEXTURE9 tex;
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
D3DXVECTOR2 imageSize;
D3DXVECTOR2 textureSize;
_prevPass() {tex=NULL;
vertexBuffer=NULL;}
_prevPass(const shaderPass &pass) {tex = pass.tex;
vertexBuffer = pass.vertexBuffer;
imageSize = pass.outputSize;
textureSize = pass.textureSize;}
} prevPass;
typedef struct _lookupTexture {
char id[PATH_MAX];
LPDIRECT3DTEXTURE9 tex;
bool linearFilter;
_lookupTexture() {tex=NULL;}
} lookupTexture;
std::vector<shaderPass> shaderPasses;
std::vector<lookupTexture> lookupTextures;
std::deque<prevPass> prevPasses;
bool shaderLoaded;
void checkForCgError(const char *situation);
void setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer,D3DXVECTOR2 inputSize,D3DXVECTOR2 textureSize,D3DXVECTOR2 outputSize);
void setViewport(DWORD x, DWORD y, DWORD width, DWORD height);
void setShaderVars(int pass);
void ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, D3DXVECTOR2 &texSize, D3DXVECTOR2 wantedSize,bool renderTarget);
void fillParameterMap(std::vector<parameterEntry> &map, CGparameter param);
void setupVertexDeclaration(shaderPass &pass);
void calculateMatrix();
LPDIRECT3DDEVICE9 pDevice;
CGcontext cgContext;
float frameCnt;
D3DXMATRIX mvp;
public:
CD3DCG(CGcontext cgContext,LPDIRECT3DDEVICE9 pDevice);
~CD3DCG(void);
bool LoadShader(const TCHAR *shaderFile);
void Render(LPDIRECT3DTEXTURE9 &origTex, D3DXVECTOR2 textureSize, D3DXVECTOR2 inputSize, D3DXVECTOR2 viewportSize, D3DXVECTOR2 windowSize);
void ClearPasses();
void OnLostDevice();
void OnResetDevice();
};
#endif

View File

@ -198,6 +198,13 @@
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
const D3DVERTEXELEMENT9 CDirect3D::vertexElems[4] = {
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
D3DDECL_END()
};
/* CDirect3D::CDirect3D()
sets default values for the variables
*/
@ -223,8 +230,9 @@ CDirect3D::CDirect3D()
shaderTimeElapsed = 0;
frameCount = 0;
cgContext = NULL;
cgVertexProgram = cgFragmentProgram = NULL;
cgAvailable = false;
cgShader = NULL;
vertexDeclaration = NULL;
}
/* CDirect3D::~CDirect3D()
@ -272,12 +280,18 @@ bool CDirect3D::Initialize(HWND hWnd)
return false;
}
hr = pDevice->CreateVertexBuffer(sizeof(triangleStripVertices),D3DUSAGE_WRITEONLY,FVF_COORDS_TEX,D3DPOOL_MANAGED,&vertexBuffer,NULL);
hr = pDevice->CreateVertexBuffer(sizeof(vertexStream),D3DUSAGE_WRITEONLY,0,D3DPOOL_MANAGED,&vertexBuffer,NULL);
if(FAILED(hr)) {
DXTRACE_ERR_MSGBOX(TEXT("Error creating vertex buffer"), hr);
return false;
}
hr = pDevice->CreateVertexDeclaration(vertexElems,&vertexDeclaration);
if(FAILED(hr)) {
DXTRACE_ERR_MSGBOX(TEXT("Error creating vertex declaration"), hr);
return false;
}
cgAvailable = loadCgFunctions();
if(cgAvailable) {
@ -286,9 +300,13 @@ bool CDirect3D::Initialize(HWND hWnd)
if(FAILED(hr)) {
DXTRACE_ERR_MSGBOX(TEXT("Error setting cg device"), hr);
}
cgShader = new CD3DCG(cgContext,pDevice);
}
pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
pDevice->SetRenderState( D3DRS_ZENABLE, FALSE);
pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
@ -305,11 +323,14 @@ void CDirect3D::DeInitialize()
DestroyDrawSurface();
SetShader(NULL);
if(cgShader) {
delete cgShader;
cgShader = NULL;
}
if(cgContext) {
cgDestroyContext(cgContext);
cgContext = NULL;
}
if(cgAvailable)
cgD3D9SetDevice(NULL);
@ -318,6 +339,11 @@ void CDirect3D::DeInitialize()
vertexBuffer = NULL;
}
if(vertexDeclaration) {
vertexDeclaration->Release();
vertexDeclaration = NULL;
}
if( pDevice ) {
pDevice->Release();
pDevice = NULL;
@ -344,7 +370,9 @@ bool CDirect3D::SetShader(const TCHAR *file)
SetShaderCG(NULL);
SetShaderHLSL(NULL);
shader_type = D3D_SHADER_NONE;
if(file!=NULL && lstrlen(file)>3 && _tcsncicmp(&file[lstrlen(file)-3],TEXT(".cg"),3)==0) {
if(file!=NULL &&
(lstrlen(file)>3 && _tcsncicmp(&file[lstrlen(file)-3],TEXT(".cg"),3)==0) ||
(lstrlen(file)>4 && _tcsncicmp(&file[lstrlen(file)-4],TEXT(".cgp"),4)==0)){
return SetShaderCG(file);
} else {
return SetShaderHLSL(file);
@ -373,62 +401,16 @@ void CDirect3D::checkForCgError(const char *situation)
bool CDirect3D::SetShaderCG(const TCHAR *file)
{
TCHAR errorMsg[MAX_PATH + 50];
HRESULT hr;
if(cgFragmentProgram) {
cgDestroyProgram(cgFragmentProgram);
cgFragmentProgram = NULL;
}
if(cgVertexProgram) {
cgDestroyProgram(cgVertexProgram);
cgVertexProgram = NULL;
}
if (file == NULL || *file==TEXT('\0'))
return true;
if(!cgAvailable) {
MessageBox(NULL, TEXT("The CG runtime is unavailable, CG shaders will not run.\nConsult the snes9x readme for information on how to obtain the runtime."), TEXT("CG Error"),
MB_OK|MB_ICONEXCLAMATION);
if(file)
MessageBox(NULL, TEXT("The CG runtime is unavailable, CG shaders will not run.\nConsult the snes9x readme for information on how to obtain the runtime."), TEXT("CG Error"),
MB_OK|MB_ICONEXCLAMATION);
return false;
}
CGprofile vertexProfile = cgD3D9GetLatestVertexProfile();
CGprofile pixelProfile = cgD3D9GetLatestPixelProfile();
const char** vertexOptions = cgD3D9GetOptimalOptions(vertexProfile);
const char** pixelOptions = cgD3D9GetOptimalOptions(pixelProfile);
char *fileContents = ReadShaderFileContents(file);
if(!fileContents)
if(!cgShader->LoadShader(file))
return false;
cgVertexProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
vertexProfile, "main_vertex", vertexOptions);
checkForCgError("Compiling vertex program");
cgFragmentProgram = cgCreateProgram( cgContext, CG_SOURCE, fileContents,
pixelProfile, "main_fragment", pixelOptions);
checkForCgError("Compiling fragment program");
delete [] fileContents;
if(!cgVertexProgram || !cgFragmentProgram) {
return false;
}
if(cgVertexProgram) {
hr = cgD3D9LoadProgram(cgVertexProgram,true,0);
hr = cgD3D9BindProgram(cgVertexProgram);
}
if(cgFragmentProgram) {
hr = cgD3D9LoadProgram(cgFragmentProgram,false,0);
hr = cgD3D9BindProgram(cgFragmentProgram);
}
shader_type = D3D_SHADER_CG;
return true;
@ -628,7 +610,7 @@ void CDirect3D::SetShaderVars(bool setMatrix)
effect->SetTexture( rubyLUTName, rubyLUT[i] );
}
}
} else if(shader_type == D3D_SHADER_CG) {
}/* else if(shader_type == D3D_SHADER_CG) {
D3DXVECTOR2 videoSize;
D3DXVECTOR2 textureSize;
@ -640,6 +622,7 @@ void CDirect3D::SetShaderVars(bool setMatrix)
outputSize.x = GUI.Stretch?(float)dPresentParams.BackBufferWidth:(float)afterRenderWidth;
outputSize.y = GUI.Stretch?(float)dPresentParams.BackBufferHeight:(float)afterRenderHeight;
frameCnt = (float)++frameCount;
videoSize = textureSize;
#define setProgramUniform(program,varname,floats)\
{\
@ -676,7 +659,7 @@ void CDirect3D::SetShaderVars(bool setMatrix)
if(cgpModelViewProj)
cgD3D9SetUniformMatrix(cgpModelViewProj,&mvp);
}
}
}*/
}
/* CDirect3D::Render
@ -745,22 +728,16 @@ void CDirect3D::Render(SSurface Src)
SetViewport();
}
pDevice->BeginScene();
pDevice->SetTexture(0, drawSurface);
pDevice->SetFVF(FVF_COORDS_TEX);
pDevice->SetVertexDeclaration(vertexDeclaration);
pDevice->SetStreamSource(0,vertexBuffer,0,sizeof(VERTEX));
SetShaderVars();
if(shader_type == D3D_SHADER_CG) {
cgD3D9BindProgram(cgFragmentProgram);
cgD3D9BindProgram(cgVertexProgram);
}
if (shader_type == D3D_SHADER_HLSL) {
UINT passes;
SetShaderVars();
SetFiltering();
UINT passes;
pDevice->BeginScene();
hr = effect->Begin(&passes, 0);
for(UINT pass = 0; pass < passes; pass++ ) {
effect->BeginPass(pass);
@ -768,11 +745,30 @@ void CDirect3D::Render(SSurface Src)
effect->EndPass();
}
effect->End();
} else {
pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
}
pDevice->EndScene();
pDevice->EndScene();
} else {
if(shader_type == D3D_SHADER_CG) {
RECT displayRect;
//Get maximum rect respecting AR setting
displayRect=CalculateDisplayRect(dPresentParams.BackBufferWidth,dPresentParams.BackBufferHeight,
dPresentParams.BackBufferWidth,dPresentParams.BackBufferHeight);
cgShader->Render(drawSurface,
D3DXVECTOR2((float)quadTextureSize, (float)quadTextureSize),
D3DXVECTOR2((float)afterRenderWidth, (float)afterRenderHeight),
D3DXVECTOR2((float)(displayRect.right - displayRect.left),
(float)(displayRect.bottom - displayRect.top)),
D3DXVECTOR2((float)dPresentParams.BackBufferWidth, (float)dPresentParams.BackBufferHeight));
}
SetFiltering();
pDevice->SetVertexDeclaration(vertexDeclaration);
pDevice->BeginScene();
pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
pDevice->EndScene();
}
pDevice->Present(NULL, NULL, NULL, NULL);
@ -876,13 +872,18 @@ void CDirect3D::SetupVertices()
float tX = (float)afterRenderWidth / (float)quadTextureSize;
float tY = (float)afterRenderHeight / (float)quadTextureSize;
triangleStripVertices[0] = VERTEX(0.0f,0.0f,0.0f,0.0f,tY);
triangleStripVertices[1] = VERTEX(0.0f,1.0f,0.0f,0.0f,0.0f);
triangleStripVertices[2] = VERTEX(1.0f,0.0f,0.0f,tX,tY);
triangleStripVertices[3] = VERTEX(1.0f,1.0f,0.0f,tX,0.0f);
vertexStream[0] = VERTEX(0.0f,0.0f,0.0f,0.0f,tY,0.0f,0.0f);
vertexStream[1] = VERTEX(0.0f,1.0f,0.0f,0.0f,0.0f,0.0f,0.0f);
vertexStream[2] = VERTEX(1.0f,0.0f,0.0f,tX,tY,0.0f,0.0f);
vertexStream[3] = VERTEX(1.0f,1.0f,0.0f,tX,0.0f,0.0f,0.0f);
for(int i=0;i<4;i++) {
vertexStream[i].x -= 0.5f / (float)dPresentParams.BackBufferWidth;
vertexStream[i].y += 0.5f / (float)dPresentParams.BackBufferHeight;
}
HRESULT hr = vertexBuffer->Lock(0,0,&pLockedVertexBuffer,NULL);
memcpy(pLockedVertexBuffer,triangleStripVertices,sizeof(triangleStripVertices));
memcpy(pLockedVertexBuffer,vertexStream,sizeof(vertexStream));
vertexBuffer->Unlock();
}
@ -952,6 +953,7 @@ bool CDirect3D::ResetDevice()
DestroyDrawSurface();
if(cgAvailable) {
cgShader->OnLostDevice();
cgD3D9SetDevice(NULL);
}
@ -989,14 +991,7 @@ bool CDirect3D::ResetDevice()
if(cgAvailable) {
cgD3D9SetDevice(pDevice);
}
if(GUI.BilinearFilter) {
pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
} else {
pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
cgShader->OnResetDevice();
}
pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
@ -1111,3 +1106,14 @@ bool CDirect3D::ApplyDisplayChanges(void)
return ChangeRenderSize(0,0);
}
void CDirect3D::SetFiltering()
{
if(GUI.BilinearFilter) {
pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
} else {
pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
}
}

View File

@ -185,6 +185,7 @@
#include <windows.h>
#include "cgFunctions.h"
#include "CD3DCG.h"
#include "render.h"
#include "wsnes9x.h"
@ -195,9 +196,10 @@
typedef struct _VERTEX {
float x, y, z;
float tx, ty;
float lutx, luty;
_VERTEX() {}
_VERTEX(float x,float y,float z,float tx,float ty) {
this->x=x;this->y=y;this->z=z;this->tx=tx;this->ty=ty;
_VERTEX(float x,float y,float z,float tx,float ty,float lutx, float luty) {
this->x=x;this->y=y;this->z=z;this->tx=tx;this->ty=ty;this->lutx=lutx;this->luty=luty;
}
} VERTEX; //our custom vertex with a constuctor for easier assignment
@ -218,15 +220,19 @@ private:
unsigned int quadTextureSize; //size of the texture (only multiples of 2)
bool fullscreen; //are we currently displaying in fullscreen mode
VERTEX triangleStripVertices[4]; //the 4 vertices that make up our display rectangle
VERTEX vertexStream[4]; //the 4 vertices that make up our display rectangle
static const D3DVERTEXELEMENT9 vertexElems[4];
LPDIRECT3DVERTEXDECLARATION9 vertexDeclaration;
LPD3DXEFFECT effect;
LPDIRECT3DTEXTURE9 rubyLUT[MAX_SHADER_TEXTURES];
CGcontext cgContext;
CGprogram cgVertexProgram, cgFragmentProgram;
current_d3d_shader_type shader_type;
bool cgAvailable;
CD3DCG *cgShader;
float shaderTimer;
int shaderTimeStart;
int shaderTimeElapsed;
@ -239,6 +245,7 @@ private:
void SetViewport();
void SetupVertices();
bool ResetDevice();
void SetFiltering();
void SetShaderVars(bool setMatrix = false);
bool SetShader(const TCHAR *file);
bool SetShaderHLSL(const TCHAR *file);

View File

@ -1,3 +1,179 @@
/***********************************************************************************
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
(c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com),
Jerremy Koot (jkoot@snes9x.com)
(c) Copyright 2002 - 2004 Matthew Kendora
(c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org)
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
(c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net)
(c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca),
Kris Bleakley (codeviolation@hotmail.com)
(c) Copyright 2002 - 2010 Brad Jorsch (anomie@users.sourceforge.net),
Nach (n-a-c-h@users.sourceforge.net),
(c) Copyright 2002 - 2011 zones (kasumitokoduck@yahoo.com)
(c) Copyright 2006 - 2007 nitsuja
(c) Copyright 2009 - 2011 BearOso,
OV2
BS-X C emulator code
(c) Copyright 2005 - 2006 Dreamer Nom,
zones
C4 x86 assembler and some C emulation code
(c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com),
Nach,
zsKnight (zsknight@zsnes.com)
C4 C++ code
(c) Copyright 2003 - 2006 Brad Jorsch,
Nach
DSP-1 emulator code
(c) Copyright 1998 - 2006 _Demo_,
Andreas Naive (andreasnaive@gmail.com),
Gary Henderson,
Ivar (ivar@snes9x.com),
John Weidman,
Kris Bleakley,
Matthew Kendora,
Nach,
neviksti (neviksti@hotmail.com)
DSP-2 emulator code
(c) Copyright 2003 John Weidman,
Kris Bleakley,
Lord Nightmare (lord_nightmare@users.sourceforge.net),
Matthew Kendora,
neviksti
DSP-3 emulator code
(c) Copyright 2003 - 2006 John Weidman,
Kris Bleakley,
Lancer,
z80 gaiden
DSP-4 emulator code
(c) Copyright 2004 - 2006 Dreamer Nom,
John Weidman,
Kris Bleakley,
Nach,
z80 gaiden
OBC1 emulator code
(c) Copyright 2001 - 2004 zsKnight,
pagefault (pagefault@zsnes.com),
Kris Bleakley
Ported from x86 assembler to C by sanmaiwashi
SPC7110 and RTC C++ emulator code used in 1.39-1.51
(c) Copyright 2002 Matthew Kendora with research by
zsKnight,
John Weidman,
Dark Force
SPC7110 and RTC C++ emulator code used in 1.52+
(c) Copyright 2009 byuu,
neviksti
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive,
John Weidman
S-RTC C emulator code
(c) Copyright 2001 - 2006 byuu,
John Weidman
ST010 C++ emulator code
(c) Copyright 2003 Feather,
John Weidman,
Kris Bleakley,
Matthew Kendora
Super FX x86 assembler emulator code
(c) Copyright 1998 - 2003 _Demo_,
pagefault,
zsKnight
Super FX C emulator code
(c) Copyright 1997 - 1999 Ivar,
Gary Henderson,
John Weidman
Sound emulator code used in 1.5-1.51
(c) Copyright 1998 - 2003 Brad Martin
(c) Copyright 1998 - 2006 Charles Bilyue'
Sound emulator code used in 1.52+
(c) Copyright 2004 - 2007 Shay Green (gblargg@gmail.com)
SH assembler code partly based on x86 assembler code
(c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
2xSaI filter
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
HQ2x, HQ3x, HQ4x filters
(c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com)
NTSC filter
(c) Copyright 2006 - 2007 Shay Green
GTK+ GUI code
(c) Copyright 2004 - 2011 BearOso
Win32 GUI code
(c) Copyright 2003 - 2006 blip,
funkyass,
Matthew Kendora,
Nach,
nitsuja
(c) Copyright 2009 - 2011 OV2
Mac OS GUI code
(c) Copyright 1998 - 2001 John Stiles
(c) Copyright 2001 - 2011 zones
Specific ports contains the works of other authors. See headers in
individual files.
Snes9x homepage: http://www.snes9x.com/
Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear
with all copies and any derived work.
This software is provided 'as-is', without any express or implied
warranty. In no event shall the authors be held liable for any damages
arising from the use of this software or it's derivatives.
Snes9x is freeware for PERSONAL USE only. Commercial users should
seek permission of the copyright holders first. Commercial use includes,
but is not limited to, charging money for Snes9x or software derived from
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
using Snes9x as a promotion for your commercial product.
The copyright holders request that bug fixes and improvements to the code
should be forwarded to them so everyone can benefit from the modifications
in future versions.
Super NES and Super Nintendo Entertainment System are trademarks of
Nintendo Co., Limited and its subsidiary companies.
***********************************************************************************/
#include "CGLCG.h"
#include "wsnes9x.h"
#include "win32_display.h"
@ -7,7 +183,7 @@
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
float npot(float desired)
static float npot(float desired)
{
float out=512.0;
while(out<desired)
@ -24,7 +200,6 @@ CGLCG::CGLCG(CGcontext cgContext)
ClearPasses();
LoadFBOFunctions();
frameCnt=0;
prevTex=0;
}
CGLCG::~CGLCG(void)
@ -53,8 +228,15 @@ void CGLCG::ClearPasses()
if(it->tex)
glDeleteTextures(1,&it->tex);
}
for(glPrevDeque::iterator it=prevPasses.begin();it!=prevPasses.end();it++) {
if(it->tex)
glDeleteTextures(1,&it->tex);
}
shaderPasses.clear();
lookupTextures.clear();
prevPasses.clear();
// prevPasses deque is always filled with PREV + PREV1-6 elements
prevPasses.resize(7);
shaderLoaded = false;
}
@ -126,11 +308,6 @@ bool CGLCG::LoadShader(const TCHAR *shaderFile)
ClearPasses();
if(prevTex) {
glDeleteTextures(1,&prevTex);
prevTex=0;
}
if (shaderFile == NULL || *shaderFile==TEXT('\0'))
return true;
@ -251,15 +428,16 @@ bool CGLCG::LoadShader(const TCHAR *shaderFile)
glTexCoordPointer(2,GL_FLOAT,0,lut_coords);
glClientActiveTexture(GL_TEXTURE0);
/* generate a texture that we can swap with the original texture
and pass back to the main opengl code
/* generate textures and set default values for the pref-filled PREV deque.
*/
glGenTextures(1,&prevTex);
glBindTexture(GL_TEXTURE_2D,prevTex);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,NULL);
glBindTexture(GL_TEXTURE_2D,0);
prevTexSize.x = prevTexSize.y = prevTexImageSize.x = prevTexImageSize.y = 0;
memset(prevTexCoords,0,sizeof(prevTexCoords));
for(int i=0;i<prevPasses.size();i++) {
glGenTextures(1,&prevPasses[i].tex);
glBindTexture(GL_TEXTURE_2D,prevPasses[i].tex);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,NULL);
glBindTexture(GL_TEXTURE_2D,0);
prevPasses[i].textureSize.x = prevPasses[i].textureSize.y = prevPasses[i].textureSize.x = prevPasses[i].textureSize.y = 0;
memset(prevPasses[i].texCoords,0,sizeof(prevPasses[i].texCoords));
}
shaderLoaded = true;
@ -334,7 +512,7 @@ void CGLCG::Render(GLuint &origTex, xySize textureSize, xySize inputSize, xySize
}
switch(shaderPasses[i].scaleParams.scaleTypeY) {
case CG_SCALE_ABSOLUTE:
shaderPasses[i].outputSize.y = (double)shaderPasses[i].scaleParams.absX;
shaderPasses[i].outputSize.y = (double)shaderPasses[i].scaleParams.absY;
break;
case CG_SCALE_SOURCE:
shaderPasses[i].outputSize.y = shaderPasses[i-1].outputSize.y * shaderPasses[i].scaleParams.scaleY;
@ -387,22 +565,30 @@ void CGLCG::Render(GLuint &origTex, xySize textureSize, xySize inputSize, xySize
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays (GL_QUADS, 0, 4);
/* reset client states enabled during setShaderVars
*/
resetAttribParams();
}
/* disable framebuffer
*/
glBindFramebuffer(GL_FRAMEBUFFER,0);
/* switch original and prev texture and make sure the
new original texture has the same size as the old one
/* set last PREV texture as original, push current texture and
sizes to the front of the PREV deque and make sure the new
original texture has the same size as the old one
*/
origTex = prevTex;
prevTex = shaderPasses[0].tex;
prevTexSize.x = textureSize.x;
prevTexSize.y = textureSize.y;
prevTexImageSize.x = inputSize.x;
prevTexImageSize.y = inputSize.y;
memcpy(prevTexCoords,shaderPasses[1].texcoords,sizeof(prevTexCoords));
origTex = prevPasses.back().tex;
prevPasses.pop_back();
prevPass pass;
pass.videoSize = inputSize;
pass.textureSize = textureSize;
pass.tex = shaderPasses[0].tex;
memcpy(pass.texCoords,shaderPasses[1].texcoords,sizeof(pass.texCoords));
prevPasses.push_front(pass);
glBindTexture(GL_TEXTURE_2D,origTex);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,textureSize.x,textureSize.y,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,NULL);
@ -429,7 +615,8 @@ void CGLCG::setShaderVars(int pass)
/* mvp paramater
*/
CGparameter cgpModelViewProj = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, "modelViewProj");
cgGLSetStateMatrixParameter(cgpModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
if(cgpModelViewProj)
cgGLSetStateMatrixParameter(cgpModelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
#define setProgram2fv(pass,varname,floats)\
{\
@ -466,6 +653,7 @@ void CGLCG::setShaderVars(int pass)
if(cgpv) {\
cgGLSetParameterPointer(cgpv, 2, GL_FLOAT, 0, val);\
cgGLEnableClientState(cgpv);\
cgAttribParams.push_back(cgpv);\
}\
}\
@ -492,13 +680,33 @@ void CGLCG::setShaderVars(int pass)
/* PREV parameter
*/
float prev_videoSize[2] = {prevTexImageSize.x,prevTexImageSize.y};
float prev_textureSize[2] = {prevTexSize.x,prevTexSize.y};
if(prevPasses[0].textureSize.x>0) {
float prev_videoSize[2] = {prevPasses[0].videoSize.x,prevPasses[0].videoSize.y};
float prev_textureSize[2] = {prevPasses[0].textureSize.x,prevPasses[0].textureSize.y};
setProgram2fv(pass,"PREV.video_size",prev_videoSize);
setProgram2fv(pass,"PREV.texture_size",prev_textureSize);
setTextureParameter(pass,"PREV.texture",prevTex);
setTexCoordsParameter(pass,"PREV.tex_coord",prevTexCoords);
setProgram2fv(pass,"PREV.video_size",prev_videoSize);
setProgram2fv(pass,"PREV.texture_size",prev_textureSize);
setTextureParameter(pass,"PREV.texture",prevPasses[0].tex);
setTexCoordsParameter(pass,"PREV.tex_coord",prevPasses[0].texCoords);
}
/* PREV1-6 parameters
*/
for(int i=1;i<prevPasses.size();i++) {
if(prevPasses[i].textureSize.x==0)
break;
char varname[100];
float prev_videoSize[2] = {prevPasses[i].videoSize.x,prevPasses[i].videoSize.y};
float prev_textureSize[2] = {prevPasses[i].textureSize.x,prevPasses[i].textureSize.y};
sprintf(varname,"PREV%d.video_size",i);
setProgram2fv(pass,varname,prev_videoSize);
sprintf(varname,"PREV%d.texture_size",i);
setProgram2fv(pass,varname,prev_textureSize);
sprintf(varname,"PREV%d.texture",i);
setTextureParameter(pass,varname,prevPasses[i].tex);
sprintf(varname,"PREV%d.tex_coord",i);
setTexCoordsParameter(pass,varname,prevPasses[i].texCoords);
}
/* LUT parameters
*/
@ -525,6 +733,13 @@ void CGLCG::setShaderVars(int pass)
}
}
void CGLCG::resetAttribParams()
{
for(int i=0;i<cgAttribParams.size();i++)
cgGLDisableClientState(cgAttribParams[i]);
cgAttribParams.clear();
}
#ifdef HAVE_LIBPNG
bool CGLCG::loadPngImage(const TCHAR *name, int &outWidth, int &outHeight, bool &outHasAlpha, GLubyte **outData) {
png_structp png_ptr;

View File

@ -1,3 +1,179 @@
/***********************************************************************************
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
(c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com),
Jerremy Koot (jkoot@snes9x.com)
(c) Copyright 2002 - 2004 Matthew Kendora
(c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org)
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
(c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net)
(c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca),
Kris Bleakley (codeviolation@hotmail.com)
(c) Copyright 2002 - 2010 Brad Jorsch (anomie@users.sourceforge.net),
Nach (n-a-c-h@users.sourceforge.net),
(c) Copyright 2002 - 2011 zones (kasumitokoduck@yahoo.com)
(c) Copyright 2006 - 2007 nitsuja
(c) Copyright 2009 - 2011 BearOso,
OV2
BS-X C emulator code
(c) Copyright 2005 - 2006 Dreamer Nom,
zones
C4 x86 assembler and some C emulation code
(c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com),
Nach,
zsKnight (zsknight@zsnes.com)
C4 C++ code
(c) Copyright 2003 - 2006 Brad Jorsch,
Nach
DSP-1 emulator code
(c) Copyright 1998 - 2006 _Demo_,
Andreas Naive (andreasnaive@gmail.com),
Gary Henderson,
Ivar (ivar@snes9x.com),
John Weidman,
Kris Bleakley,
Matthew Kendora,
Nach,
neviksti (neviksti@hotmail.com)
DSP-2 emulator code
(c) Copyright 2003 John Weidman,
Kris Bleakley,
Lord Nightmare (lord_nightmare@users.sourceforge.net),
Matthew Kendora,
neviksti
DSP-3 emulator code
(c) Copyright 2003 - 2006 John Weidman,
Kris Bleakley,
Lancer,
z80 gaiden
DSP-4 emulator code
(c) Copyright 2004 - 2006 Dreamer Nom,
John Weidman,
Kris Bleakley,
Nach,
z80 gaiden
OBC1 emulator code
(c) Copyright 2001 - 2004 zsKnight,
pagefault (pagefault@zsnes.com),
Kris Bleakley
Ported from x86 assembler to C by sanmaiwashi
SPC7110 and RTC C++ emulator code used in 1.39-1.51
(c) Copyright 2002 Matthew Kendora with research by
zsKnight,
John Weidman,
Dark Force
SPC7110 and RTC C++ emulator code used in 1.52+
(c) Copyright 2009 byuu,
neviksti
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive,
John Weidman
S-RTC C emulator code
(c) Copyright 2001 - 2006 byuu,
John Weidman
ST010 C++ emulator code
(c) Copyright 2003 Feather,
John Weidman,
Kris Bleakley,
Matthew Kendora
Super FX x86 assembler emulator code
(c) Copyright 1998 - 2003 _Demo_,
pagefault,
zsKnight
Super FX C emulator code
(c) Copyright 1997 - 1999 Ivar,
Gary Henderson,
John Weidman
Sound emulator code used in 1.5-1.51
(c) Copyright 1998 - 2003 Brad Martin
(c) Copyright 1998 - 2006 Charles Bilyue'
Sound emulator code used in 1.52+
(c) Copyright 2004 - 2007 Shay Green (gblargg@gmail.com)
SH assembler code partly based on x86 assembler code
(c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se)
2xSaI filter
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
HQ2x, HQ3x, HQ4x filters
(c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com)
NTSC filter
(c) Copyright 2006 - 2007 Shay Green
GTK+ GUI code
(c) Copyright 2004 - 2011 BearOso
Win32 GUI code
(c) Copyright 2003 - 2006 blip,
funkyass,
Matthew Kendora,
Nach,
nitsuja
(c) Copyright 2009 - 2011 OV2
Mac OS GUI code
(c) Copyright 1998 - 2001 John Stiles
(c) Copyright 2001 - 2011 zones
Specific ports contains the works of other authors. See headers in
individual files.
Snes9x homepage: http://www.snes9x.com/
Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear
with all copies and any derived work.
This software is provided 'as-is', without any express or implied
warranty. In no event shall the authors be held liable for any damages
arising from the use of this software or it's derivatives.
Snes9x is freeware for PERSONAL USE only. Commercial users should
seek permission of the copyright holders first. Commercial use includes,
but is not limited to, charging money for Snes9x or software derived from
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
using Snes9x as a promotion for your commercial product.
The copyright holders request that bug fixes and improvements to the code
should be forwarded to them so everyone can benefit from the modifications
in future versions.
Super NES and Super Nintendo Entertainment System are trademarks of
Nintendo Co., Limited and its subsidiary companies.
***********************************************************************************/
#ifndef CGGLCG_H
#define CGGLCG_H
@ -7,10 +183,12 @@
#include "cgFunctions.h"
#include "CCGShader.h"
#include <vector>
#include <deque>
typedef struct _xySize {
double x;
double y;
operator CONST FLOAT* () const;
} xySize;
class CGLCG
@ -45,6 +223,13 @@ private:
fbo=NULL;
tex=NULL;}
} shaderPass;
typedef struct _prevPass {
GLuint tex;
xySize videoSize;
xySize textureSize;
GLfloat texCoords[8];
_prevPass() {tex=0;}
} prevPass;
typedef struct _lookupTexture {
char id[PATH_MAX];
GLuint tex;
@ -53,8 +238,12 @@ private:
typedef std::vector<shaderPass> glPassVector;
typedef std::vector<lookupTexture> glLutVector;
typedef std::deque<prevPass> glPrevDeque;
typedef std::vector<CGparameter> glAttribParams;
glPassVector shaderPasses;
glLutVector lookupTextures;
glPrevDeque prevPasses;
glAttribParams cgAttribParams;
bool fboFunctionsLoaded;
bool shaderLoaded;
@ -62,16 +251,13 @@ private:
void checkForCgError(const char *situation);
void setTexCoords(int pass,xySize inputSize,xySize textureSize,bool topdown=false);
void setShaderVars(int pass);
void resetAttribParams();
bool loadPngImage(const TCHAR *name, int &outWidth, int &outHeight, bool &outHasAlpha, GLubyte **outData);
bool loadTGA(const TCHAR *filename, STGA& tgaFile);
CGcontext cgContext;
int frameCnt;
static const GLfloat lut_coords[8];
GLuint prevTex;
xySize prevTexSize;
xySize prevTexImageSize;
GLfloat prevTexCoords[8];
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;

View File

@ -192,6 +192,16 @@ CGGES cgGetErrorString = NULL;
CGGLL cgGetLastListing = NULL;
CGCP cgCreateProgram = NULL;
CGDP cgDestroyProgram = NULL;
CGGPRI cgGetParameterResourceIndex = NULL;
CGGFP cgGetFirstParameter = NULL;
CGGNEP cgGetNextParameter = NULL;
CGGPD cgGetParameterDirection = NULL;
CGGPS cgGetParameterSemantic = NULL;
CGGRS cgGetResourceString = NULL;
CGGPV cgGetParameterVariability = NULL;
CGGPT cgGetParameterType = NULL;
CGGFSP cgGetFirstStructParameter = NULL;
CGGPN cgGetParameterName = NULL;
//cgD3D9.dll
CGD3DSD cgD3D9SetDevice = NULL;
CGD3DBP cgD3D9BindProgram = NULL;
@ -201,6 +211,9 @@ CGD3DGOO cgD3D9GetOptimalOptions = NULL;
CGD3DLP cgD3D9LoadProgram = NULL;
CGD3DSUM cgD3D9SetUniformMatrix = NULL;
CGD3DSU cgD3D9SetUniform = NULL;
CGD3DST cgD3D9SetTexture = NULL;
CGD3DGVD cgD3D9GetVertexDeclaration = NULL;
CGD3DSSS cgD3D9SetSamplerState = NULL;
//cggl.dll
CGGLSSMP cgGLSetStateMatrixParameter = NULL;
CGGLSP2FV cgGLSetParameter2fv = NULL;
@ -215,6 +228,7 @@ CGGLSTP cgGLSetTextureParameter = NULL;
CGGLETP cgGLEnableTextureParameter = NULL;
CGGLSPP cgGLSetParameterPointer = NULL;
CGGLECS cgGLEnableClientState = NULL;
CGGLDCS cgGLDisableClientState = NULL;
bool loadCgFunctions()
{
@ -241,6 +255,16 @@ bool loadCgFunctions()
cgGetLastListing = (CGGLL)GetProcAddress(hCgDll,"cgGetLastListing");
cgCreateProgram = (CGCP)GetProcAddress(hCgDll,"cgCreateProgram");
cgDestroyProgram = (CGDP)GetProcAddress(hCgDll,"cgDestroyProgram");
cgGetParameterResourceIndex = (CGGPRI)GetProcAddress(hCgDll,"cgGetParameterResourceIndex");
cgGetFirstParameter = (CGGFP)GetProcAddress(hCgDll,"cgGetFirstParameter");
cgGetNextParameter = (CGGNEP)GetProcAddress(hCgDll,"cgGetNextParameter");
cgGetParameterDirection = (CGGPD)GetProcAddress(hCgDll,"cgGetParameterDirection");
cgGetParameterSemantic = (CGGPS)GetProcAddress(hCgDll,"cgGetParameterSemantic");
cgGetResourceString = (CGGRS)GetProcAddress(hCgDll,"cgGetResourceString");
cgGetParameterVariability = (CGGPV)GetProcAddress(hCgDll,"cgGetParameterVariability");
cgGetParameterType = (CGGPT)GetProcAddress(hCgDll,"cgGetParameterType");
cgGetFirstStructParameter = (CGGFSP)GetProcAddress(hCgDll,"cgGetFirstStructParameter");
cgGetParameterName = (CGGPN)GetProcAddress(hCgDll,"cgGetParameterName");
//cgD3D9.dll
cgD3D9SetDevice = (CGD3DSD)GetProcAddress(hCgD3D9Dll,"cgD3D9SetDevice");
cgD3D9BindProgram = (CGD3DBP)GetProcAddress(hCgD3D9Dll,"cgD3D9BindProgram");
@ -250,6 +274,9 @@ bool loadCgFunctions()
cgD3D9LoadProgram = (CGD3DLP)GetProcAddress(hCgD3D9Dll,"cgD3D9LoadProgram");
cgD3D9SetUniformMatrix = (CGD3DSUM)GetProcAddress(hCgD3D9Dll,"cgD3D9SetUniformMatrix");
cgD3D9SetUniform = (CGD3DSU)GetProcAddress(hCgD3D9Dll,"cgD3D9SetUniform");
cgD3D9SetTexture = (CGD3DST)GetProcAddress(hCgD3D9Dll,"cgD3D9SetTexture");
cgD3D9GetVertexDeclaration = (CGD3DGVD)GetProcAddress(hCgD3D9Dll,"cgD3D9GetVertexDeclaration");
cgD3D9SetSamplerState = (CGD3DSSS)GetProcAddress(hCgD3D9Dll,"cgD3D9SetSamplerState");
//cggl.dll
cgGLSetStateMatrixParameter = (CGGLSSMP)GetProcAddress(hCgGLDll,"cgGLSetStateMatrixParameter");
cgGLSetParameter2fv = (CGGLSP2FV)GetProcAddress(hCgGLDll,"cgGLSetParameter2fv");
@ -264,6 +291,7 @@ bool loadCgFunctions()
cgGLEnableTextureParameter = (CGGLETP)GetProcAddress(hCgGLDll,"cgGLEnableTextureParameter");
cgGLSetParameterPointer = (CGGLSPP)GetProcAddress(hCgGLDll,"cgGLSetParameterPointer");
cgGLEnableClientState = (CGGLECS)GetProcAddress(hCgGLDll,"cgGLEnableClientState");
cgGLDisableClientState = (CGGLDCS)GetProcAddress(hCgGLDll,"cgGLDisableClientState");
if(
//cg.dll
@ -275,6 +303,16 @@ bool loadCgFunctions()
!cgGetLastListing ||
!cgCreateProgram ||
!cgDestroyProgram ||
!cgGetParameterResourceIndex ||
!cgGetFirstParameter ||
!cgGetNextParameter ||
!cgGetParameterDirection ||
!cgGetParameterSemantic ||
!cgGetResourceString ||
!cgGetParameterVariability ||
!cgGetParameterType ||
!cgGetFirstStructParameter ||
!cgGetParameterName ||
//cgD3D9.dll
!cgD3D9SetDevice ||
!cgD3D9BindProgram ||
@ -284,6 +322,9 @@ bool loadCgFunctions()
!cgD3D9LoadProgram ||
!cgD3D9SetUniformMatrix ||
!cgD3D9SetUniform ||
!cgD3D9SetTexture ||
!cgD3D9GetVertexDeclaration ||
!cgD3D9SetSamplerState ||
//cggl.dll
!cgGLSetStateMatrixParameter ||
!cgGLSetParameter2fv ||
@ -297,7 +338,8 @@ bool loadCgFunctions()
!cgGLSetTextureParameter ||
!cgGLEnableTextureParameter ||
!cgGLSetParameterPointer ||
!cgGLEnableClientState) {
!cgGLEnableClientState ||
!cgGLDisableClientState) {
unloadCgLibrary();
return false;
}
@ -325,6 +367,16 @@ void unloadCgLibrary()
cgGetLastListing = NULL;
cgCreateProgram = NULL;
cgDestroyProgram = NULL;
cgGetParameterResourceIndex = NULL;
cgGetFirstParameter = NULL;
cgGetNextParameter = NULL;
cgGetParameterDirection = NULL;
cgGetParameterSemantic = NULL;
cgGetResourceString = NULL;
cgGetParameterVariability = NULL;
cgGetParameterType = NULL;
cgGetFirstStructParameter = NULL;
cgGetParameterName = NULL;
//cgD3D9.dll
cgD3D9SetDevice = NULL;
cgD3D9BindProgram = NULL;
@ -334,6 +386,9 @@ void unloadCgLibrary()
cgD3D9LoadProgram = NULL;
cgD3D9SetUniformMatrix = NULL;
cgD3D9SetUniform = NULL;
cgD3D9SetTexture = NULL;
cgD3D9GetVertexDeclaration = NULL;
cgD3D9SetSamplerState = NULL;
//cggl.dll
cgGLSetStateMatrixParameter = NULL;
cgGLSetParameter2fv = NULL;
@ -343,4 +398,6 @@ void unloadCgLibrary()
cgGLSetOptimalOptions = NULL;
cgGLLoadProgram = NULL;
cgGLBindProgram = NULL;
cgGLEnableClientState = NULL;
cgGLDisableClientState = NULL;
}

View File

@ -205,6 +205,26 @@ typedef CG_API CGprogram (CGENTRY *CGCP)(CGcontext context, CGenum program_type,
extern CGCP cgCreateProgram;
typedef CG_API void (CGENTRY *CGDP)(CGprogram program);
extern CGDP cgDestroyProgram;
typedef CG_API unsigned long (CGENTRY *CGGPRI)(CGparameter param);
extern CGGPRI cgGetParameterResourceIndex;
typedef CG_API CGparameter (CGENTRY *CGGFP)(CGprogram program, CGenum name_space);
extern CGGFP cgGetFirstParameter;
typedef CG_API CGparameter (CGENTRY *CGGNEP)(CGparameter current);
extern CGGNEP cgGetNextParameter;
typedef CG_API CGenum (CGENTRY *CGGPD)(CGparameter param);
extern CGGPD cgGetParameterDirection;
typedef CG_API const char * (CGENTRY *CGGPS)(CGparameter param);
extern CGGPS cgGetParameterSemantic;
typedef CG_API const char * (CGENTRY *CGGRS)(CGresource resource);
extern CGGRS cgGetResourceString;
typedef CG_API CGenum (CGENTRY *CGGPV)(CGparameter param);
extern CGGPV cgGetParameterVariability;
typedef CG_API CGtype (CGENTRY *CGGPT)(CGparameter param);
extern CGGPT cgGetParameterType;
typedef CG_API CGparameter (CGENTRY *CGGFSP)(CGparameter param);
extern CGGFSP cgGetFirstStructParameter;
typedef CG_API const char * (CGENTRY *CGGPN)(CGparameter param);
extern CGGPN cgGetParameterName;
//cgD3D9.dll
typedef CGD3D9DLL_API HRESULT (CGD3D9ENTRY *CGD3DSD)(IDirect3DDevice9 *pDevice);
@ -223,6 +243,12 @@ typedef CGD3D9DLL_API HRESULT (CGD3D9ENTRY *CGD3DSUM)(CGparameter param, const D
extern CGD3DSUM cgD3D9SetUniformMatrix;
typedef CGD3D9DLL_API HRESULT (CGD3D9ENTRY *CGD3DSU)(CGparameter param, const void *floats);
extern CGD3DSU cgD3D9SetUniform;
typedef CGD3D9DLL_API HRESULT (CGD3D9ENTRY *CGD3DST)(CGparameter param, IDirect3DBaseTexture9 *tex);
extern CGD3DST cgD3D9SetTexture;
typedef CGD3D9DLL_API CGbool (CGD3D9ENTRY *CGD3DGVD)(CGprogram prog, D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH]);
extern CGD3DGVD cgD3D9GetVertexDeclaration;
typedef CGD3D9DLL_API HRESULT (CGD3D9ENTRY *CGD3DSSS)(CGparameter param, D3DSAMPLERSTATETYPE type, DWORD value);
extern CGD3DSSS cgD3D9SetSamplerState;
//cggl.dll
typedef CGGL_API void (CGGLENTRY *CGGLSSMP)(CGparameter param, CGGLenum matrix, CGGLenum transform);
@ -251,7 +277,8 @@ typedef CGGL_API void (CGGLENTRY *CGGLSPP)(CGparameter param, GLint fsize, GLenu
extern CGGLSPP cgGLSetParameterPointer;
typedef CGGL_API void (CGGLENTRY *CGGLECS)(CGparameter param);
extern CGGLECS cgGLEnableClientState;
typedef CGGL_API void (CGGLENTRY *CGGLDCS)(CGparameter param);
extern CGGLDCS cgGLDisableClientState;
//cgfunctions.cpp
bool loadCgFunctions();

View File

@ -3137,6 +3137,14 @@
RelativePath=".\CCGShader.h"
>
</File>
<File
RelativePath=".\CD3DCG.cpp"
>
</File>
<File
RelativePath=".\CD3DCG.h"
>
</File>
<File
RelativePath=".\CDirect3D.cpp"
>