From a0f7f877e2e21d1b3b5f8c40cbf5d1908ad7acdc Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 17 Aug 2014 14:08:55 +0200 Subject: [PATCH] Fix vertex declarations. Hook up some more of D3D9 (doesn't work yet) --- gfx_es2/draw_buffer.cpp | 7 ++- thin3d/d3dx9_loader.cpp | 6 +- thin3d/thin3d.cpp | 54 ++++++++++++---- thin3d/thin3d.h | 29 +++++++-- thin3d/thin3d_d3d9.cpp | 134 +++++++++++++++++++++++++++++++++++----- thin3d/thin3d_gl.cpp | 36 ++--------- 6 files changed, 197 insertions(+), 69 deletions(-) diff --git a/gfx_es2/draw_buffer.cpp b/gfx_es2/draw_buffer.cpp index a89f42099b..0d4a9b60e2 100644 --- a/gfx_es2/draw_buffer.cpp +++ b/gfx_es2/draw_buffer.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "base/display.h" @@ -40,7 +41,11 @@ void DrawBuffer::Init(Thin3DContext *t3d, bool registerAsHolder) { vbuf_ = t3d_->CreateBuffer(MAX_VERTS * sizeof(Vertex), T3DBufferUsage::DYNAMIC | T3DBufferUsage::VERTEXDATA); inited_ = true; - vformat_ = t3d_->CreateVertexFormat(FVF_POS_UV_COLOR); + std::vector components; + components.push_back(Thin3DVertexComponent("Position", SEM_POSITION, FLOATx3, 0)); + components.push_back(Thin3DVertexComponent("TexCoord0", SEM_TEXCOORD0, FLOATx2, 12)); + components.push_back(Thin3DVertexComponent("Color0", SEM_COLOR0, UNORM8x4, 20)); + vformat_ = t3d_->CreateVertexFormat(components, 24); if (registerAsHolder) { register_gl_resource_holder(this); diff --git a/thin3d/d3dx9_loader.cpp b/thin3d/d3dx9_loader.cpp index 87e5898c70..a18453045f 100644 --- a/thin3d/d3dx9_loader.cpp +++ b/thin3d/d3dx9_loader.cpp @@ -252,7 +252,7 @@ void UnloadD3DXDynamic() { #define GB_D3D9_D3DXDLL_LOADER_CHECK_ENTRY_NULL_PTR(funcname) assert(false && GB_MAKE_STR2(funcname) ); -BOOL D3DXCheckVersion(UINT D3DSDKVersion, UINT D3DXSDKVersion) { +BOOL dyn_D3DXCheckVersion(UINT D3DSDKVersion, UINT D3DXSDKVersion) { if (!m_TFunc_D3DXCheckVersion) { GB_D3D9_D3DXDLL_LOADER_CHECK_ENTRY_NULL_PTR(D3DXCheckVersion) } @@ -260,7 +260,7 @@ BOOL D3DXCheckVersion(UINT D3DSDKVersion, UINT D3DXSDKVersion) { return m_TFunc_D3DXCheckVersion(D3DSDKVersion, D3DXSDKVersion); } -HRESULT D3DXAssembleShader(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines, +HRESULT dyn_D3DXAssembleShader(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER * ppErrorMsgs) { if (!m_TFunc_D3DXAssembleShader) { @@ -270,7 +270,7 @@ HRESULT D3DXAssembleShader(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pD pInclude, Flags, ppShader, ppErrorMsgs); } -HRESULT D3DXCompileShader(LPCSTR pSrcData, UINT srcDataLen, CONST D3DXMACRO* pDefines, +HRESULT dyn_D3DXCompileShader(LPCSTR pSrcData, UINT srcDataLen, CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE * ppConstantTable) diff --git a/thin3d/thin3d.cpp b/thin3d/thin3d.cpp index df652bd33b..df896d145a 100644 --- a/thin3d/thin3d.cpp +++ b/thin3d/thin3d.cpp @@ -1,21 +1,30 @@ #include -static const char * const fsTexCol = +static const char * const glsl_fsTexCol = "varying vec4 oColor0;\n" "varying vec2 oTexCoord0;\n" "uniform sampler2D Sampler0;\n" "void main() { gl_FragColor = oColor0 * texture2D(Sampler0, oTexCoord0); }\n"; -static const char * const hlslFsTexCol = ""; +static const char * const hlslFsTexCol = +"struct PS_INPUT { float4 color : COLOR0; float2 uv : TEXCOORD0; };\n" +"sampler2D tex0;\n" +"float4 main(PS_INPUT input) : COLOR0 {\n" +" return input.color * tex2D(tex0, input.uv);\n" +"}\n"; -static const char * const fsCol = +static const char * const glsl_fsCol = "varying vec4 oColor0;\n" "uniform sampler2D Sampler0;\n" "void main() { gl_FragColor = oColor0; }\n"; -static const char * const hlslFsCol = ""; +static const char * const hlslFsCol = +"struct PS_INPUT { float4 color : COLOR0; };\n" +"float4 main(PS_INPUT input) : COLOR0 {\n" +" return input.color;\n" +"}\n"; -static const char * const vsCol = +static const char * const glsl_vsCol = "attribute vec3 Position;\n" "attribute vec4 Color0;\n" "varying vec4 oColor0;\n" @@ -25,9 +34,18 @@ static const char * const vsCol = " oColor0 = Color0;\n" "}"; -static const char * const hlslVsCol = ""; +static const char * const hlslVsCol = +"struct VS_INPUT { float3 Position : POSITION; float4 Color0 : COLOR0; };\n" +"struct VS_OUTPUT { float4 Position : POSITION; float4 Color0 : COLOR0; };\n" +"float4x4 WorldViewProj : WORLDVIEWPROJ;\n" +"VS_OUTPUT main(VS_INPUT input) {\n" +" VS_OUTPUT output;\n" +" output.Position = mul(float4(input.Position, 1.0), WorldViewProj);\n" +" output.Color0 = input.Color0;\n" +" return output;\n" +"}\n"; -static const char * const vsTexCol = +static const char * const glsl_vsTexCol = "attribute vec3 Position;\n" "attribute vec4 Color0;\n" "attribute vec2 TexCoord0;\n" @@ -38,9 +56,19 @@ static const char * const vsTexCol = " gl_Position = WorldViewProj * vec4(Position, 1.0);\n" " oColor0 = Color0;\n" " oTexCoord0 = TexCoord0; \n" -"}"; +"}\n"; -static const char * const hlslVsTexCol = ""; +static const char * const hlslVsTexCol = +"struct VS_INPUT { float3 Position : POSITION; float2 Texcoord0 : TEXCOORD0; float4 Color0 : COLOR0; };\n" +"struct VS_OUTPUT { float4 Position : POSITION; float2 Texcoord0 : TEXCOORD0; float4 Color0 : COLOR0; };\n" +"float4x4 WorldViewProj : WORLDVIEWPROJ;\n" +"VS_OUTPUT main(VS_INPUT input) {\n" +" VS_OUTPUT output;\n" +" output.Position = mul(float4(input.Position, 1.0), WorldViewProj);\n" +" output.Texcoord0 = input.Texcoord0;\n" +" output.Color0 = input.Color0;\n" +" return output;\n" +"}\n"; void Thin3DContext::CreatePresets() { // Build prebuilt objects @@ -54,11 +82,11 @@ void Thin3DContext::CreatePresets() { bsPresets_[BS_STANDARD_ALPHA] = CreateBlendState(standard_alpha); bsPresets_[BS_PREMUL_ALPHA] = CreateBlendState(premul_alpha); - vsPresets_[VS_TEXTURE_COLOR_2D] = CreateVertexShader(vsTexCol, hlslVsTexCol); - vsPresets_[VS_COLOR_2D] = CreateVertexShader(vsCol, hlslVsCol); + vsPresets_[VS_TEXTURE_COLOR_2D] = CreateVertexShader(glsl_vsTexCol, hlslVsTexCol); + vsPresets_[VS_COLOR_2D] = CreateVertexShader(glsl_vsCol, hlslVsCol); - fsPresets_[FS_TEXTURE_COLOR_2D] = CreateFragmentShader(fsTexCol, hlslFsTexCol); - fsPresets_[FS_COLOR_2D] = CreateFragmentShader(fsCol, hlslFsCol); + fsPresets_[FS_TEXTURE_COLOR_2D] = CreateFragmentShader(glsl_fsTexCol, hlslFsTexCol); + fsPresets_[FS_COLOR_2D] = CreateFragmentShader(glsl_fsCol, hlslFsCol); ssPresets_[SS_TEXTURE_COLOR_2D] = CreateShaderSet(vsPresets_[VS_TEXTURE_COLOR_2D], fsPresets_[FS_TEXTURE_COLOR_2D]); ssPresets_[SS_COLOR_2D] = CreateShaderSet(vsPresets_[VS_COLOR_2D], fsPresets_[FS_COLOR_2D]); diff --git a/thin3d/thin3d.h b/thin3d/thin3d.h index 25d3a95b8b..2773106de5 100644 --- a/thin3d/thin3d.h +++ b/thin3d/thin3d.h @@ -7,6 +7,7 @@ #pragma once #include +#include class Matrix4x4; @@ -50,14 +51,19 @@ enum T3DBufferUsage : int { DYNAMIC = 16, }; -enum T3DVertexFormatPreset : int { - FVF_POS_UV_COLOR +enum T3DVertexDataType : uint8_t { + INVALID, + FLOATx2, + FLOATx3, + FLOATx4, + UNORM8x4, }; enum T3DSemantic : int { SEM_POSITION, SEM_COLOR0, SEM_TEXCOORD0, + SEM_TEXCOORD1, SEM_NORMAL, SEM_TANGENT, SEM_BINORMAL, // really BITANGENT @@ -144,6 +150,20 @@ public: virtual void SetRectangle(int x, int y, int w, int h, const uint8_t *data, int level = 0, int layer = 0); }; +struct Thin3DVertexComponent { + Thin3DVertexComponent() : name(nullptr), type(T3DVertexDataType::INVALID), semantic(255), offset(255) {} + Thin3DVertexComponent(const char *name, T3DSemantic semantic, T3DVertexDataType dataType, uint8_t offset) { + this->name = name; + this->semantic = semantic; + this->type = dataType; + this->offset = offset; + } + const char *name; + T3DVertexDataType type; + uint8_t semantic; + uint8_t offset; +}; + class Thin3DVertexFormat : public Thin3DObject { public: }; @@ -177,7 +197,7 @@ public: virtual Thin3DBlendState *CreateBlendState(const T3DBlendStateDesc &desc) = 0; virtual Thin3DBuffer *CreateBuffer(size_t size, uint32_t usageFlags) = 0; virtual Thin3DShaderSet *CreateShaderSet(Thin3DShader *vshader, Thin3DShader *fshader) = 0; - virtual Thin3DVertexFormat *CreateVertexFormat(T3DVertexFormatPreset preset) = 0; + virtual Thin3DVertexFormat *CreateVertexFormat(const std::vector &components, int stride) = 0; // Note that these DO NOT AddRef so you must not ->Release presets unless you manually AddRef them. Thin3DBlendState *GetBlendStatePreset(T3DBlendStatePreset preset) { return bsPresets_[preset]; } @@ -216,5 +236,6 @@ private: Thin3DContext *T3DCreateGLContext(); #ifdef _WIN32 -Thin3DContext *T3DCreateDX9Context(); +struct IDirect3DDevice9; +Thin3DContext *T3DCreateDX9Context(IDirect3DDevice9 *device); #endif diff --git a/thin3d/thin3d_d3d9.cpp b/thin3d/thin3d_d3d9.cpp index 03964d0eee..46fa230add 100644 --- a/thin3d/thin3d_d3d9.cpp +++ b/thin3d/thin3d_d3d9.cpp @@ -132,10 +132,11 @@ private: class Thin3DDX9VertexFormat : public Thin3DVertexFormat { public: - int GetVertexSize() { return 0; } - + Thin3DDX9VertexFormat(const std::vector &components, int stride); + int GetStride() const { return stride_; } private: LPDIRECT3DVERTEXDECLARATION9 decl_; + int stride_; }; class Thin3DDX9Shader : public Thin3DShader { @@ -165,11 +166,13 @@ private: LPD3DXCONSTANTTABLE constantTable; }; -class Thin3DDX9Pipeline : public Thin3DShaderSet { +class Thin3DDX9ShaderSet : public Thin3DShaderSet { public: Thin3DDX9Shader *vshader; Thin3DDX9Shader *pshader; void Apply(LPDIRECT3DDEVICE9 device); + void SetVector(const char *name, float *value, int n); + void SetMatrix4x4(const char *name, const Matrix4x4 &value); private: }; @@ -183,10 +186,10 @@ public: Thin3DBlendState *CreateBlendState(const T3DBlendStateDesc &desc) override; Thin3DBuffer *CreateBuffer(size_t size, uint32_t usageFlags) override; Thin3DShaderSet *CreateShaderSet(Thin3DShader *vshader, Thin3DShader *fshader) override; - Thin3DVertexFormat *CreateVertexFormat(T3DVertexFormatPreset preset) override; + Thin3DVertexFormat *CreateVertexFormat(const std::vector &components, int stride) override; - Thin3DShader *CreateVertexShader(const char *glsl_source, const char *hlsl_source); - Thin3DShader *CreateFragmentShader(const char *glsl_source, const char *hlsl_source); + Thin3DShader *CreateVertexShader(const char *glsl_source, const char *hlsl_source) override; + Thin3DShader *CreateFragmentShader(const char *glsl_source, const char *hlsl_source) override; // Bound state objects. Too cumbersome to add them all as parameters to Draw. void SetBlendState(Thin3DBlendState *state); @@ -207,11 +210,11 @@ private: }; Thin3DDX9Context::Thin3DDX9Context(LPDIRECT3DDEVICE9 device) : device_(device) { - CreatePresets(); int d3dx_ver = LoadD3DX9Dynamic(); if (!d3dx_ver) { ELOG("Failed to load D3DX9!"); } + CreatePresets(); } Thin3DDX9Context::~Thin3DDX9Context() { @@ -223,7 +226,7 @@ Thin3DDX9Context::~Thin3DDX9Context() { Thin3DShader *Thin3DDX9Context::CreateVertexShader(const char *glsl_source, const char *hlsl_source) { Thin3DDX9Shader *shader = new Thin3DDX9Shader(false); - if (shader->Compile(device_, hlsl_source, "ps_3_0")) { + if (shader->Compile(device_, hlsl_source, "vs_3_0")) { return shader; } else { delete shader; @@ -233,7 +236,7 @@ Thin3DShader *Thin3DDX9Context::CreateVertexShader(const char *glsl_source, cons Thin3DShader *Thin3DDX9Context::CreateFragmentShader(const char *glsl_source, const char *hlsl_source) { Thin3DDX9Shader *shader = new Thin3DDX9Shader(false); - if (shader->Compile(device_, hlsl_source, "vs_3_0")) { + if (shader->Compile(device_, hlsl_source, "ps_3_0")) { return shader; } else { delete shader; @@ -241,7 +244,14 @@ Thin3DShader *Thin3DDX9Context::CreateFragmentShader(const char *glsl_source, co } } -Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, T3DComparison depthCompare) { +Thin3DShaderSet *Thin3DDX9Context::CreateShaderSet(Thin3DShader *vshader, Thin3DShader *fshader) { + Thin3DDX9ShaderSet *shaderSet = new Thin3DDX9ShaderSet(); + shaderSet->vshader = static_cast(vshader); + shaderSet->pshader = static_cast(fshader); + return shaderSet; +} + +Thin3DDepthStencilState *Thin3DDX9Context::CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, T3DComparison depthCompare) { Thin3DDX9DepthStencilState *ds = new Thin3DDX9DepthStencilState(); ds->depthCompare = compareToD3D9[depthCompare]; ds->depthTestEnabled = depthTestEnabled; @@ -249,6 +259,11 @@ Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool dep return ds; } +Thin3DVertexFormat *Thin3DDX9Context::CreateVertexFormat(const std::vector &components, int stride) { + Thin3DDX9VertexFormat *fmt = new Thin3DDX9VertexFormat(components, stride); + return fmt; +} + Thin3DBlendState *Thin3DDX9Context::CreateBlendState(const T3DBlendStateDesc &desc) { Thin3DDX9BlendState *bs = new Thin3DDX9BlendState(); bs->enabled = desc.enabled; @@ -261,6 +276,56 @@ Thin3DBlendState *Thin3DDX9Context::CreateBlendState(const T3DBlendStateDesc &de return bs; } +void SemanticToD3D9UsageAndIndex(int semantic, BYTE *usage, BYTE *index) { + *index = 0; + switch (semantic) { + case SEM_POSITION: + *usage = D3DDECLUSAGE_POSITION; + break; + case SEM_NORMAL: + *usage = D3DDECLUSAGE_NORMAL; + break; + case SEM_TANGENT: + *usage = D3DDECLUSAGE_TANGENT; + break; + case SEM_BINORMAL: + *usage = D3DDECLUSAGE_BINORMAL; + break; + case SEM_COLOR0: + *usage = D3DDECLUSAGE_COLOR; + break; + case SEM_TEXCOORD0: + *usage = D3DDECLUSAGE_TEXCOORD; + break; + case SEM_TEXCOORD1: + *usage = D3DDECLUSAGE_TEXCOORD; + *index = 1; + break; + } +} + +static int VertexDataTypeToD3DType(T3DVertexDataType type) { + switch (type) { + case T3DVertexDataType::FLOATx2: return D3DDECLTYPE_FLOAT2; + case T3DVertexDataType::FLOATx3: return D3DDECLTYPE_FLOAT3; + case T3DVertexDataType::FLOATx4: return D3DDECLTYPE_FLOAT4; + case T3DVertexDataType::UNORM8x4: return D3DDECLTYPE_UBYTE4; // D3DCOLOR? + default: return D3DDECLTYPE_UNUSED; + } +} + +Thin3DDX9VertexFormat::Thin3DDX9VertexFormat(const std::vector &components, int stride) { + D3DVERTEXELEMENT9 *elements = new D3DVERTEXELEMENT9[components.size()]; + for (int i = 0; i < components.size(); i++) { + elements[i].Stream = 0; + elements[i].Offset = components[i].offset; + elements[i].Method = D3DDECLMETHOD_DEFAULT; + SemanticToD3D9UsageAndIndex(components[i].semantic, &elements[i].Usage, &elements[i].UsageIndex); + elements[i].Type = VertexDataTypeToD3DType(components[i].type); + } + stride_ = stride; +} + void Thin3DDX9Context::SetBlendState(Thin3DBlendState *state) { Thin3DDX9BlendState *bs = static_cast(state); } @@ -269,7 +334,7 @@ Thin3DBuffer *Thin3DDX9Context::CreateBuffer(size_t size, uint32_t usageFlags) { return new Thin3DDX9Buffer(device_, size, usageFlags); } -void Thin3DDX9Pipeline::Apply(LPDIRECT3DDEVICE9 device) { +void Thin3DDX9ShaderSet::Apply(LPDIRECT3DDEVICE9 device) { vshader->Apply(device); pshader->Apply(device); } @@ -277,7 +342,7 @@ void Thin3DDX9Pipeline::Apply(LPDIRECT3DDEVICE9 device) { void Thin3DDX9Context::Draw(T3DPrimitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) { Thin3DDX9Buffer *vbuf = static_cast(vdata); Thin3DDX9VertexFormat *fmt = static_cast(format); - vbuf->BindVertex(device_, fmt->GetVertexSize(), offset); + vbuf->BindVertex(device_, fmt->GetStride(), offset); device_->DrawPrimitive(primToD3D9[prim], offset, vertexCount / 3); } @@ -285,7 +350,7 @@ void Thin3DDX9Context::DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *pipeline, Thin3DDX9Buffer *vbuf = static_cast(vdata); Thin3DDX9Buffer *ibuf = static_cast(idata); Thin3DDX9VertexFormat *fmt = static_cast(format); - vbuf->BindVertex(device_, fmt->GetVertexSize(), offset); + vbuf->BindVertex(device_, fmt->GetStride(), offset); ibuf->BindIndex(device_); device_->DrawIndexedPrimitive(primToD3D9[prim], 0, 0, vertexCount, 0, vertexCount / 3); } @@ -302,6 +367,30 @@ Thin3DContext *T3DCreateDX9Context(LPDIRECT3DDEVICE9 device) { return new Thin3DDX9Context(device); } +void Thin3DDX9Context::SetScissorEnabled(bool enable) { + device_->SetRenderState(D3DRS_SCISSORTESTENABLE, enable); +} + +void Thin3DDX9Context::SetScissorRect(int left, int top, int width, int height) { + RECT rc; + rc.left = left; + rc.top = top; + rc.right = left + width; + rc.bottom = top + height; + device_->SetScissorRect(&rc); +} + +void Thin3DDX9Context::SetViewports(int count, T3DViewport *viewports) { + D3DVIEWPORT9 vp; + vp.X = viewports[0].TopLeftX; + vp.Y = viewports[0].TopLeftY; + vp.Width = viewports[0].Width; + vp.Height = viewports[0].Height; + vp.MinZ = viewports[0].MinDepth; + vp.MaxZ = viewports[0].MaxDepth; + device_->SetViewport(&vp); +} + bool Thin3DDX9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source, const char *profile) { LPD3DXMACRO defines = NULL; LPD3DXINCLUDE includes = NULL; @@ -310,7 +399,13 @@ bool Thin3DDX9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source, cons LPD3DXBUFFER errorBuffer; HRESULT hr = dyn_D3DXCompileShader(source, strlen(source), defines, includes, "main", profile, flags, &codeBuffer, &errorBuffer, &constantTable); if (FAILED(hr)) { - codeBuffer->Release(); + const char *error = (const char *)errorBuffer->GetBufferPointer(); + OutputDebugStringA(source); + OutputDebugStringA(error); + errorBuffer->Release(); + + if (codeBuffer) + codeBuffer->Release(); if (constantTable) constantTable->Release(); return false; @@ -324,8 +419,15 @@ bool Thin3DDX9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source, cons HRESULT result = device->CreateVertexShader((DWORD *)codeBuffer->GetBufferPointer(), &vshader); success = SUCCEEDED(result); } - codeBuffer->Release(); - // delete[] code; + codeBuffer->Release(); return true; } + +void Thin3DDX9ShaderSet::SetVector(const char *name, float *value, int n) { + +} + +void Thin3DDX9ShaderSet::SetMatrix4x4(const char *name, const Matrix4x4 &value) { + +} diff --git a/thin3d/thin3d_gl.cpp b/thin3d/thin3d_gl.cpp index 207ce2aa1a..872a73b229 100644 --- a/thin3d/thin3d_gl.cpp +++ b/thin3d/thin3d_gl.cpp @@ -177,28 +177,6 @@ bool Thin3DGLShader::Compile(const char *source) { return ok_; } -enum T3DVertexDataType : uint8_t { - INVALID, - FLOATx2, - FLOATx3, - FLOATx4, - UNORM8x4, -}; - -struct Thin3DVertexComponent { - Thin3DVertexComponent() : name(nullptr), type(T3DVertexDataType::INVALID), semantic(255), offset(255) {} - Thin3DVertexComponent(const char *name, T3DSemantic semantic, T3DVertexDataType dataType, uint8_t offset) { - this->name = name; - this->semantic = semantic; - this->type = dataType; - this->offset = offset; - } - const char *name; - T3DVertexDataType type; - uint8_t semantic; - uint8_t offset; -}; - class Thin3DGLVertexFormat : public Thin3DVertexFormat { public: void Apply(); @@ -253,7 +231,7 @@ public: Thin3DBlendState *CreateBlendState(const T3DBlendStateDesc &desc) override; Thin3DBuffer *CreateBuffer(size_t size, uint32_t usageFlags) override; Thin3DShaderSet *CreateShaderSet(Thin3DShader *vshader, Thin3DShader *fshader) override; - Thin3DVertexFormat *CreateVertexFormat(T3DVertexFormatPreset preset) override; + Thin3DVertexFormat *CreateVertexFormat(const std::vector &components, int stride) override; // Bound state objects void SetBlendState(Thin3DBlendState *state) override { @@ -296,16 +274,10 @@ Thin3DGLContext::Thin3DGLContext() { Thin3DGLContext::~Thin3DGLContext() { } -Thin3DVertexFormat *Thin3DGLContext::CreateVertexFormat(T3DVertexFormatPreset preset) { +Thin3DVertexFormat *Thin3DGLContext::CreateVertexFormat(const std::vector &components, int stride) { Thin3DGLVertexFormat *fmt = new Thin3DGLVertexFormat(); - switch (preset) { - case FVF_POS_UV_COLOR: - fmt->components_.push_back(Thin3DVertexComponent("Position", SEM_POSITION, FLOATx3, 0)); - fmt->components_.push_back(Thin3DVertexComponent("TexCoord0", SEM_TEXCOORD0, FLOATx2, 12)); - fmt->components_.push_back(Thin3DVertexComponent("Color0", SEM_COLOR0, UNORM8x4, 20)); - fmt->stride_ = 24; - break; - } + fmt->components_ = components; + fmt->stride_ = stride; fmt->Compile(); return fmt; }