summaryrefslogtreecommitdiff
path: root/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp
diff options
context:
space:
mode:
authorhrydgard <hrydgard@gmail.com>2008-12-25 15:56:36 +0000
committerhrydgard <hrydgard@gmail.com>2008-12-25 15:56:36 +0000
commitdcc48d6c417192dec95aa0d0562d6cc2f3cfa18a (patch)
treef64ccb07691d1df7c508403421655d882086b49d /Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp
parent3fd665502e7956ebd97391c0f4cc907d70358968 (diff)
just a bunch of random code cleanup i did on the train bored, plus a d3d implementation of NativeVertexFormat which isn't actually used yet.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1658 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp')
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp
new file mode 100644
index 0000000000..0ac4d985c8
--- /dev/null
+++ b/Source/Plugins/Plugin_VideoDX9/Src/NativeVertexFormat.cpp
@@ -0,0 +1,145 @@
+// Copyright (C) 2003-2008 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official SVN repository and contact information can be found at
+// http://code.google.com/p/dolphin-emu/
+
+#include "D3DBase.h"
+
+#include "Profiler.h"
+#include "x64Emitter.h"
+#include "ABI.h"
+#include "MemoryUtil.h"
+#include "VertexShader.h"
+
+#include "CPMemory.h"
+#include "NativeVertexFormat.h"
+
+
+class D3DVertexFormat : public NativeVertexFormat
+{
+ PortableVertexDeclaration vtx_decl;
+ LPDIRECT3DVERTEXDECLARATION9 d3d_decl;
+
+public:
+ D3DVertexFormat();
+ ~D3DVertexFormat();
+ virtual void Initialize(const PortableVertexDeclaration &_vtx_decl);
+ virtual void SetupVertexPointers() const;
+};
+
+
+NativeVertexFormat *NativeVertexFormat::Create()
+{
+ return new D3DVertexFormat();
+}
+
+D3DVertexFormat::D3DVertexFormat() : d3d_decl(NULL)
+{
+}
+
+D3DVertexFormat::~D3DVertexFormat()
+{
+ if (d3d_decl)
+ {
+ d3d_decl->Release();
+ d3d_decl = NULL;
+ }
+}
+
+
+D3DDECLTYPE VarToD3D(VarType t)
+{
+ static const D3DDECLTYPE lookup[5] =
+ {
+ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4, D3DDECLTYPE_SHORT4N, D3DDECLTYPE_USHORT4N, D3DDECLTYPE_FLOAT3,
+ };
+ return lookup[t];
+}
+
+// TODO: Ban signed bytes as normals - not likely that ATI supports them natively.
+// We probably won't see much of a speed loss, and any speed loss will be regained anyway
+// when we finally compile display lists.
+
+void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
+{
+ D3DVERTEXELEMENT9 *elems = new D3DVERTEXELEMENT9[32];
+ memset(elems, 0, sizeof(D3DVERTEXELEMENT9) * 32);
+
+ // There's only one stream and it's 0, so the above memset takes care of that - no need to set Stream.
+ // Same for method.
+
+ // So, here we go. First position:
+ int elem_idx = 0;
+ elems[elem_idx].Offset = 0; // Positions are always first, at position 0.
+ elems[elem_idx].Type = D3DDECLTYPE_FLOAT3;
+ elems[elem_idx].Usage = D3DDECLUSAGE_POSITION;
+ ++elem_idx;
+
+ for (int i = 0; i < 3; i++)
+ {
+ if (_vtx_decl.normal_offset[i] >= 0)
+ {
+ elems[elem_idx].Offset = _vtx_decl.normal_offset[i];
+ elems[elem_idx].Type = VarToD3D(_vtx_decl.normal_gl_type);
+ elems[elem_idx].Usage = D3DDECLUSAGE_NORMAL;
+ elems[elem_idx].UsageIndex = i;
+ ++elem_idx;
+ }
+ }
+
+ for (int i = 0; i < 2; i++)
+ {
+ if (_vtx_decl.color_offset[i] >= 0)
+ {
+ elems[elem_idx].Offset = _vtx_decl.color_offset[i];
+ elems[elem_idx].Type = VarToD3D(_vtx_decl.color_gl_type);
+ elems[elem_idx].Usage = D3DDECLUSAGE_COLOR;
+ elems[elem_idx].UsageIndex = i;
+ ++elem_idx;
+ }
+ }
+
+ for (int i = 0; i < 8; i++)
+ {
+ if (_vtx_decl.texcoord_offset[i] >= 0)
+ {
+ elems[elem_idx].Offset = _vtx_decl.texcoord_offset[i];
+ elems[elem_idx].Type = VarToD3D(_vtx_decl.texcoord_gl_type[i]);
+ elems[elem_idx].Usage = D3DDECLUSAGE_TEXCOORD;
+ elems[elem_idx].UsageIndex = i;
+ ++elem_idx;
+ }
+ }
+
+ if (vtx_decl.posmtx_offset != -1)
+ {
+ // glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (void *)vtx_decl.posmtx_offset);
+ elems[elem_idx].Offset = _vtx_decl.posmtx_offset;
+ elems[elem_idx].Usage = D3DDECLUSAGE_BLENDINDICES;
+ elems[elem_idx].UsageIndex = 0;
+ ++elem_idx;
+ }
+
+ if (FAILED(D3D::dev->CreateVertexDeclaration(elems, &d3d_decl)))
+ {
+ PanicAlert("Failed to create D3D vertex declaration!");
+ return;
+ }
+}
+
+void D3DVertexFormat::SetupVertexPointers() const
+{
+ D3D::dev->SetVertexDeclaration(d3d_decl);
+} \ No newline at end of file