2018-11-15 23:31:39 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
2011-12-10 14:21:37 +00:00
|
|
|
|
|
|
|
#ifndef CGD3DCG_H
|
|
|
|
#define CGD3DCG_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <d3d9.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include "CCGShader.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <deque>
|
2023-02-28 23:11:55 +00:00
|
|
|
#include <array>
|
2018-08-06 23:16:41 +00:00
|
|
|
|
2023-02-28 23:11:55 +00:00
|
|
|
struct float2
|
|
|
|
{
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
};
|
2011-12-10 14:21:37 +00:00
|
|
|
|
|
|
|
class CD3DCG
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef struct _parameterEntry {
|
|
|
|
unsigned long rIndex;
|
|
|
|
const char* semantic;
|
|
|
|
bool isKnownParam;
|
|
|
|
UINT streamNumber;
|
|
|
|
} parameterEntry;
|
|
|
|
typedef struct _shaderPass {
|
|
|
|
cgScaleParams scaleParams;
|
|
|
|
bool linearFilter;
|
2013-03-26 15:09:01 +00:00
|
|
|
bool useFloatTex;
|
2013-03-26 14:39:17 +00:00
|
|
|
unsigned int frameCounterMod;
|
2011-12-10 14:21:37 +00:00
|
|
|
CGprogram cgVertexProgram, cgFragmentProgram;
|
|
|
|
LPDIRECT3DTEXTURE9 tex;
|
|
|
|
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
|
|
|
|
LPDIRECT3DVERTEXDECLARATION9 vertexDeclaration;
|
|
|
|
std::vector<parameterEntry> parameterMap;
|
|
|
|
|
2023-02-28 23:11:55 +00:00
|
|
|
float2 outputSize;
|
|
|
|
float2 textureSize;
|
2011-12-10 14:21:37 +00:00
|
|
|
|
|
|
|
_shaderPass() {cgVertexProgram=NULL;
|
|
|
|
cgFragmentProgram=NULL;
|
|
|
|
tex=NULL;
|
|
|
|
vertexBuffer=NULL;
|
|
|
|
vertexDeclaration=NULL;}
|
|
|
|
} shaderPass;
|
|
|
|
typedef struct _prevPass {
|
|
|
|
LPDIRECT3DTEXTURE9 tex;
|
|
|
|
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
|
2023-02-28 23:11:55 +00:00
|
|
|
float2 imageSize;
|
|
|
|
float2 textureSize;
|
2011-12-10 14:21:37 +00:00
|
|
|
_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);
|
2023-02-28 23:11:55 +00:00
|
|
|
void setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer, float2 inputSize, float2 textureSize, float2 outputSize);
|
2011-12-10 14:21:37 +00:00
|
|
|
void setViewport(DWORD x, DWORD y, DWORD width, DWORD height);
|
|
|
|
void setShaderVars(int pass);
|
2023-02-28 23:11:55 +00:00
|
|
|
void ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, float2 &texSize, float2 wantedSize,bool renderTarget, bool useFloat = false);
|
2011-12-10 14:21:37 +00:00
|
|
|
void fillParameterMap(std::vector<parameterEntry> &map, CGparameter param);
|
|
|
|
void setupVertexDeclaration(shaderPass &pass);
|
|
|
|
void calculateMatrix();
|
|
|
|
|
|
|
|
LPDIRECT3DDEVICE9 pDevice;
|
|
|
|
CGcontext cgContext;
|
2013-03-26 14:39:17 +00:00
|
|
|
unsigned int frameCnt;
|
2023-02-28 23:11:55 +00:00
|
|
|
D3DMATRIX mvp;
|
2011-12-10 14:21:37 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CD3DCG(CGcontext cgContext,LPDIRECT3DDEVICE9 pDevice);
|
|
|
|
~CD3DCG(void);
|
|
|
|
|
|
|
|
bool LoadShader(const TCHAR *shaderFile);
|
2023-02-28 23:11:55 +00:00
|
|
|
void Render(LPDIRECT3DTEXTURE9 &origTex, float2 textureSize, float2 inputSize, float2 viewportSize, float2 windowSize);
|
2011-12-10 14:21:37 +00:00
|
|
|
void ClearPasses();
|
|
|
|
void OnLostDevice();
|
|
|
|
void OnResetDevice();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|