More renaming

This commit is contained in:
Henrik Rydgård 2016-12-25 21:21:56 +01:00
parent c7c541f926
commit 425940b433
7 changed files with 333 additions and 307 deletions

View file

@ -55,12 +55,12 @@ SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *_thin3D)
: gfxCtx_(gfxCtx), thin3d(_thin3D)
{
using namespace Draw;
fbTex = thin3d->CreateTexture(LINEAR2D, DataFormat::R8A8G8B8_UNORM, 480, 272, 1, 1);
fbTex = thin3d->CreateTexture(LINEAR2D, DataFormat::R8G8B8A8_UNORM, 480, 272, 1, 1);
std::vector<VertexComponent> components;
components.push_back(VertexComponent("Position", SEM_POSITION, DataFormat::FLOATx3, 0));
components.push_back(VertexComponent("TexCoord0", SEM_TEXCOORD0, DataFormat::FLOATx2, 12));
components.push_back(VertexComponent("Color0", SEM_COLOR0, DataFormat::UNORM8x4, 20));
components.push_back(VertexComponent("Position", SEM_POSITION, DataFormat::R32G32B32_FLOAT, 0));
components.push_back(VertexComponent("TexCoord0", SEM_TEXCOORD0, DataFormat::R32G32_FLOAT, 12));
components.push_back(VertexComponent("Color0", SEM_COLOR0, DataFormat::R8G8B8A8_UNORM, 20));
Shader *vshader = thin3d->GetVshaderPreset(VS_TEXTURE_COLOR_2D);
vformat = thin3d->CreateVertexFormat(components, 24, vshader);

View file

@ -42,9 +42,9 @@ void DrawBuffer::Init(Draw::DrawContext *t3d) {
inited_ = true;
std::vector<VertexComponent> components;
components.push_back(VertexComponent("Position", SEM_POSITION, DataFormat::FLOATx3, 0));
components.push_back(VertexComponent("TexCoord0", SEM_TEXCOORD0, DataFormat::FLOATx2, 12));
components.push_back(VertexComponent("Color0", SEM_COLOR0, DataFormat::UNORM8x4, 20));
components.push_back(VertexComponent("Position", SEM_POSITION, DataFormat::R32G32B32_FLOAT, 0));
components.push_back(VertexComponent("TexCoord0", SEM_TEXCOORD0, DataFormat::R32G32_FLOAT, 12));
components.push_back(VertexComponent("Color0", SEM_COLOR0, DataFormat::R8G8B8A8_UNORM, 20));
Shader *vshader = t3d_->GetVshaderPreset(VS_TEXTURE_COLOR_2D);

View file

@ -179,9 +179,9 @@ DrawContext::~DrawContext() {
static DataFormat ZimToT3DFormat(int zim) {
switch (zim) {
case ZIM_ETC1: return DataFormat::ETC1;
case ZIM_RGBA8888: return DataFormat::R8A8G8B8_UNORM;
case ZIM_RGBA8888: return DataFormat::R8G8B8A8_UNORM;
case ZIM_LUMINANCE: return DataFormat::LUMINANCE;
default: return DataFormat::R8A8G8B8_UNORM;
default: return DataFormat::R8G8B8A8_UNORM;
}
}
@ -220,7 +220,7 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType ty
case PNG:
if (1 == pngLoadPtr((const unsigned char *)data, size, &width[0], &height[0], &image[0], false)) {
*num_levels = 1;
*fmt = DataFormat::R8A8G8B8_UNORM;
*fmt = DataFormat::R8G8B8A8_UNORM;
}
break;
@ -230,7 +230,7 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType ty
unsigned char *jpegBuf = jpgd::decompress_jpeg_image_from_memory(data, (int)size, &width[0], &height[0], &actual_components, 4);
if (jpegBuf) {
*num_levels = 1;
*fmt = DataFormat::R8A8G8B8_UNORM;
*fmt = DataFormat::R8G8B8A8_UNORM;
image[0] = (uint8_t *)jpegBuf;
}
}

View file

@ -84,11 +84,6 @@ enum BlendFactor : int {
FIXED_COLOR,
};
enum class TextureAddressMode : int {
REPEAT,
CLAMP,
};
enum class TextureFilter : int {
NEAREST,
LINEAR,
@ -167,12 +162,11 @@ enum TextureType : uint8_t {
enum class DataFormat : uint8_t {
UNKNOWN,
LUMINANCE,
R8A8G8B8_UNORM,
R8G8B8A8_UNORM,
R4G4B4A4_UNORM,
FLOATx2,
FLOATx3,
FLOATx4,
UNORM8x4,
R32G32_FLOAT,
R32G32B32_FLOAT,
R32G32B32A32_FLOAT,
DXT1,
ETC1, // Needs simulation on many platforms
@ -340,12 +334,32 @@ struct BlendStateDesc {
// int colorMask;
};
enum BorderColor {
DONT_CARE,
TRANSPARENT_BLACK,
OPAQUE_BLACK,
OPAQUE_WHITE,
};
enum class TextureAddressMode {
REPEAT,
REPEAT_MIRROR,
CLAMP_TO_EDGE,
CLAMP_TO_BORDER,
};
struct SamplerStateDesc {
TextureFilter magFilt;
TextureFilter minFilt;
TextureFilter mipFilt;
TextureAddressMode wrapS;
TextureAddressMode wrapT;
TextureFilter magFilter;
TextureFilter minFilter;
TextureFilter mipFilter;
float maxAniso;
TextureAddressMode wrapU;
TextureAddressMode wrapV;
TextureAddressMode wrapW;
float maxLod;
bool shadowCompareEnabled;
Comparison shadowCompareFunc;
BorderColor borderColor;
};
enum class CullMode : uint8_t {

View file

@ -83,16 +83,18 @@ static const D3DPRIMITIVETYPE primToD3D9[] = {
D3DPT_POINTLIST,
};
inline int PrimCountDivisor(Primitive prim) {
switch (prim) {
case Primitive::POINT_LIST: return 1;
case Primitive::LINE_LIST: return 2;
case Primitive::LINE_STRIP: return 2;
case Primitive::TRIANGLE_LIST: return 3;
case Primitive::TRIANGLE_STRIP: return 3;
case Primitive::TRIANGLE_FAN: return 3;
}
}
static const int primCountDivisor[] = {
1,
2,
3,
3,
3,
1,
1,
1,
1,
1,
};
class Thin3DDX9DepthStencilState : public DepthStencilState {
public:
@ -107,8 +109,7 @@ public:
}
};
class Thin3DDX9RasterState : public RasterState {
class D3D9RasterState : public RasterState {
public:
DWORD cullMode;
@ -117,8 +118,7 @@ public:
}
};
class Thin3DDX9BlendState : public BlendState {
class D3D9BlendState : public BlendState {
public:
bool enabled;
D3DBLENDOP eqCol, eqAlpha;
@ -137,7 +137,7 @@ public:
}
};
class Thin3DDX9SamplerState : public SamplerState {
class D3D9SamplerState : public SamplerState {
public:
D3DTEXTUREADDRESS wrapS, wrapT;
D3DTEXTUREFILTERTYPE magFilt, minFilt, mipFilt;
@ -249,10 +249,10 @@ private:
int stride_;
};
class Thin3DDX9Shader : public Shader {
class D3D9Shader : public Shader {
public:
Thin3DDX9Shader(ShaderStage stage) : stage_(stage), vshader_(NULL), pshader_(NULL), constantTable_(NULL) {}
~Thin3DDX9Shader() {
D3D9Shader(ShaderStage stage) : stage_(stage), vshader_(NULL), pshader_(NULL), constantTable_(NULL) {}
~D3D9Shader() {
if (vshader_)
vshader_->Release();
if (pshader_)
@ -278,11 +278,11 @@ private:
LPD3DXCONSTANTTABLE constantTable_;
};
class Thin3DDX9ShaderSet : public ShaderSet {
class D3D9ShaderSet : public ShaderSet {
public:
Thin3DDX9ShaderSet(LPDIRECT3DDEVICE9 device) : device_(device) {}
Thin3DDX9Shader *vshader;
Thin3DDX9Shader *pshader;
D3D9ShaderSet(LPDIRECT3DDEVICE9 device) : device_(device) {}
D3D9Shader *vshader;
D3D9Shader *pshader;
void Apply(LPDIRECT3DDEVICE9 device);
void SetVector(const char *name, float *value, int n) { vshader->SetVector(device_, name, value, n); pshader->SetVector(device_, name, value, n); }
void SetMatrix4x4(const char *name, const float value[16]) { vshader->SetMatrix4x4(device_, name, value); } // pshaders don't usually have matrices
@ -290,12 +290,12 @@ private:
LPDIRECT3DDEVICE9 device_;
};
class Thin3DDX9Texture : public Texture {
class D3D9Texture : public Texture {
public:
Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx) : device_(device), deviceEx_(deviceEx), type_(TextureType::UNKNOWN), fmt_(D3DFMT_UNKNOWN), tex_(NULL), volTex_(NULL), cubeTex_(NULL) {
D3D9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx) : device_(device), deviceEx_(deviceEx), type_(TextureType::UNKNOWN), fmt_(D3DFMT_UNKNOWN), tex_(NULL), volTex_(NULL), cubeTex_(NULL) {
}
Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels);
~Thin3DDX9Texture();
D3D9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels);
~D3D9Texture();
bool Create(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override;
void SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) override;
void AutoGenMipmaps() override {}
@ -314,7 +314,7 @@ private:
D3DFORMAT FormatToD3D(DataFormat fmt) {
switch (fmt) {
case DataFormat::R8A8G8B8_UNORM: return D3DFMT_A8R8G8B8;
case DataFormat::R8G8B8A8_UNORM: return D3DFMT_A8R8G8B8;
case DataFormat::R4G4B4A4_UNORM: return D3DFMT_A4R4G4B4;
case DataFormat::D24S8: return D3DFMT_D24S8;
case DataFormat::D16: return D3DFMT_D16;
@ -322,12 +322,12 @@ D3DFORMAT FormatToD3D(DataFormat fmt) {
}
}
Thin3DDX9Texture::Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels)
D3D9Texture::D3D9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels)
: device_(device), deviceEx_(deviceEx), type_(type), tex_(NULL), volTex_(NULL), cubeTex_(NULL) {
Create(type, format, width, height, depth, mipLevels);
}
Thin3DDX9Texture::~Thin3DDX9Texture() {
D3D9Texture::~D3D9Texture() {
if (tex_) {
tex_->Release();
}
@ -339,7 +339,7 @@ Thin3DDX9Texture::~Thin3DDX9Texture() {
}
}
bool Thin3DDX9Texture::Create(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) {
bool D3D9Texture::Create(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) {
width_ = width;
height_ = height;
depth_ = depth;
@ -383,7 +383,7 @@ inline uint32_t Shuffle8888(uint32_t x) {
}
void Thin3DDX9Texture::SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) {
void D3D9Texture::SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) {
if (!tex_) {
return;
}
@ -430,7 +430,7 @@ void Thin3DDX9Texture::SetImageData(int x, int y, int z, int width, int height,
}
}
void Thin3DDX9Texture::SetToSampler(LPDIRECT3DDEVICE9 device, int sampler) {
void D3D9Texture::SetToSampler(LPDIRECT3DDEVICE9 device, int sampler) {
switch (type_) {
case LINEAR1D:
case LINEAR2D:
@ -447,10 +447,10 @@ void Thin3DDX9Texture::SetToSampler(LPDIRECT3DDEVICE9 device, int sampler) {
}
}
class Thin3DDX9Context : public DrawContext {
class D3D9Context : public DrawContext {
public:
Thin3DDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx);
~Thin3DDX9Context();
D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx);
~D3D9Context();
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc);
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
@ -465,12 +465,12 @@ public:
// Bound state objects. Too cumbersome to add them all as parameters to Draw.
void SetBlendState(BlendState *state) {
Thin3DDX9BlendState *bs = static_cast<Thin3DDX9BlendState *>(state);
D3D9BlendState *bs = static_cast<D3D9BlendState *>(state);
bs->Apply(device_);
}
void SetSamplerStates(int start, int count, SamplerState **states) {
for (int i = 0; i < count; ++i) {
Thin3DDX9SamplerState *s = static_cast<Thin3DDX9SamplerState *>(states[start + i]);
D3D9SamplerState *s = static_cast<D3D9SamplerState *>(states[start + i]);
s->Apply(device_, start + i);
}
}
@ -479,7 +479,7 @@ public:
bs->Apply(device_);
}
void SetRasterState(RasterState *state) {
Thin3DDX9RasterState *bs = static_cast<Thin3DDX9RasterState *>(state);
D3D9RasterState *bs = static_cast<D3D9RasterState *>(state);
bs->Apply(device_);
}
@ -518,7 +518,7 @@ private:
char shadeLangVersion_[64];
};
Thin3DDX9Context::Thin3DDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx)
D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx)
: d3d_(d3d), d3dEx_(d3dEx), adapterId_(adapterId), device_(device), deviceEx_(deviceEx) {
CreatePresets();
d3d->GetAdapterIdentifier(adapterId, 0, &identifier_);
@ -529,11 +529,11 @@ Thin3DDX9Context::Thin3DDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int ada
}
}
Thin3DDX9Context::~Thin3DDX9Context() {
D3D9Context::~D3D9Context() {
}
Shader *Thin3DDX9Context::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
Thin3DDX9Shader *shader = new Thin3DDX9Shader(stage);
Shader *D3D9Context::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
D3D9Shader *shader = new D3D9Shader(stage);
if (shader->Compile(device_, hlsl_source)) {
return shader;
} else {
@ -542,18 +542,18 @@ Shader *Thin3DDX9Context::CreateShader(ShaderStage stage, const char *glsl_sourc
}
}
ShaderSet *Thin3DDX9Context::CreateShaderSet(Shader *vshader, Shader *fshader) {
ShaderSet *D3D9Context::CreateShaderSet(Shader *vshader, Shader *fshader) {
if (!vshader || !fshader) {
ELOG("ShaderSet requires both a valid vertex and a fragment shader: %p %p", vshader, fshader);
return NULL;
}
Thin3DDX9ShaderSet *shaderSet = new Thin3DDX9ShaderSet(device_);
shaderSet->vshader = static_cast<Thin3DDX9Shader *>(vshader);
shaderSet->pshader = static_cast<Thin3DDX9Shader *>(fshader);
D3D9ShaderSet *shaderSet = new D3D9ShaderSet(device_);
shaderSet->vshader = static_cast<D3D9Shader *>(vshader);
shaderSet->pshader = static_cast<D3D9Shader *>(fshader);
return shaderSet;
}
DepthStencilState *Thin3DDX9Context::CreateDepthStencilState(const DepthStencilStateDesc &desc) {
DepthStencilState *D3D9Context::CreateDepthStencilState(const DepthStencilStateDesc &desc) {
Thin3DDX9DepthStencilState *ds = new Thin3DDX9DepthStencilState();
ds->depthTestEnabled = desc.depthTestEnabled;
ds->depthWriteEnabled = desc.depthWriteEnabled;
@ -561,13 +561,13 @@ DepthStencilState *Thin3DDX9Context::CreateDepthStencilState(const DepthStencilS
return ds;
}
InputLayout *Thin3DDX9Context::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
InputLayout *D3D9Context::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
Thin3DDX9VertexFormat *fmt = new Thin3DDX9VertexFormat(device_, components, stride);
return fmt;
}
BlendState *Thin3DDX9Context::CreateBlendState(const BlendStateDesc &desc) {
Thin3DDX9BlendState *bs = new Thin3DDX9BlendState();
BlendState *D3D9Context::CreateBlendState(const BlendStateDesc &desc) {
D3D9BlendState *bs = new D3D9BlendState();
bs->enabled = desc.enabled;
bs->eqCol = blendEqToD3D9[(int)desc.eqCol];
bs->srcCol = blendFactorToD3D9[(int)desc.srcCol];
@ -579,18 +579,18 @@ BlendState *Thin3DDX9Context::CreateBlendState(const BlendStateDesc &desc) {
return bs;
}
SamplerState *Thin3DDX9Context::CreateSamplerState(const SamplerStateDesc &desc) {
Thin3DDX9SamplerState *samps = new Thin3DDX9SamplerState();
samps->wrapS = texWrapToD3D9[(int)desc.wrapS];
samps->wrapT = texWrapToD3D9[(int)desc.wrapT];
samps->magFilt = texFilterToD3D9[(int)desc.magFilt];
samps->minFilt = texFilterToD3D9[(int)desc.minFilt];
samps->mipFilt = texFilterToD3D9[(int)desc.mipFilt];
SamplerState *D3D9Context::CreateSamplerState(const SamplerStateDesc &desc) {
D3D9SamplerState *samps = new D3D9SamplerState();
samps->wrapS = texWrapToD3D9[(int)desc.wrapU];
samps->wrapT = texWrapToD3D9[(int)desc.wrapV];
samps->magFilt = texFilterToD3D9[(int)desc.magFilter];
samps->minFilt = texFilterToD3D9[(int)desc.minFilter];
samps->mipFilt = texFilterToD3D9[(int)desc.mipFilter];
return samps;
}
RasterState *Thin3DDX9Context::CreateRasterState(const T3DRasterStateDesc &desc) {
Thin3DDX9RasterState *rs = new Thin3DDX9RasterState();
RasterState *D3D9Context::CreateRasterState(const T3DRasterStateDesc &desc) {
D3D9RasterState *rs = new D3D9RasterState();
rs->cullMode = D3DCULL_NONE;
if (desc.cull == CullMode::NONE) {
return rs;
@ -610,19 +610,19 @@ RasterState *Thin3DDX9Context::CreateRasterState(const T3DRasterStateDesc &desc)
return rs;
}
Texture *Thin3DDX9Context::CreateTexture() {
Thin3DDX9Texture *tex = new Thin3DDX9Texture(device_, deviceEx_);
Texture *D3D9Context::CreateTexture() {
D3D9Texture *tex = new D3D9Texture(device_, deviceEx_);
return tex;
}
Texture *Thin3DDX9Context::CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) {
Thin3DDX9Texture *tex = new Thin3DDX9Texture(device_, deviceEx_, type, format, width, height, depth, mipLevels);
Texture *D3D9Context::CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) {
D3D9Texture *tex = new D3D9Texture(device_, deviceEx_, type, format, width, height, depth, mipLevels);
return tex;
}
void Thin3DDX9Context::BindTextures(int start, int count, Texture **textures) {
void D3D9Context::BindTextures(int start, int count, Texture **textures) {
for (int i = start; i < start + count; i++) {
Thin3DDX9Texture *tex = static_cast<Thin3DDX9Texture *>(textures[i - start]);
D3D9Texture *tex = static_cast<D3D9Texture *>(textures[i - start]);
tex->SetToSampler(device_, i);
}
}
@ -657,10 +657,10 @@ static void SemanticToD3D9UsageAndIndex(int semantic, BYTE *usage, BYTE *index)
static int VertexDataTypeToD3DType(DataFormat type) {
switch (type) {
case DataFormat::FLOATx2: return D3DDECLTYPE_FLOAT2;
case DataFormat::FLOATx3: return D3DDECLTYPE_FLOAT3;
case DataFormat::FLOATx4: return D3DDECLTYPE_FLOAT4;
case DataFormat::UNORM8x4: return D3DDECLTYPE_UBYTE4N; // D3DCOLOR?
case DataFormat::R32G32_FLOAT: return D3DDECLTYPE_FLOAT2;
case DataFormat::R32G32B32_FLOAT: return D3DDECLTYPE_FLOAT3;
case DataFormat::R32G32B32A32_FLOAT: return D3DDECLTYPE_FLOAT4;
case DataFormat::R8G8B8A8_UNORM: return D3DDECLTYPE_UBYTE4N; // D3DCOLOR?
default: return D3DDECLTYPE_UNUSED;
}
}
@ -687,19 +687,19 @@ Thin3DDX9VertexFormat::Thin3DDX9VertexFormat(LPDIRECT3DDEVICE9 device, const std
stride_ = stride;
}
Buffer *Thin3DDX9Context::CreateBuffer(size_t size, uint32_t usageFlags) {
Buffer *D3D9Context::CreateBuffer(size_t size, uint32_t usageFlags) {
return new Thin3DDX9Buffer(device_, size, usageFlags);
}
void Thin3DDX9ShaderSet::Apply(LPDIRECT3DDEVICE9 device) {
void D3D9ShaderSet::Apply(LPDIRECT3DDEVICE9 device) {
vshader->Apply(device);
pshader->Apply(device);
}
void Thin3DDX9Context::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
void D3D9Context::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
Thin3DDX9Buffer *vbuf = static_cast<Thin3DDX9Buffer *>(vdata);
Thin3DDX9VertexFormat *fmt = static_cast<Thin3DDX9VertexFormat *>(format);
Thin3DDX9ShaderSet *ss = static_cast<Thin3DDX9ShaderSet*>(shaderSet);
D3D9ShaderSet *ss = static_cast<D3D9ShaderSet*>(shaderSet);
vbuf->BindAsVertexBuf(device_, fmt->GetStride(), offset);
ss->Apply(device_);
@ -707,22 +707,22 @@ void Thin3DDX9Context::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *f
device_->DrawPrimitive(primToD3D9[(int)prim], offset, vertexCount / 3);
}
void Thin3DDX9Context::DrawIndexed(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
void D3D9Context::DrawIndexed(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
Thin3DDX9Buffer *vbuf = static_cast<Thin3DDX9Buffer *>(vdata);
Thin3DDX9Buffer *ibuf = static_cast<Thin3DDX9Buffer *>(idata);
Thin3DDX9VertexFormat *fmt = static_cast<Thin3DDX9VertexFormat *>(format);
Thin3DDX9ShaderSet *ss = static_cast<Thin3DDX9ShaderSet*>(shaderSet);
D3D9ShaderSet *ss = static_cast<D3D9ShaderSet*>(shaderSet);
ss->Apply(device_);
fmt->Apply(device_);
vbuf->BindAsVertexBuf(device_, fmt->GetStride(), offset);
ibuf->BindAsIndexBuf(device_);
device_->DrawIndexedPrimitive(primToD3D9[(int)prim], 0, 0, vertexCount, 0, vertexCount / PrimCountDivisor(prim));
device_->DrawIndexedPrimitive(primToD3D9[(int)prim], 0, 0, vertexCount, 0, vertexCount / primCountDivisor[(int)prim]);
}
void Thin3DDX9Context::DrawUP(Primitive prim, ShaderSet *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
void D3D9Context::DrawUP(Primitive prim, ShaderSet *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
Thin3DDX9VertexFormat *fmt = static_cast<Thin3DDX9VertexFormat *>(format);
Thin3DDX9ShaderSet *ss = static_cast<Thin3DDX9ShaderSet*>(shaderSet);
D3D9ShaderSet *ss = static_cast<D3D9ShaderSet*>(shaderSet);
ss->Apply(device_);
fmt->Apply(device_);
@ -733,7 +733,7 @@ static uint32_t SwapRB(uint32_t c) {
return (c & 0xFF00FF00) | ((c >> 16) & 0xFF) | ((c << 16) & 0xFF0000);
}
void Thin3DDX9Context::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) {
void D3D9Context::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) {
UINT d3dMask = 0;
if (mask & ClearFlag::COLOR) d3dMask |= D3DCLEAR_TARGET;
if (mask & ClearFlag::DEPTH) d3dMask |= D3DCLEAR_ZBUFFER;
@ -742,11 +742,11 @@ void Thin3DDX9Context::Clear(int mask, uint32_t colorval, float depthVal, int st
device_->Clear(0, NULL, d3dMask, (D3DCOLOR)SwapRB(colorval), depthVal, stencilVal);
}
void Thin3DDX9Context::SetScissorEnabled(bool enable) {
void D3D9Context::SetScissorEnabled(bool enable) {
device_->SetRenderState(D3DRS_SCISSORTESTENABLE, enable);
}
void Thin3DDX9Context::SetScissorRect(int left, int top, int width, int height) {
void D3D9Context::SetScissorRect(int left, int top, int width, int height) {
RECT rc;
rc.left = left;
rc.top = top;
@ -755,7 +755,7 @@ void Thin3DDX9Context::SetScissorRect(int left, int top, int width, int height)
device_->SetScissorRect(&rc);
}
void Thin3DDX9Context::SetViewports(int count, Viewport *viewports) {
void D3D9Context::SetViewports(int count, Viewport *viewports) {
D3DVIEWPORT9 vp;
vp.X = (DWORD)viewports[0].TopLeftX;
vp.Y = (DWORD)viewports[0].TopLeftY;
@ -766,7 +766,7 @@ void Thin3DDX9Context::SetViewports(int count, Viewport *viewports) {
device_->SetViewport(&vp);
}
bool Thin3DDX9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source) {
bool D3D9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source) {
LPD3DXMACRO defines = NULL;
LPD3DXINCLUDE includes = NULL;
DWORD flags = 0;
@ -815,14 +815,14 @@ bool Thin3DDX9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source) {
return true;
}
void Thin3DDX9Shader::SetVector(LPDIRECT3DDEVICE9 device, const char *name, float *value, int n) {
void D3D9Shader::SetVector(LPDIRECT3DDEVICE9 device, const char *name, float *value, int n) {
D3DXHANDLE handle = constantTable_->GetConstantByName(NULL, name);
if (handle) {
constantTable_->SetFloatArray(device, handle, value, n);
}
}
void Thin3DDX9Shader::SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const float value[16]) {
void D3D9Shader::SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const float value[16]) {
D3DXHANDLE handle = constantTable_->GetConstantByName(NULL, name);
if (handle) {
constantTable_->SetFloatArray(device, handle, value, 16);
@ -835,7 +835,7 @@ DrawContext *T3DCreateDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapt
ELOG("Failed to load D3DX9!");
return NULL;
}
return new Thin3DDX9Context(d3d, d3dEx, adapterId, device, deviceEx);
return new D3D9Context(d3d, d3dEx, adapterId, device, deviceEx);
}
} // namespace Draw

View file

@ -102,7 +102,7 @@ static const char *glsl_fragment_prelude =
"precision mediump float;\n"
"#endif\n";
class Thin3DGLBlendState : public BlendState {
class OpenGLBlendState : public BlendState {
public:
bool enabled;
GLuint eqCol, eqAlpha;
@ -135,8 +135,10 @@ public:
}
};
class Thin3DGLSamplerState : public SamplerState {
class OpenGLSamplerState : public SamplerState {
public:
// Old school. Should also support using a sampler object.
GLint wrapS;
GLint wrapT;
GLint magFilt;
@ -161,7 +163,7 @@ public:
}
};
class Thin3DGLDepthStencilState : public DepthStencilState {
class OpenGLDepthStencilState : public DepthStencilState {
public:
bool depthTestEnabled;
bool depthWriteEnabled;
@ -180,7 +182,7 @@ public:
}
};
class Thin3DGLRasterState : public RasterState {
class OpenGLRasterState : public RasterState {
public:
void Apply() {
if (!cullEnable) {
@ -197,9 +199,9 @@ public:
GLenum frontFace;
};
class Thin3DGLBuffer : public Buffer, GfxResourceHolder {
class OpenGLBuffer : public Buffer, GfxResourceHolder {
public:
Thin3DGLBuffer(size_t size, uint32_t flags) {
OpenGLBuffer(size_t size, uint32_t flags) {
glGenBuffers(1, &buffer_);
target_ = (flags & BufferUsageFlag::INDEXDATA) ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER;
usage_ = 0;
@ -210,7 +212,7 @@ public:
knownSize_ = 0;
register_gl_resource_holder(this);
}
~Thin3DGLBuffer() override {
~OpenGLBuffer() override {
unregister_gl_resource_holder(this);
glDeleteBuffers(1, &buffer_);
}
@ -254,9 +256,9 @@ private:
// Not registering this as a resource holder, instead ShaderSet is registered. It will
// invoke Compile again to recreate the shader then link them together.
class Thin3DGLShader : public Shader {
class OpenGLShader : public Shader {
public:
Thin3DGLShader(ShaderStage stage) : shader_(0), type_(0) {
OpenGLShader(ShaderStage stage) : shader_(0), type_(0) {
type_ = stage == ShaderStage::FRAGMENT ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER;
}
@ -270,7 +272,7 @@ public:
shader_ = 0;
}
~Thin3DGLShader() {
~OpenGLShader() {
glDeleteShader(shader_);
}
@ -281,7 +283,7 @@ private:
std::string source_; // So we can recompile in case of context loss.
};
bool Thin3DGLShader::Compile(const char *source) {
bool OpenGLShader::Compile(const char *source) {
source_ = source;
shader_ = glCreateShader(type_);
@ -310,9 +312,9 @@ bool Thin3DGLShader::Compile(const char *source) {
return ok_;
}
class Thin3DGLVertexFormat : public InputLayout, GfxResourceHolder {
class OpenGLVertexFormat : public InputLayout, GfxResourceHolder {
public:
~Thin3DGLVertexFormat();
~OpenGLVertexFormat();
void Apply(const void *base = nullptr);
void Unapply();
@ -337,13 +339,13 @@ struct UniformInfo {
// TODO: Fold BlendState into this? Seems likely to be right for DX12 etc.
// TODO: Add Uniform Buffer support.
class Thin3DGLShaderSet : public ShaderSet, GfxResourceHolder {
class OpenGLShaderSet : public ShaderSet, GfxResourceHolder {
public:
Thin3DGLShaderSet() {
OpenGLShaderSet() {
program_ = 0;
register_gl_resource_holder(this);
}
~Thin3DGLShaderSet() {
~OpenGLShaderSet() {
unregister_gl_resource_holder(this);
vshader->Release();
fshader->Release();
@ -371,18 +373,18 @@ public:
Link();
}
Thin3DGLShader *vshader;
Thin3DGLShader *fshader;
OpenGLShader *vshader;
OpenGLShader *fshader;
private:
GLuint program_;
std::map<std::string, UniformInfo> uniforms_;
};
class Thin3DGLContext : public DrawContext {
class OpenGLContext : public DrawContext {
public:
Thin3DGLContext();
virtual ~Thin3DGLContext();
OpenGLContext();
virtual ~OpenGLContext();
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
@ -396,7 +398,7 @@ public:
// Bound state objects
void SetBlendState(BlendState *state) override {
Thin3DGLBlendState *s = static_cast<Thin3DGLBlendState *>(state);
OpenGLBlendState *s = static_cast<OpenGLBlendState *>(state);
s->Apply();
}
@ -406,7 +408,7 @@ public:
}
for (int i = 0; i < count; ++i) {
int index = i + start;
Thin3DGLSamplerState *s = static_cast<Thin3DGLSamplerState *>(states[index]);
OpenGLSamplerState *s = static_cast<OpenGLSamplerState *>(states[index]);
if (samplerStates_[index]) {
samplerStates_[index]->Release();
@ -424,12 +426,12 @@ public:
// Bound state objects
void SetDepthStencilState(DepthStencilState *state) override {
Thin3DGLDepthStencilState *s = static_cast<Thin3DGLDepthStencilState *>(state);
OpenGLDepthStencilState *s = static_cast<OpenGLDepthStencilState *>(state);
s->Apply();
}
void SetRasterState(RasterState *state) override {
Thin3DGLRasterState *rs = static_cast<Thin3DGLRasterState *>(state);
OpenGLRasterState *rs = static_cast<OpenGLRasterState *>(state);
rs->Apply();
}
@ -496,15 +498,15 @@ public:
}
}
std::vector<Thin3DGLSamplerState *> samplerStates_;
std::vector<OpenGLSamplerState *> samplerStates_;
};
Thin3DGLContext::Thin3DGLContext() {
OpenGLContext::OpenGLContext() {
CreatePresets();
}
Thin3DGLContext::~Thin3DGLContext() {
for (Thin3DGLSamplerState *s : samplerStates_) {
OpenGLContext::~OpenGLContext() {
for (OpenGLSamplerState *s : samplerStates_) {
if (s) {
s->Release();
}
@ -512,8 +514,8 @@ Thin3DGLContext::~Thin3DGLContext() {
samplerStates_.clear();
}
InputLayout *Thin3DGLContext::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
Thin3DGLVertexFormat *fmt = new Thin3DGLVertexFormat();
InputLayout *OpenGLContext::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
OpenGLVertexFormat *fmt = new OpenGLVertexFormat();
fmt->components_ = components;
fmt->stride_ = stride;
fmt->Compile();
@ -626,11 +628,11 @@ private:
bool canWrap_;
};
Texture *Thin3DGLContext::CreateTexture() {
Texture *OpenGLContext::CreateTexture() {
return new Thin3DGLTexture();
}
Texture *Thin3DGLContext::CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) {
Texture *OpenGLContext::CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) {
return new Thin3DGLTexture(type, format, width, height, depth, mipLevels);
}
@ -649,7 +651,7 @@ void Thin3DGLTexture::SetImageData(int x, int y, int z, int width, int height, i
int format;
int type;
switch (format_) {
case DataFormat::R8A8G8B8_UNORM:
case DataFormat::R8G8B8A8_UNORM:
internalFormat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_BYTE;
@ -688,13 +690,12 @@ void Thin3DGLTexture::Finalize(int zim_flags) {
}
Thin3DGLVertexFormat::~Thin3DGLVertexFormat() {
OpenGLVertexFormat::~OpenGLVertexFormat() {
if (id_) {
glDeleteVertexArrays(1, &id_);
}
}
void Thin3DGLVertexFormat::Compile() {
void OpenGLVertexFormat::Compile() {
int sem = 0;
for (int i = 0; i < (int)components_.size(); i++) {
sem |= 1 << components_[i].semantic;
@ -711,24 +712,24 @@ void Thin3DGLVertexFormat::Compile() {
lastBase_ = -1;
}
void Thin3DGLVertexFormat::GLLost() {
void OpenGLVertexFormat::GLLost() {
id_ = 0;
}
void Thin3DGLVertexFormat::GLRestore() {
void OpenGLVertexFormat::GLRestore() {
Compile();
}
DepthStencilState *Thin3DGLContext::CreateDepthStencilState(const DepthStencilStateDesc &desc) {
Thin3DGLDepthStencilState *ds = new Thin3DGLDepthStencilState();
DepthStencilState *OpenGLContext::CreateDepthStencilState(const DepthStencilStateDesc &desc) {
OpenGLDepthStencilState *ds = new OpenGLDepthStencilState();
ds->depthTestEnabled = desc.depthTestEnabled;
ds->depthWriteEnabled = desc.depthWriteEnabled;
ds->depthComp = compToGL[(int)desc.depthCompare];
return ds;
}
BlendState *Thin3DGLContext::CreateBlendState(const BlendStateDesc &desc) {
Thin3DGLBlendState *bs = new Thin3DGLBlendState();
BlendState *OpenGLContext::CreateBlendState(const BlendStateDesc &desc) {
OpenGLBlendState *bs = new OpenGLBlendState();
bs->enabled = desc.enabled;
bs->eqCol = blendEqToGL[(int)desc.eqCol];
bs->srcCol = blendFactorToGL[(int)desc.srcCol];
@ -743,18 +744,18 @@ BlendState *Thin3DGLContext::CreateBlendState(const BlendStateDesc &desc) {
return bs;
}
SamplerState *Thin3DGLContext::CreateSamplerState(const SamplerStateDesc &desc) {
Thin3DGLSamplerState *samps = new Thin3DGLSamplerState();
samps->wrapS = texWrapToGL[(int)desc.wrapS];
samps->wrapT = texWrapToGL[(int)desc.wrapT];
samps->magFilt = texFilterToGL[(int)desc.magFilt];
samps->minFilt = texFilterToGL[(int)desc.minFilt];
samps->mipMinFilt = texMipFilterToGL[(int)desc.minFilt][(int)desc.mipFilt];
SamplerState *OpenGLContext::CreateSamplerState(const SamplerStateDesc &desc) {
OpenGLSamplerState *samps = new OpenGLSamplerState();
samps->wrapS = texWrapToGL[(int)desc.wrapU];
samps->wrapT = texWrapToGL[(int)desc.wrapV];
samps->magFilt = texFilterToGL[(int)desc.magFilter];
samps->minFilt = texFilterToGL[(int)desc.minFilter];
samps->mipMinFilt = texMipFilterToGL[(int)desc.minFilter][(int)desc.mipFilter];
return samps;
}
RasterState *Thin3DGLContext::CreateRasterState(const T3DRasterStateDesc &desc) {
Thin3DGLRasterState *rs = new Thin3DGLRasterState();
RasterState *OpenGLContext::CreateRasterState(const T3DRasterStateDesc &desc) {
OpenGLRasterState *rs = new OpenGLRasterState();
if (desc.cull == CullMode::NONE) {
rs->cullEnable = GL_FALSE;
return rs;
@ -782,20 +783,20 @@ RasterState *Thin3DGLContext::CreateRasterState(const T3DRasterStateDesc &desc)
return rs;
}
Buffer *Thin3DGLContext::CreateBuffer(size_t size, uint32_t usageFlags) {
return new Thin3DGLBuffer(size, usageFlags);
Buffer *OpenGLContext::CreateBuffer(size_t size, uint32_t usageFlags) {
return new OpenGLBuffer(size, usageFlags);
}
ShaderSet *Thin3DGLContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
ShaderSet *OpenGLContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
if (!vshader || !fshader) {
ELOG("ShaderSet requires both a valid vertex and a fragment shader: %p %p", vshader, fshader);
return NULL;
}
Thin3DGLShaderSet *shaderSet = new Thin3DGLShaderSet();
OpenGLShaderSet *shaderSet = new OpenGLShaderSet();
vshader->AddRef();
fshader->AddRef();
shaderSet->vshader = static_cast<Thin3DGLShader *>(vshader);
shaderSet->fshader = static_cast<Thin3DGLShader *>(fshader);
shaderSet->vshader = static_cast<OpenGLShader *>(vshader);
shaderSet->fshader = static_cast<OpenGLShader *>(fshader);
if (shaderSet->Link()) {
return shaderSet;
} else {
@ -804,7 +805,7 @@ ShaderSet *Thin3DGLContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
}
}
void Thin3DGLContext::BindTextures(int start, int count, Texture **textures) {
void OpenGLContext::BindTextures(int start, int count, Texture **textures) {
for (int i = start; i < start + count; i++) {
Thin3DGLTexture *glTex = static_cast<Thin3DGLTexture *>(textures[i]);
glActiveTexture(GL_TEXTURE0 + i);
@ -818,8 +819,8 @@ void Thin3DGLContext::BindTextures(int start, int count, Texture **textures) {
}
Shader *Thin3DGLContext::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
Thin3DGLShader *shader = new Thin3DGLShader(stage);
Shader *OpenGLContext::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
OpenGLShader *shader = new OpenGLShader(stage);
if (shader->Compile(glsl_source)) {
return shader;
} else {
@ -828,7 +829,7 @@ Shader *Thin3DGLContext::CreateShader(ShaderStage stage, const char *glsl_source
}
}
bool Thin3DGLShaderSet::Link() {
bool OpenGLShaderSet::Link() {
program_ = glCreateProgram();
glAttachShader(program_, vshader->GetShader());
glAttachShader(program_, fshader->GetShader());
@ -876,7 +877,7 @@ bool Thin3DGLShaderSet::Link() {
return true;
}
int Thin3DGLShaderSet::GetUniformLoc(const char *name) {
int OpenGLShaderSet::GetUniformLoc(const char *name) {
auto iter = uniforms_.find(name);
int loc = -1;
if (iter != uniforms_.end()) {
@ -890,7 +891,7 @@ int Thin3DGLShaderSet::GetUniformLoc(const char *name) {
return loc;
}
void Thin3DGLShaderSet::SetVector(const char *name, float *value, int n) {
void OpenGLShaderSet::SetVector(const char *name, float *value, int n) {
glUseProgram(program_);
int loc = GetUniformLoc(name);
if (loc != -1) {
@ -903,7 +904,7 @@ void Thin3DGLShaderSet::SetVector(const char *name, float *value, int n) {
}
}
void Thin3DGLShaderSet::SetMatrix4x4(const char *name, const float value[16]) {
void OpenGLShaderSet::SetMatrix4x4(const char *name, const float value[16]) {
glUseProgram(program_);
int loc = GetUniformLoc(name);
if (loc != -1) {
@ -911,18 +912,18 @@ void Thin3DGLShaderSet::SetMatrix4x4(const char *name, const float value[16]) {
}
}
void Thin3DGLShaderSet::Apply() {
void OpenGLShaderSet::Apply() {
glUseProgram(program_);
}
void Thin3DGLShaderSet::Unapply() {
void OpenGLShaderSet::Unapply() {
glUseProgram(0);
}
void Thin3DGLContext::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
Thin3DGLShaderSet *ss = static_cast<Thin3DGLShaderSet *>(shaderSet);
Thin3DGLBuffer *vbuf = static_cast<Thin3DGLBuffer *>(vdata);
Thin3DGLVertexFormat *fmt = static_cast<Thin3DGLVertexFormat *>(format);
void OpenGLContext::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
OpenGLShaderSet *ss = static_cast<OpenGLShaderSet *>(shaderSet);
OpenGLBuffer *vbuf = static_cast<OpenGLBuffer *>(vdata);
OpenGLVertexFormat *fmt = static_cast<OpenGLVertexFormat *>(format);
vbuf->Bind();
fmt->Apply();
@ -934,11 +935,11 @@ void Thin3DGLContext::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *fo
fmt->Unapply();
}
void Thin3DGLContext::DrawIndexed(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
Thin3DGLShaderSet *ss = static_cast<Thin3DGLShaderSet *>(shaderSet);
Thin3DGLBuffer *vbuf = static_cast<Thin3DGLBuffer *>(vdata);
Thin3DGLBuffer *ibuf = static_cast<Thin3DGLBuffer *>(idata);
Thin3DGLVertexFormat *fmt = static_cast<Thin3DGLVertexFormat *>(format);
void OpenGLContext::DrawIndexed(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
OpenGLShaderSet *ss = static_cast<OpenGLShaderSet *>(shaderSet);
OpenGLBuffer *vbuf = static_cast<OpenGLBuffer *>(vdata);
OpenGLBuffer *ibuf = static_cast<OpenGLBuffer *>(idata);
OpenGLVertexFormat *fmt = static_cast<OpenGLVertexFormat *>(format);
vbuf->Bind();
fmt->Apply();
@ -952,9 +953,9 @@ void Thin3DGLContext::DrawIndexed(Primitive prim, ShaderSet *shaderSet, InputLay
fmt->Unapply();
}
void Thin3DGLContext::DrawUP(Primitive prim, ShaderSet *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
Thin3DGLShaderSet *ss = static_cast<Thin3DGLShaderSet *>(shaderSet);
Thin3DGLVertexFormat *fmt = static_cast<Thin3DGLVertexFormat *>(format);
void OpenGLContext::DrawUP(Primitive prim, ShaderSet *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
OpenGLShaderSet *ss = static_cast<OpenGLShaderSet *>(shaderSet);
OpenGLVertexFormat *fmt = static_cast<OpenGLVertexFormat *>(format);
fmt->Apply(vdata);
ss->Apply();
@ -967,7 +968,7 @@ void Thin3DGLContext::DrawUP(Primitive prim, ShaderSet *shaderSet, InputLayout *
fmt->Unapply();
}
void Thin3DGLContext::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) {
void OpenGLContext::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) {
float col[4];
Uint8x4ToFloat4(col, colorval);
GLuint glMask = 0;
@ -991,10 +992,10 @@ void Thin3DGLContext::Clear(int mask, uint32_t colorval, float depthVal, int ste
}
DrawContext *T3DCreateGLContext() {
return new Thin3DGLContext();
return new OpenGLContext();
}
void Thin3DGLVertexFormat::Apply(const void *base) {
void OpenGLVertexFormat::Apply(const void *base) {
if (id_ != 0) {
glBindVertexArray(id_);
}
@ -1014,16 +1015,16 @@ void Thin3DGLVertexFormat::Apply(const void *base) {
if (b != lastBase_) {
for (size_t i = 0; i < components_.size(); i++) {
switch (components_[i].type) {
case DataFormat::FLOATx2:
case DataFormat::R32G32_FLOAT:
glVertexAttribPointer(components_[i].semantic, 2, GL_FLOAT, GL_FALSE, stride_, (void *)(b + (intptr_t)components_[i].offset));
break;
case DataFormat::FLOATx3:
case DataFormat::R32G32B32_FLOAT:
glVertexAttribPointer(components_[i].semantic, 3, GL_FLOAT, GL_FALSE, stride_, (void *)(b + (intptr_t)components_[i].offset));
break;
case DataFormat::FLOATx4:
case DataFormat::R32G32B32A32_FLOAT:
glVertexAttribPointer(components_[i].semantic, 4, GL_FLOAT, GL_FALSE, stride_, (void *)(b + (intptr_t)components_[i].offset));
break;
case DataFormat::UNORM8x4:
case DataFormat::R8G8B8A8_UNORM:
glVertexAttribPointer(components_[i].semantic, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride_, (void *)(b + (intptr_t)components_[i].offset));
break;
case DataFormat::UNKNOWN:
@ -1038,7 +1039,7 @@ void Thin3DGLVertexFormat::Apply(const void *base) {
}
}
void Thin3DGLVertexFormat::Unapply() {
void OpenGLVertexFormat::Unapply() {
if (id_ == 0) {
for (int i = 0; i < (int)SEM_MAX; i++) {
if (semanticsMask_ & (1 << i)) {

View file

@ -120,7 +120,7 @@ static inline void Uint8x4ToFloat4(uint32_t u, float f[4]) {
}
class Thin3DVKBlendState : public BlendState {
class VKBlendState : public BlendState {
public:
bool blendEnabled;
VkBlendOp eqCol, eqAlpha;
@ -146,7 +146,7 @@ public:
}
};
class Thin3DVKDepthStencilState : public DepthStencilState {
class VKDepthStencilState : public DepthStencilState {
public:
bool depthTestEnabled;
bool depthWriteEnabled;
@ -163,9 +163,9 @@ public:
}
};
class Thin3DVKRasterState : public RasterState {
class VKRasterState : public RasterState {
public:
Thin3DVKRasterState(VulkanContext *vulkan, const T3DRasterStateDesc &desc) {
VKRasterState(VulkanContext *vulkan, const T3DRasterStateDesc &desc) {
cullFace = desc.cull;
frontFace = desc.facing;
}
@ -221,14 +221,14 @@ private:
// Not registering this as a resource holder, instead ShaderSet is registered. It will
// invoke Compile again to recreate the shader then link them together.
class Thin3DVKShader : public Shader {
class VKShader : public Shader {
public:
Thin3DVKShader(ShaderStage stage) : module_(VK_NULL_HANDLE), ok_(false) {
VKShader(ShaderStage stage) : module_(VK_NULL_HANDLE), ok_(false) {
stage_ = stage == ShaderStage::FRAGMENT ? VK_SHADER_STAGE_FRAGMENT_BIT : VK_SHADER_STAGE_VERTEX_BIT;
}
bool Compile(VulkanContext *vulkan, const char *source);
const std::string &GetSource() const { return source_; }
~Thin3DVKShader() {
~VKShader() {
if (module_) {
vkDestroyShaderModule(device_, module_, nullptr);
}
@ -243,7 +243,7 @@ private:
std::string source_; // So we can recompile in case of context loss.
};
bool Thin3DVKShader::Compile(VulkanContext *vulkan, const char *source) {
bool VKShader::Compile(VulkanContext *vulkan, const char *source) {
// We'll need this to free it later.
device_ = vulkan->GetDevice();
this->source_ = source;
@ -273,15 +273,15 @@ bool Thin3DVKShader::Compile(VulkanContext *vulkan, const char *source) {
inline VkFormat ConvertVertexDataTypeToVk(DataFormat type) {
switch (type) {
case DataFormat::FLOATx2: return VK_FORMAT_R32G32_SFLOAT;
case DataFormat::FLOATx3: return VK_FORMAT_R32G32B32_SFLOAT;
case DataFormat::FLOATx4: return VK_FORMAT_R32G32B32A32_SFLOAT;
case DataFormat::UNORM8x4: return VK_FORMAT_R8G8B8A8_UNORM;
case DataFormat::R32G32_FLOAT: return VK_FORMAT_R32G32_SFLOAT;
case DataFormat::R32G32B32_FLOAT: return VK_FORMAT_R32G32B32_SFLOAT;
case DataFormat::R32G32B32A32_FLOAT: return VK_FORMAT_R32G32B32A32_SFLOAT;
case DataFormat::R8G8B8A8_UNORM: return VK_FORMAT_R8G8B8A8_UNORM;
default: return VK_FORMAT_UNDEFINED;
}
}
class Thin3DVKVertexFormat : public InputLayout {
class VKVertexFormat : public InputLayout {
public:
void ToVulkan(VkPipelineVertexInputStateCreateInfo *info, VkVertexInputAttributeDescription *attrDescs, VkVertexInputBindingDescription *bindDescs) {
memset(info, 0, sizeof(*info));
@ -311,14 +311,14 @@ public:
int stride_;
};
class Thin3DVKShaderSet : public ShaderSet {
class VKShaderSet : public ShaderSet {
public:
Thin3DVKShaderSet() {
VKShaderSet() {
// HACK! Hardcoded
uboSize_ = 16 * sizeof(float); // WorldViewProj
ubo_ = new uint8_t[uboSize_];
}
~Thin3DVKShaderSet() {
~VKShaderSet() {
vshader->Release();
fshader->Release();
delete[] ubo_;
@ -339,8 +339,8 @@ public:
return uboSize_;
}
Thin3DVKShader *vshader;
Thin3DVKShader *fshader;
VKShader *vshader;
VKShader *fshader;
private:
uint8_t *ubo_;
@ -348,11 +348,11 @@ private:
};
struct PipelineKey {
Thin3DVKDepthStencilState *depthStencil;
Thin3DVKBlendState *blend;
Thin3DVKShaderSet *shaderSet;
VKDepthStencilState *depthStencil;
VKBlendState *blend;
VKShaderSet *shaderSet;
VkPrimitiveTopology topology;
Thin3DVKRasterState *raster;
VKRasterState *raster;
// etc etc
@ -369,12 +369,12 @@ struct PipelineKey {
class Thin3DVKTexture;
class Thin3DVKSamplerState;
class VKTexture;
class VKSamplerState;
struct DescriptorSetKey {
Thin3DVKTexture *texture_;
Thin3DVKSamplerState *sampler_;
VKTexture *texture_;
VKSamplerState *sampler_;
VkBuffer buffer_;
bool operator < (const DescriptorSetKey &other) const {
@ -385,10 +385,10 @@ struct DescriptorSetKey {
}
};
class Thin3DVKContext : public DrawContext {
class VKContext : public DrawContext {
public:
Thin3DVKContext(VulkanContext *vulkan);
virtual ~Thin3DVKContext();
VKContext(VulkanContext *vulkan);
virtual ~VKContext();
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
@ -402,19 +402,19 @@ public:
// Bound state objects
void SetBlendState(BlendState *state) override {
Thin3DVKBlendState *s = static_cast<Thin3DVKBlendState *>(state);
VKBlendState *s = static_cast<VKBlendState *>(state);
curBlendState_ = s;
}
// Bound state objects
void SetDepthStencilState(DepthStencilState *state) override {
Thin3DVKDepthStencilState *s = static_cast<Thin3DVKDepthStencilState *>(state);
VKDepthStencilState *s = static_cast<VKDepthStencilState *>(state);
curDepthStencilState_ = s;
}
// Bound state objects
void SetRasterState(RasterState *state) override {
Thin3DVKRasterState *s = static_cast<Thin3DVKRasterState *>(state);
VKRasterState *s = static_cast<VKRasterState *>(state);
curRasterState_ = s;
}
@ -473,12 +473,12 @@ private:
VulkanContext *vulkan_;
// These are used to compose the pipeline cache key.
Thin3DVKBlendState *curBlendState_;
Thin3DVKDepthStencilState *curDepthStencilState_;
Thin3DVKShaderSet *curShaderSet_;
VKBlendState *curBlendState_;
VKDepthStencilState *curDepthStencilState_;
VKShaderSet *curShaderSet_;
VkPrimitiveTopology curPrim_;
Thin3DVKVertexFormat *curVertexFormat_;
Thin3DVKRasterState *curRasterState_;
VKVertexFormat *curVertexFormat_;
VKRasterState *curRasterState_;
// We keep a pipeline state cache.
std::map<PipelineKey, VkPipeline> pipelines_;
@ -502,8 +502,8 @@ private:
VkRect2D noScissor_; // Simply a scissor covering the screen.
enum {MAX_BOUND_TEXTURES = 1};
Thin3DVKTexture *boundTextures_[MAX_BOUND_TEXTURES];
Thin3DVKSamplerState *boundSamplers_[MAX_BOUND_TEXTURES];
VKTexture *boundTextures_[MAX_BOUND_TEXTURES];
VKSamplerState *boundSamplers_[MAX_BOUND_TEXTURES];
VkCommandBuffer cmd_; // The current one
@ -524,7 +524,7 @@ private:
VkFormat FormatToVulkan(DataFormat fmt, int *bpp) {
switch (fmt) {
case DataFormat::R8A8G8B8_UNORM: *bpp = 32; return VK_FORMAT_R8G8B8A8_UNORM;
case DataFormat::R8G8B8A8_UNORM: *bpp = 32; return VK_FORMAT_R8G8B8A8_UNORM;
case DataFormat::R4G4B4A4_UNORM: *bpp = 16; return VK_FORMAT_R4G4B4A4_UNORM_PACK16;
case DataFormat::D24S8: *bpp = 32; return VK_FORMAT_D24_UNORM_S8_UINT;
case DataFormat::D16: *bpp = 16; return VK_FORMAT_D16_UNORM;
@ -532,21 +532,32 @@ VkFormat FormatToVulkan(DataFormat fmt, int *bpp) {
}
}
class Thin3DVKSamplerState : public SamplerState {
public:
Thin3DVKSamplerState(VulkanContext *vulkan, const SamplerStateDesc &desc) : vulkan_(vulkan) {
VkSamplerCreateInfo s = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO };
s.addressModeU = desc.wrapS == TextureAddressMode::REPEAT ? VK_SAMPLER_ADDRESS_MODE_REPEAT : VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
s.addressModeV = desc.wrapT == TextureAddressMode::REPEAT ? VK_SAMPLER_ADDRESS_MODE_REPEAT : VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
s.magFilter = desc.magFilt == TextureFilter::LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST;
s.minFilter = desc.minFilt == TextureFilter::LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST;
s.mipmapMode = desc.mipFilt == TextureFilter::LINEAR ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST;
s.maxLod = 0.0; // TODO: Actually support mipmaps
inline VkSamplerAddressMode AddressModeToVulkan(Draw::TextureAddressMode mode) {
switch (mode) {
case TextureAddressMode::CLAMP_TO_BORDER: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
case TextureAddressMode::CLAMP_TO_EDGE: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
case TextureAddressMode::REPEAT_MIRROR: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
default:
case TextureAddressMode::REPEAT: return VK_SAMPLER_ADDRESS_MODE_REPEAT;
}
}
class VKSamplerState : public SamplerState {
public:
VKSamplerState(VulkanContext *vulkan, const SamplerStateDesc &desc) : vulkan_(vulkan) {
VkSamplerCreateInfo s = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO };
s.addressModeU = AddressModeToVulkan(desc.wrapU);
s.addressModeV = AddressModeToVulkan(desc.wrapV);
s.addressModeW = AddressModeToVulkan(desc.wrapW);
s.anisotropyEnable = desc.maxAniso > 1.0f;
s.magFilter = desc.magFilter == TextureFilter::LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST;
s.minFilter = desc.minFilter == TextureFilter::LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST;
s.mipmapMode = desc.mipFilter == TextureFilter::LINEAR ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST;
s.maxLod = desc.maxLod;
VkResult res = vkCreateSampler(vulkan_->GetDevice(), &s, nullptr, &sampler_);
assert(VK_SUCCESS == res);
}
~Thin3DVKSamplerState() {
~VKSamplerState() {
vkDestroySampler(vulkan_->GetDevice(), sampler_, nullptr);
}
@ -557,17 +568,17 @@ private:
VkSampler sampler_;
};
SamplerState *Thin3DVKContext::CreateSamplerState(const SamplerStateDesc &desc) {
return new Thin3DVKSamplerState(vulkan_, desc);
SamplerState *VKContext::CreateSamplerState(const SamplerStateDesc &desc) {
return new VKSamplerState(vulkan_, desc);
}
RasterState *Thin3DVKContext::CreateRasterState(const T3DRasterStateDesc &desc) {
return new Thin3DVKRasterState(vulkan_, desc);
RasterState *VKContext::CreateRasterState(const T3DRasterStateDesc &desc) {
return new VKRasterState(vulkan_, desc);
}
void Thin3DVKContext::SetSamplerStates(int start, int count, SamplerState **state) {
void VKContext::SetSamplerStates(int start, int count, SamplerState **state) {
for (int i = start; i < start + count; i++) {
boundSamplers_[i] = (Thin3DVKSamplerState *)state[i];
boundSamplers_[i] = (VKSamplerState *)state[i];
}
}
@ -578,17 +589,17 @@ enum class TextureState {
PENDING_DESTRUCTION,
};
class Thin3DVKTexture : public Texture {
class VKTexture : public Texture {
public:
Thin3DVKTexture(VulkanContext *vulkan) : vulkan_(vulkan), vkTex_(nullptr) {
VKTexture(VulkanContext *vulkan) : vulkan_(vulkan), vkTex_(nullptr) {
}
Thin3DVKTexture(VulkanContext *vulkan, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels)
VKTexture(VulkanContext *vulkan, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels)
: vulkan_(vulkan), format_(format), mipLevels_(mipLevels) {
Create(type, format, width, height, depth, mipLevels);
}
~Thin3DVKTexture() {
~VKTexture() {
Destroy();
}
@ -625,7 +636,7 @@ private:
DataFormat format_;
};
Thin3DVKContext::Thin3DVKContext(VulkanContext *vulkan)
VKContext::VKContext(VulkanContext *vulkan)
: viewportDirty_(false), scissorDirty_(false), vulkan_(vulkan), frameNum_(0) {
device_ = vulkan->GetDevice();
@ -701,7 +712,7 @@ Thin3DVKContext::Thin3DVKContext(VulkanContext *vulkan)
pipelineCache_ = vulkan_->CreatePipelineCache();
}
Thin3DVKContext::~Thin3DVKContext() {
VKContext::~VKContext() {
for (auto x : pipelines_) {
vkDestroyPipeline(device_, x.second, nullptr);
}
@ -718,7 +729,7 @@ Thin3DVKContext::~Thin3DVKContext() {
vkDestroyPipelineCache(device_, pipelineCache_, nullptr);
}
void Thin3DVKContext::Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) {
void VKContext::Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) {
VkClearValue clearVal[2] = {};
Uint8x4ToFloat4(colorval, clearVal[0].color.float32);
@ -748,7 +759,7 @@ void Thin3DVKContext::Begin(bool clear, uint32_t colorval, float depthVal, int s
viewportDirty_ = true;
}
void Thin3DVKContext::End() {
void VKContext::End() {
// Stop collecting data in the frame's data pushbuffer.
push_->End();
vulkan_->EndSurfaceRenderPass();
@ -760,7 +771,7 @@ void Thin3DVKContext::End() {
DirtyDynamicState();
}
VkDescriptorSet Thin3DVKContext::GetOrCreateDescriptorSet(VkBuffer buf) {
VkDescriptorSet VKContext::GetOrCreateDescriptorSet(VkBuffer buf) {
DescriptorSetKey key;
FrameData *frame = &frame_[frameNum_ & 1];
@ -819,7 +830,7 @@ VkDescriptorSet Thin3DVKContext::GetOrCreateDescriptorSet(VkBuffer buf) {
return descSet;
}
VkPipeline Thin3DVKContext::GetOrCreatePipeline() {
VkPipeline VKContext::GetOrCreatePipeline() {
PipelineKey key;
key.blend = curBlendState_;
key.depthStencil = curDepthStencilState_;
@ -915,7 +926,7 @@ VkPipeline Thin3DVKContext::GetOrCreatePipeline() {
return pipeline;
}
void Thin3DVKContext::SetScissorRect(int left, int top, int width, int height) {
void VKContext::SetScissorRect(int left, int top, int width, int height) {
scissor_.offset.x = left;
scissor_.offset.y = top;
scissor_.extent.width = width;
@ -923,7 +934,7 @@ void Thin3DVKContext::SetScissorRect(int left, int top, int width, int height) {
scissorDirty_ = true;
}
void Thin3DVKContext::SetViewports(int count, Viewport *viewports) {
void VKContext::SetViewports(int count, Viewport *viewports) {
viewport_.x = viewports[0].TopLeftX;
viewport_.y = viewports[0].TopLeftY;
viewport_.width = viewports[0].Width;
@ -933,7 +944,7 @@ void Thin3DVKContext::SetViewports(int count, Viewport *viewports) {
viewportDirty_ = true;
}
void Thin3DVKContext::ApplyDynamicState() {
void VKContext::ApplyDynamicState() {
if (scissorDirty_) {
if (scissorEnabled_) {
vkCmdSetScissor(cmd_, 0, 1, &scissor_);
@ -948,27 +959,27 @@ void Thin3DVKContext::ApplyDynamicState() {
}
}
void Thin3DVKContext::DirtyDynamicState() {
void VKContext::DirtyDynamicState() {
scissorDirty_ = true;
viewportDirty_ = true;
}
InputLayout *Thin3DVKContext::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
Thin3DVKVertexFormat *fmt = new Thin3DVKVertexFormat();
InputLayout *VKContext::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
VKVertexFormat *fmt = new VKVertexFormat();
fmt->components_ = components;
fmt->stride_ = stride;
return fmt;
}
Texture *Thin3DVKContext::CreateTexture() {
return new Thin3DVKTexture(vulkan_);
Texture *VKContext::CreateTexture() {
return new VKTexture(vulkan_);
}
Texture *Thin3DVKContext::CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) {
return new Thin3DVKTexture(vulkan_, type, format, width, height, depth, mipLevels);
Texture *VKContext::CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) {
return new VKTexture(vulkan_, type, format, width, height, depth, mipLevels);
}
void Thin3DVKTexture::SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) {
void VKTexture::SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) {
int bpp;
VkFormat vulkanFormat = FormatToVulkan(format_, &bpp);
int bytesPerPixel = bpp / 8;
@ -981,20 +992,20 @@ void Thin3DVKTexture::SetImageData(int x, int y, int z, int width, int height, i
vkTex_->Unlock();
}
void Thin3DVKTexture::Finalize(int zim_flags) {
void VKTexture::Finalize(int zim_flags) {
// TODO
}
DepthStencilState *Thin3DVKContext::CreateDepthStencilState(const DepthStencilStateDesc &desc) {
Thin3DVKDepthStencilState *ds = new Thin3DVKDepthStencilState();
DepthStencilState *VKContext::CreateDepthStencilState(const DepthStencilStateDesc &desc) {
VKDepthStencilState *ds = new VKDepthStencilState();
ds->depthTestEnabled = desc.depthTestEnabled;
ds->depthWriteEnabled = desc.depthWriteEnabled;
ds->depthComp = compToVK[(int)desc.depthCompare];
return ds;
}
BlendState *Thin3DVKContext::CreateBlendState(const BlendStateDesc &desc) {
Thin3DVKBlendState *bs = new Thin3DVKBlendState();
BlendState *VKContext::CreateBlendState(const BlendStateDesc &desc) {
VKBlendState *bs = new VKBlendState();
bs->blendEnabled = desc.enabled;
bs->eqCol = blendEqToGL[(int)desc.eqCol];
bs->srcCol = blendFactorToVk[(int)desc.srcCol];
@ -1007,20 +1018,20 @@ BlendState *Thin3DVKContext::CreateBlendState(const BlendStateDesc &desc) {
return bs;
}
Buffer *Thin3DVKContext::CreateBuffer(size_t size, uint32_t usageFlags) {
Buffer *VKContext::CreateBuffer(size_t size, uint32_t usageFlags) {
return new Thin3DVKBuffer(size, usageFlags);
}
ShaderSet *Thin3DVKContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
ShaderSet *VKContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
if (!vshader || !fshader) {
ELOG("ShaderSet requires both a valid vertex and a fragment shader: %p %p", vshader, fshader);
return NULL;
}
Thin3DVKShaderSet *shaderSet = new Thin3DVKShaderSet();
VKShaderSet *shaderSet = new VKShaderSet();
vshader->AddRef();
fshader->AddRef();
shaderSet->vshader = static_cast<Thin3DVKShader *>(vshader);
shaderSet->fshader = static_cast<Thin3DVKShader *>(fshader);
shaderSet->vshader = static_cast<VKShader *>(vshader);
shaderSet->fshader = static_cast<VKShader *>(fshader);
if (shaderSet->Link()) {
return shaderSet;
} else {
@ -1029,14 +1040,14 @@ ShaderSet *Thin3DVKContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
}
}
void Thin3DVKContext::BindTextures(int start, int count, Texture **textures) {
void VKContext::BindTextures(int start, int count, Texture **textures) {
for (int i = start; i < start + count; i++) {
boundTextures_[i] = static_cast<Thin3DVKTexture *>(textures[i]);
boundTextures_[i] = static_cast<VKTexture *>(textures[i]);
}
}
Shader *Thin3DVKContext::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
Thin3DVKShader *shader = new Thin3DVKShader(stage);
Shader *VKContext::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
VKShader *shader = new VKShader(stage);
if (shader->Compile(vulkan_, vulkan_source)) {
return shader;
} else {
@ -1046,12 +1057,12 @@ Shader *Thin3DVKContext::CreateShader(ShaderStage stage, const char *glsl_source
}
}
bool Thin3DVKShaderSet::Link() {
bool VKShaderSet::Link() {
// There is no link step. However, we will create and cache Pipeline objects in the device context.
return true;
}
int Thin3DVKShaderSet::GetUniformLoc(const char *name) {
int VKShaderSet::GetUniformLoc(const char *name) {
int loc = -1;
// HACK! As we only use one uniform we hardcode it.
@ -1062,11 +1073,11 @@ int Thin3DVKShaderSet::GetUniformLoc(const char *name) {
return loc;
}
void Thin3DVKShaderSet::SetVector(const char *name, float *value, int n) {
void VKShaderSet::SetVector(const char *name, float *value, int n) {
// TODO: Implement
}
void Thin3DVKShaderSet::SetMatrix4x4(const char *name, const float value[16]) {
void VKShaderSet::SetMatrix4x4(const char *name, const float value[16]) {
int loc = GetUniformLoc(name);
if (loc != -1) {
memcpy(ubo_ + loc, value, 16 * sizeof(float));
@ -1091,12 +1102,12 @@ inline VkPrimitiveTopology PrimToVK(Primitive prim) {
}
}
void Thin3DVKContext::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
void VKContext::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
ApplyDynamicState();
curPrim_ = PrimToVK(prim);
curShaderSet_ = (Thin3DVKShaderSet *)shaderSet;
curVertexFormat_ = (Thin3DVKVertexFormat *)format;
curShaderSet_ = (VKShaderSet *)shaderSet;
curVertexFormat_ = (VKVertexFormat *)format;
Thin3DVKBuffer *vbuf = static_cast<Thin3DVKBuffer *>(vdata);
VkBuffer vulkanVbuf;
@ -1114,12 +1125,12 @@ void Thin3DVKContext::Draw(Primitive prim, ShaderSet *shaderSet, InputLayout *fo
vkCmdDraw(cmd_, vertexCount, 1, offset, 0);
}
void Thin3DVKContext::DrawIndexed(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
void VKContext::DrawIndexed(Primitive prim, ShaderSet *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
ApplyDynamicState();
curPrim_ = PrimToVK(prim);
curShaderSet_ = (Thin3DVKShaderSet *)shaderSet;
curVertexFormat_ = (Thin3DVKVertexFormat *)format;
curShaderSet_ = (VKShaderSet *)shaderSet;
curVertexFormat_ = (VKVertexFormat *)format;
Thin3DVKBuffer *ibuf = static_cast<Thin3DVKBuffer *>(idata);
Thin3DVKBuffer *vbuf = static_cast<Thin3DVKBuffer *>(vdata);
@ -1143,12 +1154,12 @@ void Thin3DVKContext::DrawIndexed(Primitive prim, ShaderSet *shaderSet, InputLay
vkCmdDrawIndexed(cmd_, vertexCount, 1, 0, offset, 0);
}
void Thin3DVKContext::DrawUP(Primitive prim, ShaderSet *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
void VKContext::DrawUP(Primitive prim, ShaderSet *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
ApplyDynamicState();
curPrim_ = PrimToVK(prim);
curShaderSet_ = (Thin3DVKShaderSet *)shaderSet;
curVertexFormat_ = (Thin3DVKVertexFormat *)format;
curShaderSet_ = (VKShaderSet *)shaderSet;
curVertexFormat_ = (VKVertexFormat *)format;
VkBuffer vulkanVbuf, vulkanUBObuf;
size_t vbBindOffset = push_->Push(vdata, vertexCount * curVertexFormat_->stride_, &vulkanVbuf);
@ -1166,7 +1177,7 @@ void Thin3DVKContext::DrawUP(Primitive prim, ShaderSet *shaderSet, InputLayout *
vkCmdDraw(cmd_, vertexCount, 1, 0, 0);
}
void Thin3DVKContext::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) {
void VKContext::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) {
if (mask & ClearFlag::COLOR) {
VkClearColorValue col;
Uint8x4ToFloat4(colorval, col.float32);
@ -1183,7 +1194,7 @@ void Thin3DVKContext::Clear(int mask, uint32_t colorval, float depthVal, int ste
}
DrawContext *T3DCreateVulkanContext(VulkanContext *vulkan) {
return new Thin3DVKContext(vulkan);
return new VKContext(vulkan);
}
void AddFeature(std::vector<std::string> &features, const char *name, VkBool32 available, VkBool32 enabled) {
@ -1192,7 +1203,7 @@ void AddFeature(std::vector<std::string> &features, const char *name, VkBool32 a
features.push_back(buf);
}
std::vector<std::string> Thin3DVKContext::GetFeatureList() {
std::vector<std::string> VKContext::GetFeatureList() {
const VkPhysicalDeviceFeatures &available = vulkan_->GetFeaturesAvailable();
const VkPhysicalDeviceFeatures &enabled = vulkan_->GetFeaturesEnabled();
std::vector<std::string> features;