Renamed AttributeUsage and AttributeType

... to VertexComponent and ComponentType.

-Renderer:
Renamed IsVertexAttributeSupported static method to
IsComponentTypeSupported

-VertexDeclaration:
Added IsTypeSupported static method
Renamed [Disable|Enable|Get]Attribute to [Disable|Enable|Get]Component
Removed GetAttributeSize static method

-VertexMapper:
Renamed GetAttributePtr method to GetComponentPtr

Former-commit-id: 7115856e1d389610c35b26f63af5d93a5ad5c690
This commit is contained in:
Lynix 2014-07-10 18:31:56 +02:00
parent 10a17bbf68
commit b54be6e25f
14 changed files with 326 additions and 305 deletions

View File

@ -127,14 +127,13 @@ class NAZARA_API NzOpenGL
static void Uninitialize(); static void Uninitialize();
static GLenum Attachment[nzAttachmentPoint_Max+1]; static GLenum Attachment[nzAttachmentPoint_Max+1];
static nzUInt8 AttributeIndex[nzAttributeUsage_Max+1];
static GLenum AttributeType[nzAttributeType_Max+1];
static GLenum BlendFunc[nzBlendFunc_Max+1]; static GLenum BlendFunc[nzBlendFunc_Max+1];
static GLenum BufferLock[nzBufferAccess_Max+1]; static GLenum BufferLock[nzBufferAccess_Max+1];
static GLenum BufferLockRange[nzBufferAccess_Max+1]; static GLenum BufferLockRange[nzBufferAccess_Max+1];
static GLenum BufferTarget[nzBufferType_Max+1]; static GLenum BufferTarget[nzBufferType_Max+1];
static GLenum BufferTargetBinding[nzBufferType_Max+1]; static GLenum BufferTargetBinding[nzBufferType_Max+1];
static GLenum BufferUsage[nzBufferUsage_Max+1]; static GLenum BufferUsage[nzBufferUsage_Max+1];
static GLenum ComponentType[nzComponentType_Max+1];
static GLenum CubemapFace[6]; // Un cube possède six faces et ça n'est pas près de changer static GLenum CubemapFace[6]; // Un cube possède six faces et ça n'est pas près de changer
static GLenum FaceFilling[nzFaceFilling_Max+1]; static GLenum FaceFilling[nzFaceFilling_Max+1];
static GLenum FaceSide[nzFaceSide_Max+1]; static GLenum FaceSide[nzFaceSide_Max+1];
@ -149,6 +148,7 @@ class NAZARA_API NzOpenGL
static GLenum TextureTarget[nzImageType_Max+1]; static GLenum TextureTarget[nzImageType_Max+1];
static GLenum TextureTargetBinding[nzImageType_Max+1]; static GLenum TextureTargetBinding[nzImageType_Max+1];
static GLenum TextureTargetProxy[nzImageType_Max+1]; static GLenum TextureTargetProxy[nzImageType_Max+1];
static nzUInt8 VertexComponentIndex[nzVertexComponent_Max+1];
private: private:
static void OnContextChanged(const NzContext* newContext); static void OnContextChanged(const NzContext* newContext);

View File

@ -70,9 +70,9 @@ class NAZARA_API NzRenderer
static bool Initialize(); static bool Initialize();
static bool IsComponentTypeSupported(nzComponentType type);
static bool IsEnabled(nzRendererParameter parameter); static bool IsEnabled(nzRendererParameter parameter);
static bool IsInitialized(); static bool IsInitialized();
static bool IsVertexAttributeSupported(nzAttributeType attributeType);
static void SetBlendFunc(nzBlendFunc srcBlend, nzBlendFunc dstBlend); static void SetBlendFunc(nzBlendFunc srcBlend, nzBlendFunc dstBlend);
static void SetClearColor(const NzColor& color); static void SetClearColor(const NzColor& color);

View File

@ -15,54 +15,6 @@ enum nzAnimationType
nzAnimationType_Max = nzAnimationType_Static nzAnimationType_Max = nzAnimationType_Static
}; };
enum nzAttributeType
{
nzAttributeType_Color,
nzAttributeType_Double1,
nzAttributeType_Double2,
nzAttributeType_Double3,
nzAttributeType_Double4,
nzAttributeType_Float1,
nzAttributeType_Float2,
nzAttributeType_Float3,
nzAttributeType_Float4,
nzAttributeType_Int1,
nzAttributeType_Int2,
nzAttributeType_Int3,
nzAttributeType_Int4,
nzAttributeType_Max = nzAttributeType_Int4
};
enum nzAttributeUsage
{
nzAttributeUsage_Unused = -1,
nzAttributeUsage_InstanceData0,
nzAttributeUsage_InstanceData1,
nzAttributeUsage_InstanceData2,
nzAttributeUsage_InstanceData3,
nzAttributeUsage_InstanceData4,
nzAttributeUsage_InstanceData5,
nzAttributeUsage_Normal,
nzAttributeUsage_Position,
nzAttributeUsage_Tangent,
nzAttributeUsage_TexCoord,
nzAttributeUsage_Userdata0,
nzAttributeUsage_Userdata1,
nzAttributeUsage_Userdata2,
nzAttributeUsage_Userdata3,
nzAttributeUsage_Userdata4,
nzAttributeUsage_Userdata5,
nzAttributeUsage_FirstInstanceData = nzAttributeUsage_InstanceData0,
nzAttributeUsage_FirstVertexData = nzAttributeUsage_Normal,
nzAttributeUsage_LastInstanceData = nzAttributeUsage_InstanceData5,
nzAttributeUsage_LastVertexData = nzAttributeUsage_Userdata5,
nzAttributeUsage_Max = nzAttributeUsage_Userdata5
};
enum nzBufferAccess enum nzBufferAccess
{ {
nzBufferAccess_DiscardAndWrite, nzBufferAccess_DiscardAndWrite,
@ -98,6 +50,25 @@ enum nzBufferUsage
nzBufferUsage_Max = nzBufferUsage_Static nzBufferUsage_Max = nzBufferUsage_Static
}; };
enum nzComponentType
{
nzComponentType_Color,
nzComponentType_Double1,
nzComponentType_Double2,
nzComponentType_Double3,
nzComponentType_Double4,
nzComponentType_Float1,
nzComponentType_Float2,
nzComponentType_Float3,
nzComponentType_Float4,
nzComponentType_Int1,
nzComponentType_Int2,
nzComponentType_Int3,
nzComponentType_Int4,
nzComponentType_Max = nzComponentType_Int4
};
enum nzCubemapFace enum nzCubemapFace
{ {
// Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap
@ -245,6 +216,35 @@ enum nzPrimitiveMode
nzPrimitiveMode_Max = nzPrimitiveMode_TriangleFan nzPrimitiveMode_Max = nzPrimitiveMode_TriangleFan
}; };
enum nzVertexComponent
{
nzVertexComponent_Unused = -1,
nzVertexComponent_InstanceData0,
nzVertexComponent_InstanceData1,
nzVertexComponent_InstanceData2,
nzVertexComponent_InstanceData3,
nzVertexComponent_InstanceData4,
nzVertexComponent_InstanceData5,
nzVertexComponent_Normal,
nzVertexComponent_Position,
nzVertexComponent_Tangent,
nzVertexComponent_TexCoord,
nzVertexComponent_Userdata0,
nzVertexComponent_Userdata1,
nzVertexComponent_Userdata2,
nzVertexComponent_Userdata3,
nzVertexComponent_Userdata4,
nzVertexComponent_Userdata5,
nzVertexComponent_FirstInstanceData = nzVertexComponent_InstanceData0,
nzVertexComponent_FirstVertexData = nzVertexComponent_Normal,
nzVertexComponent_LastInstanceData = nzVertexComponent_InstanceData5,
nzVertexComponent_LastVertexData = nzVertexComponent_Userdata5,
nzVertexComponent_Max = nzVertexComponent_Userdata5
};
enum nzVertexLayout enum nzVertexLayout
{ {
// Déclarations destinées au rendu // Déclarations destinées au rendu

View File

@ -9,6 +9,7 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp> #include <Nazara/Core/Initializer.hpp>
#include <Nazara/Utility/Enums.hpp>
class NAZARA_API NzUtility class NAZARA_API NzUtility
{ {
@ -22,6 +23,9 @@ class NAZARA_API NzUtility
static void Uninitialize(); static void Uninitialize();
static unsigned int ComponentCount[nzComponentType_Max+1];
static std::size_t ComponentStride[nzComponentType_Max+1];
private: private:
static unsigned int s_moduleReferenceCounter; static unsigned int s_moduleReferenceCounter;
}; };

View File

@ -28,10 +28,10 @@ class NAZARA_API NzVertexDeclaration : public NzResource
NzVertexDeclaration(NzVertexDeclaration& declaration); NzVertexDeclaration(NzVertexDeclaration& declaration);
~NzVertexDeclaration(); ~NzVertexDeclaration();
void DisableAttribute(nzAttributeUsage usage); void DisableComponent(nzVertexComponent component);
void EnableAttribute(nzAttributeUsage usage, nzAttributeType type, unsigned int offset); void EnableComponent(nzVertexComponent component, nzComponentType type, unsigned int offset);
void GetAttribute(nzAttributeUsage usage, bool* enabled, nzAttributeType* type, unsigned int* offset) const; void GetComponent(nzVertexComponent component, bool* enabled, nzComponentType* type, unsigned int* offset) const;
unsigned int GetStride() const; unsigned int GetStride() const;
void SetStride(unsigned int stride); void SetStride(unsigned int stride);
@ -39,15 +39,15 @@ class NAZARA_API NzVertexDeclaration : public NzResource
NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration); NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration);
static NzVertexDeclaration* Get(nzVertexLayout layout); static NzVertexDeclaration* Get(nzVertexLayout layout);
static unsigned int GetAttributeSize(nzAttributeType type); static bool IsTypeSupported(nzComponentType type);
private: private:
static bool Initialize(); static bool Initialize();
static void Uninitialize(); static void Uninitialize();
struct Attribute struct Component
{ {
nzAttributeType type; nzComponentType type;
bool enabled = false; bool enabled = false;
unsigned int offset; unsigned int offset;
@ -60,7 +60,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource
*/ */
}; };
Attribute m_attributes[nzAttributeUsage_Max+1]; Component m_components[nzVertexComponent_Max+1];
unsigned int m_stride; unsigned int m_stride;
static NzVertexDeclaration s_declarations[nzVertexLayout_Max+1]; static NzVertexDeclaration s_declarations[nzVertexLayout_Max+1];

View File

@ -24,7 +24,7 @@ class NAZARA_API NzVertexMapper
NzVertexMapper(NzSubMesh* subMesh); NzVertexMapper(NzSubMesh* subMesh);
~NzVertexMapper(); ~NzVertexMapper();
template<typename T> NzSparsePtr<T> GetAttributePtr(nzAttributeUsage attribute); template<typename T> NzSparsePtr<T> GetComponentPtr(nzVertexComponent component);
unsigned int GetVertexCount() const; unsigned int GetVertexCount() const;
void Unmap(); void Unmap();

View File

@ -5,12 +5,12 @@
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
template <typename T> template <typename T>
NzSparsePtr<T> NzVertexMapper::GetAttributePtr(nzAttributeUsage attribute) NzSparsePtr<T> NzVertexMapper::GetComponentPtr(nzVertexComponent component)
{ {
bool enabled; bool enabled;
nzAttributeType type; nzComponentType type;
unsigned int offset; unsigned int offset;
m_declaration->GetAttribute(attribute, &enabled, &type, &offset); m_declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled) if (enabled)
{ {
@ -19,7 +19,7 @@ NzSparsePtr<T> NzVertexMapper::GetAttributePtr(nzAttributeUsage attribute)
} }
else else
{ {
NazaraError("Attribute 0x" + NzString::Number(attribute, 16) + " is not enabled"); NazaraError("Attribute 0x" + NzString::Number(component, 16) + " is not enabled");
return NzSparsePtr<T>(); return NzSparsePtr<T>();
} }
} }

View File

@ -1854,47 +1854,6 @@ GLenum NzOpenGL::Attachment[] =
static_assert(nzAttachmentPoint_Max+1 == 4, "Attachment array is incomplete"); static_assert(nzAttachmentPoint_Max+1 == 4, "Attachment array is incomplete");
nzUInt8 NzOpenGL::AttributeIndex[] =
{
10, // nzAttributeUsage_InstanceData0
11, // nzAttributeUsage_InstanceData1
12, // nzAttributeUsage_InstanceData2
13, // nzAttributeUsage_InstanceData3
14, // nzAttributeUsage_InstanceData4
15, // nzAttributeUsage_InstanceData5
2, // nzAttributeUsage_Normal
0, // nzAttributeUsage_Position
3, // nzAttributeUsage_Tangent
1, // nzAttributeUsage_TexCoord
4, // nzAttributeUsage_Userdata0
5, // nzAttributeUsage_Userdata1
6, // nzAttributeUsage_Userdata2
7, // nzAttributeUsage_Userdata3
8, // nzAttributeUsage_Userdata4
9 // nzAttributeUsage_Userdata5
};
static_assert(nzAttributeUsage_Max+1 == 16, "Attribute index array is incomplete");
GLenum NzOpenGL::AttributeType[] =
{
GL_UNSIGNED_BYTE, // nzAttributeType_Color
GL_DOUBLE, // nzAttributeType_Double1
GL_DOUBLE, // nzAttributeType_Double2
GL_DOUBLE, // nzAttributeType_Double3
GL_DOUBLE, // nzAttributeType_Double4
GL_FLOAT, // nzAttributeType_Float1
GL_FLOAT, // nzAttributeType_Float2
GL_FLOAT, // nzAttributeType_Float3
GL_FLOAT, // nzAttributeType_Float4
GL_INT, // nzAttributeType_Int1
GL_INT, // nzAttributeType_Int2
GL_INT, // nzAttributeType_Int3
GL_INT // nzAttributeType_Int4
};
static_assert(nzAttributeType_Max+1 == 13, "Attribute type array is incomplete");
GLenum NzOpenGL::BlendFunc[] = GLenum NzOpenGL::BlendFunc[] =
{ {
GL_DST_ALPHA, // nzBlendFunc_DestAlpha GL_DST_ALPHA, // nzBlendFunc_DestAlpha
@ -1958,6 +1917,25 @@ GLenum NzOpenGL::BufferUsage[] =
static_assert(nzBufferUsage_Max+1 == 2, "Buffer usage array is incomplete"); static_assert(nzBufferUsage_Max+1 == 2, "Buffer usage array is incomplete");
GLenum NzOpenGL::ComponentType[] =
{
GL_UNSIGNED_BYTE, // nzComponentType_Color
GL_DOUBLE, // nzComponentType_Double1
GL_DOUBLE, // nzComponentType_Double2
GL_DOUBLE, // nzComponentType_Double3
GL_DOUBLE, // nzComponentType_Double4
GL_FLOAT, // nzComponentType_Float1
GL_FLOAT, // nzComponentType_Float2
GL_FLOAT, // nzComponentType_Float3
GL_FLOAT, // nzComponentType_Float4
GL_INT, // nzComponentType_Int1
GL_INT, // nzComponentType_Int2
GL_INT, // nzComponentType_Int3
GL_INT // nzComponentType_Int4
};
static_assert(nzComponentType_Max+1 == 13, "Attribute type array is incomplete");
GLenum NzOpenGL::CubemapFace[] = GLenum NzOpenGL::CubemapFace[] =
{ {
GL_TEXTURE_CUBE_MAP_POSITIVE_X, // nzCubemapFace_PositiveX GL_TEXTURE_CUBE_MAP_POSITIVE_X, // nzCubemapFace_PositiveX
@ -2117,6 +2095,28 @@ GLenum NzOpenGL::TextureTargetProxy[] =
static_assert(nzImageType_Max+1 == 6, "Texture target proxy array is incomplete"); static_assert(nzImageType_Max+1 == 6, "Texture target proxy array is incomplete");
nzUInt8 NzOpenGL::VertexComponentIndex[] =
{
10, // nzVertexComponent_InstanceData0
11, // nzVertexComponent_InstanceData1
12, // nzVertexComponent_InstanceData2
13, // nzVertexComponent_InstanceData3
14, // nzVertexComponent_InstanceData4
15, // nzVertexComponent_InstanceData5
2, // nzVertexComponent_Normal
0, // nzVertexComponent_Position
3, // nzVertexComponent_Tangent
1, // nzVertexComponent_TexCoord
4, // nzVertexComponent_Userdata0
5, // nzVertexComponent_Userdata1
6, // nzVertexComponent_Userdata2
7, // nzVertexComponent_Userdata3
8, // nzVertexComponent_Userdata4
9 // nzVertexComponent_Userdata5
};
static_assert(nzVertexComponent_Max+1 == 16, "Attribute index array is incomplete");
PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr;
PFNGLATTACHSHADERPROC glAttachShader = nullptr; PFNGLATTACHSHADERPROC glAttachShader = nullptr;
PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender = nullptr; PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender = nullptr;

View File

@ -897,6 +897,34 @@ bool NzRenderer::Initialize()
return true; return true;
} }
bool NzRenderer::IsComponentTypeSupported(nzComponentType type)
{
switch (type)
{
case nzComponentType_Color:
case nzComponentType_Float1:
case nzComponentType_Float2:
case nzComponentType_Float3:
case nzComponentType_Float4:
return true; // Supportés nativement
case nzComponentType_Double1:
case nzComponentType_Double2:
case nzComponentType_Double3:
case nzComponentType_Double4:
return glVertexAttribLPointer != nullptr; // Fonction requise pour envoyer des doubles
case nzComponentType_Int1:
case nzComponentType_Int2:
case nzComponentType_Int3:
case nzComponentType_Int4:
return glVertexAttribIPointer != nullptr; // Fonction requise pour envoyer des entiers
}
NazaraError("Attribute type out of enum (0x" + NzString::Number(type, 16) + ')');
return false;
}
bool NzRenderer::IsEnabled(nzRendererParameter parameter) bool NzRenderer::IsEnabled(nzRendererParameter parameter)
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
@ -915,34 +943,6 @@ bool NzRenderer::IsInitialized()
return s_moduleReferenceCounter != 0; return s_moduleReferenceCounter != 0;
} }
bool NzRenderer::IsVertexAttributeSupported(nzAttributeType attributeType)
{
switch (attributeType)
{
case nzAttributeType_Color:
case nzAttributeType_Float1:
case nzAttributeType_Float2:
case nzAttributeType_Float3:
case nzAttributeType_Float4:
return true; // Supportés nativement
case nzAttributeType_Double1:
case nzAttributeType_Double2:
case nzAttributeType_Double3:
case nzAttributeType_Double4:
return glVertexAttribLPointer != nullptr; // Fonction requise pour envoyer des doubles
case nzAttributeType_Int1:
case nzAttributeType_Int2:
case nzAttributeType_Int3:
case nzAttributeType_Int4:
return glVertexAttribIPointer != nullptr; // Fonction requise pour envoyer des entiers
}
NazaraError("Attribute type out of enum");
return false;
}
void NzRenderer::SetBlendFunc(nzBlendFunc srcBlend, nzBlendFunc dstBlend) void NzRenderer::SetBlendFunc(nzBlendFunc srcBlend, nzBlendFunc dstBlend)
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
@ -1766,51 +1766,51 @@ bool NzRenderer::EnsureStateUpdate()
bufferOffset = s_vertexBuffer->GetStartOffset(); bufferOffset = s_vertexBuffer->GetStartOffset();
vertexDeclaration = s_vertexBuffer->GetVertexDeclaration(); vertexDeclaration = s_vertexBuffer->GetVertexDeclaration();
stride = vertexDeclaration->GetStride(); stride = vertexDeclaration->GetStride();
for (unsigned int i = nzAttributeUsage_FirstVertexData; i <= nzAttributeUsage_LastVertexData; ++i) for (unsigned int i = nzVertexComponent_FirstVertexData; i <= nzVertexComponent_LastVertexData; ++i)
{ {
nzAttributeType type; nzComponentType type;
bool enabled; bool enabled;
unsigned int offset; unsigned int offset;
vertexDeclaration->GetAttribute(static_cast<nzAttributeUsage>(i), &enabled, &type, &offset); vertexDeclaration->GetComponent(static_cast<nzVertexComponent>(i), &enabled, &type, &offset);
if (!IsVertexAttributeSupported(type)) if (!IsComponentTypeSupported(type))
{ {
NazaraError("Invalid declaration: Vertex attribute 0x" + NzString::Number(i, 16) + " (0x" + NzString::Number(type, 16) + ") is not supported"); NazaraError("Invalid declaration: Vertex component 0x" + NzString::Number(i, 16) + " (type: 0x" + NzString::Number(type, 16) + ") is not supported");
updateFailed = true; updateFailed = true;
break; break;
} }
if (enabled) if (enabled)
{ {
glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]); glEnableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
if (type <= nzAttributeType_Double1 && type >= nzAttributeType_Double4) if (type <= nzComponentType_Double1 && type >= nzComponentType_Double4)
{ {
glVertexAttribLPointer(NzOpenGL::AttributeIndex[i], glVertexAttribLPointer(NzOpenGL::VertexComponentIndex[i],
NzVertexDeclaration::GetAttributeSize(type), NzUtility::ComponentCount[type],
NzOpenGL::AttributeType[type], NzOpenGL::ComponentType[type],
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
} }
else if (type <= nzAttributeType_Int1 && type >= nzAttributeType_Int4) else if (type <= nzComponentType_Int1 && type >= nzComponentType_Int4)
{ {
glVertexAttribIPointer(NzOpenGL::AttributeIndex[i], glVertexAttribIPointer(NzOpenGL::VertexComponentIndex[i],
NzVertexDeclaration::GetAttributeSize(type), NzUtility::ComponentCount[type],
NzOpenGL::AttributeType[type], NzOpenGL::ComponentType[type],
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
} }
else else
{ {
glVertexAttribPointer(NzOpenGL::AttributeIndex[i], glVertexAttribPointer(NzOpenGL::VertexComponentIndex[i],
NzVertexDeclaration::GetAttributeSize(type), NzUtility::ComponentCount[type],
NzOpenGL::AttributeType[type], NzOpenGL::ComponentType[type],
(type == nzAttributeType_Color) ? GL_TRUE : GL_FALSE, (type == nzComponentType_Color) ? GL_TRUE : GL_FALSE,
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
} }
} }
else else
glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
} }
if (!updateFailed) if (!updateFailed)
@ -1823,59 +1823,59 @@ bool NzRenderer::EnsureStateUpdate()
bufferOffset = s_instanceBuffer.GetStartOffset(); bufferOffset = s_instanceBuffer.GetStartOffset();
vertexDeclaration = s_instanceBuffer.GetVertexDeclaration(); vertexDeclaration = s_instanceBuffer.GetVertexDeclaration();
stride = vertexDeclaration->GetStride(); stride = vertexDeclaration->GetStride();
for (unsigned int i = nzAttributeUsage_FirstInstanceData; i <= nzAttributeUsage_LastInstanceData; ++i) for (unsigned int i = nzVertexComponent_FirstInstanceData; i <= nzVertexComponent_LastInstanceData; ++i)
{ {
nzAttributeType type; nzComponentType type;
bool enabled; bool enabled;
unsigned int offset; unsigned int offset;
vertexDeclaration->GetAttribute(static_cast<nzAttributeUsage>(i), &enabled, &type, &offset); vertexDeclaration->GetComponent(static_cast<nzVertexComponent>(i), &enabled, &type, &offset);
if (!IsVertexAttributeSupported(type)) if (!IsComponentTypeSupported(type))
{ {
NazaraError("Invalid declaration: Vertex attribute 0x" + NzString::Number(i, 16) + " (0x" + NzString::Number(type, 16) + ") is not supported"); NazaraError("Invalid declaration: Vertex component 0x" + NzString::Number(i, 16) + " (type: 0x" + NzString::Number(type, 16) + ") is not supported");
updateFailed = true; updateFailed = true;
break; break;
} }
if (enabled) if (enabled)
{ {
glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]); glEnableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
if (type <= nzAttributeType_Double1 && type >= nzAttributeType_Double4) if (type <= nzComponentType_Double1 && type >= nzComponentType_Double4)
{ {
glVertexAttribLPointer(NzOpenGL::AttributeIndex[i], glVertexAttribLPointer(NzOpenGL::VertexComponentIndex[i],
NzVertexDeclaration::GetAttributeSize(type), NzUtility::ComponentCount[type],
NzOpenGL::AttributeType[type], NzOpenGL::ComponentType[type],
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
} }
else if (type <= nzAttributeType_Int1 && type >= nzAttributeType_Int4) else if (type <= nzComponentType_Int1 && type >= nzComponentType_Int4)
{ {
glVertexAttribIPointer(NzOpenGL::AttributeIndex[i], glVertexAttribIPointer(NzOpenGL::VertexComponentIndex[i],
NzVertexDeclaration::GetAttributeSize(type), NzUtility::ComponentCount[type],
NzOpenGL::AttributeType[type], NzOpenGL::ComponentType[type],
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
} }
else else
{ {
glVertexAttribPointer(NzOpenGL::AttributeIndex[i], glVertexAttribPointer(NzOpenGL::VertexComponentIndex[i],
NzVertexDeclaration::GetAttributeSize(type), NzUtility::ComponentCount[type],
NzOpenGL::AttributeType[type], NzOpenGL::ComponentType[type],
(type == nzAttributeType_Color) ? GL_TRUE : GL_FALSE, (type == nzComponentType_Color) ? GL_TRUE : GL_FALSE,
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
} }
glVertexAttribDivisor(NzOpenGL::AttributeIndex[i], 1); glVertexAttribDivisor(NzOpenGL::VertexComponentIndex[i], 1);
} }
else else
glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
} }
} }
else else
{ {
for (unsigned int i = nzAttributeUsage_FirstInstanceData; i <= nzAttributeUsage_LastInstanceData; ++i) for (unsigned int i = nzVertexComponent_FirstInstanceData; i <= nzVertexComponent_LastInstanceData; ++i)
glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
} }
// Et on active l'index buffer (Un seul index buffer par VAO) // Et on active l'index buffer (Un seul index buffer par VAO)

View File

@ -149,22 +149,22 @@ bool NzShader::Create()
m_linked = false; m_linked = false;
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData0], "InstanceData0"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData0], "InstanceData0");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData1], "InstanceData1"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData1], "InstanceData1");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData2], "InstanceData2"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData2], "InstanceData2");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData3], "InstanceData3"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData3], "InstanceData3");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData4], "InstanceData4"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData4], "InstanceData4");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData5], "InstanceData5"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_InstanceData5], "InstanceData5");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Normal], "VertexNormal"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Normal], "VertexNormal");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Position], "VertexPosition"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Position], "VertexPosition");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Tangent], "VertexTangent"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Tangent], "VertexTangent");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_TexCoord], "VertexTexCoord"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_TexCoord], "VertexTexCoord");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata0], "VertexUserdata0"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata0], "VertexUserdata0");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata1], "VertexUserdata1"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata1], "VertexUserdata1");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata2], "VertexUserdata2"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata2], "VertexUserdata2");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata3], "VertexUserdata3"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata3], "VertexUserdata3");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata4], "VertexUserdata4"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata4], "VertexUserdata4");
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_Userdata5], "VertexUserdata5"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata5], "VertexUserdata5");
if (NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets)) if (NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets))
{ {

View File

@ -26,7 +26,7 @@ void NzStaticMesh::Center()
NzVector3f offset(m_aabb.x + m_aabb.width/2.f, m_aabb.y + m_aabb.height/2.f, m_aabb.z + m_aabb.depth/2.f); NzVector3f offset(m_aabb.x + m_aabb.width/2.f, m_aabb.y + m_aabb.height/2.f, m_aabb.z + m_aabb.depth/2.f);
NzVertexMapper mapper(this); NzVertexMapper mapper(this);
NzSparsePtr<NzVector3f> position = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Position); NzSparsePtr<NzVector3f> position = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position);
unsigned int vertexCount = mapper.GetVertexCount(); unsigned int vertexCount = mapper.GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i) for (unsigned int i = 0; i < vertexCount; ++i)

View File

@ -27,8 +27,8 @@ void NzSubMesh::GenerateNormals()
NzVertexMapper mapper(this); NzVertexMapper mapper(this);
unsigned int vertexCount = mapper.GetVertexCount(); unsigned int vertexCount = mapper.GetVertexCount();
NzSparsePtr<NzVector3f> normals = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Normal); NzSparsePtr<NzVector3f> normals = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Normal);
NzSparsePtr<NzVector3f> positions = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Position); NzSparsePtr<NzVector3f> positions = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position);
for (unsigned int i = 0; i < vertexCount; ++i) for (unsigned int i = 0; i < vertexCount; ++i)
normals[i].MakeZero(); normals[i].MakeZero();
@ -58,10 +58,10 @@ void NzSubMesh::GenerateNormalsAndTangents()
NzVertexMapper mapper(this); NzVertexMapper mapper(this);
unsigned int vertexCount = mapper.GetVertexCount(); unsigned int vertexCount = mapper.GetVertexCount();
NzSparsePtr<NzVector3f> normals = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Normal); NzSparsePtr<NzVector3f> normals = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Normal);
NzSparsePtr<NzVector3f> positions = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Position); NzSparsePtr<NzVector3f> positions = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position);
NzSparsePtr<NzVector3f> tangents = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Tangent); NzSparsePtr<NzVector3f> tangents = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Tangent);
NzSparsePtr<NzVector2f> texCoords = mapper.GetAttributePtr<NzVector2f>(nzAttributeUsage_TexCoord); NzSparsePtr<NzVector2f> texCoords = mapper.GetComponentPtr<NzVector2f>(nzVertexComponent_TexCoord);
for (unsigned int i = 0; i < vertexCount; ++i) for (unsigned int i = 0; i < vertexCount; ++i)
{ {
@ -113,10 +113,10 @@ void NzSubMesh::GenerateTangents()
{ {
NzVertexMapper mapper(this); NzVertexMapper mapper(this);
NzSparsePtr<NzVector3f> normals = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Normal); NzSparsePtr<NzVector3f> normals = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Normal);
NzSparsePtr<NzVector3f> positions = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Position); NzSparsePtr<NzVector3f> positions = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position);
NzSparsePtr<NzVector3f> tangents = mapper.GetAttributePtr<NzVector3f>(nzAttributeUsage_Tangent); NzSparsePtr<NzVector3f> tangents = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Tangent);
NzSparsePtr<NzVector2f> texCoords = mapper.GetAttributePtr<NzVector2f>(nzAttributeUsage_TexCoord); NzSparsePtr<NzVector2f> texCoords = mapper.GetComponentPtr<NzVector2f>(nzVertexComponent_TexCoord);
NzTriangleIterator iterator(this); NzTriangleIterator iterator(this);
do do

View File

@ -126,4 +126,42 @@ void NzUtility::Uninitialize()
NzCore::Uninitialize(); NzCore::Uninitialize();
} }
unsigned int NzUtility::ComponentCount[nzComponentType_Max+1] =
{
4, // nzComponentType_Color
1, // nzComponentType_Double1
2, // nzComponentType_Double2
3, // nzComponentType_Double3
4, // nzComponentType_Double4
1, // nzComponentType_Float1
2, // nzComponentType_Float2
3, // nzComponentType_Float3
4, // nzComponentType_Float4
1, // nzComponentType_Int1
2, // nzComponentType_Int2
3, // nzComponentType_Int3
4 // nzComponentType_Int4
};
static_assert(nzComponentType_Max+1 == 13, "Component count array is incomplete");
unsigned int NzUtility::ComponentStride[nzComponentType_Max+1] =
{
4*sizeof(nzUInt8), // nzComponentType_Color
1*sizeof(double), // nzComponentType_Double1
2*sizeof(double), // nzComponentType_Double2
3*sizeof(double), // nzComponentType_Double3
4*sizeof(double), // nzComponentType_Double4
1*sizeof(float), // nzComponentType_Float1
2*sizeof(float), // nzComponentType_Float2
3*sizeof(float), // nzComponentType_Float3
4*sizeof(float), // nzComponentType_Float4
1*sizeof(nzUInt32), // nzComponentType_Int1
2*sizeof(nzUInt32), // nzComponentType_Int2
3*sizeof(nzUInt32), // nzComponentType_Int3
4*sizeof(nzUInt32) // nzComponentType_Int4
};
static_assert(nzComponentType_Max+1 == 13, "Component stride array is incomplete");
unsigned int NzUtility::s_moduleReferenceCounter = 0; unsigned int NzUtility::s_moduleReferenceCounter = 0;

View File

@ -8,51 +8,11 @@
#include <Nazara/Core/OffsetOf.hpp> #include <Nazara/Core/OffsetOf.hpp>
#include <Nazara/Math/Matrix4.hpp> #include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/Config.hpp> #include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/VertexStruct.hpp> #include <Nazara/Utility/VertexStruct.hpp>
#include <cstring> #include <cstring>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
namespace
{
unsigned int attributeSize[] =
{
4, // nzAttributeType_Color
1, // nzAttributeType_Double1
2, // nzAttributeType_Double2
3, // nzAttributeType_Double3
4, // nzAttributeType_Double4
1, // nzAttributeType_Float1
2, // nzAttributeType_Float2
3, // nzAttributeType_Float3
4, // nzAttributeType_Float4
1, // nzAttributeType_Int1
2, // nzAttributeType_Int2
3, // nzAttributeType_Int3
4 // nzAttributeType_Int4
};
static_assert(sizeof(attributeSize)/sizeof(unsigned int) == nzAttributeType_Max+1, "Attribute size array is incomplete");
unsigned int attributeStride[] =
{
4*sizeof(nzUInt8), // nzAttributeType_Color
1*sizeof(double), // nzAttributeType_Double1
2*sizeof(double), // nzAttributeType_Double2
3*sizeof(double), // nzAttributeType_Double3
4*sizeof(double), // nzAttributeType_Double4
1*sizeof(float), // nzAttributeType_Float1
2*sizeof(float), // nzAttributeType_Float2
3*sizeof(float), // nzAttributeType_Float3
4*sizeof(float), // nzAttributeType_Float4
1*sizeof(nzUInt32), // nzAttributeType_Int1
2*sizeof(nzUInt32), // nzAttributeType_Int2
3*sizeof(nzUInt32), // nzAttributeType_Int3
4*sizeof(nzUInt32) // nzAttributeType_Int4
};
static_assert(sizeof(attributeStride)/sizeof(unsigned int) == nzAttributeType_Max+1, "Attribute stride array is incomplete");
}
NzVertexDeclaration::NzVertexDeclaration() : NzVertexDeclaration::NzVertexDeclaration() :
m_stride(0) m_stride(0)
{ {
@ -62,7 +22,7 @@ NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration& declaration) :
NzResource(), NzResource(),
m_stride(declaration.m_stride) m_stride(declaration.m_stride)
{ {
std::memcpy(m_attributes, declaration.m_attributes, sizeof(Attribute)*(nzAttributeUsage_Max+1)); std::memcpy(m_components, declaration.m_components, sizeof(Component)*(nzVertexComponent_Max+1));
} }
NzVertexDeclaration::~NzVertexDeclaration() NzVertexDeclaration::~NzVertexDeclaration()
@ -70,85 +30,93 @@ NzVertexDeclaration::~NzVertexDeclaration()
NotifyDestroy(); NotifyDestroy();
} }
void NzVertexDeclaration::DisableAttribute(nzAttributeUsage usage) void NzVertexDeclaration::DisableComponent(nzVertexComponent component)
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (usage > nzAttributeUsage_Max) if (component > nzVertexComponent_Max)
{ {
NazaraError("Attribute usage out of enum"); NazaraError("Vertex component out of enum");
return; return;
} }
#endif #endif
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (usage == nzAttributeUsage_Unused) if (component == nzVertexComponent_Unused)
{ {
NazaraError("Cannot disable \"unused\" attribute"); NazaraError("Cannot disable \"unused\" component");
return; return;
} }
#endif #endif
Attribute& attribute = m_attributes[usage]; Component& vertexComponent = m_components[component];
if (attribute.enabled) if (vertexComponent.enabled)
{ {
attribute.enabled = false; vertexComponent.enabled = false;
m_stride -= attributeStride[attribute.type]; m_stride -= NzUtility::ComponentStride[vertexComponent.type];
} }
} }
void NzVertexDeclaration::EnableAttribute(nzAttributeUsage usage, nzAttributeType type, unsigned int offset) void NzVertexDeclaration::EnableComponent(nzVertexComponent component, nzComponentType type, unsigned int offset)
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (usage > nzAttributeUsage_Max) if (component > nzVertexComponent_Max)
{ {
NazaraError("Attribute usage out of enum"); NazaraError("Vertex component out of enum");
return; return;
} }
#endif #endif
if (usage != nzAttributeUsage_Unused) #if NAZARA_UTILITY_SAFE
if (!IsTypeSupported(type))
{ {
Attribute& attribute = m_attributes[usage]; NazaraError("Component type 0x" + NzString::Number(type, 16) + " is not supported by vertex declarations");
if (attribute.enabled) return;
m_stride -= attributeStride[attribute.type]; }
#endif
if (component != nzVertexComponent_Unused)
{
Component& vertexComponent = m_components[component];
if (vertexComponent.enabled)
m_stride -= NzUtility::ComponentStride[vertexComponent.type];
else else
attribute.enabled = true; vertexComponent.enabled = true;
attribute.offset = offset; vertexComponent.offset = offset;
attribute.type = type; vertexComponent.type = type;
} }
m_stride += attributeStride[type]; m_stride += NzUtility::ComponentStride[type];
} }
void NzVertexDeclaration::GetAttribute(nzAttributeUsage usage, bool* enabled, nzAttributeType* type, unsigned int* offset) const void NzVertexDeclaration::GetComponent(nzVertexComponent component, bool* enabled, nzComponentType* type, unsigned int* offset) const
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (usage > nzAttributeUsage_Max) if (component > nzVertexComponent_Max)
{ {
NazaraError("Attribute usage out of enum"); NazaraError("Vertex component out of enum");
return; return;
} }
#endif #endif
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (usage == nzAttributeUsage_Unused) if (component == nzVertexComponent_Unused)
{ {
NazaraError("Cannot get \"unused\" attribute"); NazaraError("Cannot get \"unused\" component");
return; return;
} }
#endif #endif
const Attribute& attribute = m_attributes[usage]; const Component& vertexComponent = m_components[component];
if (enabled) if (enabled)
*enabled = attribute.enabled; *enabled = vertexComponent.enabled;
if (type) if (type)
*type = attribute.type; *type = vertexComponent.type;
if (offset) if (offset)
*offset = attribute.offset; *offset = vertexComponent.offset;
} }
unsigned int NzVertexDeclaration::GetStride() const unsigned int NzVertexDeclaration::GetStride() const
@ -163,7 +131,7 @@ void NzVertexDeclaration::SetStride(unsigned int stride)
NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration) NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration)
{ {
std::memcpy(m_attributes, declaration.m_attributes, sizeof(Attribute)*(nzAttributeUsage_Max+1)); std::memcpy(m_components, declaration.m_components, sizeof(Component)*(nzVertexComponent_Max+1));
m_stride = declaration.m_stride; m_stride = declaration.m_stride;
return *this; return *this;
@ -182,17 +150,28 @@ NzVertexDeclaration* NzVertexDeclaration::Get(nzVertexLayout layout)
return &s_declarations[layout]; return &s_declarations[layout];
} }
unsigned int NzVertexDeclaration::GetAttributeSize(nzAttributeType type) bool NzVertexDeclaration::IsTypeSupported(nzComponentType type)
{ {
#ifdef NAZARA_DEBUG switch (type)
if (type > nzAttributeType_Max)
{ {
NazaraError("Attribute type out of enum"); case nzComponentType_Color:
return 0; case nzComponentType_Double1:
case nzComponentType_Double2:
case nzComponentType_Double3:
case nzComponentType_Double4:
case nzComponentType_Float1:
case nzComponentType_Float2:
case nzComponentType_Float3:
case nzComponentType_Float4:
case nzComponentType_Int1:
case nzComponentType_Int2:
case nzComponentType_Int3:
case nzComponentType_Int4:
return true;
} }
#endif
return attributeSize[type]; NazaraError("Component type not handled (0x" + NzString::Number(type, 16) + ')');
return false;
} }
bool NzVertexDeclaration::Initialize() bool NzVertexDeclaration::Initialize()
@ -206,72 +185,72 @@ bool NzVertexDeclaration::Initialize()
// nzVertexLayout_XY : NzVertexStruct_XY // nzVertexLayout_XY : NzVertexStruct_XY
declaration = &s_declarations[nzVertexLayout_XY]; declaration = &s_declarations[nzVertexLayout_XY];
declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XY, position)); declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY, position));
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY), "Invalid stride for declaration NzVertexStruct_XY"); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY), "Invalid stride for declaration NzVertexStruct_XY");
// nzVertexLayout_XY_UV : NzVertexStruct_XY_UV // nzVertexLayout_XY_UV : NzVertexStruct_XY_UV
declaration = &s_declarations[nzVertexLayout_XY_UV]; declaration = &s_declarations[nzVertexLayout_XY_UV];
declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, position)); declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, position));
declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, uv)); declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, uv));
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY_UV), "Invalid stride for declaration nzVertexLayout_XY_UV"); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY_UV), "Invalid stride for declaration nzVertexLayout_XY_UV");
// nzVertexLayout_XYZ : NzVertexStruct_XYZ // nzVertexLayout_XYZ : NzVertexStruct_XYZ
declaration = &s_declarations[nzVertexLayout_XYZ]; declaration = &s_declarations[nzVertexLayout_XYZ];
declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ, position)); declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ, position));
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ), "Invalid stride for declaration nzVertexLayout_XYZ"); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ), "Invalid stride for declaration nzVertexLayout_XYZ");
// nzVertexLayout_XYZ_Normal : NzVertexStruct_XYZ_Normal // nzVertexLayout_XYZ_Normal : NzVertexStruct_XYZ_Normal
declaration = &s_declarations[nzVertexLayout_XYZ_Normal]; declaration = &s_declarations[nzVertexLayout_XYZ_Normal];
declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, position)); declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, position));
declaration->EnableAttribute(nzAttributeUsage_Normal, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, normal)); declaration->EnableComponent(nzVertexComponent_Normal, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, normal));
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal), "Invalid stride for declaration nzVertexLayout_XYZ_Normal"); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal), "Invalid stride for declaration nzVertexLayout_XYZ_Normal");
// nzVertexLayout_XYZ_Normal_UV : NzVertexStruct_XYZ_Normal_UV // nzVertexLayout_XYZ_Normal_UV : NzVertexStruct_XYZ_Normal_UV
declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV]; declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV];
declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, position)); declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, position));
declaration->EnableAttribute(nzAttributeUsage_Normal, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, normal)); declaration->EnableComponent(nzVertexComponent_Normal, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, normal));
declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, uv)); declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, uv));
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV"); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV");
// nzVertexLayout_XYZ_Normal_UV_Tangent : NzVertexStruct_XYZ_Normal_UV_Tangent // nzVertexLayout_XYZ_Normal_UV_Tangent : NzVertexStruct_XYZ_Normal_UV_Tangent
declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent]; declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent];
declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, position)); declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, position));
declaration->EnableAttribute(nzAttributeUsage_Normal, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, normal)); declaration->EnableComponent(nzVertexComponent_Normal, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, normal));
declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, uv)); declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, uv));
declaration->EnableAttribute(nzAttributeUsage_Tangent, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, tangent)); declaration->EnableComponent(nzVertexComponent_Tangent, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, tangent));
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent"); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent");
// nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning : NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning // nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning : NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning
declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning]; declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning];
declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, position)); declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, position));
declaration->EnableAttribute(nzAttributeUsage_Normal, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, normal)); declaration->EnableComponent(nzVertexComponent_Normal, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, normal));
declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, uv)); declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, uv));
declaration->EnableAttribute(nzAttributeUsage_Tangent, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, tangent)); declaration->EnableComponent(nzVertexComponent_Tangent, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, tangent));
declaration->EnableAttribute(nzAttributeUsage_Unused, nzAttributeType_Int1, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weightCount)); declaration->EnableComponent(nzVertexComponent_Unused, nzComponentType_Int1, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weightCount));
declaration->EnableAttribute(nzAttributeUsage_Userdata0, nzAttributeType_Float4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weights)); declaration->EnableComponent(nzVertexComponent_Userdata0, nzComponentType_Float4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weights));
declaration->EnableAttribute(nzAttributeUsage_Userdata1, nzAttributeType_Int4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, jointIndexes)); declaration->EnableComponent(nzVertexComponent_Userdata1, nzComponentType_Int4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, jointIndexes));
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning"); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning");
// nzVertexLayout_XYZ_UV : NzVertexStruct_XYZ_UV // nzVertexLayout_XYZ_UV : NzVertexStruct_XYZ_UV
declaration = &s_declarations[nzVertexLayout_XYZ_UV]; declaration = &s_declarations[nzVertexLayout_XYZ_UV];
declaration->EnableAttribute(nzAttributeUsage_Position, nzAttributeType_Float3, NzOffsetOf(NzVertexStruct_XYZ_UV, position)); declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_UV, position));
declaration->EnableAttribute(nzAttributeUsage_TexCoord, nzAttributeType_Float2, NzOffsetOf(NzVertexStruct_XYZ_UV, uv)); declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_UV, uv));
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_UV), "Invalid stride for declaration nzVertexLayout_XYZ_UV"); NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_UV), "Invalid stride for declaration nzVertexLayout_XYZ_UV");
// nzVertexLayout_Matrix4 : NzMatrix4f // nzVertexLayout_Matrix4 : NzMatrix4f
declaration = &s_declarations[nzVertexLayout_Matrix4]; declaration = &s_declarations[nzVertexLayout_Matrix4];
declaration->EnableAttribute(nzAttributeUsage_InstanceData0, nzAttributeType_Float4, NzOffsetOf(NzMatrix4f, m11)); declaration->EnableComponent(nzVertexComponent_InstanceData0, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m11));
declaration->EnableAttribute(nzAttributeUsage_InstanceData1, nzAttributeType_Float4, NzOffsetOf(NzMatrix4f, m21)); declaration->EnableComponent(nzVertexComponent_InstanceData1, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m21));
declaration->EnableAttribute(nzAttributeUsage_InstanceData2, nzAttributeType_Float4, NzOffsetOf(NzMatrix4f, m31)); declaration->EnableComponent(nzVertexComponent_InstanceData2, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m31));
declaration->EnableAttribute(nzAttributeUsage_InstanceData3, nzAttributeType_Float4, NzOffsetOf(NzMatrix4f, m41)); declaration->EnableComponent(nzVertexComponent_InstanceData3, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m41));
NazaraAssert(declaration->GetStride() == sizeof(NzMatrix4f), "Invalid stride for declaration nzVertexLayout_Matrix4"); NazaraAssert(declaration->GetStride() == sizeof(NzMatrix4f), "Invalid stride for declaration nzVertexLayout_Matrix4");
} }