Results 1 to 8 of 8

Thread: Interleaved (Vertex) Arrays with different types?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Interleaved (Vertex) Arrays with different types?

    Hello.
    I hope I formulated the topic in a proper way, but I think you will soon understand what I mean anyway.
    Here we go:
    I was considering to use this type GL_T2F_C4UB_V3F .
    But I don't know what type the array should be declared as. As a float? What is the point then of using unsigned bytes for the colors?
    A byte takes less memory than a float, right? This memory will be lost due to the float array, right?
    Also if I am using integers for the TexCoords right now, this memory will also be lost?

    I hope you can clear things upp a bit for me, thanks!


    [This message has been edited by B_old (edited 12-24-2002).]
    I may not be good looking but I sure am dumb.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: Interleaved (Vertex) Arrays with different types?

    It doesnīt matter which type you use for the array. Think of the array only as a chunk of memory. First you calculate the amount of memory you need. Say you need memory for 10 vertices, each with texcoords and color = 10 * ((2 * sizeof (float)) + (4 * sizeof (byte)) + (3 * sizeof (float)))
    This yields to:
    8 byte for texcoords
    4 byte for colors
    12 byte for the vertex
    times 10 for all vertices = 240 byte

    And now you allocate your array. How you do this exactly depends on your favor. Which type of array you use does not matter. BUT you have to consider, that different types have different sizes:

    BYTE* array = new byte[size]
    is not equal to
    float* array = new float[size]

    because sizeof (float) = 4 bytes and sizeof (byte) = 1 bytes.

    So

    BYTE* array = new byte[size]
    is equal to
    float* array = new float[size/4]

    After all OpenGL doesnīt work with floats if you allocated a float array. It just takes a pointer to your data (and an argument that tells gl how much data there is) and uses this data.

    I advise you to always use byte* arrays instead of float* arrays. There is no speed difference or anything else. The only difference is, that one easily forgets, that a float is 4 bytes big. Therefore it could happen to you (as it happened to me), that you allocate an array, that is 4 times bigger than needed.

    Also remember that

    byte *pointer = someadress;
    pointer++; //increases the pointer by 1

    is not equal to

    float *pointer = someadress;
    pointer++; //increases the pointer by 4!


    I hope you now understand, that your choice for the arraytype has no influence on OpenGLīs behaviour at all.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  3. #3
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Interleaved (Vertex) Arrays with different types?

    WOW, that was a great answer, thanks a lot!

    I have just a minor question left:
    GL_T2F_C4UB_V3F, this means that OGL is expection floats for the texcoords, right?

    Do I have to locate space for floats or can I save them as integers and OGL transforms them to it's liking?
    hmmm I guess that will mess things up.
    I am only considering interleaved arrays because I can make all I need with so little code, but if I took integers instead of floats I had to mess around with stride and stuff like that, don't I?

    Is there an advantage with interleaved arrays apart from the fact that it looks tidy?

    Thanks again for the detailed answer!
    I may not be good looking but I sure am dumb.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Interleaved (Vertex) Arrays with different types?

    For interleaved arrays, it can also be useful to just create a struct of the format you plan to use. In your case the struct would look something like so:

    Code :
    struct Vertex
    {
       float s, t;
       unsigned char r, g, b, a;
       float x, y, z;
    };
    You can then create an array of your struct to store your data in and just pass a pointer to that array to glInterleavedArrays.
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Interleaved (Vertex) Arrays with different types?

    Hmmm, that is not an bad idea I think, thanks.

    Still, what about the integers that are supposed to be floats?
    I may not be good looking but I sure am dumb.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Interleaved (Vertex) Arrays with different types?

    Well... that format you are using expects to use floats for the texcoords. You should also be aware that even if you were to use integers for the texcoords, the range of the tex coords are still 0-1. So unless you were to use the texture matrix to scale it differently, using integers you could only really specify the outermost corners of the texture as the texcoords.
    Deiussum
    Software Engineer and OpenGL enthusiast

  7. #7
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Interleaved (Vertex) Arrays with different types?

    hmmm.
    This is all for a particle renderer.
    So I guess I will never use anything but the whole texture? hmmm Or maybe for animated particles it would be nice to let the texture scroll like a movie, interesting point indeed!
    Would it be possible to use 3D-textures for this? I have no idea what they actually mean and if they would be any good in this case...

    By the way it seems that there is no interleaved array that lets me choose float for 2 texcoords and float for RGBA and float for 3 vertices. Isn't that kind of uncool?

    Thanks for your help all.
    I may not be good looking but I sure am dumb.

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Interleaved (Vertex) Arrays with different types?

    Yeah, it appears that glInterleavedArrays doesn't allow you to use that specific format. You can always setup your own format of interleaved arrays by enabling the right arrays and setting all the strides correctly, though. It's a bit more work, but it is an option.
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. Vertex Arrays, interleaved arrays, mouseMove func
    By Nibirue in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-13-2012, 11:17 AM
  2. interleaved vertex arrays with multitexturing
    By imported_bobby_newmark in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-19-2006, 02:32 AM
  3. Vertex Arrays: Interleaved or seperated arrays?
    By Jan in forum OpenGL: Advanced Coding
    Replies: 16
    Last Post: 06-21-2005, 05:25 AM
  4. interleaved vertex arrays and multitexture...
    By miko in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-27-2003, 04:35 PM
  5. Vertex and Face normals in Interleaved arrays.
    By TJ in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 03-18-2002, 12:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean