mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa Vertex e IndexBuffer
This commit is contained in:
parent
451d48f020
commit
28dae3df60
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# Add source to this project's executable.
|
# Add source to this project's executable.
|
||||||
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizer-dx.cpp")
|
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizer-dx.cpp" "platform/vertexbuffer-dx.cpp" "platform/indexbuffer-dx.cpp")
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||||
set_property(TARGET xna PROPERTY CXX_STANDARD 20)
|
set_property(TARGET xna PROPERTY CXX_STANDARD 20)
|
||||||
|
18
framework/common/color.hpp
Normal file
18
framework/common/color.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef XNA_COMMON_COLOR_HPP
|
||||||
|
#define XNA_COMMON_COLOR_HPP
|
||||||
|
|
||||||
|
#include "../default.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
struct Color {
|
||||||
|
constexpr Color() = default;
|
||||||
|
|
||||||
|
Uint packedValue{0};
|
||||||
|
|
||||||
|
constexpr bool operator==(const Color& other) const {
|
||||||
|
return packedValue == other.packedValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -79,6 +79,8 @@ namespace xna {
|
|||||||
//Graphics
|
//Graphics
|
||||||
class BlendState;
|
class BlendState;
|
||||||
using PBlendState = std::shared_ptr<BlendState>;
|
using PBlendState = std::shared_ptr<BlendState>;
|
||||||
|
class ConstantBuffer;
|
||||||
|
using PConstantBuffer = std::shared_ptr<ConstantBuffer>;
|
||||||
class DisplayMode;
|
class DisplayMode;
|
||||||
using PDisplayMode = std::shared_ptr<DisplayMode>;
|
using PDisplayMode = std::shared_ptr<DisplayMode>;
|
||||||
class DisplayModeCollection;
|
class DisplayModeCollection;
|
||||||
@ -103,8 +105,12 @@ namespace xna {
|
|||||||
using PRasterizerState = std::shared_ptr<RasterizerState>;
|
using PRasterizerState = std::shared_ptr<RasterizerState>;
|
||||||
class Shader;
|
class Shader;
|
||||||
using PShader = std::shared_ptr<Shader>;
|
using PShader = std::shared_ptr<Shader>;
|
||||||
|
class VertexBuffer;
|
||||||
|
using PVertexBuffer = std::shared_ptr<VertexBuffer>;
|
||||||
class VertexInputLayout;
|
class VertexInputLayout;
|
||||||
using PVertexInputLayout = std::shared_ptr<VertexInputLayout>;
|
using PVertexInputLayout = std::shared_ptr<VertexInputLayout>;
|
||||||
|
struct VertexPositionColor;
|
||||||
|
using PVertexPositionColor = std::shared_ptr<VertexPositionColor>;
|
||||||
class VertexShader;
|
class VertexShader;
|
||||||
using pVertexShader = std::shared_ptr<VertexShader>;
|
using pVertexShader = std::shared_ptr<VertexShader>;
|
||||||
struct Viewport;
|
struct Viewport;
|
||||||
|
0
framework/graphics/constbuffer.hpp
Normal file
0
framework/graphics/constbuffer.hpp
Normal file
14
framework/graphics/indexbuffer.hpp
Normal file
14
framework/graphics/indexbuffer.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef XNA_GRAPHICS_INDEXBUFFER_HPP
|
||||||
|
#define XNA_GRAPHICS_INDEXBUFFER_HPP
|
||||||
|
|
||||||
|
#include "../default.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
class IIndexBuffer {
|
||||||
|
public:
|
||||||
|
virtual ~IIndexBuffer() {}
|
||||||
|
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
14
framework/graphics/vertexbuffer.hpp
Normal file
14
framework/graphics/vertexbuffer.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef XNA_GRAPHICS_VERTEXBUFFER_HPP
|
||||||
|
#define XNA_GRAPHICS_VERTEXBUFFER_HPP
|
||||||
|
|
||||||
|
#include "../default.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
class IVertexBuffer {
|
||||||
|
public:
|
||||||
|
virtual ~IVertexBuffer(){}
|
||||||
|
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
61
framework/graphics/vertexposition.hpp
Normal file
61
framework/graphics/vertexposition.hpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#ifndef XNA_GRAPHICS_VERTEXPOSITION_HPP
|
||||||
|
#define XNA_GRAPHICS_VERTEXPOSITION_HPP
|
||||||
|
|
||||||
|
#include "../common/vectors.hpp"
|
||||||
|
#include "../common/color.hpp"
|
||||||
|
#include "../default.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
struct VertexPositionColor {
|
||||||
|
Vector3 position{};
|
||||||
|
Color color{};
|
||||||
|
|
||||||
|
constexpr VertexPositionColor() = default;
|
||||||
|
|
||||||
|
constexpr bool operator==(const VertexPositionColor& other) const {
|
||||||
|
return position == other.position && color == other.color;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexPositionTexture {
|
||||||
|
Vector3 position{};
|
||||||
|
Vector2 textureCoordinate{};
|
||||||
|
|
||||||
|
constexpr VertexPositionTexture() = default;
|
||||||
|
|
||||||
|
constexpr bool operator==(const VertexPositionTexture& other) const {
|
||||||
|
return position == other.position
|
||||||
|
&& textureCoordinate == other.textureCoordinate;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexPositionColorTexture {
|
||||||
|
Vector3 position{};
|
||||||
|
Vector2 textureCoodinate{};
|
||||||
|
Color color{};
|
||||||
|
|
||||||
|
constexpr VertexPositionColorTexture() = default;
|
||||||
|
|
||||||
|
constexpr bool operator==(const VertexPositionColorTexture& other) const {
|
||||||
|
return position == other.position
|
||||||
|
&& textureCoodinate == other.textureCoodinate
|
||||||
|
&& color == other.color;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexPositionNormalTexture {
|
||||||
|
Vector3 position{};
|
||||||
|
Vector3 normal{};
|
||||||
|
Vector2 textureCoodinate{};
|
||||||
|
|
||||||
|
constexpr VertexPositionNormalTexture() = default;
|
||||||
|
|
||||||
|
bool operator==(const VertexPositionNormalTexture& other) const {
|
||||||
|
return position == other.position
|
||||||
|
&& normal == other.normal
|
||||||
|
&& textureCoodinate == other.textureCoodinate;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
#include "dxgi.h"
|
#include "dxgi.h"
|
||||||
#include "d3d11.h"
|
#include "d3d11.h"
|
||||||
#include <d3dcompiler.h>
|
#include <d3dcompiler.h>
|
||||||
|
#include <DirectXMath.h>
|
47
framework/platform/indexbuffer-dx.cpp
Normal file
47
framework/platform/indexbuffer-dx.cpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include "indexbuffer-dx.hpp"
|
||||||
|
#include "device-dx.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
bool IndexBuffer::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
|
||||||
|
{
|
||||||
|
if (!device._device) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_buffer) {
|
||||||
|
_buffer->Release();
|
||||||
|
_buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: refatorar isso aqui
|
||||||
|
int IndicesPerSprite = 4;
|
||||||
|
int MaxBatchSize = 4096;
|
||||||
|
int VerticesPerSprite = 4;
|
||||||
|
|
||||||
|
std::vector<short> indices;
|
||||||
|
indices.reserve(MaxBatchSize * IndicesPerSprite);
|
||||||
|
|
||||||
|
for (short i = 0; i < (MaxBatchSize * VerticesPerSprite); i += VerticesPerSprite)
|
||||||
|
{
|
||||||
|
indices.push_back(i);
|
||||||
|
indices.push_back(i + 1);
|
||||||
|
indices.push_back(i + 2);
|
||||||
|
|
||||||
|
indices.push_back(i + 1);
|
||||||
|
indices.push_back(i + 3);
|
||||||
|
indices.push_back(i + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
_initialData.pSysMem = &indices.front();
|
||||||
|
|
||||||
|
const auto hr = device._device->CreateBuffer(&_description, &_initialData, &_buffer);
|
||||||
|
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
40
framework/platform/indexbuffer-dx.hpp
Normal file
40
framework/platform/indexbuffer-dx.hpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifndef XNA_PLATFORM_INDEXBUFFER_DX_HPP
|
||||||
|
#define XNA_PLATFORM_INDEXBUFFER_DX_HPP
|
||||||
|
|
||||||
|
#include "../graphics/indexbuffer.hpp"
|
||||||
|
#include "dxheaders.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
class IndexBuffer : public IIndexBuffer {
|
||||||
|
public:
|
||||||
|
IndexBuffer() {
|
||||||
|
_description.Usage = D3D11_USAGE_DEFAULT;
|
||||||
|
_description.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexBuffer(size_t size) {
|
||||||
|
_description.ByteWidth = static_cast<UINT>(size);
|
||||||
|
_description.Usage = D3D11_USAGE_DEFAULT;
|
||||||
|
_description.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexBuffer(D3D11_BUFFER_DESC desc) : _description(desc){}
|
||||||
|
|
||||||
|
virtual ~IndexBuffer() override {
|
||||||
|
if (_buffer) {
|
||||||
|
_buffer->Release();
|
||||||
|
_buffer = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
D3D11_BUFFER_DESC _description;
|
||||||
|
ID3D11Buffer* _buffer = nullptr;
|
||||||
|
D3D11_SUBRESOURCE_DATA _initialData{}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
29
framework/platform/vertexbuffer-dx.cpp
Normal file
29
framework/platform/vertexbuffer-dx.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "vertexbuffer-dx.hpp"
|
||||||
|
#include "device-dx.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
bool VertexBuffer::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
|
||||||
|
{
|
||||||
|
if (!device._device) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_buffer) {
|
||||||
|
_buffer->Release();
|
||||||
|
_buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto hr = device._device->CreateBuffer(
|
||||||
|
&_description,
|
||||||
|
_useInitialData ? &_initialData : nullptr,
|
||||||
|
&_buffer);
|
||||||
|
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
43
framework/platform/vertexbuffer-dx.hpp
Normal file
43
framework/platform/vertexbuffer-dx.hpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#ifndef XNA_PLATFORM_VERTEXBUFFER_DX_HPP
|
||||||
|
#define XNA_PLATFORM_VERTEXBUFFER_DX_HPP
|
||||||
|
|
||||||
|
#include "../graphics/vertexbuffer.hpp"
|
||||||
|
#include "dxheaders.hpp"
|
||||||
|
#include "../graphics/vertexposition.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
class VertexBuffer : public IVertexBuffer {
|
||||||
|
public:
|
||||||
|
VertexBuffer() {
|
||||||
|
_description.Usage = D3D11_USAGE_DYNAMIC;
|
||||||
|
_description.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||||
|
_description.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VertexBuffer(size_t size) {
|
||||||
|
_description.ByteWidth = static_cast<UINT>(size);
|
||||||
|
_description.Usage = D3D11_USAGE_DYNAMIC;
|
||||||
|
_description.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||||
|
_description.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VertexBuffer(D3D11_BUFFER_DESC desc) : _description(desc){}
|
||||||
|
|
||||||
|
virtual ~VertexBuffer() override {
|
||||||
|
if (_buffer) {
|
||||||
|
_buffer->Release();
|
||||||
|
_buffer = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
D3D11_BUFFER_DESC _description{};
|
||||||
|
D3D11_SUBRESOURCE_DATA _initialData{};
|
||||||
|
bool _useInitialData{ false };
|
||||||
|
ID3D11Buffer* _buffer = nullptr;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -7,6 +7,7 @@ namespace xna {
|
|||||||
ARGUMENT_OUT_OF_RANGE,
|
ARGUMENT_OUT_OF_RANGE,
|
||||||
ARGUMENT_IS_NULL,
|
ARGUMENT_IS_NULL,
|
||||||
INVALID_OPERATION,
|
INVALID_OPERATION,
|
||||||
|
FAILED_OPERATION,
|
||||||
OVERFLOW_OPERATION,
|
OVERFLOW_OPERATION,
|
||||||
NULL_CAST,
|
NULL_CAST,
|
||||||
BAD_CAST,
|
BAD_CAST,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user