boo/include/boo/graphicsdev/IGraphicsDataFactory.hpp

308 lines
8.6 KiB
C++
Raw Normal View History

#ifndef IGFXDATAFACTORY_HPP
#define IGFXDATAFACTORY_HPP
#include <memory>
2016-03-30 13:42:36 -07:00
#include <functional>
2017-12-28 23:54:26 -08:00
#include <cstdint>
#include "boo/System.hpp"
2016-03-31 21:24:05 -07:00
#include "boo/ThreadLocalPtr.hpp"
#include "boo/BooObject.hpp"
2015-12-18 13:59:54 -08:00
namespace boo
{
struct IGraphicsCommandQueue;
/** Supported buffer uses */
enum class BufferUse
{
Null,
Vertex,
Index,
Uniform
};
/** Typeless graphics buffer */
struct IGraphicsBuffer : IObj
{
bool dynamic() const { return m_dynamic; }
protected:
bool m_dynamic;
explicit IGraphicsBuffer(bool dynamic) : m_dynamic(dynamic) {}
};
/** Static resource buffer for verts, indices, uniform constants */
struct IGraphicsBufferS : IGraphicsBuffer
{
protected:
IGraphicsBufferS() : IGraphicsBuffer(false) {}
};
/** Dynamic resource buffer for verts, indices, uniform constants */
struct IGraphicsBufferD : IGraphicsBuffer
{
virtual void load(const void* data, size_t sz)=0;
virtual void* map(size_t sz)=0;
virtual void unmap()=0;
protected:
IGraphicsBufferD() : IGraphicsBuffer(true) {}
2015-10-29 23:26:02 -07:00
};
/** Texture access types */
2015-11-20 17:12:22 -08:00
enum class TextureType
2015-11-03 16:27:32 -08:00
{
2015-11-20 17:12:22 -08:00
Static,
2015-11-26 15:03:01 -08:00
StaticArray,
2015-11-20 17:12:22 -08:00
Dynamic,
Render
2015-11-03 16:27:32 -08:00
};
/** Supported texture formats */
enum class TextureFormat
{
RGBA8,
I8,
2018-01-19 19:02:29 -08:00
I16,
DXT1,
PVRTC4
};
/** Supported texture clamp modes */
enum class TextureClampMode
{
Repeat,
ClampToWhite,
2018-02-01 15:12:42 -08:00
ClampToEdge,
ClampToEdgeNearest
};
/** Typeless texture */
struct ITexture : IObj
{
TextureType type() const { return m_type; }
/* Only applies on GL and Vulkan. Use shader semantics on other platforms */
virtual void setClampMode(TextureClampMode mode) {}
protected:
2015-11-20 17:12:22 -08:00
TextureType m_type;
explicit ITexture(TextureType type) : m_type(type) {}
};
/** Static resource buffer for textures */
struct ITextureS : ITexture
{
protected:
ITextureS() : ITexture(TextureType::Static) {}
};
2015-11-26 15:03:01 -08:00
/** Static-array resource buffer for array textures */
struct ITextureSA : ITexture
{
protected:
ITextureSA() : ITexture(TextureType::StaticArray) {}
2015-11-26 15:03:01 -08:00
};
/** Dynamic resource buffer for textures */
struct ITextureD : ITexture
{
virtual void load(const void* data, size_t sz)=0;
virtual void* map(size_t sz)=0;
virtual void unmap()=0;
protected:
ITextureD() : ITexture(TextureType::Dynamic) {}
2015-11-03 16:27:32 -08:00
};
/** Resource buffer for render-target textures */
struct ITextureR : ITexture
{
protected:
ITextureR() : ITexture(TextureType::Render) {}
2017-09-30 21:23:28 -07:00
};
2015-10-29 17:00:56 -07:00
/** Opaque token for representing the data layout of a vertex
* in a VBO. Also able to reference buffers for platforms like
* OpenGL that cache object refs */
struct IVertexFormat : IObj {};
2015-10-29 17:00:56 -07:00
2015-10-29 23:26:02 -07:00
/** Types of vertex attributes */
2015-11-20 17:12:22 -08:00
enum class VertexSemantic
2015-10-29 23:26:02 -07:00
{
None = 0,
2015-11-25 16:22:05 -08:00
Position3,
Position4,
Normal3,
Normal4,
2015-11-20 17:12:22 -08:00
Color,
2015-11-25 16:22:05 -08:00
ColorUNorm,
UV2,
UV4,
Weight,
ModelView,
SemanticMask = 0xf,
Instanced = 0x10
2015-10-29 23:26:02 -07:00
};
ENABLE_BITWISE_ENUM(VertexSemantic)
2015-10-29 23:26:02 -07:00
/** Used to create IVertexFormat */
struct VertexElementDescriptor
{
ObjToken<IGraphicsBuffer> vertBuffer;
ObjToken<IGraphicsBuffer> indexBuffer;
2015-10-29 23:26:02 -07:00
VertexSemantic semantic;
2015-11-01 21:41:24 -08:00
int semanticIdx = 0;
2015-11-04 16:00:29 -08:00
VertexElementDescriptor() = default;
VertexElementDescriptor(const ObjToken<IGraphicsBuffer>& v, const ObjToken<IGraphicsBuffer>& i,
VertexSemantic s, int idx=0)
2015-11-04 16:00:29 -08:00
: vertBuffer(v), indexBuffer(i), semantic(s), semanticIdx(idx) {}
2015-10-29 23:26:02 -07:00
};
/** Opaque token for referencing a complete graphics pipeline state necessary
* to rasterize geometry (shaders and blending modes mainly) */
struct IShaderPipeline : IObj {};
/** Opaque token serving as indirection table for shader resources
* and IShaderPipeline reference. Each renderable surface-material holds one
* as a reference */
struct IShaderDataBinding : IObj {};
2016-04-03 23:13:11 -07:00
/** Used wherever distinction of pipeline stages is needed */
enum class PipelineStage
{
Vertex,
Fragment
};
/** Used by platform shader pipeline constructors */
enum class Primitive
{
Triangles,
TriStrips
};
2017-03-10 12:38:00 -08:00
/** Used by platform shader pipeline constructors */
enum class CullMode
{
None,
Backface,
Frontface
};
/** Used by platform shader pipeline constructors */
enum class ZTest
{
None,
LEqual, /* Flipped on Vulkan, D3D, Metal */
Greater,
GEqual,
Equal
};
2015-10-29 23:26:02 -07:00
/** Used by platform shader pipeline constructors */
2015-11-20 17:12:22 -08:00
enum class BlendFactor
{
Zero,
One,
SrcColor,
InvSrcColor,
DstColor,
InvDstColor,
SrcAlpha,
InvSrcAlpha,
DstAlpha,
InvDstAlpha,
SrcColor1,
InvSrcColor1,
/* Special value that activates DstColor - SrcColor blending */
Subtract
2015-10-29 23:26:02 -07:00
};
/** Factory object for creating batches of resources as an IGraphicsData token */
struct IGraphicsDataFactory
{
virtual ~IGraphicsDataFactory() = default;
2015-11-20 17:12:22 -08:00
enum class Platform
{
2015-11-20 17:12:22 -08:00
Null,
OpenGL,
2015-11-20 17:12:22 -08:00
D3D11,
Metal,
2016-01-14 13:10:48 -08:00
Vulkan,
2015-11-20 17:12:22 -08:00
GX,
GX2
};
virtual Platform platform() const=0;
virtual const SystemChar* platformName() const=0;
struct Context
{
virtual Platform platform() const=0;
virtual const SystemChar* platformName() const=0;
virtual ObjToken<IGraphicsBufferS>
newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count)=0;
virtual ObjToken<IGraphicsBufferD>
newDynamicBuffer(BufferUse use, size_t stride, size_t count)=0;
virtual ObjToken<ITextureS>
newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
2017-09-30 21:23:28 -07:00
TextureClampMode clampMode, const void* data, size_t sz)=0;
virtual ObjToken<ITextureSA>
2017-01-28 19:56:17 -08:00
newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips,
2017-09-30 21:23:28 -07:00
TextureFormat fmt, TextureClampMode clampMode, const void* data, size_t sz)=0;
virtual ObjToken<ITextureD>
2017-09-30 21:23:28 -07:00
newDynamicTexture(size_t width, size_t height, TextureFormat fmt, TextureClampMode clampMode)=0;
virtual ObjToken<ITextureR>
2017-09-30 21:23:28 -07:00
newRenderTexture(size_t width, size_t height, TextureClampMode clampMode,
size_t colorBindingCount, size_t depthBindingCount)=0;
virtual bool bindingNeedsVertexFormat() const=0;
virtual ObjToken<IVertexFormat>
2016-12-09 18:31:50 -08:00
newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements,
size_t baseVert = 0, size_t baseInst = 0)=0;
virtual ObjToken<IShaderDataBinding>
newShaderDataBinding(const ObjToken<IShaderPipeline>& pipeline,
const ObjToken<IVertexFormat>& vtxFormat,
const ObjToken<IGraphicsBuffer>& vbo,
const ObjToken<IGraphicsBuffer>& instVbo,
const ObjToken<IGraphicsBuffer>& ibo,
size_t ubufCount, const ObjToken<IGraphicsBuffer>* ubufs, const PipelineStage* ubufStages,
const size_t* ubufOffs, const size_t* ubufSizes,
size_t texCount, const ObjToken<ITexture>* texs,
const int* texBindIdx, const bool* depthBind,
size_t baseVert = 0, size_t baseInst = 0)=0;
ObjToken<IShaderDataBinding>
newShaderDataBinding(const ObjToken<IShaderPipeline>& pipeline,
const ObjToken<IVertexFormat>& vtxFormat,
const ObjToken<IGraphicsBuffer>& vbo,
const ObjToken<IGraphicsBuffer>& instVbo,
const ObjToken<IGraphicsBuffer>& ibo,
size_t ubufCount, const ObjToken<IGraphicsBuffer>* ubufs, const PipelineStage* ubufStages,
size_t texCount, const ObjToken<ITexture>* texs,
const int* texBindIdx, const bool* depthBind,
size_t baseVert = 0, size_t baseInst = 0)
{
return newShaderDataBinding(pipeline, vtxFormat, vbo, instVbo, ibo,
2016-12-09 18:31:50 -08:00
ubufCount, ubufs, ubufStages, nullptr,
nullptr, texCount, texs, texBindIdx, depthBind,
baseVert, baseInst);
}
};
2018-05-19 23:11:49 -07:00
virtual void commitTransaction(const std::function<bool(Context& ctx)>& __BooTraceArgs)=0;
2018-05-19 23:11:49 -07:00
virtual ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs)=0;
2018-01-19 21:50:01 -08:00
virtual void setDisplayGamma(float gamma)=0;
};
using GraphicsDataFactoryContext = IGraphicsDataFactory::Context;
using FactoryCommitFunc = std::function<bool(GraphicsDataFactoryContext& ctx)>;
2016-12-09 18:31:50 -08:00
}
#endif // IGFXDATAFACTORY_HPP