Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Problem with using glDrawElementsBaseVertex - bad draws

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2018
    Posts
    4

    Problem with using glDrawElementsBaseVertex - bad draws

    Hey
    Before I get on with my problem, does any1 know how to change this forum from that weird "round" style - mobile like to a normal desktop like? I tried searching for the answer, it but I cant because the catch check is under a search button and I can't get it to work at all! the hell o.O went with opera, now it works. Chrome is broken o.O
    Anyway, I'm trying to optimize my render a little, with some glDrawElementsBaseVertex to help with frame rate.

    This is my rough loop that I use for the render :

    Code :
        int x = 0;
        for (auto &geo:mNodeList) { << geometry array
            mShader->setUniformValue("mvp_matrix", matrix *  geo->mAbsoluteMatrix); << set matrix for next node ( kinda wonder how could I pass an array of matrices so that I can do it all in 1 call one day... anyway issue for another day)
            glDrawElementsBaseVertex(GL_TRIANGLES, mMeshesCountList[x], GL_UNSIGNED_INT, (const GLvoid *) (skip * sizeof(indices.first())), skip);<< this is broken, it generated "broken" meshes. I tried a number of different things. Cant get it to run at all : -(
            skip += mMeshesCountList[x];
            ++x;
        }


    Anyway

    So I'm trying to render 10k objects-geometries. Just simple draw for testing.
    QVector<int> mMeshesCountList - bad naming but what it is a indices count that needs drawing per object [x]
    skip = the offset to next mesh in indices;
    I also tried this lately :

    Code :
     glDrawElementsBaseVertex(GL_TRIANGLES, mMeshesCountList[x], GL_UNSIGNED_INT,(const void*) (skip * sizeof(unsigned int), skip);



    I'm struggling to wrap my head around it, it must be somehow very basic issue because there is almost no tutorials/info on it on the net and "The official guide to learning opengl 4.3" has also very little code with examples for it. I mean... suhhhh

    So what did I do wrong here if I may ?
    Last edited by Dariusz; 01-13-2019 at 01:52 PM.

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,087
    Quote Originally Posted by Dariusz View Post
    Hey
    Before I get on with my problem, does any1 know how to change this forum from that weird "round" style - mobile like to a normal desktop like?
    Can't you just have your mobile browser display the site in desktop mode?

    Quote Originally Posted by Dariusz View Post
    So what did I do wrong here if I may ?
    Well, it's kind of hard to say one way or the other, since the correctness or incorrectness of your code is based on your actual data. Which you haven't shown.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2018
    Posts
    4
    Quote Originally Posted by Alfonse Reinheart View Post
    Can't you just have your mobile browser display the site in desktop mode?
    Im on desktop chrome... I dont know how to tell this forum to run in desktop mode on my dekstop system o.O - ok I've opened it in opera. Opera works. wow O_O

    Quote Originally Posted by Alfonse Reinheart View Post
    Well, it's kind of hard to say one way or the other, since the correctness or incorrectness of your code is based on your actual data. Which you haven't shown.
    Oh hmmm

    Well I have something like this for data :

    Code :
        /// Gather the size of each vector and create indices list
        std::shared_ptr<geometryObj> geo;
        QVector<unsigned int>mMeshesCountList(listSize);
        for (int x = 0; x < listSize; ++x) {
            geo = mNodeList[x]->getGeometryPtr();
            verteSize += geo->mVertexCount;
            normalsSize += geo->mNormalsCount;
            indicesSize += geo->mIndicesCount;
            mMeshesCountList[x] = geo->mIndicesCount;
        }
        /// create vectors
        QVector<QVector3D> mVertex(verteSize);
        QVector<QVector3D> mNormals(normalsSize);
        mIndices.resize(indicesSize);
        unsigned long long int offsetVert = 0;
        unsigned long long int offsetNormal = 0;
        offsetIndice = 0;
        /// Gather data for each vector
        for (auto &node:mNodeList) {
            geo = node->getGeometryPtr();
            for (int x = 0; x < geo->mVertexCount; ++x) {
                mVertex[offsetVert] = geo->mVertex[x];
                ++offsetVert;
            }
            for (int x = 0; x < geo->mNormalsCount; ++x) {
                mNormals[offsetNormal] = geo->mVertexNormal[x];
                ++offsetNormal;
            }
            for (int x = 0; x < geo->mIndicesCount; ++x) {
                mIndices[offsetIndice] = geo->mIndices[x];
                ++offsetIndice;
            }
        }
     
        /// allocate data
        mVao->bind();
     
        mBufferVertex->bind();
        mBufferVertex->allocate(mVertex.get(), verteSize * sizeof(QVector3D));
        mBufferVertex->release();
     
        mBufferNormals->bind();
        mBufferNormals->allocate(mNormals.get(), normalsSize * sizeof(QVector3D));
        mBufferNormals->release();
     
        mBufferIndices->bind();
        mBufferIndices->allocate(mIndices.data(), indicesSize * sizeof(unsigned int));
        mBufferIndices->release();
    I'm using QT openGL...

    also the render code before loop is this :

    Code :
        mShader->bind();
        mVao->bind();
        mBufferVertex->bind();
        mBufferIndices->bind();
        bindPosition();// enableAttr/setAttr
        mBufferNormals->bind();
        bindColor();// enableAttr/setAttr
    Last edited by Dariusz; 01-13-2019 at 01:57 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
  •