From d0e70dbeb6e90bf8dee52a861c70210871ce9cb9 Mon Sep 17 00:00:00 2001 From: Benlitz Date: Sat, 14 Sep 2013 17:34:05 +0000 Subject: [PATCH] gpu: moved VertexUsage to shader.h and added GetUsage() and GetIndex() to ShaderAttrib --- src/lol/gpu/shader.h | 87 ++++++++++++++++++++++++++++++++++++++ src/lol/gpu/vertexbuffer.h | 84 ------------------------------------ 2 files changed, 87 insertions(+), 84 deletions(-) diff --git a/src/lol/gpu/shader.h b/src/lol/gpu/shader.h index 5cd2c494..d66179f2 100644 --- a/src/lol/gpu/shader.h +++ b/src/lol/gpu/shader.h @@ -21,6 +21,90 @@ namespace lol { +/* A safe enum to indicate how a vertex stream is going to be used. For + * now there is only TexCoord and not TexCoord0 TexCoord1 etc. because + * we can always reorganise the vertex declaration for the indices to + * match. If the need arises these enums will be added. */ +struct VertexUsage +{ + enum Value + { + Position = 0, + BlendWeight, + BlendIndices, + Normal, + PointSize, + TexCoord, + TexCoordExt, + Tangent, + Binormal, + TessFactor, + PositionT, + Color, + Fog, + Depth, + Sample, + + Max + } + m_value; + +private: + static String GetName(Value v, bool use_simple) + { + String tmp = String(""); + if (!use_simple) tmp += "<"; + switch (v) + { + case Position: { tmp += "Position"; break; } + case BlendWeight: { tmp += "BlendWeight"; break; } + case BlendIndices: { tmp += "BlendIndices";break; } + case Normal: { tmp += "Normal"; break; } + case PointSize: { tmp += "PointSize"; break; } + case TexCoord: { tmp += "TexCoord"; break; } + case TexCoordExt: { tmp += "TexCoordExt"; break; } + case Tangent: { tmp += "Tangent"; break; } + case Binormal: { tmp += "Binormal"; break; } + case TessFactor: { tmp += "TessFactor"; break; } + case PositionT: { tmp += "PositionT"; break; } + case Color: { tmp += "Color"; break; } + case Fog: { tmp += "Fog"; break; } + case Depth: { tmp += "Depth"; break; } + case Sample: { tmp += "Sample"; break; } + default: { tmp += "UNDEFINED"; break; } + } + if (!use_simple) tmp += ">"; + return tmp; + } + +public: + static String GetName(Value v) + { + return GetName(v, false); + } + + static String GetNameList(uint32_t v) + { + String tmp = String("<"); + int nb = 0; + for (int i = 0; i < Max; ++i) + { + if (v & (1<"; + } + + inline VertexUsage(Value v) : m_value(v) {} + inline VertexUsage(int v) : m_value((Value)v) {} + inline operator Value() { return m_value; } +}; + struct ShaderUniform { friend class Shader; @@ -41,6 +125,9 @@ struct ShaderAttrib public: inline ShaderAttrib() : m_flags((uint64_t)0 - 1) {} + inline bool IsValid() { return m_flags != (uint64_t)0 - 1; } + inline VertexUsage GetUsage() { return VertexUsage((int)(m_flags >> 16) & 0xffff); } + inline int GetIndex() { return (int)(m_flags & 0xffff); } private: uint64_t m_flags; diff --git a/src/lol/gpu/vertexbuffer.h b/src/lol/gpu/vertexbuffer.h index 465a41ee..34c5582f 100644 --- a/src/lol/gpu/vertexbuffer.h +++ b/src/lol/gpu/vertexbuffer.h @@ -38,90 +38,6 @@ private: class VertexBufferData *m_data; }; -/* A safe enum to indicate how a vertex stream is going to be used. For - * now there is only TexCoord and not TexCoord0 TexCoord1 etc. because - * we can always reorganise the vertex declaration for the indices to - * match. If the need arises these enums will be added. */ -struct VertexUsage -{ - enum Value - { - Position = 0, - BlendWeight, - BlendIndices, - Normal, - PointSize, - TexCoord, - TexCoordExt, - Tangent, - Binormal, - TessFactor, - PositionT, - Color, - Fog, - Depth, - Sample, - - Max - } - m_value; - -private: - static String GetName(Value v, bool use_simple) - { - String tmp = String(""); - if (!use_simple) tmp += "<"; - switch (v) - { - case Position: { tmp += "Position"; break; } - case BlendWeight: { tmp += "BlendWeight"; break; } - case BlendIndices: { tmp += "BlendIndices";break; } - case Normal: { tmp += "Normal"; break; } - case PointSize: { tmp += "PointSize"; break; } - case TexCoord: { tmp += "TexCoord"; break; } - case TexCoordExt: { tmp += "TexCoordExt"; break; } - case Tangent: { tmp += "Tangent"; break; } - case Binormal: { tmp += "Binormal"; break; } - case TessFactor: { tmp += "TessFactor"; break; } - case PositionT: { tmp += "PositionT"; break; } - case Color: { tmp += "Color"; break; } - case Fog: { tmp += "Fog"; break; } - case Depth: { tmp += "Depth"; break; } - case Sample: { tmp += "Sample"; break; } - default: { tmp += "UNDEFINED"; break; } - } - if (!use_simple) tmp += ">"; - return tmp; - } - -public: - static String GetName(Value v) - { - return GetName(v, false); - } - - static String GetNameList(uint32_t v) - { - String tmp = String("<"); - int nb = 0; - for (int i = 0; i < Max; ++i) - { - if (v & (1<"; - } - - inline VertexUsage(Value v) : m_value(v) {} - inline VertexUsage(int v) : m_value((Value)v) {} - inline operator Value() { return m_value; } -}; - /* A safe enum to indicate what kind of primitive to draw. Used in * VertexDeclaration::DrawElements() for instance. */ struct MeshPrimitive