Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Transform data received on shader looks different than data sent
Forum Updated to NodeBB v4.3 + New Features

Transform data received on shader looks different than data sent

Scheduled Pinned Locked Moved Solved Game Development
2 Posts 2 Posters 492 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheOwnageGuy
    wrote on last edited by TheOwnageGuy
    #1

    I am getting an issue where the transform data being sent to the shader for use in Instanced Draw calls looks different than the data that is actually being received.

    I am sending an array of floats.

    The number of floats in the array is a multiple of 16 (every 16 floats represents a transform).

    Right now I am just sending a bunch of identity transforms but when I view the array on render doc, the set of 4 vectors that each instance of the draw call is using does not match expectations.

    This is the data each instance is using in render doc

    I am expecting the data to be like this:

    
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1
    
    

    How my data looks like in my debugger:
    transform on the debugger.png

    But the first 16 floats looks like this in the render doc (each row contains 16 floats, only 11 are shown here:
    transform on render doc.png

    1 0 0 0
    0 0 0 0
    0 0 0 1
    0 0 1 0
    
    

    This is the code I use to allocate the data to the shader. (This is a qt creator c++ project. Qt has their own opengl function bindings)

    m_transformbo.create();
            m_transformbo.setUsagePattern(QOpenGLBuffer::DynamicDraw);
            m_transformbo.bind();
            m_transformbo.allocate(m_listOfTransforms.data(), m_listOfTransforms.size() * sizeof(float));
    
            if (m_listOfTransforms.size() > 0)
            {
                for (int i = 0; i < 4; i++) {
                    m_view->shaderProgram()->enableAttributeArray(m_shader_locs.transforms + i);
                    int shaderLocation = m_shader_locs.transforms + i;
                    int offset = i * sizeof(float);
                    int stride = 16 * sizeof(float);
                    int tupleSize = 4;
    
                    m_view->shaderProgram()->setAttributeBuffer(shaderLocation, GL_FLOAT, offset, tupleSize,stride);
                    m_view->glVertexAttribDivisor(shaderLocation, 1);
                }
            }
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      TheOwnageGuy
      wrote on last edited by
      #2

      I figured it out, my

      int offset = i * sizeof(float);
      

      should have been

      int offset = i * sizeof(float) * 4;
      

      This makes sense since the offset should be every 4 floats

      1 Reply Last reply
      0
      • T TheOwnageGuy has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved