Merge remote-tracking branch 'origin/master' into Particle-Update

Former-commit-id: 7ec9fba80c2b47a1fb811c7912df67262986c9f0
This commit is contained in:
Lynix 2014-08-25 23:09:36 +02:00
commit 54382afc37
12 changed files with 44 additions and 49 deletions

View File

@ -95,6 +95,10 @@ int main()
// Ce paramètre sert à indiquer la mise à l'échelle désirée lors du chargement du modèle.
params.mesh.scale.Set(0.01f); // Un centième de la taille originelle
// Les UVs de ce fichier sont retournées (repère OpenGL, origine coin bas-gauche) par rapport à ce que le moteur attend
// Nous devons dire au moteur de les retourner lors du chargement
params.mesh.flipUVs = true;
// On charge ensuite le modèle depuis son fichier
// Le moteur va charger le fichier et essayer de retrouver les fichiers associés (comme les matériaux, textures, ...)
if (!spaceship.LoadFromFile("resources/Spaceship/spaceship.obj", params))

View File

@ -135,7 +135,7 @@ class NAZARA_API NzMaterial : public NzResource
struct ShaderInstance
{
const NzShader* shader;
NzUberShaderInstance* uberInstance;
NzUberShaderInstance* uberInstance = nullptr;
int uniforms[nzMaterialUniform_Max+1];
};

View File

@ -221,12 +221,14 @@ enum nzVertexComponent
{
nzVertexComponent_Unused = -1,
// Nous nous limitons à 16 composants de sommets car c'est le minimum supporté par le GPU
nzVertexComponent_InstanceData0,
nzVertexComponent_InstanceData1,
nzVertexComponent_InstanceData2,
nzVertexComponent_InstanceData3,
nzVertexComponent_InstanceData4,
nzVertexComponent_InstanceData5,
nzVertexComponent_Color,
nzVertexComponent_Normal,
nzVertexComponent_Position,
nzVertexComponent_Tangent,
@ -236,14 +238,13 @@ enum nzVertexComponent
nzVertexComponent_Userdata2,
nzVertexComponent_Userdata3,
nzVertexComponent_Userdata4,
nzVertexComponent_Userdata5,
nzVertexComponent_FirstInstanceData = nzVertexComponent_InstanceData0,
nzVertexComponent_FirstVertexData = nzVertexComponent_Normal,
nzVertexComponent_FirstVertexData = nzVertexComponent_Color,
nzVertexComponent_LastInstanceData = nzVertexComponent_InstanceData5,
nzVertexComponent_LastVertexData = nzVertexComponent_Userdata5,
nzVertexComponent_LastVertexData = nzVertexComponent_Userdata4,
nzVertexComponent_Max = nzVertexComponent_Userdata5
nzVertexComponent_Max = nzVertexComponent_Userdata4
};
enum nzVertexLayout

View File

@ -9,6 +9,7 @@
#ifndef NAZARA_EVENT_HPP
#define NAZARA_EVENT_HPP
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/Mouse.hpp>

View File

@ -36,6 +36,9 @@ struct NAZARA_API NzMeshParams
// Faut-il centrer le mesh autour de l'origine ?
bool center = false;
// Faut-il retourner les UV ?
bool flipUVs = false;
// Faut-il optimiser les index buffers ? (Rendu plus rapide, mais le chargement dure plus longtemps)
bool optimizeIndexBuffers = true;

View File

@ -142,7 +142,7 @@ namespace
if (index >= 0)
{
const NzVector3f& uvw = texCoords[index];
vertex.uv.Set(uvw.x, uvw.y);
vertex.uv.Set(uvw.x, (parameters.mesh.flipUVs) ? 1.f - uvw.y : uvw.y); // Inversion des UVs si demandé
}
else
hasTexCoords = false;

View File

@ -2104,16 +2104,16 @@ nzUInt8 NzOpenGL::VertexComponentIndex[] =
13, // nzVertexComponent_InstanceData3
14, // nzVertexComponent_InstanceData4
15, // nzVertexComponent_InstanceData5
4, // nzVertexComponent_Color
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
5, // nzVertexComponent_Userdata0
6, // nzVertexComponent_Userdata1
7, // nzVertexComponent_Userdata2
8, // nzVertexComponent_Userdata3
9 // nzVertexComponent_Userdata4
};
static_assert(nzVertexComponent_Max+1 == 16, "Attribute index array is incomplete");

View File

@ -155,6 +155,7 @@ bool NzShader::Create()
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_Color], "VertexColor");
glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Normal], "VertexNormal");
glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Position], "VertexPosition");
glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Tangent], "VertexTangent");
@ -164,7 +165,6 @@ bool NzShader::Create()
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))
{

View File

@ -1048,33 +1048,25 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int s
return false;
}
nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_impl->format);
unsigned int size = box.width*box.height*box.depth*bpp;
std::unique_ptr<nzUInt8[]> flipped(new nzUInt8[size]);
NzImage::Copy(flipped.get(), pixels, bpp, box.width, box.height, box.depth, 0, 0, srcWidth, srcHeight);
// Inversion de la texture pour le repère d'OpenGL
if (!NzPixelFormat::Flip(nzPixelFlipping_Horizontally, m_impl->format, box.width, box.height, box.depth, flipped.get(), flipped.get()))
NazaraWarning("Failed to flip image");
SetUnpackAlignement(bpp);
SetUnpackAlignement(NzPixelFormat::GetBytesPerPixel(m_impl->format));
glPixelStorei(GL_UNPACK_ROW_LENGTH, srcWidth);
glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, srcHeight);
NzOpenGL::BindTexture(m_impl->type, m_impl->id);
switch (m_impl->type)
{
case nzImageType_1D:
glTexSubImage1D(GL_TEXTURE_1D, level, box.x, box.width, format.dataFormat, format.dataType, flipped.get());
glTexSubImage1D(GL_TEXTURE_1D, level, box.x, box.width, format.dataFormat, format.dataType, pixels);
break;
case nzImageType_1D_Array:
case nzImageType_2D:
glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, box.x, height-box.height-box.y, box.width, box.height, format.dataFormat, format.dataType, flipped.get());
glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, box.x, height-box.height-box.y, box.width, box.height, format.dataFormat, format.dataType, pixels);
break;
case nzImageType_2D_Array:
case nzImageType_3D:
glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, box.x, height-box.height-box.y, box.z, box.width, box.height, box.depth, format.dataFormat, format.dataType, flipped.get());
glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, box.x, height-box.height-box.y, box.z, box.width, box.height, box.depth, format.dataFormat, format.dataType, pixels);
break;
case nzImageType_Cubemap:
@ -1192,20 +1184,12 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRe
return false;
}
nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_impl->format);
// Inversion de la texture pour le repère d'OpenGL
unsigned int size = rect.width*rect.height*bpp;
std::unique_ptr<nzUInt8[]> flipped(new nzUInt8[size]);
NzImage::Copy(flipped.get(), pixels, bpp, rect.width, rect.height, 1, 0, 0, srcWidth, srcHeight);
if (!NzPixelFormat::Flip(nzPixelFlipping_Horizontally, m_impl->format, rect.width, rect.height, 1, flipped.get(), flipped.get()))
NazaraWarning("Failed to flip image");
SetUnpackAlignement(bpp);
SetUnpackAlignement(NzPixelFormat::GetBytesPerPixel(m_impl->format));
glPixelStorei(GL_UNPACK_ROW_LENGTH, srcWidth);
glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, srcHeight);
NzOpenGL::BindTexture(m_impl->type, m_impl->id);
glTexSubImage2D(NzOpenGL::CubemapFace[face], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, flipped.get());
glTexSubImage2D(NzOpenGL::CubemapFace[face], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, pixels);
return true;
}

View File

@ -922,15 +922,17 @@ bool NzImage::LoadArrayFromImage(const NzImage& image, const NzVector2ui& atlasS
NzVector2ui faceSize = imageSize/atlasSize;
unsigned int layerCount = atlasSize.x*atlasSize.y;
// Selon le type de l'image de base, on va créer un array d'images 2D ou 1D
if (type == nzImageType_2D)
Create(nzImageType_2D_Array, image.GetFormat(), faceSize.x, faceSize.y);
Create(nzImageType_2D_Array, image.GetFormat(), faceSize.x, faceSize.y, layerCount);
else
Create(nzImageType_1D_Array, image.GetFormat(), faceSize.x, 1);
Create(nzImageType_1D_Array, image.GetFormat(), faceSize.x, layerCount);
unsigned int layer = 0;
for (unsigned int i = 0; i < atlasSize.x; ++i)
for (unsigned int j = 0; j < atlasSize.y; ++j)
for (unsigned int i = 0; i < atlasSize.x; ++i)
Copy(image, NzRectui(i*faceSize.x, j*faceSize.y, faceSize.x, faceSize.y), NzVector3ui(0, 0, layer++));
return true;

View File

@ -200,7 +200,10 @@ namespace
{
const unsigned int fixedIndex = indexFix[j];
const MD2_TexCoord& texC = texCoords[triangles[i].texCoords[fixedIndex]];
vertex[triangles[i].vertices[fixedIndex]].uv.Set(static_cast<float>(texC.u) / header.skinwidth, 1.f - static_cast<float>(texC.v)/header.skinheight);
float u = static_cast<float>(texC.u) / header.skinwidth;
float v = static_cast<float>(texC.v) / header.skinheight;
vertex[triangles[i].vertices[fixedIndex]].uv.Set(u, (parameters.flipUVs) ? 1.f - v : v);
}
}

View File

@ -178,10 +178,7 @@ namespace
}
vertices->position = finalPos;
// Le format MD5 spécifie ses UV avec l'origine en bas à gauche, contrairement au moteur
// dont l'origine est en haut à gauche, nous inversons donc la valeur en Y.
vertices->uv.Set(vertex.uv.x, 1.f - vertex.uv.y);
vertices->uv.Set(vertex.uv.x, (parameters.flipUVs) ? 1.f - vertex.uv.y : vertex.uv.y); // Inversion des UV si demandé
vertices++;
}
@ -271,7 +268,7 @@ namespace
// On retourne le modèle dans le bon sens
vertex->position = scale * (rotationQuat * finalPos);
vertex->uv.Set(md5Vertex.uv.x, 1.f - md5Vertex.uv.y);
vertex->uv.Set(md5Vertex.uv.x, (parameters.flipUVs) ? 1.f - md5Vertex.uv.y : md5Vertex.uv.y); // Inversion des UV si demandé
vertex++;
}