Commit 92fbc837 authored by rarnu's avatar rarnu

add: 上传用到的三方组件

parent 6ac0f8aa
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Makefile Value="2"/>
<Params Value="-Fu.;source;source/FX11;source/Math;source/Classes;../../../packager/units/$(CPU_TARGET)-$(OS_TARGET) -Fisource;source/FX11;source/Math;source/Classes -MObjFPC -Scghi -O1 -gw2 -godwarfsets -gl -l -vewnhibq pl_win_directx12.pas"/>
</CONFIG>
# CodeTyphon Studio
# ct9999
# File generated automatically by Typhon IDE Package Manager
# Makefile.fpc for pl_Win_DirectX12 8.4.1
# This file was generated on 2024-04-08
[package]
name=pl_win_directx12
version=8.4.1
[default]
fpcdir=../../../../fpcsrc
[compiler]
unittargetdir=lib/$(CPU_TARGET)-$(OS_TARGET)/$(LCL_PLATFORM)
unitdir=. source source/FX11 source/Math source/Classes ../../../packager/units/$(CPU_TARGET)-$(OS_TARGET)
includedir=source source/FX11 source/Math source/Classes
options=-MObjFPC -Scghi -O1 -gw2 -godwarfsets -gl -l -vewnhibq $(DBG_OPTIONS)
[target]
units=pl_win_directx12.pas
[clean]
files=$(wildcard $(COMPILER_UNITTARGETDIR)/*$(OEXT)) \
$(wildcard $(COMPILER_UNITTARGETDIR)/*$(PPUEXT)) \
$(wildcard $(COMPILER_UNITTARGETDIR)/*$(RSTEXT)) \
$(wildcard $(COMPILER_UNITTARGETDIR)/*.frm) \
$(wildcard $(COMPILER_UNITTARGETDIR)/*.res) \
$(wildcard $(COMPILER_UNITTARGETDIR)/*.rsj) \
$(wildcard $(COMPILER_UNITTARGETDIR)/*.compiled) \
$(wildcard *$(OEXT)) $(wildcard *$(PPUEXT)) $(wildcard *$(RSTEXT))
[prerules]
# LCL Platform
ifndef LCL_PLATFORM
ifeq ($(OS_TARGET),win32)
LCL_PLATFORM=win32
else
ifeq ($(OS_TARGET),win64)
LCL_PLATFORM=win32
else
ifeq ($(OS_TARGET),darwin)
LCL_PLATFORM=cocoa
else
LCL_PLATFORM=gtk2
endif
endif
endif
endif
export LCL_PLATFORM
DBG_OPTIONS=
ifeq ($(OS_TARGET),darwin)
DBG_OPTIONS=-gw
endif
[rules]
.PHONY: cleartarget compiled all
cleartarget:
-$(DEL) $(COMPILER_UNITTARGETDIR)/pl_win_directx12$(PPUEXT)
compiled:
$(CPPROG) -f Makefile.compiled $(COMPILER_UNITTARGETDIR)/pl_win_directx12.compiled
all: cleartarget $(COMPILER_UNITTARGETDIR) pl_win_directx12$(PPUEXT) compiled
distclean: clean
${DELTREE} lib/$(CPU_TARGET)-$(OS_TARGET)/*
This diff is collapsed.
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}
unit pl_Win_DirectX12;
{$warn 5023 off : no warning about unused units}
interface
uses
DX12.D2D1, DX12.D2D1_3, DX12.D2D1EffectAuthor_1, DX12.D2D1Effects2,
DX12.D2D1SVG, DX12.D3D10, DX12.D3D10_1, DX12.D3D11, DX12.D3D11_1,
DX12.D3D11_2, DX12.D3D11_3, DX12.D3D11_4, DX12.D3D11On12,
DX12.D3D11SDKLayers, DX12.D3D12, DX12.D3D12SDKLayers, DX12.D3D12Shader,
DX12.D3D12Video, DX12.D3D9, DX12.D3D9On12, DX12.D3D9Types, DX12.D3DCommon,
DX12.D3DCompiler, DX12.D3DCSX, DX12.D3DUKMDT, DX12.D3DX10, DX12.D3DX11,
DX12.D3DX11Effect, DX12.D3DX12, DX12.DCommon, DX12.DComp,
DX12.DCompAnimation, DX12.DCompTypes, DX12.DInput, DX12.DirectML,
DX12.DocumentTarget, DX12.DWrite, DX12.DWrite3, DX12.DXCore, DX12.DXGI,
DX12.DXGI1_2, DX12.DXGI1_3, DX12.DXGI1_4, DX12.DXGI1_5, DX12.DXGI1_6,
DX12.DXGIDebug, DX12.DXGIMessages, DX12.DXProgrammableCapture, DX12.OCIdl,
DX12.WinCodec, DX12.Xinput, DirectXTK11.DDS, DirectXTK11.DDSTextureLoader,
DirectXTK11.LoadHelpers, DirectXTK11.Targa, FX11.Effect,
FX11.EffectBinaryFormat, FX11.EffectStateBase11, FX11.EffectStates11,
DirectX.Collision, DirectX.Colors, DirectX.ColorsLinear, DirectX.Math,
DirectX.MatrixStack, DirectX.PackedVector, DirectX.SH, DirectX.SHD3D12,
DirectX.Stereo3DMatrixHelper, DirectX.XDSP, LazarusPackageIntf;
implementation
procedure Register;
begin
end;
initialization
RegisterPackage('pl_Win_DirectX12', @Register);
end.
unit Basetypes;
{$IFDEF FPC}
{$mode DelphiUnicode}{$H+}
{$ENDIF}
interface
uses
Classes, SysUtils,
DX12.D3D11,
DirectX.Math;
type
TVertexType = packed record
position: TXMFLOAT3;
texture: TXMFLOAT2;
end;
implementation
end.
This diff is collapsed.
unit CameraClass;
{$IFDEF FPC}
{$mode delphi}{$H+}
{$ENDIF}
{$DEFINE xxx}
interface
uses
Classes, SysUtils,
DirectX.Math;
type
{ TCameraClass }
TCameraClass = class(TObject)
private
m_positionX, m_positionY, m_positionZ: single;
m_rotationX, m_rotationY, m_rotationZ: single;
m_viewMatrix: TXMMATRIX;
m_baseViewMatrix: TXMMATRIX;
public
constructor Create;
destructor Destroy; override;
procedure SetPosition(x, y, z: single);
procedure SetRotation(x, y, z: single);
function GetPosition(): TXMFLOAT3;
function GetRotation(): TXMFLOAT3;
procedure Render();
procedure RenderBaseViewMatrix();
procedure GetViewMatrix( out viewMatrix: TXMMATRIX);
procedure GetBaseViewMatrix (out viewMatrix: TXMMATRIX);
end;
implementation
uses
DX12.D3DX10;
constructor TCameraClass.Create;
begin
m_positionX := 0.0;
m_positionY := 0.0;
m_positionZ := 0.0;
m_rotationX := 0.0;
m_rotationY := 0.0;
m_rotationZ := 0.0;
end;
destructor TCameraClass.Destroy;
begin
inherited;
end;
procedure TCameraClass.SetPosition(x, y, z: single);
begin
m_positionX := x;
m_positionY := y;
m_positionZ := z;
end;
procedure TCameraClass.SetRotation(x, y, z: single);
begin
m_rotationX := x;
m_rotationY := y;
m_rotationZ := z;
end;
function TCameraClass.GetPosition(): TXMFLOAT3;
begin
Result := TXMFLOAT3.Create(m_positionX, m_positionY, m_positionZ);
end;
function TCameraClass.GetRotation(): TXMFLOAT3;
begin
Result := TXMFLOAT3.Create(m_rotationX, m_rotationY, m_rotationZ);
end;
procedure TCameraClass.Render();
var
{$IFDEF xxx}
up, position, lookAt: TXMFLOAT3;
upVector, positionVector, lookAtVector: TXMVECTOR;
yaw, pitch, roll: single;
rotationMatrix: TXMMATRIX;
rotationMatrix2: TD3DXMATRIX;
{$else}
up, position, lookAt, lookAt3: TD3DXVECTOR3;
lookAt2: PD3DXVECTOR3;
pos4D: TD3DXVector4;
yaw, pitch, roll: single;
rotationMatrix: TD3DXMATRIX;
tempmatrix: TD3DXMATRIX;
{$ENDIF}
begin
{$IFDEF xxx}
// Setup the vector that points upwards.
up.x := 0.0;
up.y := 1.0;
up.z := 0.0;
// Load it into a XMVECTOR structure.
upVector := XMLoadFloat3(up);
// Setup the position of the camera in the world.
position.x := m_positionX;
position.y := m_positionY;
position.z := m_positionZ;
// Load it into a XMVECTOR structure.
positionVector := XMLoadFloat3(position);
// Setup where the camera is looking by default.
lookAt.x := 0.0;
lookAt.y := 0.0;
lookAt.z := 1.0;
// Load it into a XMVECTOR structure.
lookAtVector := XMLoadFloat3(lookAt);
// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
pitch := m_rotationX * 0.0174532925;
yaw := m_rotationY * 0.0174532925;
roll := m_rotationZ * 0.0174532925;
// Create the rotation matrix from the yaw, pitch, and roll values.
rotationMatrix := XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
// Create the rotation matrix from the yaw, pitch, and roll values.
D3DXMatrixRotationYawPitchRoll(@rotationMatrix2, yaw, pitch, roll);
// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
lookAtVector := XMVector3TransformCoord(lookAtVector, rotationMatrix);
upVector := XMVector3TransformCoord(upVector, rotationMatrix);
// Translate the rotated camera position to the location of the viewer.
lookAtVector := XMVectorAdd(positionVector, lookAtVector);
// Finally create the view matrix from the three updated vectors.
m_viewMatrix := XMMatrixLookAtLH(positionVector, lookAtVector, upVector);
{$else}
// Setup the vector that points upwards.
up.x := 0.0;
up.y := 1.0;
up.z := 0.0;
// Setup the position of the camera in the world.
position.x := m_positionX;
position.y := m_positionY;
position.z := m_positionZ;
// Setup where the camera is looking by default.
lookAt.x := 0.0;
lookAt.y := 0.0;
lookAt.z := 1.0;
// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
pitch := m_rotationX * 0.0174532925;
yaw := m_rotationY * 0.0174532925;
roll := m_rotationZ * 0.0174532925;
// Create the rotation matrix from the yaw, pitch, and roll values.
D3DXMatrixRotationYawPitchRoll(rotationMatrix, yaw, pitch, roll);
// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
{$IFDEF FPC}
pos4D := TD3DXVector4.Create(lookAt.x, lookAt.y, lookAt.z, 1);
d3dxvec4transform(pos4D, pos4D, rotationMatrix);
lookAt.x := pos4D.x;
lookAt.y := pos4D.y;
lookAt.z := pos4D.z;
pos4D := TD3DXVector4.Create(up.x, up.y, up.z, 1);
d3dxvec4transform(pos4D, pos4D, rotationMatrix);
up.x := pos4D.x;
up.y := pos4D.y;
up.z := pos4D.z;
{$ELSE}
D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
D3DXVec3TransformCoord(up, up, rotationMatrix);
{$ENDIF}
// Translate the rotated camera position to the location of the viewer.
lookAt := position + lookAt;
// Finally create the view matrix from the three updated vectors.
D3DXMatrixLookAtLH(tempmatrix, position, lookAt, up);
m_viewMatrix._11:= tempmatrix._11;
m_viewMatrix._12:= tempmatrix._12;
m_viewMatrix._13:= tempmatrix._13;
m_viewMatrix._14:= tempmatrix._14;
m_viewMatrix._21:= tempmatrix._21;
m_viewMatrix._22:= tempmatrix._22;
m_viewMatrix._23:= tempmatrix._23;
m_viewMatrix._24:= tempmatrix._24;
m_viewMatrix._31:= tempmatrix._31;
m_viewMatrix._32:= tempmatrix._32;
m_viewMatrix._33:= tempmatrix._33;
m_viewMatrix._34:= tempmatrix._34;
m_viewMatrix._41:= tempmatrix._41;
m_viewMatrix._42:= tempmatrix._42;
m_viewMatrix._43:= tempmatrix._43;
m_viewMatrix._44:= tempmatrix._44;
{$endif}
end;
procedure TCameraClass.GetViewMatrix(out viewMatrix: TXMMATRIX);
begin
viewMatrix := m_viewMatrix;
end;
procedure TCameraClass.RenderBaseViewMatrix();
var
up, position, lookAt: TXMFLOAT3;
upVector, positionVector, lookAtVector: TXMVECTOR;
yaw, pitch, roll: single;
rotationMatrix: TXMMATRIX;
begin
// Setup the vector that points upwards.
up.x := 0.0;
up.y := 1.0;
up.z := 0.0;
// Load it into a XMVECTOR structure.
upVector := XMLoadFloat3(up);
// Setup the position of the camera in the world.
position.x := m_positionX;
position.y := m_positionY;
position.z := m_positionZ;
// Load it into a XMVECTOR structure.
positionVector := XMLoadFloat3(position);
// Setup where the camera is looking by default.
lookAt.x := 0.0;
lookAt.y := 0.0;
lookAt.z := 1.0;
// Load it into a XMVECTOR structure.
lookAtVector := XMLoadFloat3(lookAt);
// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
pitch := m_rotationX * 0.0174532925;
yaw := m_rotationY * 0.0174532925;
roll := m_rotationZ * 0.0174532925;
// Create the rotation matrix from the yaw, pitch, and roll values.
rotationMatrix := XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
lookAtVector := XMVector3TransformCoord(lookAtVector, rotationMatrix);
upVector := XMVector3TransformCoord(upVector, rotationMatrix);
// Translate the rotated camera position to the location of the viewer.
lookAtVector := XMVectorAdd(positionVector, lookAtVector);
// Finally create the view matrix from the three updated vectors.
m_baseViewMatrix := XMMatrixLookAtLH(positionVector, lookAtVector, upVector);
end;
procedure TCameraClass.GetBaseViewMatrix(out viewMatrix: TXMMATRIX);
begin
viewMatrix := m_baseViewMatrix;
end;
end.
This diff is collapsed.
unit DebugWindowClass;
{$mode DelphiUnicode}{$H+}
interface
uses
Classes, SysUtils,
Windows,
DX12.D3D11,
DX12.DXGI,
DX12.D3DCommon,
DirectX.Math;
type
TVertexType = record
position: TXMFLOAT3;
texture: TXMFLOAT2;
end;
{ TDebugWindowClass }
TDebugWindowClass = class(TObject)
private
m_vertexBuffer, m_indexBuffer: ID3D11Buffer;
m_vertexCount, m_indexCount: integer;
m_screenWidth, m_screenHeight: integer;
m_bitmapWidth, m_bitmapHeight: integer;
m_previousPosX, m_previousPosY: integer;
public
constructor Create;
destructor Destroy; override;
function Initialize(device: ID3D11Device; screenWidth, screenHeight, bitmapWidth, bitmapHeight: integer): HResult;
procedure Shutdown();
function Render(deviceContext: ID3D11DeviceContext; positionX, positionY: integer): HResult;
function GetIndexCount(): integer;
private
function InitializeBuffers(device: ID3D11Device): HResult;
procedure ShutdownBuffers();
function UpdateBuffers(deviceContext: ID3D11DeviceContext; positionX, positionY: integer): HResult;
procedure RenderBuffers(deviceContext: ID3D11DeviceContext);
end;
implementation
{ TDebugWindowClass }
constructor TDebugWindowClass.Create;
begin
end;
destructor TDebugWindowClass.Destroy;
begin
inherited Destroy;
end;
function TDebugWindowClass.Initialize(device: ID3D11Device; screenWidth, screenHeight, bitmapWidth, bitmapHeight: integer): HResult;
begin
// Store the screen size.
m_screenWidth := screenWidth;
m_screenHeight := screenHeight;
// Store the size in pixels that this bitmap should be rendered at.
m_bitmapWidth := bitmapWidth;
m_bitmapHeight := bitmapHeight;
// Initialize the previous rendering position to negative one.
m_previousPosX := -1;
m_previousPosY := -1;
// Initialize the vertex and index buffers.
Result := InitializeBuffers(device);
end;
procedure TDebugWindowClass.Shutdown();
begin
// Shutdown the vertex and index buffers.
ShutdownBuffers();
end;
function TDebugWindowClass.Render(deviceContext: ID3D11DeviceContext; positionX, positionY: integer): HResult;
begin
// Re-build the dynamic vertex buffer for rendering to possibly a different location on the screen.
Result := UpdateBuffers(deviceContext, positionX, positionY);
if (Result <> S_OK) then Exit;
// Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
RenderBuffers(deviceContext);
end;
function TDebugWindowClass.GetIndexCount(): integer;
begin
Result := m_indexCount;
end;
function TDebugWindowClass.InitializeBuffers(device: ID3D11Device): HResult;
var
vertices: array of TVertexType;
indices: array of uint32;
vertexBufferDesc, indexBufferDesc: TD3D11_BUFFER_DESC;
vertexData, indexData: TD3D11_SUBRESOURCE_DATA;
i: integer;
begin
// Set the number of vertices in the vertex array.
m_vertexCount := 6;
// Set the number of indices in the index array.
m_indexCount := m_vertexCount;
// Create the vertex array.
SetLength(vertices, m_vertexCount);
// Create the index array.
SetLength(indices, m_indexCount);
// Initialize vertex array to zeros at first.
ZeroMemory(@vertices[0], (sizeof(TVertexType) * m_vertexCount));
// Load the index array with data.
for i := 0 to m_indexCount - 1 do
begin
indices[i] := i;
end;
// Set up the description of the static vertex buffer.
vertexBufferDesc.Usage := D3D11_USAGE_DYNAMIC;
vertexBufferDesc.ByteWidth := sizeof(TVertexType) * m_vertexCount;
vertexBufferDesc.BindFlags := Ord(D3D11_BIND_VERTEX_BUFFER);
vertexBufferDesc.CPUAccessFlags := Ord(D3D11_CPU_ACCESS_WRITE);
vertexBufferDesc.MiscFlags := 0;
vertexBufferDesc.StructureByteStride := 0;
// Give the subresource structure a pointer to the vertex data.
vertexData.pSysMem := vertices;
vertexData.SysMemPitch := 0;
vertexData.SysMemSlicePitch := 0;
// Now create the vertex buffer.
Result := device.CreateBuffer(vertexBufferDesc, @vertexData, m_vertexBuffer);
if (Result <> S_OK) then Exit;
// Set up the description of the static index buffer.
indexBufferDesc.Usage := D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth := sizeof(uint32) * m_indexCount;
indexBufferDesc.BindFlags := Ord(D3D11_BIND_INDEX_BUFFER);
indexBufferDesc.CPUAccessFlags := 0;
indexBufferDesc.MiscFlags := 0;
indexBufferDesc.StructureByteStride := 0;
// Give the subresource structure a pointer to the index data.
indexData.pSysMem := indices;
indexData.SysMemPitch := 0;
indexData.SysMemSlicePitch := 0;
// Create the index buffer.
Result := device.CreateBuffer(indexBufferDesc, @indexData, m_indexBuffer);
// Release the arrays now that the vertex and index buffers have been created and loaded.
SetLength(vertices, 0);
SetLength(indices, 0);
end;
procedure TDebugWindowClass.ShutdownBuffers();
begin
// Release the index buffer.
m_indexBuffer := nil;
// Release the vertex buffer.
m_vertexBuffer := nil;
end;
function TDebugWindowClass.UpdateBuffers(deviceContext: ID3D11DeviceContext; positionX, positionY: integer): HResult;
var
left, right, top, bottom: single;
vertices: array of TVertexType;
mappedResource: TD3D11_MAPPED_SUBRESOURCE;
verticesPtr: ^TVertexType;
begin
Result:=S_OK;
// If the position we are rendering this bitmap to has not changed then don't update the vertex buffer since it
// currently has the correct parameters.
if ((positionX = m_previousPosX) and (positionY = m_previousPosY)) then exit;
// If it has changed then update the position it is being rendered to.
m_previousPosX := positionX;
m_previousPosY := positionY;
// Calculate the screen coordinates of the left side of the bitmap.
left := ((m_screenWidth / 2) * -1) + positionX;
// Calculate the screen coordinates of the right side of the bitmap.
right := left + m_bitmapWidth;
// Calculate the screen coordinates of the top of the bitmap.
top := (m_screenHeight / 2) - positionY;
// Calculate the screen coordinates of the bottom of the bitmap.
bottom := top - m_bitmapHeight;
// Create the vertex array.
SetLength(vertices, m_vertexCount);
// Load the vertex array with data.
// First triangle.
vertices[0].position := TXMFLOAT3.Create(left, top, 0.0); // Top left.
vertices[0].texture := TXMFLOAT2.Create(0.0, 0.0);
vertices[1].position := TXMFLOAT3.Create(right, bottom, 0.0); // Bottom right.
vertices[1].texture := TXMFLOAT2.Create(1.0, 1.0);
vertices[2].position := TXMFLOAT3.Create(left, bottom, 0.0); // Bottom left.
vertices[2].texture := TXMFLOAT2.Create(0.0, 1.0);
// Second triangle.
vertices[3].position := TXMFLOAT3.Create(left, top, 0.0); // Top left.
vertices[3].texture := TXMFLOAT2.Create(0.0, 0.0);
vertices[4].position := TXMFLOAT3.Create(right, top, 0.0); // Top right.
vertices[4].texture := TXMFLOAT2.Create(1.0, 0.0);
vertices[5].position := TXMFLOAT3.Create(right, bottom, 0.0); // Bottom right.
vertices[5].texture := TXMFLOAT2.Create(1.0, 1.0);
// Lock the vertex buffer so it can be written to.
Result := deviceContext.Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (Result <> S_OK) then Exit;
// Get a pointer to the data in the vertex buffer.
verticesPtr := mappedResource.pData;
// Copy the data into the vertex buffer.
Move(vertices[0], verticesPtr^, (sizeof(TVertexType) * m_vertexCount));
// Unlock the vertex buffer.
deviceContext.Unmap(m_vertexBuffer, 0);
// Release the vertex array as it is no longer needed.
SetLength(vertices, 0);
end;
procedure TDebugWindowClass.RenderBuffers(deviceContext: ID3D11DeviceContext);
var
stride: UINT;
offset: UINT;
begin
// Set vertex buffer stride and offset.
stride := sizeof(TVertexType);
offset := 0;
// Set the vertex buffer to active in the input assembler so it can be rendered.
deviceContext.IASetVertexBuffers(0, 1, @m_vertexBuffer, @stride, @offset);
// Set the index buffer to active in the input assembler so it can be rendered.
deviceContext.IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
deviceContext.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
end;
end.
unit DepthShaderClass;
{$mode DelphiUnicode}{$H+}
interface
uses
Classes, SysUtils;
type
TDepthShaderClass = class(TObject)
end;
implementation
end.
unit FPSClass;
{$IFDEF FPC}
{$mode DelphiUnicode}{$H+}
{$ENDIF}
interface
uses
Classes, SysUtils, Windows, MMSystem;
type
{ TFPSClass }
TFPSClass = class(TObject)
private
m_fps, m_count: integer;
m_startTime: uint32;
public
constructor Create;
destructor Destroy; override;
procedure Initialize();
procedure Frame();
function GetFps(): integer;
end;
implementation
{ TFPSClass }
constructor TFPSClass.Create;
begin
end;
destructor TFPSClass.Destroy;
begin
inherited Destroy;
end;
procedure TFPSClass.Initialize();
begin
m_fps := 0;
m_count := 0;
m_startTime := timeGetTime();
end;
procedure TFPSClass.Frame();
begin
Inc(m_count);
if (timeGetTime() >= (m_startTime + 1000)) then
begin
m_fps := m_count;
m_count := 0;
m_startTime := timeGetTime();
end;
end;
function TFPSClass.GetFps(): integer;
begin
Result := m_fps;
end;
end.
This diff is collapsed.
This diff is collapsed.
unit FontClass;
{$IFDEF FPC}
{$mode DelphiUnicode}{$H+}
{$ENDIF}
interface
uses
Classes, SysUtils, Windows,
TextureClass,
DX12.D3D11,
Basetypes,
DirectX.Math;
type
TFontType = packed record
left, right: single;
size: integer;
end;
{ TFontClass }
TFontClass = class(TObject)
private
m_Font: array of TFontType;
m_Texture: TTextureClass;
m_fontHeight: single;
m_spaceSize: integer;
private
function LoadFontData(filename: WideString): HResult;
procedure ReleaseFontData();
function LoadTexture(device: ID3D11Device; deviceContext: ID3D11DeviceContext; filename: WideString): HResult;
procedure ReleaseTexture();
public
constructor Create;
destructor Destroy; override;
function Initialize(device: ID3D11Device; deviceContext: ID3D11DeviceContext; fontFilename: WideString;
textureFilename: WideString; fontHeight: single; spaceSize: integer): HResult;
procedure Shutdown();
function GetTexture(): ID3D11ShaderResourceView;
procedure BuildVertexArray(var vertexPtr: array of TVertexType; sentence: ansistring; drawX, drawY: single);
function GetFontHeight: single;
function GetSentencePixelLength(sentence: ansistring): single;
end;
implementation
{ TFontClass }
function TFontClass.LoadFontData(filename: WideString): HResult;
var
f: Textfile;
i, j: integer;
s, s1: ansistring;
k: integer;
code: integer;
begin
// Create the font spacing buffer.
SetLength(m_Font, 95);
FormatSettings.DecimalSeparator := '.';
// Read in the font size and spacing between chars.
AssignFile(f, filename);
Reset(f);
// Read in the 95 used ascii characters for text.
for i := 0 to 94 do
begin
k := 1;
readln(f, s);
j := 1;
while s[j] <> ' ' do
Inc(j);
Inc(j);
while s[j] <> ' ' do
Inc(j);
Inc(j);
k := j;
while s[j] <> ' ' do
Inc(j);
s1 := copy(s, k, j - k);
Val(s1, m_Font[i].left, code);
while (s[j] = ' ') do
Inc(j);
k := j;
while (s[j] <> ' ') do
Inc(j);
s1 := copy(s, k, j - k);
Val(s1, m_Font[i].right, code);
while (s[j] = ' ') do
Inc(j);
s1 := copy(s, j, length(s) - j + 1);
Val(s1, m_Font[i].size, code);
end;
// Close the file.
CloseFile(f);
Result := S_OK;
end;
procedure TFontClass.ReleaseFontData();
begin
// Release the font data array.
{ if (m_Font <> nil) then
begin
m_Font.Free;
m_Font := nil;
end; }
end;
function TFontClass.LoadTexture(device: ID3D11Device; deviceContext: ID3D11DeviceContext; filename: WideString): HResult;
begin
// Create the texture object.
m_Texture := TTextureClass.Create;
// Initialize the texture object.
Result := m_Texture.Initialize(device, deviceContext, filename);
end;
procedure TFontClass.ReleaseTexture();
begin
// Release the texture object.
if (m_Texture <> nil) then
begin
m_Texture.Shutdown();
m_Texture.Free;
m_Texture := nil;
end;
end;
constructor TFontClass.Create;
begin
end;
destructor TFontClass.Destroy;
begin
inherited Destroy;
end;
function TFontClass.Initialize(device: ID3D11Device; deviceContext: ID3D11DeviceContext; fontFilename: WideString;
textureFilename: WideString; fontHeight: single; spaceSize: integer): HResult;
var
hr: HResult;
begin
// Store the height of the font.
m_fontHeight := fontHeight;
// Store the size of spaces in pixel size.
m_spaceSize := spaceSize;
// Load in the text file containing the font data.
Result := LoadFontData(fontFilename);
if (Result <> S_OK) then Exit;
// Load the texture that has the font characters on it.
hr := LoadTexture(device, deviceContext, textureFilename);
Result:=hr;
end;
procedure TFontClass.Shutdown();
begin
// Release the font texture.
ReleaseTexture();
// Release the font data.
ReleaseFontData();
end;
function TFontClass.GetTexture(): ID3D11ShaderResourceView;
begin
Result := m_Texture.GetTexture();
end;
procedure TFontClass.BuildVertexArray(var vertexPtr: array of TVertexType; sentence: ansistring; drawX, drawY: single);
var
numLetters, index, i, letter: integer;
begin
// Coerce the input vertices into a VertexType structure.
// Get the number of letters in the sentence.
numLetters := length(sentence);
// Initialize the index to the vertex array.
index := 0;
// Draw each letter onto a quad.
for i := 1 to numLetters do
begin
letter := Ord(sentence[i]) - 32;
// If the letter is a space then just move over three pixels.
if (letter = 0) then
begin
drawX := drawX + m_spaceSize;
end
else
begin
// First triangle in quad.
vertexPtr[index].position := TXMFLOAT3.Create(drawX, drawY, 0.0); // Top left.
vertexPtr[index].texture := TXMFLOAT2.Create(m_Font[letter].left, 0.0);
Inc(index);
vertexPtr[index].position := TXMFLOAT3.Create((drawX + m_Font[letter].size), (drawY - m_fontHeight), 0.0); // Bottom right.
vertexPtr[index].texture := TXMFLOAT2.Create(m_Font[letter].right, 1.0);
Inc(index);
vertexPtr[index].position := TXMFLOAT3.Create(drawX, (drawY - m_fontHeight), 0.0); // Bottom left.
vertexPtr[index].texture := TXMFLOAT2.Create(m_Font[letter].left, 1.0);
Inc(index);
// Second triangle in quad.
vertexPtr[index].position := TXMFLOAT3.Create(drawX, drawY, 0.0); // Top left.
vertexPtr[index].texture := TXMFLOAT2.Create(m_Font[letter].left, 0.0);
Inc(index);
vertexPtr[index].position := TXMFLOAT3.Create(drawX + m_Font[letter].size, drawY, 0.0); // Top right.
vertexPtr[index].texture := TXMFLOAT2.Create(m_Font[letter].right, 0.0);
Inc(index);
vertexPtr[index].position := TXMFLOAT3.Create((drawX + m_Font[letter].size), (drawY - m_fontHeight), 0.0); // Bottom right.
vertexPtr[index].texture := TXMFLOAT2.Create(m_Font[letter].right, 1.0);
Inc(index);
// Update the x location for drawing by the size of the letter and one pixel.
drawX := drawX + m_Font[letter].size + 1.0;
end;
end;
end;
function TFontClass.GetFontHeight: single;
begin
Result := m_fontHeight;
end;
function TFontClass.GetSentencePixelLength(sentence: ansistring): single;
var
pixelLength: single;
i: integer;
letter: integer;
begin
Result := 0;
for i := 1 to Length(sentence) do
begin
letter := Ord(sentence[i]) - 32;
// If the letter is a space then count it as three pixels.
if (letter = 0) then
begin
Result := Result + m_spaceSize;
end
else
begin
Result := Result + (m_Font[letter].size + 1);
end;
end;
end;
end.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
unit DX12.D3D9Types;
(*==========================================================================;
*
* Copyright (C) Microsoft Corporation. All Rights Reserved.
*
* File: d3d9types.h
* Content: Direct3D capabilities include file
*
***************************************************************************)
{$mode delphi}
interface
uses
Windows, Classes, SysUtils;
const
DIRECT3D_VERSION = $0900;
type
TD3DMATRIX = record
case integer of
0: (
_11, _12, _13, _14: single;
_21, _22, _23, _24: single;
_31, _32, _33, _34: single;
_41, _42, _43, _44: single;
);
1: (m: array[0..3, 0..3] of single);
end;
implementation
end.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment