Makefile: use GCC/mingw by default

This commit is contained in:
Zack Buhman 2026-01-13 11:29:03 -06:00
parent 2a46f6e550
commit 12e04e1f40
21 changed files with 3904 additions and 3817 deletions

View File

@ -1,10 +1,29 @@
BUILD_TYPE ?= debug BUILD_TYPE ?= debug
all: $(BUILD_TYPE)/d3d10.exe PREFIX = i686-w64-mingw32-
$(BUILD_TYPE)/d3d10.exe WINDRES = $(PREFIX)windres
CXX = $(PREFIX)g++
OPT = -g -Og
CXXSTD += -std=gnu++14
CFLAGS += -Wall -Werror -Wfatal-errors
CFLAGS += -Wno-unused-but-set-variable
CXXFLAGS += -fno-exceptions
CFLAGS += -municode
WOPT += -municode
FXC ?= C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Utilities/bin/x86/fxc.exe
INCLUDE = \
-I./include
%.fxo: %.fx %.fxo: %.fx
fxc.exe @"shader_$(BUILD_TYPE).rsp" /T fx_4_0 /nologo /Fo $@ $< @echo fxc.exe @"shader_$(BUILD_TYPE).rsp" /T fx_4_0 /nologo /Fo $@ $<
@wine "$(FXC)" @"shader_$(BUILD_TYPE).rsp" /T fx_4_0 /nologo /Fo $@ $<
SHADERS = \ SHADERS = \
main.fxo \ main.fxo \
@ -14,10 +33,10 @@ SHADERS = \
static.fxo static.fxo
$(BUILD_TYPE)/%.res: %.rc $(SHADERS) $(BUILD_TYPE)/%.res: %.rc $(SHADERS)
rc.exe /d "_UNICODE" /d "UNICODE" /fo $@ $< $(WINDRES) -O coff -o $@ $<
$(BUILD_TYPE)/%.obj: src/%.cpp $(BUILD_TYPE)/%.obj: src/%.cpp
cl.exe /Fo"$@" /Fd"$(BUILD_TYPE)\vc80.pdb" @"compile_$(BUILD_TYPE).rsp" $< $(CXX) $(CXXSTD) $(CFLAGS) $(CXXFLAGS) $(WOPT) $(OPT) -o $@ $(INCLUDE) -c $<
OBJS = \ OBJS = \
$(BUILD_TYPE)/robot_player.obj \ $(BUILD_TYPE)/robot_player.obj \
@ -28,5 +47,4 @@ OBJS = \
$(BUILD_TYPE)/main.res $(BUILD_TYPE)/main.res
$(BUILD_TYPE)/d3d10.exe: $(OBJS) $(BUILD_TYPE)/d3d10.exe: $(OBJS)
link.exe /OUT:"$(BUILD_TYPE)\d3d10.exe" /PDB:"$(BUILD_TYPE)\d3d10.pdb" @"link_$(BUILD_TYPE).rsp" $(OBJS) /NOLOGO /ERRORREPORT:PROMPT $(CXX) $(LDFLAGS) $(WOPT) -o $@ $(OBJS) -ld3dx10 -ld3d10
mt.exe -manifest d3d10.exe.${BUILD_TYPE}.manifest -outputresource:$(BUILD_TYPE)\d3d10.exe;1 -nologo

View File

@ -1,37 +0,0 @@
BUILD_TYPE ?= debug
PREFIX = i686-w64-mingw32-
WINDRES = $(PREFIX)windres
CXX = $(PREFIX)g++
FXC = C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Utilities/bin/x86/fxc.exe
INCLUDE = \
-I./include
%.fxo: %.fx
wine "$(FXC)" @"shader_$(BUILD_TYPE).rsp" /T fx_4_0 /nologo /Fo $@ $<
SHADERS = \
main.fxo \
font.fxo \
volume.fxo \
bloom.fxo \
static.fxo
$(BUILD_TYPE)/%.res: %.rc $(SHADERS)
$(WINDRES) -O coff -o $@ $<
$(BUILD_TYPE)/%.obj: src/%.cpp
$(CXX) -municode -o $@ $(INCLUDE) -c $<
OBJS = \
$(BUILD_TYPE)/robot_player.obj \
$(BUILD_TYPE)/cube.obj \
$(BUILD_TYPE)/main.obj \
$(BUILD_TYPE)/print.obj \
$(BUILD_TYPE)/render_state.obj \
$(BUILD_TYPE)/main.res
$(BUILD_TYPE)/d3d10.exe: $(OBJS)
$(CXX) -municode -o $@ $(OBJS) -ld3dx10 -ld3d10

32
Makefile_msvc Normal file
View File

@ -0,0 +1,32 @@
BUILD_TYPE ?= debug
all: $(BUILD_TYPE)/d3d10.exe
$(BUILD_TYPE)/d3d10.exe
%.fxo: %.fx
fxc.exe @"shader_$(BUILD_TYPE).rsp" /T fx_4_0 /nologo /Fo $@ $<
SHADERS = \
main.fxo \
font.fxo \
volume.fxo \
bloom.fxo \
static.fxo
$(BUILD_TYPE)/%.res: %.rc $(SHADERS)
rc.exe /d "_UNICODE" /d "UNICODE" /fo $@ $<
$(BUILD_TYPE)/%.obj: src/%.cpp
cl.exe /Fo"$@" /Fd"$(BUILD_TYPE)\vc80.pdb" @"compile_$(BUILD_TYPE).rsp" $<
OBJS = \
$(BUILD_TYPE)/robot_player.obj \
$(BUILD_TYPE)/cube.obj \
$(BUILD_TYPE)/main.obj \
$(BUILD_TYPE)/print.obj \
$(BUILD_TYPE)/render_state.obj \
$(BUILD_TYPE)/main.res
$(BUILD_TYPE)/d3d10.exe: $(OBJS)
link.exe /OUT:"$(BUILD_TYPE)\d3d10.exe" /PDB:"$(BUILD_TYPE)\d3d10.pdb" @"link_$(BUILD_TYPE).rsp" $(OBJS) /NOLOGO /ERRORREPORT:PROMPT
mt.exe -manifest d3d10.exe.${BUILD_TYPE}.manifest -outputresource:$(BUILD_TYPE)\d3d10.exe;1 -nologo

View File

@ -52,8 +52,8 @@ PS_INPUT VS(VS_INPUT input)
output.Joint = input.Joint; output.Joint = input.Joint;
output.Tex = input.Tex; output.Tex = input.Tex;
output.Normal = mul(input.Normal, mSkin).xyz; output.Normal = mul(float4(input.Normal, 0), mSkin).xyz;
output.Normal = mul(output.Normal, World).xyz; output.Normal = mul(float4(output.Normal, 0), World).xyz;
return output; return output;
} }

View File

@ -97,6 +97,7 @@ ID3D10EffectShaderResourceVariable * g_pDiffuseVariableVolume = NULL;
// static // static
ID3D10Effect * g_pEffectStatic = NULL; ID3D10Effect * g_pEffectStatic = NULL;
ID3D10EffectTechnique * g_pTechniqueStatic = NULL; ID3D10EffectTechnique * g_pTechniqueStatic = NULL;
ID3D10EffectTechnique * g_pTechniqueStaticInstanced = NULL;
ID3D10InputLayout * g_pVertexLayoutStatic = NULL; ID3D10InputLayout * g_pVertexLayoutStatic = NULL;
ID3D10EffectMatrixVariable * g_pWorldVariableStatic = NULL; ID3D10EffectMatrixVariable * g_pWorldVariableStatic = NULL;
@ -747,6 +748,7 @@ HRESULT InitStaticEffect()
} }
g_pTechniqueStatic = g_pEffectStatic->GetTechniqueByName("Static"); g_pTechniqueStatic = g_pEffectStatic->GetTechniqueByName("Static");
g_pTechniqueStaticInstanced = g_pEffectStatic->GetTechniqueByName("StaticInstanced");
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// layout // layout
@ -1341,7 +1343,7 @@ static inline int sprint(LPCSTR fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
char * end; char * end = sprintbuf;
StringCbVPrintfExA(sprintbuf, StringCbVPrintfExA(sprintbuf,
(sizeof (sprintbuf)), (sizeof (sprintbuf)),
&end, &end,
@ -1568,6 +1570,42 @@ void RenderVolume(float t)
void RenderVolumeMesh() void RenderVolumeMesh()
{ {
const Mesh * mesh = cube::node_0.mesh;
int indices_length = mesh->indices_size / (sizeof (DWORD));
g_pViewVariableStatic->SetMatrix((float *)&g_View);
g_pProjectionVariableStatic->SetMatrix((float *)&g_Projection);
UINT stride[] = {
(sizeof (mesh->position[0])),
(sizeof (mesh->normal[0])),
(sizeof (mesh->texcoord_0[0])),
};
UINT offset[] = { 0, 0, 0 };
g_pd3dDevice->IASetInputLayout(g_pVertexLayoutStatic);
g_pd3dDevice->IASetVertexBuffers(0, g_dwVertexBufferCountCube, g_pVertexBufferCube, stride, offset);
g_pd3dDevice->IASetIndexBuffer(g_pIndexBufferCube, DXGI_FORMAT_R32_UINT, 0);
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
D3D10_TECHNIQUE_DESC techDesc;
g_pTechniqueStatic->GetDesc(&techDesc);
D3DXMATRIX mWorldScale;
D3DXMATRIX mWorldTranslate;
D3DXMatrixScaling(&mWorldScale, 0.2f, 0.2f, 0.2f);
D3DXMatrixTranslation(&mWorldTranslate, 0.5f, 0.5f, 0.5f);
D3DXMATRIX mWorld = mWorldScale * mWorldTranslate;
g_pWorldVariableStatic->SetMatrix((float *)&mWorld);
D3DXMatrixIdentity(&mWorld);
g_pWorldNormalVariableStatic->SetMatrix((float *)&mWorld);
D3DXVECTOR4 vColor = D3DXVECTOR4(0.0f, 0.9f, 0.0f, 1.0f) ;
g_pOutputColorVariableStatic->SetFloatVector((float *)&vColor);
for (UINT p = 0; p < techDesc.Passes; p++) {
g_pTechniqueStatic->GetPassByIndex(p)->Apply(0);
g_pd3dDevice->DrawIndexed(indices_length, 0, 0);
}
} }
void Render() void Render()
@ -1607,8 +1645,8 @@ void Render()
//RenderBloom(); //RenderBloom();
//print("%f\n", t); //print("%f\n", t);
RenderVolume(t); //RenderVolume(t);
//RenderVolumeMesh(); RenderVolumeMesh();
// present // present
g_pSwapChain->Present(0, 0); g_pSwapChain->Present(0, 0);

View File

@ -18,10 +18,10 @@ void print(LPCSTR fmt, ...)
fmt, fmt,
args); args);
va_end(args); va_end(args);
size_t length = end - &buf[0];
#ifdef _DEBUG #ifdef _DEBUG
OutputDebugStringA(buf); OutputDebugStringA(buf);
#endif #endif
//size_t length = end - &buf[0];
//HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); //HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
//WriteConsoleA(hOutput, buf, (DWORD)length, NULL, NULL); //WriteConsoleA(hOutput, buf, (DWORD)length, NULL, NULL);
} }

View File

@ -25,7 +25,7 @@ HRESULT LoadTexture2D(const wchar_t * resourceName,
} }
DWORD dwResourceSize = SizeofResource(NULL, hRes); DWORD dwResourceSize = SizeofResource(NULL, hRes);
assert(pitch >= width); assert(pitch >= width);
assert(pitch * height == dwResourceSize); assert(pitch * height == (int)dwResourceSize);
HGLOBAL hData = LoadResource(NULL, hRes); HGLOBAL hData = LoadResource(NULL, hRes);
D3D10_SUBRESOURCE_DATA subresourceData; D3D10_SUBRESOURCE_DATA subresourceData;
@ -85,7 +85,7 @@ HRESULT LoadTexture3D(const wchar_t * resourceName,
DWORD dwResourceSize = SizeofResource(NULL, hRes); DWORD dwResourceSize = SizeofResource(NULL, hRes);
assert(pitch >= width); assert(pitch >= width);
assert(slicePitch >= depth); assert(slicePitch >= depth);
assert(slicePitch * depth == dwResourceSize); assert(slicePitch * depth == (int)dwResourceSize);
HGLOBAL hData = LoadResource(NULL, hRes); HGLOBAL hData = LoadResource(NULL, hRes);
D3D10_SUBRESOURCE_DATA subresourceData; D3D10_SUBRESOURCE_DATA subresourceData;

View File

@ -1,11 +1,3 @@
matrix World;
matrix View;
matrix Projection;
matrix WorldNormal;
float3 vOutputColor;
struct VS_INPUT struct VS_INPUT
{ {
float4 Pos : POSITION; float4 Pos : POSITION;
@ -13,6 +5,14 @@ struct VS_INPUT
float2 Tex : TEXCOORD0; float2 Tex : TEXCOORD0;
}; };
struct VS_INPUT_INSTANCED
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
float2 Tex : TEXCOORD0;
row_major float4x4 mTransform : mTransform;
};
struct PS_INPUT struct PS_INPUT
{ {
float4 Pos : SV_POSITION; float4 Pos : SV_POSITION;
@ -26,6 +26,19 @@ struct PS_OUTPUT
float4 color1 : SV_TARGET1; float4 color1 : SV_TARGET1;
}; };
cbuffer ceveryframe
{
matrix World;
matrix View;
matrix Projection;
matrix<float, 3, 3> WorldNormal;
};
cbuffer crarely
{
float3 vOutputColor;
};
PS_INPUT VS(VS_INPUT input) PS_INPUT VS(VS_INPUT input)
{ {
PS_INPUT output = (PS_INPUT)0; PS_INPUT output = (PS_INPUT)0;
@ -41,6 +54,17 @@ PS_INPUT VS(VS_INPUT input)
return output; return output;
} }
PS_INPUT VSInstanced(VS_INPUT_INSTANCED input)
{
VS_INPUT input_vs = (VS_INPUT)0;
input_vs.Pos = mul(input.Pos, input.mTransform);
input_vs.Normal = input.Normal;
input_vs.Tex = input.Tex;
return VS(input_vs);
}
PS_OUTPUT PS(PS_INPUT input) PS_OUTPUT PS(PS_INPUT input)
{ {
PS_OUTPUT output; PS_OUTPUT output;
@ -71,3 +95,15 @@ technique10 Static
SetDepthStencilState(EnableDepth, 0); SetDepthStencilState(EnableDepth, 0);
} }
} }
technique10 StaticInstanced
{
pass P0
{
SetVertexShader(CompileShader(vs_4_0, VSInstanced()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PS()));
SetBlendState(DisableBlending, float4(0.0, 0.0, 0.0, 0.0), 0xffffffff);
SetDepthStencilState(EnableDepth, 0);
}
}