win32: Remove need for DirectXMath.

It only compiles with VC.
This commit is contained in:
BearOso 2023-02-28 17:11:55 -06:00
parent 6ae1a4478e
commit a6560f70b5
5 changed files with 72 additions and 38 deletions

3
.gitmodules vendored
View File

@ -4,9 +4,6 @@
[submodule "win32/zlib/src"] [submodule "win32/zlib/src"]
path = win32/zlib/src path = win32/zlib/src
url = https://github.com/madler/zlib.git url = https://github.com/madler/zlib.git
[submodule "win32/DirectXMath"]
path = win32/DirectXMath
url = https://github.com/Microsoft/DirectXMath
[submodule "shaders/SPIRV-Cross"] [submodule "shaders/SPIRV-Cross"]
path = external/SPIRV-Cross path = external/SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross.git url = https://github.com/KhronosGroup/SPIRV-Cross.git

View File

@ -233,8 +233,8 @@ bool CD3DCG::LoadShader(const TCHAR *shaderFile)
return true; return true;
} }
void CD3DCG::ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, XMFLOAT2 &texSize, void CD3DCG::ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, float2 &texSize,
XMFLOAT2 wantedSize,bool renderTarget,bool useFloat) float2 wantedSize,bool renderTarget,bool useFloat)
{ {
HRESULT hr; HRESULT hr;
@ -261,7 +261,7 @@ void CD3DCG::ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, XMFLOAT2 &texSize,
} }
void CD3DCG::setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer, void CD3DCG::setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer,
XMFLOAT2 inputSize, XMFLOAT2 textureSize, XMFLOAT2 outputSize) float2 inputSize, float2 textureSize, float2 outputSize)
{ {
float tX = inputSize.x / textureSize.x; float tX = inputSize.x / textureSize.x;
float tY = inputSize.y / textureSize.y; float tY = inputSize.y / textureSize.y;
@ -302,8 +302,8 @@ void CD3DCG::setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer,
pDevice->SetStreamSource(3,vertexBuffer,0,sizeof(VERTEX)); pDevice->SetStreamSource(3,vertexBuffer,0,sizeof(VERTEX));
} }
void CD3DCG::Render(LPDIRECT3DTEXTURE9 &origTex, XMFLOAT2 textureSize, void CD3DCG::Render(LPDIRECT3DTEXTURE9 &origTex, float2 textureSize,
XMFLOAT2 inputSize, XMFLOAT2 viewportSize, XMFLOAT2 windowSize) float2 inputSize, float2 viewportSize, float2 windowSize)
{ {
LPDIRECT3DSURFACE9 pRenderSurface = NULL,pBackBuffer = NULL; LPDIRECT3DSURFACE9 pRenderSurface = NULL,pBackBuffer = NULL;
frameCnt++; frameCnt++;
@ -355,7 +355,7 @@ void CD3DCG::Render(LPDIRECT3DTEXTURE9 &origTex, XMFLOAT2 textureSize,
/* make sure the render target exists and has an appropriate size, /* make sure the render target exists and has an appropriate size,
then set as current render target with last pass as source then set as current render target with last pass as source
*/ */
ensureTextureSize(shaderPasses[i].tex,shaderPasses[i].textureSize, XMFLOAT2(texSize,texSize),true,shaderPasses[i].useFloatTex); ensureTextureSize(shaderPasses[i].tex, shaderPasses[i].textureSize, float2{ texSize,texSize }, true, shaderPasses[i].useFloatTex);
shaderPasses[i].tex->GetSurfaceLevel(0,&pRenderSurface); shaderPasses[i].tex->GetSurfaceLevel(0,&pRenderSurface);
pDevice->SetTexture(0, shaderPasses[i-1].tex); pDevice->SetTexture(0, shaderPasses[i-1].tex);
pDevice->SetRenderTarget(0,pRenderSurface); pDevice->SetRenderTarget(0,pRenderSurface);
@ -425,22 +425,50 @@ void CD3DCG::Render(LPDIRECT3DTEXTURE9 &origTex, XMFLOAT2 textureSize,
setViewport(displayRect.left,displayRect.top,displayRect.right - displayRect.left,displayRect.bottom - displayRect.top); setViewport(displayRect.left,displayRect.top,displayRect.right - displayRect.left,displayRect.bottom - displayRect.top);
setVertexStream(shaderPasses.back().vertexBuffer, setVertexStream(shaderPasses.back().vertexBuffer,
shaderPasses.back().outputSize,shaderPasses.back().textureSize, shaderPasses.back().outputSize,shaderPasses.back().textureSize,
XMFLOAT2((float)(displayRect.right - displayRect.left),(float)(displayRect.bottom - displayRect.top))); float2{ (float)(displayRect.right - displayRect.left),(float)(displayRect.bottom - displayRect.top) });
pDevice->SetVertexShader(NULL); pDevice->SetVertexShader(NULL);
pDevice->SetPixelShader(NULL); pDevice->SetPixelShader(NULL);
} }
static D3DMATRIX matrix_mul(D3DMATRIX& mat1, D3DMATRIX& mat2)
{
D3DMATRIX out;
for (auto y = 0; y < 4; y++)
{
for (auto x = 0; x < 4; x++)
{
out.m[y][x] =
mat1.m[y][0] * mat2.m[0][x] +
mat1.m[y][1] * mat2.m[1][x] +
mat1.m[y][2] * mat2.m[2][x] +
mat1.m[y][3] * mat2.m[3][x];
}
}
return out;
}
static D3DMATRIX matrix_transpose(D3DMATRIX& mat)
{
D3DMATRIX out;
for (auto y = 0; y < 4; y++)
for (auto x = 0; x < 4; x++)
out.m[y][x] = mat.m[x][y];
return out;
}
void CD3DCG::calculateMatrix() void CD3DCG::calculateMatrix()
{ {
XMMATRIX matWorld; D3DMATRIX matWorld;
XMMATRIX matView; D3DMATRIX matView;
XMMATRIX matProj; D3DMATRIX matProj;
pDevice->GetTransform(D3DTS_WORLD, (D3DMATRIX*)&matWorld); pDevice->GetTransform(D3DTS_WORLD, (D3DMATRIX*)&matWorld);
pDevice->GetTransform(D3DTS_VIEW, (D3DMATRIX*)&matView); pDevice->GetTransform(D3DTS_VIEW, (D3DMATRIX*)&matView);
pDevice->GetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&matProj); pDevice->GetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&matProj);
XMStoreFloat4x4(&mvp, XMMatrixTranspose(XMMatrixMultiply(matProj, XMMatrixMultiply(matWorld, matView)))); mvp = matrix_transpose(matrix_mul(matProj, matrix_mul(matWorld, matView)));
} }
void CD3DCG::setViewport(DWORD x, DWORD y, DWORD width, DWORD height) void CD3DCG::setViewport(DWORD x, DWORD y, DWORD width, DWORD height)
@ -457,9 +485,9 @@ void CD3DCG::setViewport(DWORD x, DWORD y, DWORD width, DWORD height)
void CD3DCG::setShaderVars(int pass) void CD3DCG::setShaderVars(int pass)
{ {
XMFLOAT2 inputSize = shaderPasses[pass-1].outputSize; float2 inputSize = shaderPasses[pass-1].outputSize;
XMFLOAT2 textureSize = shaderPasses[pass-1].textureSize; float2 textureSize = shaderPasses[pass-1].textureSize;
XMFLOAT2 outputSize = shaderPasses[pass].outputSize; float2 outputSize = shaderPasses[pass].outputSize;
/* mvp paramater /* mvp paramater
*/ */

View File

@ -13,10 +13,13 @@
#include "CCGShader.h" #include "CCGShader.h"
#include <vector> #include <vector>
#include <deque> #include <deque>
#undef Zero // DirectXMath uses Zero as a variable name #include <array>
#include "DirectXMath/Inc/DirectXMath.h"
using namespace DirectX; struct float2
{
float x;
float y;
};
class CD3DCG class CD3DCG
{ {
@ -38,8 +41,8 @@ private:
LPDIRECT3DVERTEXDECLARATION9 vertexDeclaration; LPDIRECT3DVERTEXDECLARATION9 vertexDeclaration;
std::vector<parameterEntry> parameterMap; std::vector<parameterEntry> parameterMap;
XMFLOAT2 outputSize; float2 outputSize;
XMFLOAT2 textureSize; float2 textureSize;
_shaderPass() {cgVertexProgram=NULL; _shaderPass() {cgVertexProgram=NULL;
cgFragmentProgram=NULL; cgFragmentProgram=NULL;
@ -50,8 +53,8 @@ private:
typedef struct _prevPass { typedef struct _prevPass {
LPDIRECT3DTEXTURE9 tex; LPDIRECT3DTEXTURE9 tex;
LPDIRECT3DVERTEXBUFFER9 vertexBuffer; LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
XMFLOAT2 imageSize; float2 imageSize;
XMFLOAT2 textureSize; float2 textureSize;
_prevPass() {tex=NULL; _prevPass() {tex=NULL;
vertexBuffer=NULL;} vertexBuffer=NULL;}
_prevPass(const shaderPass &pass) {tex = pass.tex; _prevPass(const shaderPass &pass) {tex = pass.tex;
@ -72,10 +75,10 @@ private:
bool shaderLoaded; bool shaderLoaded;
void checkForCgError(const char *situation); void checkForCgError(const char *situation);
void setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer, XMFLOAT2 inputSize, XMFLOAT2 textureSize, XMFLOAT2 outputSize); void setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer, float2 inputSize, float2 textureSize, float2 outputSize);
void setViewport(DWORD x, DWORD y, DWORD width, DWORD height); void setViewport(DWORD x, DWORD y, DWORD width, DWORD height);
void setShaderVars(int pass); void setShaderVars(int pass);
void ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, XMFLOAT2 &texSize, XMFLOAT2 wantedSize,bool renderTarget, bool useFloat = false); void ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, float2 &texSize, float2 wantedSize,bool renderTarget, bool useFloat = false);
void fillParameterMap(std::vector<parameterEntry> &map, CGparameter param); void fillParameterMap(std::vector<parameterEntry> &map, CGparameter param);
void setupVertexDeclaration(shaderPass &pass); void setupVertexDeclaration(shaderPass &pass);
void calculateMatrix(); void calculateMatrix();
@ -83,14 +86,14 @@ private:
LPDIRECT3DDEVICE9 pDevice; LPDIRECT3DDEVICE9 pDevice;
CGcontext cgContext; CGcontext cgContext;
unsigned int frameCnt; unsigned int frameCnt;
XMFLOAT4X4 mvp; D3DMATRIX mvp;
public: public:
CD3DCG(CGcontext cgContext,LPDIRECT3DDEVICE9 pDevice); CD3DCG(CGcontext cgContext,LPDIRECT3DDEVICE9 pDevice);
~CD3DCG(void); ~CD3DCG(void);
bool LoadShader(const TCHAR *shaderFile); bool LoadShader(const TCHAR *shaderFile);
void Render(LPDIRECT3DTEXTURE9 &origTex, XMFLOAT2 textureSize, XMFLOAT2 inputSize, XMFLOAT2 viewportSize, XMFLOAT2 windowSize); void Render(LPDIRECT3DTEXTURE9 &origTex, float2 textureSize, float2 inputSize, float2 viewportSize, float2 windowSize);
void ClearPasses(); void ClearPasses();
void OnLostDevice(); void OnLostDevice();
void OnResetDevice(); void OnResetDevice();

View File

@ -319,11 +319,10 @@ void CDirect3D::Render(SSurface Src)
displayRect=CalculateDisplayRect(dPresentParams.BackBufferWidth,dPresentParams.BackBufferHeight, displayRect=CalculateDisplayRect(dPresentParams.BackBufferWidth,dPresentParams.BackBufferHeight,
dPresentParams.BackBufferWidth,dPresentParams.BackBufferHeight); dPresentParams.BackBufferWidth,dPresentParams.BackBufferHeight);
cgShader->Render(drawSurface, cgShader->Render(drawSurface,
XMFLOAT2((float)quadTextureSize, (float)quadTextureSize), float2{ (float)quadTextureSize, (float)quadTextureSize },
XMFLOAT2((float)afterRenderWidth, (float)afterRenderHeight), float2{ (float)afterRenderWidth, (float)afterRenderHeight },
XMFLOAT2((float)(displayRect.right - displayRect.left), float2{ (float)(displayRect.right - displayRect.left), (float)(displayRect.bottom - displayRect.top) },
(float)(displayRect.bottom - displayRect.top)), float2{ (float)dPresentParams.BackBufferWidth, (float)dPresentParams.BackBufferHeight });
XMFLOAT2((float)dPresentParams.BackBufferWidth, (float)dPresentParams.BackBufferHeight));
} }
SetFiltering(); SetFiltering();
@ -469,11 +468,19 @@ void CDirect3D::SetupVertices()
void CDirect3D::SetViewport() void CDirect3D::SetViewport()
{ {
XMMATRIX matIdentity; D3DMATRIX matIdentity;
XMMATRIX matProjection; D3DMATRIX matProjection;
matIdentity = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
matProjection = { 2.0f, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f, 0.0f, 0.0f,
0.0f, 0.0f, -1.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 1.0f };
matProjection = XMMatrixOrthographicOffCenterLH(0.0f,1.0f,0.0f,1.0f,0.0f,1.0f);
matIdentity = XMMatrixIdentity();
pDevice->SetTransform(D3DTS_WORLD,(D3DMATRIX*)&matIdentity); pDevice->SetTransform(D3DTS_WORLD,(D3DMATRIX*)&matIdentity);
pDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&matIdentity); pDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&matIdentity);
pDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&matProjection); pDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&matProjection);

@ -1 +0,0 @@
Subproject commit ffb2edbd1627e9eec75f68b4ff00e0861ad84ebe