[DEV] VBO work correctly on computer

This commit is contained in:
Edouard DUPIN 2013-01-16 23:42:34 +01:00
parent 857d475d23
commit 53a678cdd1
7 changed files with 35 additions and 21 deletions

View File

@ -11,5 +11,5 @@ varying vec4 f_color;
void main(void) {
gl_FragColor = texture2D(EW_texID, f_texcoord) * f_color;
gl_FragColor = vec4(1.0,1.0,0.2,0.6);
//gl_FragColor = vec4(1.0,1.0,0.2,0.6);
}

View File

@ -13,6 +13,7 @@
ewol::Mesh::Mesh(etk::UString genName) :
ewol::Resource(genName),
m_numberOfElments(0),
m_texture1(NULL)
{
etk::UString tmpString("DATA:textured3D.prog");
@ -36,12 +37,13 @@ ewol::Mesh::~Mesh(void)
}
ewol::resource::Release(m_GLprogram);
ewol::resource::Release(m_verticesVBO);
m_numberOfElments=0;
}
void ewol::Mesh::Draw(mat4& positionMatrix)
{
if (m_vertices.Size()<=0) {
if (m_numberOfElments<=0) {
return;
}
if (NULL == m_texture1) {
@ -63,16 +65,13 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
// TextureID
m_GLprogram->SetTexture0(m_GLtexID, m_texture1->GetId());
// position :
//m_GLprogram->SendAttribute(m_GLPosition, 3/*x,y,z*/, &m_vertices[0]);
m_GLprogram->SendAttributePointer(m_GLPosition, 3/*x,y,z*/, m_verticesVBO, 0);
// Texture :
//m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_uvTextures[0]);
//m_GLprogram->SendAttributePointer(m_GLPosition, 2/*u,v*/, m_verticesVBO, 1);
m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, 1);
// color :
//m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
//m_GLprogram->SendAttributePointer(m_GLPosition, 4/*r,g,b,a*/, m_verticesVBO, 2);
m_GLprogram->SendAttributePointer(m_GLColor, 4/*r,g,b,a*/, m_verticesVBO, 2);
// Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_vertices.Size());
glDrawArrays(GL_TRIANGLES, 0, m_numberOfElments);
m_GLprogram->UnUse();
glDisable(GL_DEPTH_TEST);
glBindBuffer(GL_ARRAY_BUFFER,0);

View File

@ -20,6 +20,15 @@ namespace ewol
{
class Mesh : public ewol::Resource
{
// 3 "float" elements
#define MESH_VBO_VERTICES (0)
// 2 "float" elements
#define MESH_VBO_TEXTURE (1)
// 4 "float" elements
#define MESH_VBO_COLOR (2)
// 3 "float" elements
#define MESH_VBO_NORMAL (3)
// TODO : Use indice system ...
protected:
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
@ -27,15 +36,17 @@ namespace ewol
int32_t m_GLColor;
int32_t m_GLtexture;
int32_t m_GLtexID;
int32_t m_bufferOfset;
int32_t m_numberOfElments;
public:
etk::Vector<uint32_t> m_indices;
ewol::VirtualBufferObject* m_verticesVBO;
etk::Vector<vec3> m_vertices;
etk::Vector<vec2> m_uvTextures;
etk::Vector<vec3> m_normals;
protected:
ewol::TextureFile* m_texture1;
etk::Vector<uint32_t> m_indices;
etk::Vector<vec3> m_vertices;
etk::Vector<vec2> m_uvTextures;
etk::Vector<vec3> m_normals;
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
protected:
ewol::VirtualBufferObject* m_verticesVBO;
ewol::TextureFile* m_texture1;
public:
Mesh(etk::UString genName);
virtual ~Mesh(void);

View File

@ -173,6 +173,8 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
}
}
fileName.FileClose();
// update the number of element in the display ...
m_numberOfElments = indicesVertices.Size();
// For each vertex of each triangle
for( uint32_t iii=0; iii<indicesVertices.Size(); iii++ ){
// Get the indices of its attributes
@ -203,6 +205,7 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
m_verticesVBO->GetRefBuffer(3).PushBack(normals[normalIndex-1].z);
}
}
// update all the VBO elements ...
m_verticesVBO->Flush();
}

View File

@ -71,7 +71,6 @@ ewol::Program::Program(etk::UString& filename) :
file.FileClose();
UpdateContext();
}
@ -301,7 +300,7 @@ void ewol::Program::SendAttribute(int32_t idElem, int32_t nbElement, void* point
//checkGlError("glEnableVertexAttribArray", __LINE__);
}
void ewol::Program::SendAttributePointer(int32_t idElem, int32_t nbElement, ewol::VirtualBufferObject* vbo, int32_t index, int32_t jumpBetweenSample)
void ewol::Program::SendAttributePointer(int32_t idElem, int32_t nbElement, ewol::VirtualBufferObject* vbo, int32_t index, int32_t jumpBetweenSample, int32_t offset)
{
if (0==m_program) {
return;
@ -319,7 +318,7 @@ void ewol::Program::SendAttributePointer(int32_t idElem, int32_t nbElement, ewol
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
jumpBetweenSample, // no extra data between each position
0); // Pointer on the buffer
(GLvoid *)offset); // Pointer on the buffer
//checkGlError("glVertexAttribPointer", __LINE__);
glEnableVertexAttribArray(m_elementList[idElem].m_elementId);
//checkGlError("glEnableVertexAttribArray", __LINE__);

View File

@ -82,7 +82,7 @@ namespace ewol
* @param[in] jumpBetweenSample Number of byte to jump between 2 vertex (this permit to enterlace informations)
*/
void SendAttribute(int32_t idElem, int32_t nbElement, void* pointer, int32_t jumpBetweenSample=0);
void SendAttributePointer(int32_t idElem, int32_t nbElement, ewol::VirtualBufferObject* vbo, int32_t index, int32_t jumpBetweenSample=0);
void SendAttributePointer(int32_t idElem, int32_t nbElement, ewol::VirtualBufferObject* vbo, int32_t index, int32_t jumpBetweenSample=0, int32_t offset=0);
/**
* @brief User request an Uniform on this program.
* @note uniform value is availlable for all the fragment shader in the program (only one value for all)

View File

@ -46,8 +46,10 @@ void ewol::VirtualBufferObject::UpdateContext(void)
for (int32_t iii=0; iii<m_nbVBO; iii++) {
EWOL_INFO("VBO : Add [" << m_uniqueId << "]=" << m_buffer[iii].Size() << "*sizeof(float) OGl_Id=" << m_vbo[iii]);
// select the buffer to set data inside it ...
glBindBuffer(GL_ARRAY_BUFFER, m_vbo[iii]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*m_buffer[iii].Size(), &((m_buffer[iii])[0]), GL_STATIC_DRAW);
if (m_buffer[iii].Size()>0) {
glBindBuffer(GL_ARRAY_BUFFER, m_vbo[iii]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*m_buffer[iii].Size(), &((m_buffer[iii])[0]), GL_STATIC_DRAW);
}
}
// un-bind it to permet to have no erreor in the next display ...
glBindBuffer(GL_ARRAY_BUFFER, 0);