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

@@ -1854,47 +1854,6 @@ GLenum NzOpenGL::Attachment[] =
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[] =
{
GL_DST_ALPHA, // nzBlendFunc_DestAlpha
@@ -1958,6 +1917,25 @@ GLenum NzOpenGL::BufferUsage[] =
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[] =
{
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");
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;
PFNGLATTACHSHADERPROC glAttachShader = nullptr;
PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender = nullptr;

View File

@@ -897,6 +897,34 @@ bool NzRenderer::Initialize()
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)
{
#ifdef NAZARA_DEBUG
@@ -915,34 +943,6 @@ bool NzRenderer::IsInitialized()
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)
{
#ifdef NAZARA_DEBUG
@@ -1766,51 +1766,51 @@ bool NzRenderer::EnsureStateUpdate()
bufferOffset = s_vertexBuffer->GetStartOffset();
vertexDeclaration = s_vertexBuffer->GetVertexDeclaration();
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;
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;
break;
}
if (enabled)
{
glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]);
if (type <= nzAttributeType_Double1 && type >= nzAttributeType_Double4)
glEnableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
if (type <= nzComponentType_Double1 && type >= nzComponentType_Double4)
{
glVertexAttribLPointer(NzOpenGL::AttributeIndex[i],
NzVertexDeclaration::GetAttributeSize(type),
NzOpenGL::AttributeType[type],
glVertexAttribLPointer(NzOpenGL::VertexComponentIndex[i],
NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type],
stride,
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],
NzVertexDeclaration::GetAttributeSize(type),
NzOpenGL::AttributeType[type],
glVertexAttribIPointer(NzOpenGL::VertexComponentIndex[i],
NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type],
stride,
reinterpret_cast<void*>(bufferOffset + offset));
}
else
{
glVertexAttribPointer(NzOpenGL::AttributeIndex[i],
NzVertexDeclaration::GetAttributeSize(type),
NzOpenGL::AttributeType[type],
(type == nzAttributeType_Color) ? GL_TRUE : GL_FALSE,
glVertexAttribPointer(NzOpenGL::VertexComponentIndex[i],
NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type],
(type == nzComponentType_Color) ? GL_TRUE : GL_FALSE,
stride,
reinterpret_cast<void*>(bufferOffset + offset));
}
}
else
glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]);
glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
}
if (!updateFailed)
@@ -1823,59 +1823,59 @@ bool NzRenderer::EnsureStateUpdate()
bufferOffset = s_instanceBuffer.GetStartOffset();
vertexDeclaration = s_instanceBuffer.GetVertexDeclaration();
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;
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;
break;
}
if (enabled)
{
glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]);
if (type <= nzAttributeType_Double1 && type >= nzAttributeType_Double4)
glEnableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
if (type <= nzComponentType_Double1 && type >= nzComponentType_Double4)
{
glVertexAttribLPointer(NzOpenGL::AttributeIndex[i],
NzVertexDeclaration::GetAttributeSize(type),
NzOpenGL::AttributeType[type],
glVertexAttribLPointer(NzOpenGL::VertexComponentIndex[i],
NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type],
stride,
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],
NzVertexDeclaration::GetAttributeSize(type),
NzOpenGL::AttributeType[type],
glVertexAttribIPointer(NzOpenGL::VertexComponentIndex[i],
NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type],
stride,
reinterpret_cast<void*>(bufferOffset + offset));
}
else
{
glVertexAttribPointer(NzOpenGL::AttributeIndex[i],
NzVertexDeclaration::GetAttributeSize(type),
NzOpenGL::AttributeType[type],
(type == nzAttributeType_Color) ? GL_TRUE : GL_FALSE,
glVertexAttribPointer(NzOpenGL::VertexComponentIndex[i],
NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type],
(type == nzComponentType_Color) ? GL_TRUE : GL_FALSE,
stride,
reinterpret_cast<void*>(bufferOffset + offset));
}
glVertexAttribDivisor(NzOpenGL::AttributeIndex[i], 1);
glVertexAttribDivisor(NzOpenGL::VertexComponentIndex[i], 1);
}
else
glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]);
glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
}
}
else
{
for (unsigned int i = nzAttributeUsage_FirstInstanceData; i <= nzAttributeUsage_LastInstanceData; ++i)
glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]);
for (unsigned int i = nzVertexComponent_FirstInstanceData; i <= nzVertexComponent_LastInstanceData; ++i)
glDisableVertexAttribArray(NzOpenGL::VertexComponentIndex[i]);
}
// Et on active l'index buffer (Un seul index buffer par VAO)

View File

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