This commit is contained in:
Wiesner András 2020-02-29 10:33:37 +01:00
commit 26dec991e4
28 changed files with 6352 additions and 0 deletions

8
CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10)
project(WinApi)
set(CMAKE_CXX_STANDARD 14)
add_executable(WinApi WIN32 main.cpp d3dx12.h DXWindow.cpp DXWindow.h Logger.cpp Logger.h utils.cpp utils.h Window.cpp Window.h Timer.cpp Timer.h IDrawable.h Geometry.h)
target_link_libraries(WinApi d3d12.lib dxgi.lib dxguid.lib d3dcompiler.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib)

17
CMakeSettings.json Normal file
View File

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${workspaceRoot}\\RUNTIME",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
]
}

481
DXWindow.cpp Normal file
View File

@ -0,0 +1,481 @@
#include "DXWindow.h"
#include "IDrawable.h"
namespace eg3d {
DXWindow::DXWindow() : Window(true)
{
init();
initDrawObjects();
}
DXWindow::~DXWindow()
{
}
void DXWindow::init()
{
LOG("Initializing DXWindow!");
createDevice();
createSyncObjects();
queryDescriptorSizes();
createCommandObjects();
createSwapChain();
createDescriptorHeaps();
createRTVs();
createDSV();
setViewPort();
setScissorRectangle();
}
void DXWindow::createDevice()
{
LOG("Creating device!");
#if defined(DEBUG) | defined(_DEBUG)
LOG("Debug ON!");
if (FAILED(D3D12GetDebugInterface(IID_PPV_ARGS(mDebugController.GetAddressOf()))))
LOG("Failed to create debug interface!");
mDebugController->EnableDebugLayer();
#endif
//-------------------------------
HRESULT hardwareResult = D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(mDevice.GetAddressOf()));
if (FAILED(hardwareResult))
{
LOG("Could not create D3D12 Device!");
}
//-------------------------------
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(mFactory.GetAddressOf()))))
LOG("Failed to create DXGI factory!");
}
void DXWindow::createSyncObjects()
{
if (FAILED(mDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(mFence.GetAddressOf()))))
LOG("Failed to create fence!");
}
void DXWindow::queryDescriptorSizes()
{
LOG("Querying descriptor sizes!");
mRTVDescSize = mDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
mDSVDescSize = mDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
mCBVSRVDescSize = mDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
}
void DXWindow::createCommandObjects()
{
LOG("Creating command objects!");
// command queue létrehozása
D3D12_COMMAND_QUEUE_DESC cqDesc = {};
cqDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
cqDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
if (FAILED(mDevice->CreateCommandQueue(&cqDesc, IID_PPV_ARGS(mCommandQueue.GetAddressOf()))))
LOG("Failed to create command queue!");
// command allocator létrehozása
if (FAILED(mDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(mCommandAllocator.GetAddressOf()))))
LOG("Failed to create command allocator!");
// command list létrehozása
if (FAILED(mDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, mCommandAllocator.Get(), nullptr,
IID_PPV_ARGS(mCommandList.GetAddressOf()))))
LOG("Failed to create command list!");
mCommandList->Close(); // command list lezárása
}
void DXWindow::createSwapChain()
{
LOG("Creating swap chain!");
SIZE size = getSize(); // ablak méretének lekérése
DXGI_SWAP_CHAIN_DESC swD = {};
swD.BufferDesc.Width = size.cx; // buffer méretének beállítása (px)
swD.BufferDesc.Height = size.cy;
swD.BufferDesc.RefreshRate = { 60, 1 }; // FPS
swD.BufferDesc.Format = cBackBufferFormat; // back buffer formátuma
swD.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swD.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swD.BufferCount = cSwapChainBufferCount;
swD.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swD.OutputWindow = mHWND; // ablak fogantyúja
swD.Windowed = true;
swD.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swD.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
swD.SampleDesc.Count = 1; // ~élsimítás
swD.SampleDesc.Quality = 0;
if (FAILED(mFactory->CreateSwapChain(mCommandQueue.Get(), &swD, mSwapChain.GetAddressOf())))
LOG("Failed to create swap chain!");
mCurrentBackBuffer = 0;
}
void DXWindow::createDescriptorHeaps()
{
LOG("Creating descriptor heaps!");
// ---------- RTV
D3D12_DESCRIPTOR_HEAP_DESC hD = {};
hD.NumDescriptors = cSwapChainBufferCount;
hD.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
hD.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
hD.NodeMask = 0;
if (FAILED(mDevice->CreateDescriptorHeap(&hD, IID_PPV_ARGS(mRtvDescriptorHeap.GetAddressOf()))))
LOG("Failed to create render target view descriptor heap!");
// ---------- DSV
hD.NumDescriptors = 1;
hD.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
if (FAILED(mDevice->CreateDescriptorHeap(&hD, IID_PPV_ARGS(mDsvDescriptorHeap.GetAddressOf()))))
LOG("Failed to create DSV descriptor heap!");
}
void DXWindow::createRTVs()
{
LOG("Creating RTV!");
CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHeapHandle(mRtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart());
for (UINT i = 0; i < cSwapChainBufferCount; i++)
{
if (FAILED(mSwapChain->GetBuffer(i, IID_PPV_ARGS(&mSwapChainBuffer[i]))))
LOG("Failed to get buffer in createTRVs()!");
mDevice->CreateRenderTargetView(mSwapChainBuffer[i].Get(), nullptr, rtvHeapHandle);
rtvHeapHandle.Offset(1, mRTVDescSize);
}
}
void DXWindow::createDSV()
{
LOG("Creating DSV!");
SIZE size = getSize();
D3D12_RESOURCE_DESC dsD = {};
dsD.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
dsD.Alignment = 0;
dsD.Width = size.cx;
dsD.Height = size.cy;
dsD.DepthOrArraySize = 1;
dsD.MipLevels = 1;
dsD.Format = cDepthStencilFormat;
dsD.SampleDesc.Count = 1;
dsD.SampleDesc.Quality = 0;
dsD.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
dsD.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
D3D12_CLEAR_VALUE optClear;
optClear.Format = cDepthStencilFormat;
optClear.DepthStencil.Depth = 1.0f;
optClear.DepthStencil.Stencil = 0;
if (FAILED(mDevice->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&dsD,
D3D12_RESOURCE_STATE_DEPTH_WRITE,
&optClear,
IID_PPV_ARGS(mDepthStencilBuffer.GetAddressOf())
)))
LOG("Failed to create depth buffer committed resource!");
mDevice->CreateDepthStencilView(
mDepthStencilBuffer.Get(),
nullptr,
getDSVHandle());
}
void DXWindow::setViewPort()
{
LOG("Setting viewport!");
SIZE size = getSize();
mViewPort.TopLeftX = 0.0f;
mViewPort.TopLeftY = 0.0f;
mViewPort.Width = static_cast<float>(size.cx);
mViewPort.Height = static_cast<float>(size.cy);
mViewPort.MinDepth = 0.0f;
mViewPort.MaxDepth = 1.0f;
mCommandList->RSSetViewports(1, &mViewPort);
}
void DXWindow::setScissorRectangle()
{
LOG("Setting scissor rectangle!");
SIZE size = getSize();
mScissorRect = { 0, 0, size.cx, size.cy };
mCommandList->RSSetScissorRects(1, &mScissorRect);
}
D3D12_CPU_DESCRIPTOR_HANDLE DXWindow::getCurrentBackBufferRTVHandle() const {
return CD3DX12_CPU_DESCRIPTOR_HANDLE(
mRtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart(),
mCurrentBackBuffer,
mRTVDescSize);
}
D3D12_CPU_DESCRIPTOR_HANDLE DXWindow::getDSVHandle() const
{
return mDsvDescriptorHeap->GetCPUDescriptorHandleForHeapStart();
}
ID3D12Resource* DXWindow::getCurrentBackBuffer() const
{
return mSwapChainBuffer[mCurrentBackBuffer].Get();
}
void DXWindow::Draw(const DrawablePool &drawables)
{
updateConstantBuffers(); // konstansbufferek frissítése
// ----------------------
if (FAILED(mCommandAllocator->Reset()))
LOG("Couldn't reset command allocator!");
if (FAILED(mCommandList->Reset(mCommandAllocator.Get(), pso.Get())))
LOG("Couldn't reset command list!");
// --------
mCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(getCurrentBackBuffer(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
// ---
mCommandList->SetGraphicsRootSignature(rootSignature.Get());
mCommandList->RSSetViewports(1, &mViewPort);
mCommandList->RSSetScissorRects(1, &mScissorRect);
mCommandList->ClearRenderTargetView(getCurrentBackBufferRTVHandle(), DirectX::Colors::LightSteelBlue, 0, nullptr);
mCommandList->ClearDepthStencilView(getDSVHandle(), D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, nullptr);
mCommandList->OMSetRenderTargets(1, &getCurrentBackBufferRTVHandle(), true, &getDSVHandle());
// TODO konstansbuffer bekötése
////////// OBJEKTUMOK KIRAJZOLÁSA
drawObject();
// TODO drawables kirajzolása
//////////
mCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(getCurrentBackBuffer(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
// ---
if (FAILED(mCommandList->Close()))
LOG("Failed to close command list in Draw()!");
// ---
ID3D12CommandList * cmdLists[] = { mCommandList.Get() };
mCommandQueue->ExecuteCommandLists(_countof(cmdLists), cmdLists);
// ---
if (FAILED(mSwapChain->Present(0, 0)))
LOG("Failed to present current buffer!");
mCurrentBackBuffer = (mCurrentBackBuffer + 1) % cSwapChainBufferCount;
flushCommandQueue();
}
void DXWindow::flushCommandQueue()
{
mCurrentFence++;
if (FAILED(mCommandQueue->Signal(mFence.Get(), mCurrentFence)))
LOG("Couldn't signal command queue!");
if (mFence->GetCompletedValue() < mCurrentFence)
{
HANDLE eventHandle = CreateEventEx(nullptr, false, false, EVENT_ALL_ACCESS);
if (FAILED(mFence->SetEventOnCompletion(mCurrentFence, eventHandle)))
LOG("Couldn't set event to trigger on completion!");
WaitForSingleObject(eventHandle, INFINITE);
CloseHandle(eventHandle);
}
}
ComPtr<ID3D12Device> DXWindow::getDevice() const {
return mDevice;
}
// ------------------
void DXWindow::initDrawObjects()
{
initVertices();
setupInputLayout();
createBuffers();
uploadBuffers();
loadShaders();
createConstantBuffers();
createRootSignature();
createPSO();
}
void DXWindow::initVertices()
{
vertices = {
{ -0.5f, -0.5f, 0.1f },
{ 0.5f, -0.5f, 0.1f },
{ 0, 0.98f, 0.1f },
};
indices = { 0, 2, 1 };
}
void DXWindow::setupInputLayout()
{
inputElements = {
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
// TODO további elemek létrehozása
};
}
void DXWindow::createBuffers()
{
// --- vertex buffer létrehozása
vertexBuffer = createBuffer_UH(mDevice, vertices.size() * sizeof(Vertex));
vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
vertexBufferView.StrideInBytes = sizeof(Vertex);
vertexBufferView.SizeInBytes = vertices.size() * sizeof(Vertex);
// --- index buffer létrehozása TODO átírás createBuffer_UH() használatával
indexBuffer = createBuffer_UH(mDevice, indices.size() * sizeof(uint32_t));
indexBufferView.Format = DXGI_FORMAT_R32_UINT;
indexBufferView.BufferLocation = indexBuffer->GetGPUVirtualAddress();
indexBufferView.SizeInBytes = indices.size() * sizeof(uint32_t);
}
void DXWindow::uploadBuffers()
{
// --- vertex buffer feltöltése
bufferMapCopy(vertexBuffer, vertices.data(), vertices.size() * sizeof(Vertex));
// --- index buffer feltöltése
bufferMapCopy(indexBuffer, indices.data(), indices.size() * sizeof(uint32_t));
}
void DXWindow::createConstantBuffers()
{
// konstansbuffer létrehozása
}
void DXWindow::updateConstantBuffers()
{
// TODO konstansbuffer feltöltése
}
void DXWindow::createRootSignature()
{
// TODO root paraméterek megadása
CD3DX12_ROOT_SIGNATURE_DESC rsD(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
ComPtr<ID3DBlob> serializedRS = nullptr, errorBlob = nullptr;
if (FAILED(D3D12SerializeRootSignature(&rsD, D3D_ROOT_SIGNATURE_VERSION_1, serializedRS.GetAddressOf(), errorBlob.GetAddressOf())))
LOG("Error when serializing root signature: " + std::string((char *)errorBlob.Get()));
if (FAILED(mDevice->CreateRootSignature(0, serializedRS->GetBufferPointer(), serializedRS->GetBufferSize(), IID_PPV_ARGS(rootSignature.GetAddressOf()))))
LOG("Error creating root signature!");
}
void DXWindow::loadShaders()
{
vertexShader = loadBlob("shaders\\vs.cso");
pixelShader = loadBlob("shaders\\ps.cso");
}
void DXWindow::createPSO()
{
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoD = {};
psoD.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
psoD.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
psoD.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
psoD.SampleMask = UINT_MAX;
psoD.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoD.NumRenderTargets = 1;
psoD.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
psoD.SampleDesc.Count = 1;
psoD.SampleDesc.Quality = 0;
psoD.DSVFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
// shaderprogamok beállítása
psoD.VS = { vertexShader->GetBufferPointer(), vertexShader->GetBufferSize() };
psoD.PS = { pixelShader->GetBufferPointer(), pixelShader->GetBufferSize() };
// input layout beállítása
psoD.InputLayout = { inputElements.data(), (UINT)inputElements.size() };
// root signature beállítása
psoD.pRootSignature = rootSignature.Get();
// PSO legyártása
HRESULT hardwareResult = mDevice->CreateGraphicsPipelineState(&psoD, IID_PPV_ARGS(pso.GetAddressOf()));
if (FAILED(hardwareResult))
{
LOG("Failed to create PSO!");
_com_error err(hardwareResult);
LOG(err.ErrorMessage());
}
}
void DXWindow::drawObject()
{
mCommandList->IASetVertexBuffers(0, 1, &vertexBufferView);
mCommandList->IASetIndexBuffer(&indexBufferView);
mCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
mCommandList->DrawIndexedInstanced(indices.size(), 1, 0, 0, 0);
}
}

130
DXWindow.h Normal file
View File

@ -0,0 +1,130 @@
#pragma once
#include "Window.h"
#include <d3d12.h>
#include <dxgi.h>
#include "Logger.h"
#include <dxgi1_4.h>
#include <DirectXColors.h>
#include "d3dx12.h"
#include "comdef.h"
#include "IDrawable.h"
// Vertex struktúrája
struct Vertex
{
float x, y, z;
};
// TODO konstansbuffer típus
namespace eg3d {
class DXWindow : public Window {
public:
static constexpr DXGI_FORMAT cBackBufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM; // back buffer formátum
static constexpr UINT cSwapChainBufferCount = 2; // double buffering
static constexpr DXGI_FORMAT cDepthStencilFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
// TODO
private:
#if defined(DEBUG) | defined(_DEBUG)
ComPtr<ID3D12Debug> mDebugController; // debug vezérlõ
#endif
// TODO
ComPtr<ID3D12Device> mDevice; // device
ComPtr<IDXGIFactory1> mFactory; // DXGI factory
ComPtr<ID3D12Fence> mFence; // fence
ULONG64 mCurrentFence;
ComPtr<ID3D12CommandQueue> mCommandQueue; // command queue
ComPtr<ID3D12CommandAllocator> mCommandAllocator; // command allocator
ComPtr<ID3D12GraphicsCommandList> mCommandList; // command list
UINT mRTVDescSize, mDSVDescSize, mCBVSRVDescSize; // deszkriptorméretek
ComPtr<IDXGISwapChain> mSwapChain; // swap chain
ComPtr<ID3D12DescriptorHeap> mRtvDescriptorHeap; // render target view descriptor heap
ComPtr<ID3D12DescriptorHeap> mDsvDescriptorHeap; // DSV descriptor heap
ComPtr<ID3D12Resource> mSwapChainBuffer[cSwapChainBufferCount]; // swap chain bufferek
ComPtr<ID3D12Resource> mDepthStencilBuffer; // depth/stencil buffer
UINT mCurrentBackBuffer; // aktuális backbuffer
D3D12_VIEWPORT mViewPort; // viewport
D3D12_RECT mScissorRect; // scissor rect
protected:
// --- KIRAJZOLANDÓ OBJEKTUMOK
std::vector<Vertex> vertices; // vertexek
std::vector<uint32_t> indices; // indexek
ComPtr<ID3D12Resource> vertexBuffer; // vertex buffer
ComPtr<ID3D12Resource> indexBuffer; // index buffer
D3D12_VERTEX_BUFFER_VIEW vertexBufferView; // ...
D3D12_INDEX_BUFFER_VIEW indexBufferView;
std::vector<D3D12_INPUT_ELEMENT_DESC> inputElements; // input layout elemei
ComPtr<ID3D12RootSignature> rootSignature; // root signature
ComPtr<ID3D12PipelineState> pso; // pipeline state object
ComPtr<ID3DBlob> vertexShader, pixelShader; // vertex- és pixel-shader program
// TODO konstansbuffer példány és DX-objektum
// TODO TRANSZFORMÁCIÓS TULAJDONSÁGOK
void initDrawObjects(); // kirajzolandó objektumok inicializálása
void initVertices(); // vertexek inicializálása
void setupInputLayout(); // input layout beállítása
void createBuffers(); // bufferek elkészítése, tartalmuk betöltése
void uploadBuffers(); // bufferek feltöltése
void loadShaders(); // shaderek betöltése
void createConstantBuffers(); // konstansbufferek létrehozása
void createRootSignature(); // root signature létrehozása
void createPSO(); // PSO létrehozása
void drawObject(); // objektum kirajzolása
void updateConstantBuffers(); // konstansbufferek frissítése
// --------------------
virtual void init(); // inicializáció
void createDevice(); // ...
void createSyncObjects(); // CPU-GPU szinkronizációs objektumok létrehozása
void queryDescriptorSizes(); // lekéri a descriptorok méretét
void createCommandObjects(); // command queue létrehozása
void createSwapChain(); // swap chain létrehozása
void createDescriptorHeaps(); // descriptor heap-ek létrehozása
void createRTVs(); // render target view-k létrehozása
void createDSV(); // depth/stencil létrehozása
void setViewPort(); // viewport beállítása
void setScissorRectangle(); // scissor rectangle beállítása
D3D12_CPU_DESCRIPTOR_HANDLE getCurrentBackBufferRTVHandle() const; // lekéri az aktuális backbuffer handle-jét
D3D12_CPU_DESCRIPTOR_HANDLE getDSVHandle() const; // lekéri az DSV handle-jét
ID3D12Resource * getCurrentBackBuffer() const; // lekéri az aktuális bakcbuffert
void flushCommandQueue(); // ...
public:
DXWindow();
virtual ~DXWindow();
void Draw(const DrawablePool &drawables);
ComPtr<ID3D12Device> getDevice() const; // device elkérése
};
}

113
Geometry.h Normal file
View File

@ -0,0 +1,113 @@
#pragma once
#include <vector>
#include <mutex>
#include "IDrawable.h"
#include <DirectXMath.h>
namespace eg3d {
template<typename vertex_t>
class Geometry : public IDrawable {
private:
ComPtr<ID3D12Device> mDevice; // device
std::vector<vertex_t> mVertices; // vertexek
std::vector<uint32_t> mIndices; // indexek
std::mutex mModifMtx; // ...
// topológia
D3D_PRIMITIVE_TOPOLOGY mTopology;
// bufferek
ComPtr<ID3D12Resource> mVertexBuffer;
ComPtr<ID3D12Resource> mIndexBuffer;
// leírók
D3D12_VERTEX_BUFFER_VIEW mVertexBufferView;
D3D12_INDEX_BUFFER_VIEW mIndexBufferView;
public:
explicit Geometry(ComPtr<ID3D12Device> device) : mDevice(device) {
// topológia beállítása
setTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
}
// másolókonstruktor
Geometry(const Geometry& other) : mDevice(other.mDevice) {
setTopology(other.getTopology());
setVertices(other.getVertices());
setIndices(other.getIndices());
}
// vertexek beállítása
void setVertices(const std::vector<vertex_t> &vertices) {
mVertices = vertices;
size_t bufferSize = mVertices.size() * sizeof(vertex_t); // buffer mérete
mVertexBuffer.Reset(); // buffer törlése
mVertexBuffer = createBuffer_UH(mDevice, bufferSize); // buffer létrehozása
bufferMapCopy(mVertexBuffer, (void *) mVertices.data(), bufferSize); // buffer feltöltése
// vertex buffer view beállítása
mVertexBufferView.BufferLocation = mVertexBuffer->GetGPUVirtualAddress();
mVertexBufferView.StrideInBytes = sizeof(vertex_t);
mVertexBufferView.SizeInBytes = bufferSize;
}
// vertexek lekérése
std::vector<vertex_t> getVertices() const {
return mVertices;
}
// indexek beállítása
void setIndices(const std::vector<uint32_t> &indices) {
mIndices = indices;
size_t bufferSize = mIndices.size() * sizeof(uint32_t); // buffer mérete
mIndexBuffer.Reset(); // buffer törlése
mIndexBuffer = createBuffer_UH(mDevice, bufferSize); // buffer létrehozása
bufferMapCopy(mIndexBuffer, (void *) mIndices.data(), bufferSize); // buffer feltöltése
// index buffer view beállítása
mIndexBufferView.Format = /*(sizeof(IT) == 2) ? DXGI_FORMAT_R16_UINT :*/ DXGI_FORMAT_R32_UINT;
mIndexBufferView.BufferLocation = mIndexBuffer->GetGPUVirtualAddress();
mIndexBufferView.SizeInBytes = bufferSize;
}
// indexek lekérése
std::vector<uint32_t> getIndices() const {
return mIndices;
}
// topológia beállítása
void setTopology(D3D_PRIMITIVE_TOPOLOGY topology) {
mTopology = topology;
}
// topológia beállítása
D3D_PRIMITIVE_TOPOLOGY getTopology() const {
return mTopology;
}
// input assembler beállítása
void setupInputAssembler(ComPtr<ID3D12GraphicsCommandList> commandList) const {
commandList->IASetVertexBuffers(0, 1, &mVertexBufferView);
commandList->IASetIndexBuffer(&mIndexBufferView);
commandList->IASetPrimitiveTopology(mTopology);
}
// kirajzolás
void draw(ComPtr<ID3D12GraphicsCommandList> commandList) const override {
setupInputAssembler(commandList); // input assembler beállítása
commandList->DrawIndexedInstanced(mIndices.size(), 1, 0, 0, 0); // rajzolás
}
};
// geometriatároló típusa
template <typename vertex_t>
using GeometryPool = std::vector<std::shared_ptr<Geometry<vertex_t>>>;
}

15
IDrawable.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <d3d12.h>
#include "utils.h"
namespace eg3d {
class IDrawable {
public:
virtual void draw(ComPtr<ID3D12GraphicsCommandList> commandList) const = 0;
};
// kirajzolható objektumok tárolója
using DrawablePool = std::vector<std::shared_ptr<IDrawable>>;
}

112
Logger.cpp Normal file
View File

@ -0,0 +1,112 @@
#include "Logger.h"
eg3d::Logger gLogger;
namespace eg3d {
const char * Logger::sDEF_LoggerCaption = "Logger";
bool Logger::sWindowClassInitialized = false;
Logger::Logger()
{
// új window class létrehozása
if (!sWindowClassInitialized) {
WNDCLASSEX wcl;
wcl.hInstance = gEntryArgs.hThisInstance;
wcl.lpszClassName = "LoggerWndClass";
wcl.lpfnWndProc = smLoggerWindowFunc;
wcl.style = 0;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(nullptr, IDI_WINLOGO);
wcl.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcl.lpszMenuName = nullptr;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = static_cast<HBRUSH>(GetStockObject(DKGRAY_BRUSH));
if (!RegisterClassEx(&wcl))
{
ERRBOX("Couldn't register window class for eg3d::Window");
}
sWindowClassInitialized = true;
}
// ablak létrehozása
mHWND = CreateWindowA("LoggerWndClass",
"logger",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
nullptr,
gEntryArgs.hThisInstance,
nullptr);
SetWindowLongA(mHWND, GWL_STYLE, GetWindowLongA(mHWND, GWL_STYLE) ^ (WS_THICKFRAME | WS_MAXIMIZEBOX));
UpdateWindow(mHWND);
ShowWindow(mHWND, SW_SHOW);
SetWindowTextA(mHWND, sDEF_LoggerCaption);
// listbox létrehozása
mhListBox = CreateWindow("LISTBOX",
nullptr,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL,
0, 0, sDEF_width, sDEF_height,
mHWND,
nullptr,
gEntryArgs.hThisInstance,
nullptr);
// átméretezés
RECT winRect;
GetWindowRect(mHWND, &winRect);
// terület beállítása
winRect.right = winRect.left + sDEF_width;
winRect.bottom = winRect.top + sDEF_height;
// keret hozzáadása
AdjustWindowRect(&winRect, GetWindowLong(mHWND, GWL_STYLE), false);
//SetWindowPos(mHWND, HWND_TOP, winRect.left, winRect.top, width, height, 0);
SetWindowPos(mHWND, HWND_TOP, winRect.top, winRect.left, winRect.right - winRect.left, winRect.bottom - winRect.top, 0);
UpdateWindow(mHWND);
}
Logger::~Logger()
{
DestroyWindow(mhListBox);
}
void Logger::log(const std::string& text) const
{
SendMessageA(mhListBox, LB_ADDSTRING, 0, (LPARAM)text.c_str());
SendMessageA(mhListBox, WM_VSCROLL, SB_BOTTOM, (LPARAM) nullptr);
}
LRESULT Logger::smLoggerWindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message)
{
// case WM_DESTROY:
// PostQuitMessage(0);
// break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
}

32
Logger.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include "Window.h"
#include "utils.h"
namespace eg3d {
class Logger {
protected:
HWND mHWND; // ablak handle-je
HWND mhListBox; // a gomb handle-je
static bool sWindowClassInitialized; // inicializálva van a window class?
static LRESULT CALLBACK smLoggerWindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); // window process
public:
// ablak szélessége és magassága
static constexpr unsigned sDEF_width = 600;
static constexpr unsigned sDEF_height = 100;
static const char * sDEF_LoggerCaption; // alapértelmezett ablakfelirat
public:
Logger();
~Logger();
void log(const std::string& text) const; // sor felvétele a logba
};
}
extern eg3d::Logger gLogger;
#define LOG(text) gLogger.log(text)

View File

@ -0,0 +1,623 @@
#ifdef __cplusplus
# error "A C++ compiler has been selected for C."
#endif
#if defined(__18CXX)
# define ID_VOID_MAIN
#endif
#if defined(__CLASSIC_C__)
/* cv-qualifiers did not exist in K&R C */
# define const
# define volatile
#endif
/* Version number components: V=Version, R=Revision, P=Patch
Version date components: YYYY=Year, MM=Month, DD=Day */
#if defined(__INTEL_COMPILER) || defined(__ICC)
# define COMPILER_ID "Intel"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
/* __INTEL_COMPILER = VRP */
# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100)
# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10)
# if defined(__INTEL_COMPILER_UPDATE)
# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE)
# else
# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10)
# endif
# if defined(__INTEL_COMPILER_BUILD_DATE)
/* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */
# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE)
# endif
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
#elif defined(__PATHCC__)
# define COMPILER_ID "PathScale"
# define COMPILER_VERSION_MAJOR DEC(__PATHCC__)
# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__)
# if defined(__PATHCC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__)
# endif
#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
# define COMPILER_ID "Embarcadero"
# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF)
# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF)
# define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF)
#elif defined(__BORLANDC__)
# define COMPILER_ID "Borland"
/* __BORLANDC__ = 0xVRR */
# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8)
# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)
#elif defined(__WATCOMC__) && __WATCOMC__ < 1200
# define COMPILER_ID "Watcom"
/* __WATCOMC__ = VVRR */
# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100)
# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
# if (__WATCOMC__ % 10) > 0
# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
# endif
#elif defined(__WATCOMC__)
# define COMPILER_ID "OpenWatcom"
/* __WATCOMC__ = VVRP + 1100 */
# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100)
# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
# if (__WATCOMC__ % 10) > 0
# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
# endif
#elif defined(__SUNPRO_C)
# define COMPILER_ID "SunPro"
# if __SUNPRO_C >= 0x5100
/* __SUNPRO_C = 0xVRRP */
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12)
# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF)
# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
# else
/* __SUNPRO_CC = 0xVRP */
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8)
# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF)
# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
# endif
#elif defined(__HP_cc)
# define COMPILER_ID "HP"
/* __HP_cc = VVRRPP */
# define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000)
# define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100)
# define COMPILER_VERSION_PATCH DEC(__HP_cc % 100)
#elif defined(__DECC)
# define COMPILER_ID "Compaq"
/* __DECC_VER = VVRRTPPPP */
# define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000)
# define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100)
# define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000)
#elif defined(__IBMC__) && defined(__COMPILER_VER__)
# define COMPILER_ID "zOS"
# if defined(__ibmxl__)
# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__)
# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__)
# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__)
# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__)
# else
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
# endif
#elif defined(__ibmxl__) || (defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800)
# define COMPILER_ID "XL"
# if defined(__ibmxl__)
# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__)
# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__)
# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__)
# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__)
# else
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
# endif
#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800
# define COMPILER_ID "VisualAge"
# if defined(__ibmxl__)
# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__)
# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__)
# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__)
# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__)
# else
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
# endif
#elif defined(__PGI)
# define COMPILER_ID "PGI"
# define COMPILER_VERSION_MAJOR DEC(__PGIC__)
# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__)
# if defined(__PGIC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__)
# endif
#elif defined(_CRAYC)
# define COMPILER_ID "Cray"
# define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR)
# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)
#elif defined(__TI_COMPILER_VERSION__)
# define COMPILER_ID "TI"
/* __TI_COMPILER_VERSION__ = VVVRRRPPP */
# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000)
# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000)
# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)
#elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version)
# define COMPILER_ID "Fujitsu"
#elif defined(__TINYC__)
# define COMPILER_ID "TinyCC"
#elif defined(__BCC__)
# define COMPILER_ID "Bruce"
#elif defined(__SCO_VERSION__)
# define COMPILER_ID "SCO"
#elif defined(__clang__) && defined(__apple_build_version__)
# define COMPILER_ID "AppleClang"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
# define COMPILER_VERSION_MAJOR DEC(__clang_major__)
# define COMPILER_VERSION_MINOR DEC(__clang_minor__)
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__)
#elif defined(__clang__)
# define COMPILER_ID "Clang"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
# define COMPILER_VERSION_MAJOR DEC(__clang_major__)
# define COMPILER_VERSION_MINOR DEC(__clang_minor__)
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
#elif defined(__GNUC__)
# define COMPILER_ID "GNU"
# define COMPILER_VERSION_MAJOR DEC(__GNUC__)
# if defined(__GNUC_MINOR__)
# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__)
# endif
# if defined(__GNUC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
# endif
#elif defined(_MSC_VER)
# define COMPILER_ID "MSVC"
/* _MSC_VER = VVRR */
# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100)
# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100)
# if defined(_MSC_FULL_VER)
# if _MSC_VER >= 1400
/* _MSC_FULL_VER = VVRRPPPPP */
# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000)
# else
/* _MSC_FULL_VER = VVRRPPPP */
# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000)
# endif
# endif
# if defined(_MSC_BUILD)
# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD)
# endif
#elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
# define COMPILER_ID "ADSP"
#if defined(__VISUALDSPVERSION__)
/* __VISUALDSPVERSION__ = 0xVVRRPP00 */
# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24)
# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF)
# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF)
#endif
#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
# define COMPILER_ID "IAR"
# if defined(__VER__)
# define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000)
# define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000)
# define COMPILER_VERSION_PATCH DEC((__VER__) % 1000)
# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__)
# endif
#elif defined(__ARMCC_VERSION)
# define COMPILER_ID "ARMCC"
#if __ARMCC_VERSION >= 1000000
/* __ARMCC_VERSION = VRRPPPP */
# define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000)
# define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100)
# define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000)
#else
/* __ARMCC_VERSION = VRPPPP */
# define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000)
# define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10)
# define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000)
#endif
#elif defined(__SDCC_VERSION_MAJOR) || defined(SDCC)
# define COMPILER_ID "SDCC"
# if defined(__SDCC_VERSION_MAJOR)
# define COMPILER_VERSION_MAJOR DEC(__SDCC_VERSION_MAJOR)
# define COMPILER_VERSION_MINOR DEC(__SDCC_VERSION_MINOR)
# define COMPILER_VERSION_PATCH DEC(__SDCC_VERSION_PATCH)
# else
/* SDCC = VRP */
# define COMPILER_VERSION_MAJOR DEC(SDCC/100)
# define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10)
# define COMPILER_VERSION_PATCH DEC(SDCC % 10)
# endif
#elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)
# define COMPILER_ID "MIPSpro"
# if defined(_SGI_COMPILER_VERSION)
/* _SGI_COMPILER_VERSION = VRP */
# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100)
# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10)
# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10)
# else
/* _COMPILER_VERSION = VRP */
# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100)
# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10)
# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10)
# endif
/* These compilers are either not known or too old to define an
identification macro. Try to identify the platform and guess that
it is the native compiler. */
#elif defined(__sgi)
# define COMPILER_ID "MIPSpro"
#elif defined(__hpux) || defined(__hpua)
# define COMPILER_ID "HP"
#else /* unknown compiler */
# define COMPILER_ID ""
#endif
/* Construct the string literal in pieces to prevent the source from
getting matched. Store it in a pointer rather than an array
because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */
char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
#ifdef SIMULATE_ID
char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
#endif
#ifdef __QNXNTO__
char const* qnxnto = "INFO" ":" "qnxnto[]";
#endif
#if defined(__CRAYXE) || defined(__CRAYXC)
char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
#endif
#define STRINGIFY_HELPER(X) #X
#define STRINGIFY(X) STRINGIFY_HELPER(X)
/* Identify known platforms by name. */
#if defined(__linux) || defined(__linux__) || defined(linux)
# define PLATFORM_ID "Linux"
#elif defined(__CYGWIN__)
# define PLATFORM_ID "Cygwin"
#elif defined(__MINGW32__)
# define PLATFORM_ID "MinGW"
#elif defined(__APPLE__)
# define PLATFORM_ID "Darwin"
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
# define PLATFORM_ID "Windows"
#elif defined(__FreeBSD__) || defined(__FreeBSD)
# define PLATFORM_ID "FreeBSD"
#elif defined(__NetBSD__) || defined(__NetBSD)
# define PLATFORM_ID "NetBSD"
#elif defined(__OpenBSD__) || defined(__OPENBSD)
# define PLATFORM_ID "OpenBSD"
#elif defined(__sun) || defined(sun)
# define PLATFORM_ID "SunOS"
#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
# define PLATFORM_ID "AIX"
#elif defined(__sgi) || defined(__sgi__) || defined(_SGI)
# define PLATFORM_ID "IRIX"
#elif defined(__hpux) || defined(__hpux__)
# define PLATFORM_ID "HP-UX"
#elif defined(__HAIKU__)
# define PLATFORM_ID "Haiku"
#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
# define PLATFORM_ID "BeOS"
#elif defined(__QNX__) || defined(__QNXNTO__)
# define PLATFORM_ID "QNX"
#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
# define PLATFORM_ID "Tru64"
#elif defined(__riscos) || defined(__riscos__)
# define PLATFORM_ID "RISCos"
#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
# define PLATFORM_ID "SINIX"
#elif defined(__UNIX_SV__)
# define PLATFORM_ID "UNIX_SV"
#elif defined(__bsdos__)
# define PLATFORM_ID "BSDOS"
#elif defined(_MPRAS) || defined(MPRAS)
# define PLATFORM_ID "MP-RAS"
#elif defined(__osf) || defined(__osf__)
# define PLATFORM_ID "OSF1"
#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
# define PLATFORM_ID "SCO_SV"
#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
# define PLATFORM_ID "ULTRIX"
#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
# define PLATFORM_ID "Xenix"
#elif defined(__WATCOMC__)
# if defined(__LINUX__)
# define PLATFORM_ID "Linux"
# elif defined(__DOS__)
# define PLATFORM_ID "DOS"
# elif defined(__OS2__)
# define PLATFORM_ID "OS2"
# elif defined(__WINDOWS__)
# define PLATFORM_ID "Windows3x"
# else /* unknown platform */
# define PLATFORM_ID
# endif
#else /* unknown platform */
# define PLATFORM_ID
#endif
/* For windows compilers MSVC and Intel we can determine
the architecture of the compiler being used. This is because
the compilers do not have flags that can change the architecture,
but rather depend on which compiler is being used
*/
#if defined(_WIN32) && defined(_MSC_VER)
# if defined(_M_IA64)
# define ARCHITECTURE_ID "IA64"
# elif defined(_M_X64) || defined(_M_AMD64)
# define ARCHITECTURE_ID "x64"
# elif defined(_M_IX86)
# define ARCHITECTURE_ID "X86"
# elif defined(_M_ARM64)
# define ARCHITECTURE_ID "ARM64"
# elif defined(_M_ARM)
# if _M_ARM == 4
# define ARCHITECTURE_ID "ARMV4I"
# elif _M_ARM == 5
# define ARCHITECTURE_ID "ARMV5I"
# else
# define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM)
# endif
# elif defined(_M_MIPS)
# define ARCHITECTURE_ID "MIPS"
# elif defined(_M_SH)
# define ARCHITECTURE_ID "SHx"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#elif defined(__WATCOMC__)
# if defined(_M_I86)
# define ARCHITECTURE_ID "I86"
# elif defined(_M_IX86)
# define ARCHITECTURE_ID "X86"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
# if defined(__ICCARM__)
# define ARCHITECTURE_ID "ARM"
# elif defined(__ICCAVR__)
# define ARCHITECTURE_ID "AVR"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#else
# define ARCHITECTURE_ID
#endif
/* Convert integer to decimal digit literals. */
#define DEC(n) \
('0' + (((n) / 10000000)%10)), \
('0' + (((n) / 1000000)%10)), \
('0' + (((n) / 100000)%10)), \
('0' + (((n) / 10000)%10)), \
('0' + (((n) / 1000)%10)), \
('0' + (((n) / 100)%10)), \
('0' + (((n) / 10)%10)), \
('0' + ((n) % 10))
/* Convert integer to hex digit literals. */
#define HEX(n) \
('0' + ((n)>>28 & 0xF)), \
('0' + ((n)>>24 & 0xF)), \
('0' + ((n)>>20 & 0xF)), \
('0' + ((n)>>16 & 0xF)), \
('0' + ((n)>>12 & 0xF)), \
('0' + ((n)>>8 & 0xF)), \
('0' + ((n)>>4 & 0xF)), \
('0' + ((n) & 0xF))
/* Construct a string literal encoding the version number components. */
#ifdef COMPILER_VERSION_MAJOR
char const info_version[] = {
'I', 'N', 'F', 'O', ':',
'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',
COMPILER_VERSION_MAJOR,
# ifdef COMPILER_VERSION_MINOR
'.', COMPILER_VERSION_MINOR,
# ifdef COMPILER_VERSION_PATCH
'.', COMPILER_VERSION_PATCH,
# ifdef COMPILER_VERSION_TWEAK
'.', COMPILER_VERSION_TWEAK,
# endif
# endif
# endif
']','\0'};
#endif
/* Construct a string literal encoding the internal version number. */
#ifdef COMPILER_VERSION_INTERNAL
char const info_version_internal[] = {
'I', 'N', 'F', 'O', ':',
'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_',
'i','n','t','e','r','n','a','l','[',
COMPILER_VERSION_INTERNAL,']','\0'};
#endif
/* Construct a string literal encoding the version number components. */
#ifdef SIMULATE_VERSION_MAJOR
char const info_simulate_version[] = {
'I', 'N', 'F', 'O', ':',
's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[',
SIMULATE_VERSION_MAJOR,
# ifdef SIMULATE_VERSION_MINOR
'.', SIMULATE_VERSION_MINOR,
# ifdef SIMULATE_VERSION_PATCH
'.', SIMULATE_VERSION_PATCH,
# ifdef SIMULATE_VERSION_TWEAK
'.', SIMULATE_VERSION_TWEAK,
# endif
# endif
# endif
']','\0'};
#endif
/* Construct the string literal in pieces to prevent the source from
getting matched. Store it in a pointer rather than an array
because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */
char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]";
char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]";
#if !defined(__STDC__)
# if (defined(_MSC_VER) && !defined(__clang__)) \
|| (defined(__ibmxl__) || defined(__IBMC__))
# define C_DIALECT "90"
# else
# define C_DIALECT
# endif
#elif __STDC_VERSION__ >= 201000L
# define C_DIALECT "11"
#elif __STDC_VERSION__ >= 199901L
# define C_DIALECT "99"
#else
# define C_DIALECT "90"
#endif
const char* info_language_dialect_default =
"INFO" ":" "dialect_default[" C_DIALECT "]";
/*--------------------------------------------------------------------------*/
#ifdef ID_VOID_MAIN
void main() {}
#else
# if defined(__CLASSIC_C__)
int main(argc, argv) int argc; char *argv[];
# else
int main(int argc, char* argv[])
# endif
{
int require = 0;
require += info_compiler[argc];
require += info_platform[argc];
require += info_arch[argc];
#ifdef COMPILER_VERSION_MAJOR
require += info_version[argc];
#endif
#ifdef COMPILER_VERSION_INTERNAL
require += info_version_internal[argc];
#endif
#ifdef SIMULATE_ID
require += info_simulate[argc];
#endif
#ifdef SIMULATE_VERSION_MAJOR
require += info_simulate_version[argc];
#endif
#if defined(__CRAYXE) || defined(__CRAYXC)
require += info_cray[argc];
#endif
require += info_language_dialect_default[argc];
(void)argv;
return require;
}
#endif

View File

@ -0,0 +1,2 @@
#include "foo.h"
int main(){}

View File

@ -0,0 +1,20 @@
const char features[] = {"\n"
"C_FEATURE:"
#if _MSC_VER >= 1600
"1"
#else
"0"
#endif
"c_function_prototypes\n"
"C_FEATURE:"
#if _MSC_VER >= 1600
"1"
#else
"0"
#endif
"c_variadic_macros\n"
};
int main(int argc, char** argv) { (void)argv; return features[argc]; }

View File

@ -0,0 +1,35 @@
struct VSInput // vertex shader bemeneti struktúra
{
float3 position_D : POSITION;
};
struct VSOutput // vertex shader kimeneti struktúra
{
float4 position_H : SV_Position;
float3 color : COLOR;
};
VSOutput vs_main(VSInput input)
{
VSOutput output; // vertex shader kimenete
output.position_H = float4(input.position_D, 1.0);
output.color = input.position_D;
return output;
}
struct PSOutput
{
float4 color : SV_Target;
};
PSOutput ps_main(VSOutput input)
{
PSOutput output;
//output.color = float4(0.0f, 1.0f, 0.0f, 1.0f);
output.color = float4(input.color, 1.0f);
return output;
}

View File

@ -0,0 +1,7 @@
SET PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\;C:\Program Files (x86)\HTML Help Workshop;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86;C:\Program Files (x86)\Windows Kits\10\bin\x86;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\\MSBuild\15.0\bin;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\;C:\Program Files (x86)\STMicroelectronics\st_toolset\asm;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Git\cmd;C:\Program Files\CMake\bin;C:\Users\Epagris\AppData\Local\Microsoft\WindowsApps;C:\Users\Epagris\SDK;;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja
:: itt kell megadni a shaderek fordítását
fxc "basic_shader.hlsl" /Od /Zi /T vs_5_0 /E "vs_main" /Fo "vs.cso"
fxc "basic_shader.hlsl" /Od /Zi /T ps_5_0 /E "ps_main" /Fo "ps.cso"
::PAUSE

38
RUNTIME/shaders/ps.asm Normal file
View File

@ -0,0 +1,38 @@
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position 0 xyzw 0 POS float
// COLOR 0 xyz 1 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed | skipOptimization
dcl_input_ps linear v1.xyz
dcl_output o0.xyzw
dcl_temps 1
//
// Initial variable locations:
// v0.x <- input.position_H.x; v0.y <- input.position_H.y; v0.z <- input.position_H.z; v0.w <- input.position_H.w;
// v1.x <- input.color.x; v1.y <- input.color.y; v1.z <- input.color.z;
// o0.x <- <ps_main return value>.color.x; o0.y <- <ps_main return value>.color.y; o0.z <- <ps_main return value>.color.z; o0.w <- <ps_main return value>.color.w
//
#line 32 "C:\Users\Epagris\Desktop\GRAFIKA\WinApi\RUNTIME\shaders\basic_shader.hlsl"
mov r0.xyz, v1.xyzx // r0.x <- output.color.x; r0.y <- output.color.y; r0.z <- output.color.z
mov r0.w, l(1.000000) // r0.w <- output.color.w
#line 34
mov o0.xyzw, r0.xyzw
ret
// Approximately 4 instruction slots used

BIN
RUNTIME/shaders/ps.bin Normal file

Binary file not shown.

BIN
RUNTIME/shaders/ps.cso Normal file

Binary file not shown.

43
RUNTIME/shaders/vs.asm Normal file
View File

@ -0,0 +1,43 @@
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION 0 xyz 0 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position 0 xyzw 0 POS float xyzw
// COLOR 0 xyz 1 NONE float xyz
//
vs_5_0
dcl_globalFlags refactoringAllowed | skipOptimization
dcl_input v0.xyz
dcl_output_siv o0.xyzw, position
dcl_output o1.xyz
dcl_temps 2
//
// Initial variable locations:
// v0.x <- input.position_D.x; v0.y <- input.position_D.y; v0.z <- input.position_D.z;
// o1.x <- <vs_main return value>.color.x; o1.y <- <vs_main return value>.color.y; o1.z <- <vs_main return value>.color.z;
// o0.x <- <vs_main return value>.position_H.x; o0.y <- <vs_main return value>.position_H.y; o0.z <- <vs_main return value>.position_H.z; o0.w <- <vs_main return value>.position_H.w
//
#line 16 "C:\Users\Epagris\Desktop\GRAFIKA\WinApi\RUNTIME\shaders\basic_shader.hlsl"
itof r0.w, l(1) // r0.w <- output.position_H.w
mov r0.xyz, v0.xyzx // r0.x <- output.position_H.x; r0.y <- output.position_H.y; r0.z <- output.position_H.z
#line 17
mov r1.xyz, v0.xyzx // r1.x <- output.color.x; r1.y <- output.color.y; r1.z <- output.color.z
#line 19
mov o0.xyzw, r0.xyzw
mov o1.xyz, r1.xyzx
ret
// Approximately 6 instruction slots used

BIN
RUNTIME/shaders/vs.bin Normal file

Binary file not shown.

BIN
RUNTIME/shaders/vs.cso Normal file

Binary file not shown.

90
Timer.cpp Normal file
View File

@ -0,0 +1,90 @@
//
// Created by Epagris on 2019. 12. 08..
//
#include "Timer.h"
namespace eg3d {
Timer gTmr1s; // 1 másodperces triggeridejû globális idõzítõ
Timer::Timer() : mTriggerTime(sDEF_triggerTime) {
// seconds per count beállítása
int64_t countsPerSecond = 1;
QueryPerformanceFrequency((LARGE_INTEGER *) & countsPerSecond);
mSecondsPerCount = 1.0 / (double) countsPerSecond;
QueryPerformanceCounter((LARGE_INTEGER *) &mLastTimestamp); // aktuális idõ lekérése
mLastTriggerTimestamp = mLastTimestamp;
}
void Timer::tick() {
int64_t currentTime = 0;
QueryPerformanceCounter((LARGE_INTEGER * ) &currentTime);
// eltelt idõ kiszámítása
int64_t timeElapsed = currentTime - mLastTimestamp;
mTimeElapsed = timeElapsed * mSecondsPerCount;
// legutolsó trigger óta eltelt idõ kiszámítása
double triggerTimeElapsed = (currentTime - mLastTriggerTimestamp) * mSecondsPerCount;
// ha elértük a triggeridõt
if (triggerTimeElapsed > mTriggerTime) {
mLastTriggerTimestamp = currentTime;
mRegCBMtx.lock(); // MUTEX!!
// minden feliratkozott függvény meghívása
for (auto cbData : mRegCallbacks) {
cbData.callBackFn(this, &triggerTimeElapsed, cbData.ptr);
}
mRegCBMtx.unlock(); // MUTEX kioldás!!
}
mLastTimestamp = currentTime;
}
bool Timer::reg(const TimerCallbackData &tmrCBData) {
std::unique_lock<std::mutex> lock (mRegCBMtx); // MUTEX!!
if (mRegCallbacks.find(tmrCBData) == mRegCallbacks.end()) { //ha nincs benne az elem
mRegCallbacks.insert(tmrCBData);
return true;
}
// ha benne van
return false;
}
bool Timer::unreg(const TimerCallbackData &tmrCBData) {
std::unique_lock<std::mutex> lock (mRegCBMtx); // MUTEX!!
if (mRegCallbacks.find(tmrCBData) != mRegCallbacks.end()) { //ha benne van az elem, akkor töröljük
mRegCallbacks.erase(tmrCBData);
return true;
}
return false;
}
void Timer::setTriggerTime(const double &triggerTime) {
mTriggerTime = triggerTime;
}
double Timer::getTriggerTime() const {
return mTriggerTime;
}
double Timer::getElapsedTime() const {
return mTimeElapsed;
}
//-----------------------------------------------------------------
bool TimerCallbackData::operator<(const TimerCallbackData &other) const {
return callBackFn < other.callBackFn;
}
}

60
Timer.h Normal file
View File

@ -0,0 +1,60 @@
//
// Created by Epagris on 2019. 12. 08..
//
#ifndef EG3D_TIMER_H
#define EG3D_TIMER_H
#include <cstdint>
#include <windows.h>
#include <profileapi.h>
#include <set>
#include <mutex>
namespace eg3d {
class Timer;
typedef void(*TickCallBackFn)(Timer * pTimer, const double * pTrigTimeElapsed, void * ptr);
struct TimerCallbackData {
TickCallBackFn callBackFn;
void * ptr;
bool operator<(const TimerCallbackData& other) const;
};
class Timer {
private:
double mSecondsPerCount; // óraütések másodpercenként
int64_t mLastTimestamp; // utolsó rögzített idõpont countban
int64_t mLastTriggerTimestamp; // utolsó triggeridõpont countban
double mTimeElapsed; // két tick között eltelt idõt mutatja másodpercben
double mTriggerTime; // idõ melynél jelez az óra másodpercben
std::set<TimerCallbackData> mRegCallbacks;
std::mutex mRegCBMtx;
public:
static constexpr double sDEF_triggerTime = 1; // 1 másodperces triggeridõ
Timer(); // konstr.
void tick(); // léptetés
bool reg(const TimerCallbackData& tmrCBData); // ráfûzés a tick listára
bool unreg(const TimerCallbackData& tmrCBData); // lefûzés a tick listáról
void setTriggerTime(const double& triggerTime); // triggeridõ beállítása
double getTriggerTime() const; // triggeridõ lekérése
double getElapsedTime() const; // lekéri az utolsó két tick közöt eltelt idõt
};
// GLOBLÁIS idõzítõk
extern Timer gTmr1s;
}
#endif //EG3D_TIMER_H

162
Window.cpp Normal file
View File

@ -0,0 +1,162 @@
#include "Window.h"
namespace eg3d {
bool eg3d::Window::mWndClassInitialized = false;
const char * eg3d::Window::sWndClassName = "eg3d_winclass";
Window * Window::pMainWindow = nullptr;
Window::Window(bool show, WinFn pWindowFunction) : pWindowFunction(pWindowFunction == nullptr ? smWindowFunc : pWindowFunction) // ha nullptr van megadva, akkor visszaáll az eredeti függvényre
{
initializeWndClass(this->pWindowFunction); // window class inicializálása
create(); // ablak létrehozása
this->show(show);
}
Window::~Window()
{
DestroyWindow(mHWND);
}
void Window::initializeWndClass(WinFn pWindowFunction)
{
if (!mWndClassInitialized) // ha nincs még inicializálva a window class
{
WNDCLASSEX wcl;
wcl.hInstance = gEntryArgs.hThisInstance;
wcl.lpszClassName = sWndClassName;
wcl.lpfnWndProc = pWindowFunction;
wcl.style = 0;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(nullptr, IDI_WINLOGO);
wcl.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcl.lpszMenuName = nullptr;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = static_cast<HBRUSH>(GetStockObject(DKGRAY_BRUSH));
if (!RegisterClassEx(&wcl))
{
ERRBOX("Couldn't register window class for eg3d::Window");
}
mWndClassInitialized = true;
}
}
void Window::setSize(unsigned width, unsigned height) const
{
RECT winRect = getRect(); // ablak-téglalap lekérése
// terület beállítása
winRect.right = winRect.left + width;
winRect.bottom = winRect.top + height;
// keret hozzáadása
AdjustWindowRect(&winRect, GetWindowLong(mHWND, GWL_STYLE), false);
//SetWindowPos(mHWND, HWND_TOP, winRect.left, winRect.top, width, height, 0);
SetWindowPos(mHWND, HWND_TOP, winRect.top, winRect.left, winRect.right - winRect.left, winRect.bottom - winRect.top, 0);
UpdateWindow(mHWND);
}
SIZE Window::getSize() const
{
SIZE result;
RECT clientRect = getClientRect();
result.cx = clientRect.right - clientRect.left;
result.cy = clientRect.bottom - clientRect.top;
return result;
}
void Window::setTitle(const std::string& title) const
{
SetWindowTextA(mHWND, title.c_str());
}
std::string Window::getTitle() const
{
int titleLength = GetWindowTextLengthA(mHWND);
auto szTitle = new char[titleLength + 1];
GetWindowTextA(mHWND, szTitle, titleLength + 1);
std::string title(szTitle);
delete[] szTitle;
return title;
}
void Window::show(bool show) const
{
ShowWindow(mHWND, show ? SW_SHOW : SW_HIDE);
}
RECT Window::getRect() const
{
RECT winRect;
GetWindowRect(mHWND, &winRect);
return winRect;
}
RECT Window::getClientRect() const
{
RECT clRect;
GetClientRect(mHWND, &clRect);
return clRect;
}
////////////////////////////////////////////
LRESULT Window::smWindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
void Window::create()
{
// ablak létrehozása
mHWND = CreateWindowA(sWndClassName,
"window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
nullptr,
gEntryArgs.hThisInstance,
nullptr);
SetWindowLongPtrA(mHWND, GWLP_USERDATA, (LONG_PTR) this);
}
HWND Window::getHandle() const {
return mHWND;
}
double Window::getAspectRatio() const {
SIZE size = getSize();
return (double) size.cx / (double) size.cy;
}
void Window::setThisAsMainWindow() {
pMainWindow = this;
}
}

50
Window.h Normal file
View File

@ -0,0 +1,50 @@
#pragma once
#include <Windows.h>
#include <string>
#include "utils.h"
namespace eg3d {
typedef LRESULT /*CALLBACK*/ (*WinFn)(HWND, UINT, WPARAM, LPARAM);
class Window {
private:
static bool mWndClassInitialized; // már inicializálva van a window class
static void initializeWndClass(WinFn pWindowFunction); // használt window class inicializálása
//////////////
static LRESULT CALLBACK smWindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); // window process, mely az ablakhoz lesz kötve
protected:
void create(); // ablak létrehozása
HWND mHWND; // ablak-handler
const WinFn pWindowFunction; // ablakkezelõ függvény pointere
static Window * pMainWindow; // fõablak
public:
static const char * sWndClassName;
explicit Window(bool show = true, WinFn pWindowFunction = smWindowFunc); // konstr.
//explicit Window(WinFn pWindowFunction = smWindowFunc); // ablakkezelõ-függvény beállítása
virtual ~Window(); // destr.
void setSize(unsigned width, unsigned height) const; // méret beállítása
SIZE getSize() const; // méret lekérése
RECT getRect() const; // ablakot leíró téglalap lekérése
RECT getClientRect() const; // felhasználható területet leíró téglalap lekérése
void setTitle(const std::string& title) const; // cím beállítása
std::string getTitle() const; // cím lekérése
void show(bool show) const; // megjelenítés vagy elrejtés
HWND getHandle() const; // lekéri a HANDLE-t
double getAspectRatio() const; // lekéri a képarányt
void setThisAsMainWindow(); // ezt az ablakot állítja be fõablaknak
};
}

View File

@ -0,0 +1,665 @@
#ifdef __cplusplus
# error "A C++ compiler has been selected for C."
#endif
#if defined(__18CXX)
# define ID_VOID_MAIN
#endif
#if defined(__CLASSIC_C__)
/* cv-qualifiers did not exist in K&R C */
# define const
# define volatile
#endif
/* Version number components: V=Version, R=Revision, P=Patch
Version date components: YYYY=Year, MM=Month, DD=Day */
#if defined(__INTEL_COMPILER) || defined(__ICC)
# define COMPILER_ID "Intel"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
# if defined(__GNUC__)
# define SIMULATE_ID "GNU"
# endif
/* __INTEL_COMPILER = VRP */
# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100)
# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10)
# if defined(__INTEL_COMPILER_UPDATE)
# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE)
# else
# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10)
# endif
# if defined(__INTEL_COMPILER_BUILD_DATE)
/* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */
# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE)
# endif
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
# if defined(__GNUC__)
# define SIMULATE_VERSION_MAJOR DEC(__GNUC__)
# elif defined(__GNUG__)
# define SIMULATE_VERSION_MAJOR DEC(__GNUG__)
# endif
# if defined(__GNUC_MINOR__)
# define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__)
# endif
# if defined(__GNUC_PATCHLEVEL__)
# define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
# endif
#elif defined(__PATHCC__)
# define COMPILER_ID "PathScale"
# define COMPILER_VERSION_MAJOR DEC(__PATHCC__)
# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__)
# if defined(__PATHCC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__)
# endif
#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
# define COMPILER_ID "Embarcadero"
# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF)
# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF)
# define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF)
#elif defined(__BORLANDC__)
# define COMPILER_ID "Borland"
/* __BORLANDC__ = 0xVRR */
# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8)
# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)
#elif defined(__WATCOMC__) && __WATCOMC__ < 1200
# define COMPILER_ID "Watcom"
/* __WATCOMC__ = VVRR */
# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100)
# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
# if (__WATCOMC__ % 10) > 0
# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
# endif
#elif defined(__WATCOMC__)
# define COMPILER_ID "OpenWatcom"
/* __WATCOMC__ = VVRP + 1100 */
# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100)
# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
# if (__WATCOMC__ % 10) > 0
# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
# endif
#elif defined(__SUNPRO_C)
# define COMPILER_ID "SunPro"
# if __SUNPRO_C >= 0x5100
/* __SUNPRO_C = 0xVRRP */
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12)
# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF)
# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
# else
/* __SUNPRO_CC = 0xVRP */
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8)
# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF)
# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
# endif
#elif defined(__HP_cc)
# define COMPILER_ID "HP"
/* __HP_cc = VVRRPP */
# define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000)
# define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100)
# define COMPILER_VERSION_PATCH DEC(__HP_cc % 100)
#elif defined(__DECC)
# define COMPILER_ID "Compaq"
/* __DECC_VER = VVRRTPPPP */
# define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000)
# define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100)
# define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000)
#elif defined(__IBMC__) && defined(__COMPILER_VER__)
# define COMPILER_ID "zOS"
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
#elif defined(__ibmxl__) && defined(__clang__)
# define COMPILER_ID "XLClang"
# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__)
# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__)
# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__)
# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__)
#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800
# define COMPILER_ID "XL"
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800
# define COMPILER_ID "VisualAge"
/* __IBMC__ = VRP */
# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
#elif defined(__PGI)
# define COMPILER_ID "PGI"
# define COMPILER_VERSION_MAJOR DEC(__PGIC__)
# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__)
# if defined(__PGIC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__)
# endif
#elif defined(_CRAYC)
# define COMPILER_ID "Cray"
# define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR)
# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)
#elif defined(__TI_COMPILER_VERSION__)
# define COMPILER_ID "TI"
/* __TI_COMPILER_VERSION__ = VVVRRRPPP */
# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000)
# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000)
# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)
#elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version)
# define COMPILER_ID "Fujitsu"
#elif defined(__ghs__)
# define COMPILER_ID "GHS"
/* __GHS_VERSION_NUMBER = VVVVRP */
# ifdef __GHS_VERSION_NUMBER
# define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100)
# define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10)
# define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10)
# endif
#elif defined(__TINYC__)
# define COMPILER_ID "TinyCC"
#elif defined(__BCC__)
# define COMPILER_ID "Bruce"
#elif defined(__SCO_VERSION__)
# define COMPILER_ID "SCO"
#elif defined(__ARMCC_VERSION) && !defined(__clang__)
# define COMPILER_ID "ARMCC"
#if __ARMCC_VERSION >= 1000000
/* __ARMCC_VERSION = VRRPPPP */
# define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000)
# define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100)
# define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000)
#else
/* __ARMCC_VERSION = VRPPPP */
# define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000)
# define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10)
# define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000)
#endif
#elif defined(__clang__) && defined(__apple_build_version__)
# define COMPILER_ID "AppleClang"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
# define COMPILER_VERSION_MAJOR DEC(__clang_major__)
# define COMPILER_VERSION_MINOR DEC(__clang_minor__)
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__)
#elif defined(__clang__) && defined(__ARMCOMPILER_VERSION)
# define COMPILER_ID "ARMClang"
# define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000)
# define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100)
# define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000)
# define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION)
#elif defined(__clang__)
# define COMPILER_ID "Clang"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# endif
# define COMPILER_VERSION_MAJOR DEC(__clang_major__)
# define COMPILER_VERSION_MINOR DEC(__clang_minor__)
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
#elif defined(__GNUC__)
# define COMPILER_ID "GNU"
# define COMPILER_VERSION_MAJOR DEC(__GNUC__)
# if defined(__GNUC_MINOR__)
# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__)
# endif
# if defined(__GNUC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
# endif
#elif defined(_MSC_VER)
# define COMPILER_ID "MSVC"
/* _MSC_VER = VVRR */
# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100)
# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100)
# if defined(_MSC_FULL_VER)
# if _MSC_VER >= 1400
/* _MSC_FULL_VER = VVRRPPPPP */
# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000)
# else
/* _MSC_FULL_VER = VVRRPPPP */
# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000)
# endif
# endif
# if defined(_MSC_BUILD)
# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD)
# endif
#elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
# define COMPILER_ID "ADSP"
#if defined(__VISUALDSPVERSION__)
/* __VISUALDSPVERSION__ = 0xVVRRPP00 */
# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24)
# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF)
# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF)
#endif
#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
# define COMPILER_ID "IAR"
# if defined(__VER__) && defined(__ICCARM__)
# define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000)
# define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000)
# define COMPILER_VERSION_PATCH DEC((__VER__) % 1000)
# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__)
# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__))
# define COMPILER_VERSION_MAJOR DEC((__VER__) / 100)
# define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100))
# define COMPILER_VERSION_PATCH DEC(__SUBVERSION__)
# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__)
# endif
#elif defined(__SDCC_VERSION_MAJOR) || defined(SDCC)
# define COMPILER_ID "SDCC"
# if defined(__SDCC_VERSION_MAJOR)
# define COMPILER_VERSION_MAJOR DEC(__SDCC_VERSION_MAJOR)
# define COMPILER_VERSION_MINOR DEC(__SDCC_VERSION_MINOR)
# define COMPILER_VERSION_PATCH DEC(__SDCC_VERSION_PATCH)
# else
/* SDCC = VRP */
# define COMPILER_VERSION_MAJOR DEC(SDCC/100)
# define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10)
# define COMPILER_VERSION_PATCH DEC(SDCC % 10)
# endif
/* These compilers are either not known or too old to define an
identification macro. Try to identify the platform and guess that
it is the native compiler. */
#elif defined(__hpux) || defined(__hpua)
# define COMPILER_ID "HP"
#else /* unknown compiler */
# define COMPILER_ID ""
#endif
/* Construct the string literal in pieces to prevent the source from
getting matched. Store it in a pointer rather than an array
because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */
char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
#ifdef SIMULATE_ID
char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
#endif
#ifdef __QNXNTO__
char const* qnxnto = "INFO" ":" "qnxnto[]";
#endif
#if defined(__CRAYXE) || defined(__CRAYXC)
char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
#endif
#define STRINGIFY_HELPER(X) #X
#define STRINGIFY(X) STRINGIFY_HELPER(X)
/* Identify known platforms by name. */
#if defined(__linux) || defined(__linux__) || defined(linux)
# define PLATFORM_ID "Linux"
#elif defined(__CYGWIN__)
# define PLATFORM_ID "Cygwin"
#elif defined(__MINGW32__)
# define PLATFORM_ID "MinGW"
#elif defined(__APPLE__)
# define PLATFORM_ID "Darwin"
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
# define PLATFORM_ID "Windows"
#elif defined(__FreeBSD__) || defined(__FreeBSD)
# define PLATFORM_ID "FreeBSD"
#elif defined(__NetBSD__) || defined(__NetBSD)
# define PLATFORM_ID "NetBSD"
#elif defined(__OpenBSD__) || defined(__OPENBSD)
# define PLATFORM_ID "OpenBSD"
#elif defined(__sun) || defined(sun)
# define PLATFORM_ID "SunOS"
#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
# define PLATFORM_ID "AIX"
#elif defined(__hpux) || defined(__hpux__)
# define PLATFORM_ID "HP-UX"
#elif defined(__HAIKU__)
# define PLATFORM_ID "Haiku"
#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
# define PLATFORM_ID "BeOS"
#elif defined(__QNX__) || defined(__QNXNTO__)
# define PLATFORM_ID "QNX"
#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
# define PLATFORM_ID "Tru64"
#elif defined(__riscos) || defined(__riscos__)
# define PLATFORM_ID "RISCos"
#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
# define PLATFORM_ID "SINIX"
#elif defined(__UNIX_SV__)
# define PLATFORM_ID "UNIX_SV"
#elif defined(__bsdos__)
# define PLATFORM_ID "BSDOS"
#elif defined(_MPRAS) || defined(MPRAS)
# define PLATFORM_ID "MP-RAS"
#elif defined(__osf) || defined(__osf__)
# define PLATFORM_ID "OSF1"
#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
# define PLATFORM_ID "SCO_SV"
#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
# define PLATFORM_ID "ULTRIX"
#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
# define PLATFORM_ID "Xenix"
#elif defined(__WATCOMC__)
# if defined(__LINUX__)
# define PLATFORM_ID "Linux"
# elif defined(__DOS__)
# define PLATFORM_ID "DOS"
# elif defined(__OS2__)
# define PLATFORM_ID "OS2"
# elif defined(__WINDOWS__)
# define PLATFORM_ID "Windows3x"
# else /* unknown platform */
# define PLATFORM_ID
# endif
#elif defined(__INTEGRITY)
# if defined(INT_178B)
# define PLATFORM_ID "Integrity178"
# else /* regular Integrity */
# define PLATFORM_ID "Integrity"
# endif
#else /* unknown platform */
# define PLATFORM_ID
#endif
/* For windows compilers MSVC and Intel we can determine
the architecture of the compiler being used. This is because
the compilers do not have flags that can change the architecture,
but rather depend on which compiler is being used
*/
#if defined(_WIN32) && defined(_MSC_VER)
# if defined(_M_IA64)
# define ARCHITECTURE_ID "IA64"
# elif defined(_M_X64) || defined(_M_AMD64)
# define ARCHITECTURE_ID "x64"
# elif defined(_M_IX86)
# define ARCHITECTURE_ID "X86"
# elif defined(_M_ARM64)
# define ARCHITECTURE_ID "ARM64"
# elif defined(_M_ARM)
# if _M_ARM == 4
# define ARCHITECTURE_ID "ARMV4I"
# elif _M_ARM == 5
# define ARCHITECTURE_ID "ARMV5I"
# else
# define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM)
# endif
# elif defined(_M_MIPS)
# define ARCHITECTURE_ID "MIPS"
# elif defined(_M_SH)
# define ARCHITECTURE_ID "SHx"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#elif defined(__WATCOMC__)
# if defined(_M_I86)
# define ARCHITECTURE_ID "I86"
# elif defined(_M_IX86)
# define ARCHITECTURE_ID "X86"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
# if defined(__ICCARM__)
# define ARCHITECTURE_ID "ARM"
# elif defined(__ICCRX__)
# define ARCHITECTURE_ID "RX"
# elif defined(__ICCRH850__)
# define ARCHITECTURE_ID "RH850"
# elif defined(__ICCRL78__)
# define ARCHITECTURE_ID "RL78"
# elif defined(__ICCRISCV__)
# define ARCHITECTURE_ID "RISCV"
# elif defined(__ICCAVR__)
# define ARCHITECTURE_ID "AVR"
# elif defined(__ICC430__)
# define ARCHITECTURE_ID "MSP430"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#elif defined(__ghs__)
# if defined(__PPC64__)
# define ARCHITECTURE_ID "PPC64"
# elif defined(__ppc__)
# define ARCHITECTURE_ID "PPC"
# elif defined(__ARM__)
# define ARCHITECTURE_ID "ARM"
# elif defined(__x86_64__)
# define ARCHITECTURE_ID "x64"
# elif defined(__i386__)
# define ARCHITECTURE_ID "X86"
# else /* unknown architecture */
# define ARCHITECTURE_ID ""
# endif
#else
# define ARCHITECTURE_ID
#endif
/* Convert integer to decimal digit literals. */
#define DEC(n) \
('0' + (((n) / 10000000)%10)), \
('0' + (((n) / 1000000)%10)), \
('0' + (((n) / 100000)%10)), \
('0' + (((n) / 10000)%10)), \
('0' + (((n) / 1000)%10)), \
('0' + (((n) / 100)%10)), \
('0' + (((n) / 10)%10)), \
('0' + ((n) % 10))
/* Convert integer to hex digit literals. */
#define HEX(n) \
('0' + ((n)>>28 & 0xF)), \
('0' + ((n)>>24 & 0xF)), \
('0' + ((n)>>20 & 0xF)), \
('0' + ((n)>>16 & 0xF)), \
('0' + ((n)>>12 & 0xF)), \
('0' + ((n)>>8 & 0xF)), \
('0' + ((n)>>4 & 0xF)), \
('0' + ((n) & 0xF))
/* Construct a string literal encoding the version number components. */
#ifdef COMPILER_VERSION_MAJOR
char const info_version[] = {
'I', 'N', 'F', 'O', ':',
'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',
COMPILER_VERSION_MAJOR,
# ifdef COMPILER_VERSION_MINOR
'.', COMPILER_VERSION_MINOR,
# ifdef COMPILER_VERSION_PATCH
'.', COMPILER_VERSION_PATCH,
# ifdef COMPILER_VERSION_TWEAK
'.', COMPILER_VERSION_TWEAK,
# endif
# endif
# endif
']','\0'};
#endif
/* Construct a string literal encoding the internal version number. */
#ifdef COMPILER_VERSION_INTERNAL
char const info_version_internal[] = {
'I', 'N', 'F', 'O', ':',
'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_',
'i','n','t','e','r','n','a','l','[',
COMPILER_VERSION_INTERNAL,']','\0'};
#endif
/* Construct a string literal encoding the version number components. */
#ifdef SIMULATE_VERSION_MAJOR
char const info_simulate_version[] = {
'I', 'N', 'F', 'O', ':',
's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[',
SIMULATE_VERSION_MAJOR,
# ifdef SIMULATE_VERSION_MINOR
'.', SIMULATE_VERSION_MINOR,
# ifdef SIMULATE_VERSION_PATCH
'.', SIMULATE_VERSION_PATCH,
# ifdef SIMULATE_VERSION_TWEAK
'.', SIMULATE_VERSION_TWEAK,
# endif
# endif
# endif
']','\0'};
#endif
/* Construct the string literal in pieces to prevent the source from
getting matched. Store it in a pointer rather than an array
because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */
char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]";
char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]";
#if !defined(__STDC__)
# if (defined(_MSC_VER) && !defined(__clang__)) \
|| (defined(__ibmxl__) || defined(__IBMC__))
# define C_DIALECT "90"
# else
# define C_DIALECT
# endif
#elif __STDC_VERSION__ >= 201000L
# define C_DIALECT "11"
#elif __STDC_VERSION__ >= 199901L
# define C_DIALECT "99"
#else
# define C_DIALECT "90"
#endif
const char* info_language_dialect_default =
"INFO" ":" "dialect_default[" C_DIALECT "]";
/*--------------------------------------------------------------------------*/
#ifdef ID_VOID_MAIN
void main() {}
#else
# if defined(__CLASSIC_C__)
int main(argc, argv) int argc; char *argv[];
# else
int main(int argc, char* argv[])
# endif
{
int require = 0;
require += info_compiler[argc];
require += info_platform[argc];
require += info_arch[argc];
#ifdef COMPILER_VERSION_MAJOR
require += info_version[argc];
#endif
#ifdef COMPILER_VERSION_INTERNAL
require += info_version_internal[argc];
#endif
#ifdef SIMULATE_ID
require += info_simulate[argc];
#endif
#ifdef SIMULATE_VERSION_MAJOR
require += info_simulate_version[argc];
#endif
#if defined(__CRAYXE) || defined(__CRAYXC)
require += info_cray[argc];
#endif
require += info_language_dialect_default[argc];
(void)argv;
return require;
}
#endif

3468
d3dx12.h Normal file

File diff suppressed because it is too large Load Diff

48
main.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <iostream>
#include <Windows.h>
#include "utils.h"
#include "Logger.h"
#include "DXWindow.h"
#include "Timer.h"
#include "Geometry.h"
// FPS-mérés
size_t gFrames = 0;
void CB_FPSaux(eg3d::Timer *pTimer, const double *pTrigTimeElapsed, void *ptr) {
// TODO képkockaidő és FPS kiszámítása; képkockaszámláló nullázása; eredmények kiírása
}
using namespace eg3d;
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgs, int nWinMode) {
eg3d::DXWindow win; // megjelenítés be, alapértelmezett window procedure használata
win.setTitle("Keretszöveg"); // keretszöveg beállítása
// TODO geometria és pool létrehozása
MSG msg = { };
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} else
{
Sleep(50);
win.Draw(DrawablePool());
}
// TODO egy másodperces periódusidejű óra léptetése
}
return msg.wParam;
}

55
utils.cpp Normal file
View File

@ -0,0 +1,55 @@
#include "utils.h"
void printCurrentDirectory() {
DWORD nBufferLength = 250;
LPWSTR lpBuffer = new WCHAR[nBufferLength];
GetCurrentDirectoryW(nBufferLength, lpBuffer);
//OutputDebugStringW(lpBuffer);
MessageBoxW(nullptr, lpBuffer, L"Current working directory", MB_OK);
}
EntryArgs gEntryArgs;
void EntryArgs::fill(HINSTANCE hThisInstance, LPSTR lpszArgs, int nWinMode) {
this->hThisInstance = hThisInstance;
this->lpszArgs = lpszArgs;
this->nWinMode = nWinMode;
}
ComPtr<ID3DBlob> loadBlob(const std::string& fileName)
{
//printCurrentDirectory();
std::ifstream blobFile(fileName, std::ios::binary);
if (!blobFile.is_open()) // ha nem sikerült megnyitni a fájlt
{
ERRBOX("Could not open blob file '" + fileName + "'!");
return nullptr;
}
blobFile.seekg(0, std::ios::end);
size_t fileSize = blobFile.tellg();
ComPtr<ID3DBlob> pBlob { nullptr }; // blob létrehozása
if(D3DCreateBlob(fileSize, pBlob.GetAddressOf()) != S_OK )
{
ERRBOX("Could not create D3DBlob for loading '" + fileName + "'!");
return nullptr;
}
// fájl beolvasása a blob-ba
blobFile.seekg(0, std::ios::beg);
if (blobFile.read(reinterpret_cast<char*>(pBlob->GetBufferPointer()), fileSize))
{
return pBlob;
}
ERRBOX("Failed to load '" + fileName + "' into buffer!");
return nullptr;
}
size_t calc256AlignedSize(size_t origSize) {
return (origSize + 255) & ~255;
}

78
utils.h Normal file
View File

@ -0,0 +1,78 @@
#pragma once
#include <string>
#include <wrl.h>
#include <d3dcompiler.h>
#include <d3d12.h>
#include <fstream>
#include <locale>
#include <codecvt>
#include "Logger.h"
#include "d3dx12.h"
#define ERRBOX(msg) MessageBoxA(nullptr, std::string(msg).c_str(), "Error!", MB_OK)
#define MSGBOX(msg) MessageBoxA(nullptr, std::string(msg).c_str(), "Info", MB_OK)
template<typename T>
using ComPtr = Microsoft::WRL::ComPtr<T>;
void printCurrentDirectory(); // aktuális környezet elérésének kiírása
// GLOBÁLIS WinApi paraméterek
struct EntryArgs {
HINSTANCE hThisInstance;
LPSTR lpszArgs;
int nWinMode;
void fill(HINSTANCE hThisInstance, LPSTR lpszArgs, int nWinMode); // mezõk kitöltése
};
extern EntryArgs gEntryArgs;
// bináris fájl betöltése egy blobba
ComPtr<ID3DBlob> loadBlob(const std::string& fileName);
// kiszámítja a mérethez tartozó legkisebb 256-bájtos blokkból álló memóriablokk méretét
size_t calc256AlignedSize(size_t origSize);
inline std::wstring AnsiToWString(const std::string& str)
{
WCHAR buffer[512];
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, buffer, 512);
return std::wstring(buffer);
}
inline std::string WStringToAnsi(const std::wstring& wstr)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
return converter.to_bytes(wstr);
}
// buffer létrehozása az upload heapen
inline ComPtr<ID3D12Resource> createBuffer_UH(ComPtr<ID3D12Device> device, size_t bufferSize)
{
ComPtr<ID3D12Resource> buffer = nullptr;
if (FAILED(device->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(bufferSize),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(buffer.GetAddressOf()))))
ERRBOX("Failed to create buffer on upload heap!");
return buffer;
}
// upload heapen elhelyezkedõ buffer feltöltése adattal a rendszermemóriából
inline void bufferMapCopy(ComPtr<ID3D12Resource> bufferResource, void * data, size_t size)
{
BYTE * mappedData;
bufferResource->Map(0, nullptr, reinterpret_cast<void**>(&mappedData));
memcpy(mappedData, data, size);
bufferResource->Unmap(0, nullptr);
}