2014-08-17 10:16:57 +00:00
|
|
|
|
// Very thin API wrapper, suitable for porting UI code (like the native/ui framework) and similar but not real rendering.
|
|
|
|
|
// Does not involve context creation etc, that should be handled separately - only does drawing.
|
|
|
|
|
|
|
|
|
|
// The goals may change in the future though.
|
|
|
|
|
// MIT licensed, by Henrik Rydg<64>rd 2014.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2014-08-23 09:11:45 +00:00
|
|
|
|
#include <cstddef>
|
2014-08-17 12:08:55 +00:00
|
|
|
|
#include <vector>
|
2014-09-06 11:49:01 +00:00
|
|
|
|
#include <string>
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
2016-04-09 16:21:31 +00:00
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
|
2014-08-17 10:16:57 +00:00
|
|
|
|
class Matrix4x4;
|
|
|
|
|
|
2016-12-25 17:18:19 +00:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
|
|
struct IDirect3DDevice9;
|
|
|
|
|
struct IDirect3D9;
|
|
|
|
|
struct IDirect3DDevice9Ex;
|
|
|
|
|
struct IDirect3D9Ex;
|
2016-12-26 22:51:17 +00:00
|
|
|
|
struct ID3D11Device;
|
|
|
|
|
struct ID3D11DeviceContext;
|
2016-12-25 17:18:19 +00:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
class VulkanContext;
|
|
|
|
|
|
|
|
|
|
namespace Draw {
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
// Useful in UBOs
|
|
|
|
|
typedef int bool32;
|
|
|
|
|
|
2016-12-25 20:10:46 +00:00
|
|
|
|
enum class Comparison : int {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
NEVER,
|
|
|
|
|
LESS,
|
|
|
|
|
EQUAL,
|
|
|
|
|
LESS_EQUAL,
|
|
|
|
|
GREATER,
|
|
|
|
|
NOT_EQUAL,
|
|
|
|
|
GREATER_EQUAL,
|
|
|
|
|
ALWAYS,
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-04 16:57:52 +00:00
|
|
|
|
// Had to prefix with LOGIC, too many clashes
|
2016-12-25 17:52:05 +00:00
|
|
|
|
enum class LogicOp : int {
|
2015-01-04 16:57:52 +00:00
|
|
|
|
LOGIC_CLEAR,
|
|
|
|
|
LOGIC_SET,
|
|
|
|
|
LOGIC_COPY,
|
|
|
|
|
LOGIC_COPY_INVERTED,
|
|
|
|
|
LOGIC_NOOP,
|
|
|
|
|
LOGIC_INVERT,
|
|
|
|
|
LOGIC_AND,
|
|
|
|
|
LOGIC_NAND,
|
|
|
|
|
LOGIC_OR,
|
|
|
|
|
LOGIC_NOR,
|
|
|
|
|
LOGIC_XOR,
|
|
|
|
|
LOGIC_EQUIV,
|
|
|
|
|
LOGIC_AND_REVERSE,
|
|
|
|
|
LOGIC_AND_INVERTED,
|
|
|
|
|
LOGIC_OR_REVERSE,
|
|
|
|
|
LOGIC_OR_INVERTED,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 22:51:17 +00:00
|
|
|
|
enum class BlendOp : int {
|
|
|
|
|
ADD,
|
|
|
|
|
SUBTRACT,
|
|
|
|
|
REV_SUBTRACT,
|
|
|
|
|
MIN,
|
|
|
|
|
MAX,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class BlendFactor : uint8_t {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
ZERO,
|
|
|
|
|
ONE,
|
|
|
|
|
SRC_COLOR,
|
|
|
|
|
ONE_MINUS_SRC_COLOR,
|
|
|
|
|
DST_COLOR,
|
|
|
|
|
ONE_MINUS_DST_COLOR,
|
2016-12-26 22:51:17 +00:00
|
|
|
|
SRC_ALPHA,
|
|
|
|
|
ONE_MINUS_SRC_ALPHA,
|
|
|
|
|
DST_ALPHA,
|
2014-08-17 10:16:57 +00:00
|
|
|
|
ONE_MINUS_DST_ALPHA,
|
2016-12-26 22:51:17 +00:00
|
|
|
|
CONSTANT_COLOR,
|
|
|
|
|
ONE_MINUS_CONSTANT_COLOR,
|
|
|
|
|
CONSTANT_ALPHA,
|
|
|
|
|
ONE_MINUS_CONSTANT_ALPHA,
|
|
|
|
|
SRC1_COLOR,
|
|
|
|
|
ONE_MINUS_SRC1_COLOR,
|
|
|
|
|
SRC1_ALPHA,
|
|
|
|
|
ONE_MINUS_SRC1_ALPHA,
|
2014-08-17 10:16:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 22:11:31 +00:00
|
|
|
|
enum class StencilOp {
|
|
|
|
|
KEEP = 0,
|
|
|
|
|
ZERO = 1,
|
|
|
|
|
REPLACE = 2,
|
|
|
|
|
INCREMENT_AND_CLAMP = 3,
|
|
|
|
|
DECREMENT_AND_CLAMP = 4,
|
|
|
|
|
INVERT = 5,
|
|
|
|
|
INCREMENT_AND_WRAP = 6,
|
|
|
|
|
DECREMENT_AND_WRAP = 7,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
enum class TextureFilter : int {
|
2016-02-13 21:37:00 +00:00
|
|
|
|
NEAREST,
|
|
|
|
|
LINEAR,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
enum BufferUsageFlag : int {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
VERTEXDATA = 1,
|
|
|
|
|
INDEXDATA = 2,
|
|
|
|
|
GENERIC = 4,
|
|
|
|
|
|
|
|
|
|
DYNAMIC = 16,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
enum Semantic : int {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
SEM_POSITION,
|
|
|
|
|
SEM_COLOR0,
|
|
|
|
|
SEM_TEXCOORD0,
|
2014-08-17 12:08:55 +00:00
|
|
|
|
SEM_TEXCOORD1,
|
2014-08-17 10:16:57 +00:00
|
|
|
|
SEM_NORMAL,
|
|
|
|
|
SEM_TANGENT,
|
|
|
|
|
SEM_BINORMAL, // really BITANGENT
|
|
|
|
|
SEM_MAX,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
enum class Primitive {
|
|
|
|
|
POINT_LIST,
|
|
|
|
|
LINE_LIST,
|
|
|
|
|
LINE_STRIP,
|
|
|
|
|
TRIANGLE_LIST,
|
|
|
|
|
TRIANGLE_STRIP,
|
|
|
|
|
TRIANGLE_FAN,
|
2016-12-25 20:01:57 +00:00
|
|
|
|
// Tesselation shader only
|
2016-12-25 17:52:05 +00:00
|
|
|
|
PATCH_LIST,
|
|
|
|
|
// These are for geometry shaders only.
|
|
|
|
|
LINE_LIST_ADJ,
|
|
|
|
|
LINE_STRIP_ADJ,
|
|
|
|
|
TRIANGLE_LIST_ADJ,
|
|
|
|
|
TRIANGLE_STRIP_ADJ,
|
2014-08-17 10:16:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 19:54:37 +00:00
|
|
|
|
enum VertexShaderPreset : int {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
VS_COLOR_2D,
|
|
|
|
|
VS_TEXTURE_COLOR_2D,
|
|
|
|
|
VS_MAX_PRESET,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 19:54:37 +00:00
|
|
|
|
enum FragmentShaderPreset : int {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
FS_COLOR_2D,
|
|
|
|
|
FS_TEXTURE_COLOR_2D,
|
|
|
|
|
FS_MAX_PRESET,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
enum ClearFlag : int {
|
2014-08-17 14:04:27 +00:00
|
|
|
|
COLOR = 1,
|
|
|
|
|
DEPTH = 2,
|
|
|
|
|
STENCIL = 4,
|
2014-08-17 10:16:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-01-16 16:43:07 +00:00
|
|
|
|
enum class TextureType : uint8_t {
|
2014-09-06 11:49:01 +00:00
|
|
|
|
UNKNOWN,
|
|
|
|
|
LINEAR1D,
|
|
|
|
|
LINEAR2D,
|
|
|
|
|
LINEAR3D,
|
|
|
|
|
CUBE,
|
|
|
|
|
ARRAY1D,
|
|
|
|
|
ARRAY2D,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
enum class DataFormat : uint8_t {
|
2016-12-25 21:11:14 +00:00
|
|
|
|
UNDEFINED,
|
|
|
|
|
|
|
|
|
|
R8_UNORM,
|
|
|
|
|
R8G8_UNORM,
|
|
|
|
|
R8G8B8_UNORM,
|
|
|
|
|
|
2016-12-25 20:21:56 +00:00
|
|
|
|
R8G8B8A8_UNORM,
|
2016-12-25 21:11:14 +00:00
|
|
|
|
R8G8B8A8_UNORM_SRGB,
|
|
|
|
|
|
|
|
|
|
R8G8B8A8_SNORM,
|
|
|
|
|
R8G8B8A8_UINT,
|
|
|
|
|
R8G8B8A8_SINT,
|
|
|
|
|
|
|
|
|
|
R4G4_UNORM,
|
2016-12-23 08:58:15 +00:00
|
|
|
|
R4G4B4A4_UNORM,
|
2016-12-25 21:11:14 +00:00
|
|
|
|
|
|
|
|
|
R16_FLOAT,
|
|
|
|
|
R16G16_FLOAT,
|
|
|
|
|
R16G16B16A16_FLOAT,
|
|
|
|
|
|
|
|
|
|
R32_FLOAT,
|
2016-12-25 20:21:56 +00:00
|
|
|
|
R32G32_FLOAT,
|
|
|
|
|
R32G32B32_FLOAT,
|
|
|
|
|
R32G32B32A32_FLOAT,
|
2016-12-23 08:58:15 +00:00
|
|
|
|
|
2016-12-25 21:11:14 +00:00
|
|
|
|
// Block compression formats.
|
|
|
|
|
// These are modern names for DXT and friends, now patent free.
|
|
|
|
|
// https://msdn.microsoft.com/en-us/library/bb694531.aspx
|
|
|
|
|
BC1_RGBA_UNORM_BLOCK,
|
|
|
|
|
BC1_RGBA_SRGB_BLOCK,
|
|
|
|
|
BC2_UNORM_BLOCK, // 4-bit straight alpha + DXT1 color. Usually not worth using
|
|
|
|
|
BC2_SRGB_BLOCK,
|
|
|
|
|
BC3_UNORM_BLOCK, // 3-bit alpha with 2 ref values (+ magic) + DXT1 color
|
|
|
|
|
BC3_SRGB_BLOCK,
|
|
|
|
|
BC4_UNORM_BLOCK, // 1-channel, same storage as BC3 alpha
|
|
|
|
|
BC4_SNORM_BLOCK,
|
|
|
|
|
BC5_UNORM_BLOCK, // 2-channel RG, each has same storage as BC3 alpha
|
|
|
|
|
BC5_SNORM_BLOCK,
|
|
|
|
|
BC6H_UFLOAT_BLOCK, // TODO
|
|
|
|
|
BC6H_SFLOAT_BLOCK,
|
|
|
|
|
BC7_UNORM_BLOCK, // Highly advanced, very expensive to compress, very good quality.
|
|
|
|
|
BC7_SRGB_BLOCK,
|
|
|
|
|
|
|
|
|
|
ETC1,
|
|
|
|
|
|
|
|
|
|
S8,
|
2014-09-06 11:49:01 +00:00
|
|
|
|
D16,
|
2016-12-25 21:11:14 +00:00
|
|
|
|
D24_S8,
|
|
|
|
|
D32F,
|
|
|
|
|
D32F_S8,
|
2014-09-06 11:49:01 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 22:11:31 +00:00
|
|
|
|
enum class ShaderStage {
|
|
|
|
|
VERTEX,
|
|
|
|
|
FRAGMENT,
|
|
|
|
|
GEOMETRY,
|
|
|
|
|
CONTROL, // HULL
|
|
|
|
|
EVALUATION, // DOMAIN
|
|
|
|
|
COMPUTE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class CullMode : uint8_t {
|
|
|
|
|
NONE,
|
|
|
|
|
FRONT,
|
|
|
|
|
BACK,
|
|
|
|
|
FRONT_AND_BACK, // Not supported on D3D9
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class Facing {
|
|
|
|
|
CCW,
|
|
|
|
|
CW,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum BorderColor {
|
|
|
|
|
DONT_CARE,
|
|
|
|
|
TRANSPARENT_BLACK,
|
|
|
|
|
OPAQUE_BLACK,
|
|
|
|
|
OPAQUE_WHITE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
COLOR_MASK_R = 1,
|
|
|
|
|
COLOR_MASK_G = 2,
|
|
|
|
|
COLOR_MASK_B = 4,
|
|
|
|
|
COLOR_MASK_A = 8,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class TextureAddressMode {
|
|
|
|
|
REPEAT,
|
|
|
|
|
REPEAT_MIRROR,
|
|
|
|
|
CLAMP_TO_EDGE,
|
|
|
|
|
CLAMP_TO_BORDER,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class ShaderLanguage {
|
2016-12-27 15:33:54 +00:00
|
|
|
|
GLSL_ES_200 = 1,
|
|
|
|
|
GLSL_ES_300 = 2,
|
|
|
|
|
GLSL_410 = 4,
|
|
|
|
|
GLSL_VULKAN = 8,
|
|
|
|
|
SPIRV_VULKAN = 16,
|
|
|
|
|
HLSL_D3D9 = 32,
|
|
|
|
|
HLSL_D3D11 = 64,
|
|
|
|
|
HLSL_D3D9_BYTECODE = 128,
|
|
|
|
|
HLSL_D3D11_BYTECODE = 256,
|
|
|
|
|
METAL = 512,
|
|
|
|
|
METAL_BYTECODE = 1024,
|
2016-12-26 22:11:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
enum InfoField {
|
2014-09-06 11:49:01 +00:00
|
|
|
|
APINAME,
|
|
|
|
|
APIVERSION,
|
2015-07-21 18:46:31 +00:00
|
|
|
|
VENDORSTRING,
|
2014-09-06 11:49:01 +00:00
|
|
|
|
VENDOR,
|
|
|
|
|
SHADELANGVERSION,
|
|
|
|
|
RENDERER,
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-17 10:16:57 +00:00
|
|
|
|
// Binary compatible with D3D11 viewport.
|
2016-12-25 17:52:05 +00:00
|
|
|
|
struct Viewport {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
float TopLeftX;
|
|
|
|
|
float TopLeftY;
|
|
|
|
|
float Width;
|
|
|
|
|
float Height;
|
|
|
|
|
float MinDepth;
|
|
|
|
|
float MaxDepth;
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
class RefCountedObject {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
public:
|
2016-12-25 20:01:57 +00:00
|
|
|
|
RefCountedObject() : refcount_(1) {}
|
|
|
|
|
virtual ~RefCountedObject() {}
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
2016-12-26 17:32:52 +00:00
|
|
|
|
void AddRef() { refcount_++; }
|
|
|
|
|
bool Release();
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int refcount_;
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
class BlendState : public RefCountedObject {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
public:
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
class SamplerState : public RefCountedObject {
|
2016-02-13 21:37:00 +00:00
|
|
|
|
public:
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
class DepthStencilState : public RefCountedObject {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
public:
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
class Buffer : public RefCountedObject {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
public:
|
|
|
|
|
virtual void SetData(const uint8_t *data, size_t size) = 0;
|
|
|
|
|
virtual void SubData(const uint8_t *data, size_t offset, size_t size) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
class Texture : public RefCountedObject {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
public:
|
2014-08-22 18:47:40 +00:00
|
|
|
|
virtual void SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) = 0;
|
2014-08-17 13:02:43 +00:00
|
|
|
|
virtual void AutoGenMipmaps() = 0;
|
2016-12-27 21:26:49 +00:00
|
|
|
|
virtual void Finalize() = 0; // TODO: Tidy up
|
2014-08-17 19:28:34 +00:00
|
|
|
|
|
|
|
|
|
int Width() { return width_; }
|
|
|
|
|
int Height() { return height_; }
|
|
|
|
|
int Depth() { return depth_; }
|
|
|
|
|
protected:
|
|
|
|
|
int width_, height_, depth_;
|
2014-08-17 10:16:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 12:22:48 +00:00
|
|
|
|
struct BindingDesc {
|
|
|
|
|
int stride;
|
|
|
|
|
bool instanceRate;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct AttributeDesc {
|
|
|
|
|
int binding;
|
|
|
|
|
int location; // corresponds to semantic
|
|
|
|
|
DataFormat format;
|
|
|
|
|
int offset;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct InputLayoutDesc {
|
|
|
|
|
std::vector<BindingDesc> bindings;
|
|
|
|
|
std::vector<AttributeDesc> attributes;
|
2014-08-17 12:08:55 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 16:03:01 +00:00
|
|
|
|
class InputLayout : public RefCountedObject { };
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
2016-12-25 22:03:20 +00:00
|
|
|
|
enum class UniformType : int8_t {
|
|
|
|
|
FLOAT, FLOAT2, FLOAT3, FLOAT4,
|
|
|
|
|
MATRIX4X4,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// For emulation of uniform buffers on D3D9/GL
|
|
|
|
|
struct UniformDesc {
|
|
|
|
|
int16_t offset;
|
|
|
|
|
UniformType type;
|
|
|
|
|
int8_t reg; // For D3D
|
|
|
|
|
|
|
|
|
|
// TODO: Support array elements etc.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct UniformBufferDesc {
|
|
|
|
|
std::vector<UniformDesc> uniforms;
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 21:24:14 +00:00
|
|
|
|
class ShaderModule : public RefCountedObject {
|
|
|
|
|
public:
|
|
|
|
|
virtual ShaderStage GetStage() const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 10:06:17 +00:00
|
|
|
|
class Pipeline : public RefCountedObject {
|
2016-12-25 21:24:14 +00:00
|
|
|
|
public:
|
2016-12-25 22:03:20 +00:00
|
|
|
|
// TODO: Use a uniform-buffer based interface instead.
|
2016-12-25 21:24:14 +00:00
|
|
|
|
virtual void SetVector(const char *name, float *value, int n) = 0;
|
|
|
|
|
virtual void SetMatrix4x4(const char *name, const float value[16]) = 0;
|
2016-12-26 16:03:01 +00:00
|
|
|
|
virtual bool RequiresBuffer() = 0;
|
2016-12-25 21:24:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 16:03:01 +00:00
|
|
|
|
class RasterState : public RefCountedObject {};
|
2016-12-25 21:24:14 +00:00
|
|
|
|
|
2016-12-26 22:11:31 +00:00
|
|
|
|
struct StencilSide {
|
|
|
|
|
StencilOp failOp;
|
|
|
|
|
StencilOp passOp;
|
|
|
|
|
StencilOp depthFailOp;
|
|
|
|
|
Comparison compareOp;
|
|
|
|
|
uint8_t compareMask;
|
|
|
|
|
uint8_t writeMask;
|
|
|
|
|
uint8_t reference;
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:10:46 +00:00
|
|
|
|
struct DepthStencilStateDesc {
|
|
|
|
|
bool depthTestEnabled;
|
|
|
|
|
bool depthWriteEnabled;
|
|
|
|
|
Comparison depthCompare;
|
2016-12-26 22:11:31 +00:00
|
|
|
|
bool stencilEnabled;
|
|
|
|
|
StencilSide front;
|
|
|
|
|
StencilSide back;
|
2016-12-25 20:10:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
struct BlendStateDesc {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
bool enabled;
|
2016-12-26 17:32:52 +00:00
|
|
|
|
int colorMask;
|
2016-12-25 17:52:05 +00:00
|
|
|
|
BlendFactor srcCol;
|
|
|
|
|
BlendFactor dstCol;
|
|
|
|
|
BlendOp eqCol;
|
|
|
|
|
BlendFactor srcAlpha;
|
|
|
|
|
BlendFactor dstAlpha;
|
|
|
|
|
BlendOp eqAlpha;
|
2015-01-04 16:57:52 +00:00
|
|
|
|
bool logicEnabled;
|
2016-12-25 17:52:05 +00:00
|
|
|
|
LogicOp logicOp;
|
2016-12-26 17:32:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 19:54:37 +00:00
|
|
|
|
struct SamplerStateDesc {
|
2016-12-25 20:21:56 +00:00
|
|
|
|
TextureFilter magFilter;
|
|
|
|
|
TextureFilter minFilter;
|
|
|
|
|
TextureFilter mipFilter;
|
|
|
|
|
float maxAniso;
|
|
|
|
|
TextureAddressMode wrapU;
|
|
|
|
|
TextureAddressMode wrapV;
|
|
|
|
|
TextureAddressMode wrapW;
|
|
|
|
|
float maxLod;
|
|
|
|
|
bool shadowCompareEnabled;
|
|
|
|
|
Comparison shadowCompareFunc;
|
|
|
|
|
BorderColor borderColor;
|
2016-02-13 21:37:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 21:24:14 +00:00
|
|
|
|
struct RasterStateDesc {
|
2016-12-25 17:52:05 +00:00
|
|
|
|
CullMode cull;
|
2016-12-27 14:52:03 +00:00
|
|
|
|
Facing frontFace;
|
2016-12-23 22:46:11 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 10:06:17 +00:00
|
|
|
|
struct PipelineDesc {
|
2016-12-26 16:03:01 +00:00
|
|
|
|
Primitive prim;
|
2016-12-25 22:03:20 +00:00
|
|
|
|
std::vector<ShaderModule *> shaders;
|
2016-12-26 16:03:01 +00:00
|
|
|
|
InputLayout *inputLayout;
|
|
|
|
|
DepthStencilState *depthStencil;
|
|
|
|
|
BlendState *blend;
|
|
|
|
|
RasterState *raster;
|
2016-12-25 22:03:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-26 16:31:20 +00:00
|
|
|
|
struct DeviceCaps {
|
|
|
|
|
DataFormat preferredDepthBufferFormat;
|
|
|
|
|
DataFormat preferredShadowMapFormatLow;
|
|
|
|
|
DataFormat preferredShadowMapFormatHigh;
|
|
|
|
|
bool anisoSupported;
|
|
|
|
|
bool depthRangeMinusOneToOne; // OpenGL style depth
|
|
|
|
|
bool geometryShaderSupported;
|
|
|
|
|
bool tesselationShaderSupported;
|
|
|
|
|
bool multiViewport;
|
|
|
|
|
bool dualSourceBlend;
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-16 16:43:07 +00:00
|
|
|
|
struct TextureDesc {
|
|
|
|
|
TextureType type;
|
|
|
|
|
DataFormat format;
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
int depth;
|
|
|
|
|
int mipLevels;
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
class DrawContext : public RefCountedObject {
|
2014-08-17 10:16:57 +00:00
|
|
|
|
public:
|
2016-12-25 20:01:57 +00:00
|
|
|
|
virtual ~DrawContext();
|
2014-08-17 13:02:43 +00:00
|
|
|
|
|
2016-12-26 16:31:20 +00:00
|
|
|
|
virtual const DeviceCaps &GetDeviceCaps() const = 0;
|
|
|
|
|
virtual std::vector<std::string> GetFeatureList() const { return std::vector<std::string>(); }
|
2016-01-03 13:00:05 +00:00
|
|
|
|
|
2016-12-27 15:33:54 +00:00
|
|
|
|
virtual uint32_t GetSupportedShaderLanguages() const = 0;
|
|
|
|
|
|
2016-12-26 16:03:01 +00:00
|
|
|
|
// Partial pipeline state, used to create pipelines. (in practice, in d3d11 they'll use the native state objects directly).
|
2016-12-25 20:10:46 +00:00
|
|
|
|
virtual DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) = 0;
|
2016-12-25 17:52:05 +00:00
|
|
|
|
virtual BlendState *CreateBlendState(const BlendStateDesc &desc) = 0;
|
2016-12-25 19:54:37 +00:00
|
|
|
|
virtual SamplerState *CreateSamplerState(const SamplerStateDesc &desc) = 0;
|
2016-12-25 21:24:14 +00:00
|
|
|
|
virtual RasterState *CreateRasterState(const RasterStateDesc &desc) = 0;
|
2016-12-26 16:03:01 +00:00
|
|
|
|
// virtual ComputePipeline CreateComputePipeline(const ComputePipelineDesc &desc) = 0
|
2016-12-26 12:22:48 +00:00
|
|
|
|
virtual InputLayout *CreateInputLayout(const InputLayoutDesc &desc) = 0;
|
2014-09-06 11:49:01 +00:00
|
|
|
|
|
2014-08-17 10:16:57 +00:00
|
|
|
|
// Note that these DO NOT AddRef so you must not ->Release presets unless you manually AddRef them.
|
2016-12-25 21:24:14 +00:00
|
|
|
|
ShaderModule *GetVshaderPreset(VertexShaderPreset preset) { return fsPresets_[preset]; }
|
|
|
|
|
ShaderModule *GetFshaderPreset(FragmentShaderPreset preset) { return vsPresets_[preset]; }
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
2016-12-26 16:03:01 +00:00
|
|
|
|
// Resources
|
|
|
|
|
virtual Buffer *CreateBuffer(size_t size, uint32_t usageFlags) = 0;
|
2017-01-16 16:43:07 +00:00
|
|
|
|
virtual Texture *CreateTexture(const TextureDesc &desc) = 0;
|
2016-12-27 16:38:26 +00:00
|
|
|
|
virtual ShaderModule *CreateShaderModule(ShaderStage stage, ShaderLanguage language, const uint8_t *data, size_t dataSize) = 0;
|
|
|
|
|
virtual Pipeline *CreateGraphicsPipeline(const PipelineDesc &desc) = 0;
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
2016-12-26 16:03:01 +00:00
|
|
|
|
// Dynamic state
|
|
|
|
|
virtual void SetScissorRect(int left, int top, int width, int height) = 0;
|
|
|
|
|
virtual void SetViewports(int count, Viewport *viewports) = 0;
|
2016-12-27 14:52:03 +00:00
|
|
|
|
virtual void SetBlendFactor(float color[4]) = 0;
|
2014-08-17 13:02:43 +00:00
|
|
|
|
|
2016-12-26 16:03:01 +00:00
|
|
|
|
virtual void BindSamplerStates(int start, int count, SamplerState **state) = 0;
|
2016-12-25 19:54:37 +00:00
|
|
|
|
virtual void BindTextures(int start, int count, Texture **textures) = 0;
|
2017-01-17 16:14:47 +00:00
|
|
|
|
virtual void BindVertexBuffers(int start, int count, Buffer **buffers, int *offsets) = 0;
|
|
|
|
|
virtual void BindIndexBuffer(Buffer *indexBuffer, int offset) = 0;
|
|
|
|
|
|
2016-12-25 19:54:37 +00:00
|
|
|
|
void BindTexture(int stage, Texture *texture) {
|
2016-12-23 22:56:50 +00:00
|
|
|
|
BindTextures(stage, 1, &texture);
|
2014-08-17 13:02:43 +00:00
|
|
|
|
} // from sampler 0 and upwards
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
2016-12-26 10:16:59 +00:00
|
|
|
|
virtual void BindPipeline(Pipeline *pipeline) = 0;
|
|
|
|
|
|
2014-08-17 10:16:57 +00:00
|
|
|
|
// TODO: Add more sophisticated draws with buffer offsets, and multidraws.
|
2017-01-17 16:14:47 +00:00
|
|
|
|
virtual void Draw(int vertexCount, int offset) = 0;
|
|
|
|
|
virtual void DrawIndexed(int vertexCount, int offset) = 0;
|
2016-12-26 16:03:01 +00:00
|
|
|
|
virtual void DrawUP(const void *vdata, int vertexCount) = 0;
|
2015-10-10 14:41:19 +00:00
|
|
|
|
|
|
|
|
|
// Render pass management. Default implementations here.
|
|
|
|
|
virtual void Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) {
|
|
|
|
|
Clear(0xF, colorval, depthVal, stencilVal);
|
|
|
|
|
}
|
|
|
|
|
virtual void End() {}
|
2014-08-17 10:16:57 +00:00
|
|
|
|
virtual void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) = 0;
|
2015-10-10 14:41:19 +00:00
|
|
|
|
|
2014-08-17 13:29:50 +00:00
|
|
|
|
// Necessary to correctly flip scissor rectangles etc for OpenGL.
|
|
|
|
|
void SetTargetSize(int w, int h) {
|
|
|
|
|
targetWidth_ = w;
|
|
|
|
|
targetHeight_ = h;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-25 17:52:05 +00:00
|
|
|
|
virtual std::string GetInfoString(InfoField info) const = 0;
|
2014-08-22 17:55:39 +00:00
|
|
|
|
|
2014-08-17 10:16:57 +00:00
|
|
|
|
protected:
|
|
|
|
|
void CreatePresets();
|
|
|
|
|
|
2016-12-25 21:24:14 +00:00
|
|
|
|
ShaderModule *vsPresets_[VS_MAX_PRESET];
|
|
|
|
|
ShaderModule *fsPresets_[FS_MAX_PRESET];
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
2014-08-17 13:29:50 +00:00
|
|
|
|
int targetWidth_;
|
|
|
|
|
int targetHeight_;
|
2014-08-17 10:16:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
DrawContext *T3DCreateGLContext();
|
2014-08-17 10:16:57 +00:00
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2016-12-25 20:01:57 +00:00
|
|
|
|
DrawContext *T3DCreateDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx);
|
2016-12-26 22:59:42 +00:00
|
|
|
|
DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context);
|
2014-08-17 10:16:57 +00:00
|
|
|
|
#endif
|
2015-10-10 14:41:19 +00:00
|
|
|
|
|
2016-12-25 20:01:57 +00:00
|
|
|
|
DrawContext *T3DCreateVulkanContext(VulkanContext *context);
|
2016-12-25 17:18:19 +00:00
|
|
|
|
|
|
|
|
|
} // namespace Draw
|