Bonjour,

Je viens vous voir car j'ai quelques soucis de performances pour l'affichage de mes objets 3D.
Pour simplifier un peu la création d'un objet, j'ai décidé de créer une classe permettant de gérer tout ça pour moi. Sauf que je remarque que quand j'utilise cette classe pour afficher un certain nombre de cubes, le PC commence à saturer un peu (j'ai affiché 500 cubes pour mes tests, autrement dit pas grand chose).

Voici ma fameuse classe :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef _OBJET3D
#define _OBJET3D
 
#include "Texture.hpp"
#include "SHader.hpp"
 
#include <vector>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>
 
class Objet3D
{
	public :
		Objet3D(int nombreTriangles);
		bool modifierStructure(const std::vector<float>& coordonneesSommets, const std::vector<float>& coordonneesTexture, const std::vector<int>& identifiantsTextures);
		void afficher(const Shader& shader, const glm::mat4& matriceProjection, const glm::mat4& matriceVue);
		void tourner(float angle, glm::vec3 axes);
		void translater(glm::vec3 translation);
		void echelonner(glm::vec3 echelle);
		void reinitialiserTransformations();
		int ajouterTexture(std::string fichierTexture);
		void supprimerTexture(int identifiantTexture);
 
	private :
		std::vector<Texture> m_textures;
		std::vector<int> m_identifiantsTextures;
		GLuint m_identifiantVBO;
		GLuint m_identifiantVAO;
		int m_nombreTriangles;
		glm::mat4 m_matriceTransformations;
};
 
#endif
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "Objet3D.hpp"
 
Objet3D::Objet3D(int nombreTriangles) :
m_nombreTriangles(nombreTriangles),
m_matriceTransformations(glm::mat4(1))
{
	glGenBuffers(1, &m_identifiantVBO);
	glBindBuffer(GL_ARRAY_BUFFER, m_identifiantVBO);
	glBufferData(GL_ARRAY_BUFFER, (m_nombreTriangles * 15)* sizeof(float), 0, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
 
 
	glGenVertexArrays(1, &m_identifiantVAO);
	glBindVertexArray(m_identifiantVAO);
 
	glBindBuffer(GL_ARRAY_BUFFER, m_identifiantVBO);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)(m_nombreTriangles * 9 * sizeof(float)));
	glEnableVertexAttribArray(2);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
 
	glBindVertexArray(0);
 
	m_matriceTransformations = glm::rotate(m_matriceTransformations, 20.0f, glm::vec3(0, 1, 0));
}
 
bool Objet3D::modifierStructure(const std::vector<float>& coordonneesSommets, const std::vector<float>& coordonneesTexture, const std::vector<int>& identifiantsTextures)
{
	m_identifiantsTextures = identifiantsTextures;
 
	glBindBuffer(GL_ARRAY_BUFFER, m_identifiantVBO);
 
	void *adresseVBO = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
	if (adresseVBO == NULL)
	{
		std::cout << "[ERREUR] Récuperation du VBO" << std::endl;
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		return false;
	}
 
	memcpy((char*)adresseVBO, coordonneesSommets.data(), (m_nombreTriangles * 9)* sizeof(float));
	memcpy((char*)adresseVBO + m_nombreTriangles * 9 * sizeof(float), coordonneesTexture.data(), m_nombreTriangles * 6 * sizeof(float));
 
	glUnmapBuffer(GL_ARRAY_BUFFER);
	adresseVBO = 0;
 
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
void Objet3D::afficher(const Shader& shader, const glm::mat4& matriceProjection, const glm::mat4& matriceVue)
{
	glUseProgram(shader.identifiant());
	glBindVertexArray(m_identifiantVAO);
 
	glUniformMatrix4fv(glGetUniformLocation(shader.identifiant(), "matriceAffichage"), 1, GL_FALSE, glm::value_ptr(matriceProjection * matriceVue * m_matriceTransformations));
 
	glBindTexture(GL_TEXTURE_2D, m_textures[0].identifiant());
	glDrawArrays(GL_TRIANGLES, 0, m_nombreTriangles * 3);
 
	glBindTexture(GL_TEXTURE_2D, 0);
	glBindVertexArray(0);
	glUseProgram(0);
}
 
void Objet3D::tourner(float angle, glm::vec3 axes)
{
	m_matriceTransformations = glm::rotate(m_matriceTransformations, angle, axes);
}
 
void Objet3D::translater(glm::vec3 translation)
{
	m_matriceTransformations = glm::translate(m_matriceTransformations, translation);
}
 
void Objet3D::echelonner(glm::vec3 echelle)
{
	m_matriceTransformations = glm::scale(m_matriceTransformations, echelle);
}
 
void Objet3D::reinitialiserTransformations()
{
	m_matriceTransformations = glm::mat4(1);
}
 
int Objet3D::ajouterTexture(std::string fichierTexture)
{
	m_textures.push_back(Texture());
	m_textures[m_textures.size() - 1].charger(fichierTexture);
 
	return m_textures.size() - 1;
}
 
void Objet3D::supprimerTexture(int identifiantTexture)
{
	m_textures.erase(m_textures.begin() + identifiantTexture);
}
Mes 500 cubes, je les ai affiché de 2 façons : j'ai dans un premier temps créé 500 objets de type Objet3D, et je les ai affiché, et ensuite j'ai essayé avec une seul objet de type Objet3D, mais avec un nombre suffisant de vertex pour avoir 500 cubes (comme ça je ne fais qu'un appel à glDrawArrays). Mais dans les deux cas le PC supporte mal.

Pourtant je pense que 500 cubes c'est pas grand chose, donc j'aimerais savoir ce qui cloche dans mon code (car j'imagine que le problème vient de cette classe).
Merci d'avance