init commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API DeviceBuffer
|
||||
{
|
||||
public:
|
||||
void init(size_t _length);
|
||||
void clear(void);
|
||||
|
||||
size_t length(void) const { return m_length; }
|
||||
|
||||
const uint8_t* ptr(size_t offseet) const {
|
||||
return m_ptr + offseet;
|
||||
}
|
||||
|
||||
uint8_t* ptr(size_t offseet) {
|
||||
return m_ptr + offseet;
|
||||
}
|
||||
private:
|
||||
uint8_t* m_ptr;
|
||||
size_t m_length;
|
||||
|
||||
public:
|
||||
DeviceBuffer();
|
||||
DeviceBuffer(size_t _length);
|
||||
~DeviceBuffer();
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_buffer_view.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API DeviceBufferAccessor
|
||||
{
|
||||
public:
|
||||
const DeviceBufferViewConstPtr getBufferView(void) const {
|
||||
return m_bufferView;
|
||||
}
|
||||
|
||||
void walk(std::function<bool(const uint8_t*, size_t)> callback, size_t start = 0, size_t end = ((size_t)-1)) const;
|
||||
void walk2(std::function<bool(const uint8_t*, const uint8_t*, size_t)> callback, size_t start = 0, size_t end = ((size_t)-1)) const;
|
||||
void walk3(std::function<bool(const uint8_t*, const uint8_t*, const uint8_t*, size_t)> callback, size_t start = 0, size_t end = ((size_t)-1)) const;
|
||||
|
||||
const uint8_t* getElement(size_t index) const;
|
||||
|
||||
size_t getOffset(void) const {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
size_t getCount(void) const {
|
||||
return m_count;
|
||||
}
|
||||
|
||||
ComponentType getComponentType(void) const {
|
||||
return m_componentType;
|
||||
}
|
||||
|
||||
DataType getDataType(void) const {
|
||||
return m_dataType;
|
||||
}
|
||||
|
||||
size_t getElementSize(void) const {
|
||||
return m_elementSize;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
DeviceBufferViewConstPtr m_bufferView;
|
||||
size_t m_offset;
|
||||
size_t m_count;
|
||||
ComponentType m_componentType;
|
||||
DataType m_dataType;
|
||||
|
||||
size_t m_elementSize;
|
||||
|
||||
public:
|
||||
DeviceBufferAccessor(DeviceBufferViewConstPtr bufferView, size_t offset, size_t count, ComponentType componentType, DataType dataType);
|
||||
~DeviceBufferAccessor();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_buffer.h"
|
||||
#include "dvc_pre_declare.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API DeviceBufferView
|
||||
{
|
||||
public:
|
||||
const DeviceBufferConstPtr getBuffer(void) const {
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
size_t getOffset(void) const {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
size_t getLength(void) const {
|
||||
return m_length;
|
||||
}
|
||||
|
||||
size_t getStride(void) const {
|
||||
return m_stride;
|
||||
}
|
||||
|
||||
private:
|
||||
DeviceBufferConstPtr m_buffer;
|
||||
size_t m_offset;
|
||||
size_t m_length;
|
||||
size_t m_stride;
|
||||
|
||||
public:
|
||||
DeviceBufferView(DeviceBufferConstPtr buffer, size_t offset, size_t length, size_t stride);
|
||||
~DeviceBufferView();
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
template<typename T>
|
||||
class PixelBuffer
|
||||
{
|
||||
public:
|
||||
void init(int width, int height, const T& pixel) {
|
||||
assert(width > 0 && width < 0xFFFF);
|
||||
assert(height > 0 && height < 0xFFFF);
|
||||
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_pixelBuffer.resize((size_t)(width * height));
|
||||
clear(pixel);
|
||||
}
|
||||
|
||||
void clear(const T& pixel) {
|
||||
std::fill(m_pixelBuffer.begin(), m_pixelBuffer.end(), pixel);
|
||||
}
|
||||
|
||||
void setPixel(int32_t x, int32_t y, const T& pixel) {
|
||||
assert(x >= 0 && x < m_width);
|
||||
assert(y >= 0 && y < m_height);
|
||||
|
||||
m_pixelBuffer[(size_t)(y * m_width + x)] = pixel;
|
||||
}
|
||||
|
||||
const T& getPixel(int32_t x, int32_t y) const {
|
||||
assert(x >= 0 && x < m_width);
|
||||
assert(y >= 0 && y < m_height);
|
||||
|
||||
return m_pixelBuffer[(size_t)(y * m_width + x)];
|
||||
}
|
||||
|
||||
const T* ptr(void) const {
|
||||
return &(m_pixelBuffer[0]);
|
||||
}
|
||||
|
||||
int32_t getWidth(void) const { return m_width; }
|
||||
int32_t getHeight(void) const { return m_height; }
|
||||
|
||||
protected:
|
||||
std::vector<T> m_pixelBuffer;
|
||||
int32_t m_width;
|
||||
int32_t m_height;
|
||||
|
||||
public:
|
||||
PixelBuffer() : m_width(0), m_height(0) {}
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "math/dvc_vector4.h"
|
||||
#include "dvc_pixel_buffer.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API RenderTarget
|
||||
{
|
||||
public:
|
||||
void init(int32_t width, int32_t height);
|
||||
void clear();
|
||||
void setPixel(int32_t x, int32_t y, const fVector4& color, float32_t depth);
|
||||
|
||||
int32_t getWidth(void) const { return m_width; }
|
||||
int32_t getHeight(void) const { return m_height; }
|
||||
|
||||
const PixelBuffer<fVector4>& getColorBuffer(void) const { return m_colorBuffer; }
|
||||
const PixelBuffer<float32_t>& getDepthBuffer(void) const { return m_depthBuffer; }
|
||||
|
||||
private:
|
||||
int32_t m_width;
|
||||
int32_t m_height;
|
||||
PixelBuffer<fVector4> m_colorBuffer;
|
||||
PixelBuffer<float32_t> m_depthBuffer;
|
||||
|
||||
public:
|
||||
RenderTarget();
|
||||
~RenderTarget() {}
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
#include "math/dvc_vector2.h"
|
||||
#include "math/dvc_vector3.h"
|
||||
#include "math/dvc_vector4.h"
|
||||
#include "math/dvc_matrix3.h"
|
||||
#include "math/dvc_matrix4.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
class DV_CORE_API UniformBuffer
|
||||
{
|
||||
public:
|
||||
struct AttributeValue
|
||||
{
|
||||
std::string name;
|
||||
ComponentType componentType;
|
||||
DataType dataType;
|
||||
void* value;
|
||||
};
|
||||
typedef std::map<std::string, AttributeValue> AttributeMap;
|
||||
|
||||
public:
|
||||
void clear();
|
||||
|
||||
void updateStandardAttribute(const Scene& scene);
|
||||
|
||||
void setAttribute(const std::string& name, ComponentType componentType, DataType dataType, const void* value);
|
||||
|
||||
void setAttribute(const std::string& name, const int32_t& value);
|
||||
void setAttribute(const std::string& name, const float32_t& value);
|
||||
void setAttribute(const std::string& name, const fVector2& value);
|
||||
void setAttribute(const std::string& name, const fVector3& value);
|
||||
void setAttribute(const std::string& name, const fVector4& value);
|
||||
void setAttribute(const std::string& name, const fMatrix3& value);
|
||||
void setAttribute(const std::string& name, const fMatrix4& value);
|
||||
|
||||
void* getAttribute(const std::string& name) const;
|
||||
|
||||
void removeAttribute(const std::string& name);
|
||||
|
||||
private:
|
||||
void* mallocMemory(size_t size);
|
||||
void freeMemory(void* memory);
|
||||
|
||||
protected:
|
||||
AttributeMap m_attributeMap;
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "dvc_config.h"
|
||||
|
||||
DV_CORE_BEGIN_NAMESPACE
|
||||
|
||||
//Description of a vertex data
|
||||
class DV_CORE_API VertexDesc
|
||||
{
|
||||
public:
|
||||
struct Element
|
||||
{
|
||||
std::string name;
|
||||
VertexElementType elementType;
|
||||
ComponentType componentType;
|
||||
DataType dataType;
|
||||
size_t offset; //byte offset
|
||||
size_t size; //byte size
|
||||
};
|
||||
|
||||
public:
|
||||
bool addElement(const std::string& name, VertexElementType elementType,
|
||||
ComponentType componentType, DataType dataType);
|
||||
|
||||
const Element* getElement(size_t index) const;
|
||||
const Element* getElement(VertexElementType elementType) const;
|
||||
const Element* getElement(const std::string& name) const;
|
||||
|
||||
//total byte size of each vertex
|
||||
size_t vertexByteSize(void) const { return m_vertexSize; }
|
||||
|
||||
private:
|
||||
typedef std::vector< Element > ElementBuf;
|
||||
ElementBuf m_elements;
|
||||
|
||||
size_t m_vertexSize;
|
||||
|
||||
std::map< VertexElementType, ElementBuf::size_type> m_elementTypeMap;
|
||||
std::map< std::string, ElementBuf::size_type> m_nameMap;
|
||||
|
||||
public:
|
||||
VertexDesc();
|
||||
VertexDesc(const VertexDesc& other);
|
||||
~VertexDesc() {}
|
||||
};
|
||||
|
||||
DV_CORE_END_NAMESPACE
|
||||
Reference in New Issue
Block a user