Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mickaël Sereno mickael.serneo@inria.fr Graphics Memory Mickaël Sereno mickael.serneo@inria.fr 11/07/2019 Mickaël Sereno - mickael.sereno@inria.fr.

Similar presentations


Presentation on theme: "Mickaël Sereno mickael.serneo@inria.fr Graphics Memory Mickaël Sereno mickael.serneo@inria.fr 11/07/2019 Mickaël Sereno - mickael.sereno@inria.fr."— Presentation transcript:

1 Mickaël Sereno mickael.serneo@inria.fr
Graphics Memory Mickaël Sereno 11/07/2019 Mickaël Sereno -

2 Mickaël Sereno - mickael.sereno@inria.fr
Introduction « Device » memory (GPU memory) Copy « Host » memory (RAM) Pre-requisite : Copy the « Host » memory to the « Device » device memory. Do this the minimum possible. Less the communication between these two, more the program will be efficient. 11/07/2019 Mickaël Sereno -

3 Graphics Memory: VBO ALL THESE VARIABLES ARE NOT ALLWAYS NECESSARY !!!
VBO : Vertex Buffer Object. It is a Buffer containing the memory used by the graphics card, used for the Vertices (Points) The graphics card works only with triangles or lines (the last is less used). Usual types of variables used in programs : Position Normal UV mapping Color ALL THESE VARIABLES ARE NOT ALLWAYS NECESSARY !!! Source : Wikipédia 11/07/2019 Mickaël Sereno -

4 Graphics Memory : VBO Two way of packing
Device memory V1 N1 UV1 V2 N2 UV2 V3 N3 UV3 Forms a triangle (three points). Each point contains a position, a UV and a normal. Each of these variables can have one, two of three components per value (vector) Device memory V1 V2 V3 N1 N2 N3 UV1 UV2 UV3 Each color represents a point First we pack ALL the positions, then ALL the normals and finally ALL the UVs It is usually like this we packed the vertex values because we can modify directly one type of variable in one call (modify the beginning, middle or the end of the buffer) 11/07/2019 Mickaël Sereno -

5 Graphics Memory : VBO Example in OpenGL 3.0
//We generate our buffer GLuint myBuffer; glGenBuffers(1, &myBuffer); //We fill this buffer as a GL_ARRAY_BUFFER (buffer containing vertices (points) information). //Remind to close this buffer for not misusing it(glBindBuffer(GL_ARRAY_BUFFER, 0);) glBindBuffer(GL_ARRAY_BUFFER, myBuffer); //target (GL_ARRAY_BUFFER), length, data, use case. The data size must not be superior than the buffer size, and not superior than « vertices » length, or a segmentation fault can be thrown. Here we considerate that vertices is typed « float* » (array of float) with at least 3*nbVertices values. glBufferData(GL_ARRAY_BUFFER, 3*sizeof(float)*nbVertices, vertices, GL_DYNAMIC_DRAW); //GL_DYNAMIC_DRAW signifies that we can update this buffer later if necessary glBindBuffer(GL_ARRAY_BUFFER, 0) //Not mandatory, but recommended. We close the buffer for not misusing it //TODO do your thing glDeleteBuffers(1, &myBuffer); //Delete at the end the buffer 11/07/2019 Mickaël Sereno -

6 Graphics Memory : VBO Example in OpenGL 3.0
//We generate our buffer GLuint myBuffer; glGenBuffers(1, &myBuffer); //We fill this buffer as a GL_ARRAY_BUFFER (buffer containing vertices (points) information). //Remind to close this buffer for not misusing it(glBindBuffer(GL_ARRAY_BUFFER, 0);) glBindBuffer(GL_ARRAY_BUFFER, myBuffer); //2 coordinates per UV, 3 per normal and 3 per position. We do not yet copy these data (hence the NULL) glBufferData(GL_ARRAY_BUFFER, ( ) * sizeof(float)*nbVertices, NULL, GL_DYNAMIC_DRAW); //Copy one by one the data (first positions, then normals and finally UV). //We remind that we do not necessarily need all of these variables, and that other variables may be needed for your usecase //parameters : Target, buffer offset, size to copy, CPU data. //We consider that each data are typed « float* » with sizeof(float)*nbVertices*nbCoordinate bytes where nbCoordinate = 2 or 3 following the number of components per value for this variable glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*nbVertices, vertices); glBufferSubData(GL_ARRAY_BUFFER, 3*sizeof(float)*nbVertices, 3*sizeof(float)*nbVertices, normals); glBufferSubData(GL_ARRAY_BUFFER, 3*3sizeof(float)*nbVertices, 2*sizeof(float)*nbVertices, uvData); glBindBuffer(GL_ARRAY_BUFFER, 0) //Close the buffer //TODO do your thing glDeleteBuffers(1, &myBuffer); //Delete at the end the buffer 11/07/2019 Mickaël Sereno -

7 Mickaël Sereno - mickael.sereno@inria.fr
Graphics Memory: EBO EBO : Element Buffer Object. This is a buffer telling what points forms a triangle (the EBO indexes the triangle). We can (its optional) use the EBO if we want to reuse vertices -> less memory used. VBO, out data. It is the EBO which tells in what order these data has to be read to form triangles V1 N1 UV1 V2 N2 UV2 V3 N3 UV3 EBO. Use the vertices « 1 », « 3 » et « 2 » IN THAT ORDER to form the triangle. The order is really important due to the culling process in the rendering pipeline 1 3 2 11/07/2019 Mickaël Sereno -

8 Graphics Memory : EBO Example in OpenGL 3.0
//Generate the buffer GLuint myBuffer; glGenBuffers(1, &myBuffer); //Fill the buffer as a GL_ELEMENT_BUFFER (buffer containing the order of reading in the VBO). //Remember to close the buffer (glBindBuffer(GL_ELEMENT_BUFFER, 0);) glBindBuffer(GL_ELEMENT_BUFFER, myBuffer); //target (GL_ELEMENT_BUFFER), size, data, usecase. glBufferData(GL_ELEMENT_BUFFER, 3*sizeof(int)*nbTriangles, triangles, GL_DYNAMIC_DRAW); //Each index is an int. 3 points per triangles glBindBuffer(GL_ELEMENT_BUFFER, 0) //Close the buffer glDeleteBuffers(1, &myBuffer); 11/07/2019 Mickaël Sereno -


Download ppt "Mickaël Sereno mickael.serneo@inria.fr Graphics Memory Mickaël Sereno mickael.serneo@inria.fr 11/07/2019 Mickaël Sereno - mickael.sereno@inria.fr."

Similar presentations


Ads by Google