Are my lines instanced?

SirYakalot
  • Are my lines instanced? SirYakalot

    I have a class which "collects" line mesh transformations throughout the update and then draws them in one place by drawing one line over and over again. I'll post the code below. I'm just wondering if this is instanced or if the idea is to join them all into one mega-mesh and send that through?

    Or if I'm missing some key-part altogether....

    void BatchLineRenderer::RenderLines(D3DXMATRIX matView, D3DXMATRIX matProjection)
    {
        device->IASetInputLayout(pVertexLayout);
    
        device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP);
    
        // select which vertex buffer and index buffer to display
        UINT stride = sizeof(LINE);
        UINT offset = 0;
        device->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset);
        device->IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0);
    
        std::vector<LINE>::size_type allLines = permanentLines.size();
    
        for(int i = 0; i < allLines; i++)
        {
            pColour->SetFloatVector(permanentLines[i].colour); // in the line loop too?
    
            // combine the matrices and render
            D3DXMATRIX matFinal = 
            permanentLines[i].scale     * 
            permanentLines[i].rotation  * 
            permanentLines[i].position  * 
            matView * matProjection;
    
            pTransform->SetMatrix(&matFinal._11); 
            pRotation->SetMatrix(&permanentLines[i].rotation._11);    // set the rotation matrix in the effect
    
            pPass->Apply(0);
    
            device->DrawIndexed(2, 0, 0);
        }
    
        allLines = temporaryLines.size();
    
        for(int i = 0; i < allLines; i++)
        {
            pColour->SetFloatVector(temporaryLines[i].colour); // in the line loop too?
    
            // combine the matrices and render
            D3DXMATRIX matFinal = 
            temporaryLines[i].scale * 
            temporaryLines[i].rotation * 
            temporaryLines[i].position * 
            matView * matProjection;
    
            pTransform->SetMatrix(&matFinal._11); 
            pRotation->SetMatrix(&temporaryLines[i].rotation._11);    // set the rotation matrix in the effect
    
            pPass->Apply(0);
    
            device->DrawIndexed(2, 0, 0);
        }
    
        temporaryLines.clear();
    }
    

  • The purpose of "instanced" rendering is to make one draw call to draw all of the instances. You are making allLines number of draw calls. So no, that's not instancing.

    Since each instance is completely separate from the other, sharing absolutely no data at all (the matrix is basically just a bulky way to encode the two endpoints of each line), you would gain nothing from instancing. Instead, you should build a vertex buffer that contains all of the lines (and their colors). If lines change, you change the buffer.

    This way, you draw all of them at once.

  • I would consider instanced rendering to either be a single Draw call of some sort, where the geometry itself is either duplicated in the buffer N times, or the drawing API renders the mesh N times for you with some per-instance vertex buffer data, or multiple Draw calls with no other API calls in between them (i.e. only changing the starting index or vertex and number of primitives, which you would need to do if you wish to draw less than a whole mesh, but in parts).

    Any other API to change textures, rendertargets, shader constants, render state, and shaders calls can incur quite a lot of overhead.

Tags
c++ directx graphics-programming directx10
Related questions and answers
  • UINT stride = sizeof(LINE); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); device-&gt;IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0); allLines = temporaryLines.size(); for(int i = 0; i &lt; allLines; i++) { pColour-&gt;SetFloatVector(temporaryLines[i].colour); // in the line loop too? // combine the matrices and render D3DXMATRIX...); pRotation-&gt;SetMatrix(&amp;temporaryLines[i].rotation._11); // set the rotation matrix in the effect pPass-&gt;Apply(0); device-&gt;DrawIndexed(2, 0, 0); } temporaryLines.clear

  • ); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); device-&gt;IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0); D3DXMATRIX matRotate, matView... buffer and use it to create the render target ID3D10Texture2D* pBackBuffer; swapchain-&gt;GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&amp;pBackBuffer); device-&gt;CreateRenderTargetView(pBackBuffer, NULL, &amp;rtv); pBackBuffer-&gt;Release(); // set the back buffer as the render target device-&gt;OMSetRenderTargets(1, &amp;rtv, dsv); D3D10_VIEWPORT viewport; // create a struct to hold

  • (D3D10_PRIMITIVE_TOPOLOGY_LINELIST); UINT stride = sizeof(VERTEX); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); screenPass-&gt;Apply(0...I'm writing a simple class to draw all the debugging lines I have in my scene at once. The code in the draw loop is this so far: (If I put for example, 2 instead of temporary2DVerts.size() where I have marked with //THIS LINE, the code works fine.) when I run the code below the line breaks //HERE. Access violation reading location 0x00000000. seems like the create buffer line is not working

  • ;IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST); // select which vertex buffer to display UINT stride = sizeof(VERTEX); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); // apply the appropriate pass screenPass-&gt;Apply(0); // draw the vertex buffer to the back buffer device-&gt;Draw(temporary2DVerts.size... it all separately? Basically how would I extend this code to include more vectors of vertices? if (temporary2DVerts.size() &gt; 0) { // create the vertex buffer and store the pointer into pBuffer

  • , 0.0f, 1.0f); glScalef(scale, scale, scale); // Loop through the objects for (int i = 0; i &lt; numObjects; i++) { // Enable texture coordiantes, normals..., In); // Get The Current Line ( NEW ) shaderData[i][0] = shaderData[i][1] = shaderData[i][2] = float(atof (Line)); // Copy Over The Value ( NEW ) } fclose...); // Set The Color Of The Model ( NEW ) // ORIGINAL DRAWING CODE //Draw the model as an interpolation between the two frames glBegin(GL_TRIANGLES); for(int i = 0; i

  • ; bd.MiscFlags = 0; device-&gt;CreateBuffer(&amp;bd, NULL, &amp;pBuffer); void* pVoid; // the void pointer pBuffer-&gt;Map(D3D10_MAP_WRITE_DISCARD, 0, &amp;pVoid); // map the vertex buffer...; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device-&gt;CreateBuffer(&amp;bd, NULL, &amp;iBuffer); iBuffer-&gt;Map(D3D10_MAP_WRITE_DISCARD, 0, &amp;pVoid); // map the index buffer memcpy...Like many beginner graphics programmers I followed a tutorial which showed me how to set up buffer descriptions and fill out the vertex buffer etc... - the steps involved in drawing a simple indexed

  • GeneratePath( vector<string>&amp; buff){// the buff is the seed too int wall= RandNumb(80)/2, space = (RandNumb(75)/2)+5, wall2= 80-(space+wall); int swall= 0...}; // for the old/new screen command // Some nCurses setup int r = 0, c = 0; // current row and column (upper-left is (0,0)) const int nrows = 56, // number of rows in window ncols = 79...--; cspace++;}} for(int s= 0; s &lt;sspace; s++) buff[buff.size()-1].push_back(' '); // cwall2 //if(cwall2!= 0){ // if(cwall2&gt;0

  • in the shader code) for( int n = 0; n &lt; vShaderArgs.size(); n ++) glBindAttribLocation( m_nProgramId, n, vShaderArgs[n].sFieldName.c_str() ); // Create and bind to a vertex array object, which...: float m_Position[3]; // x, y, z // offset 0, size = 3*sizeof(float) float m_TexCoords[2]; // u, v // offset 3*sizeof(float), size = 2*sizeof(float) float m_Normal[3]; // nx, ny, nz; float colour[4]; // r, g, b, a float padding[20]; // padded for performance }; I've already written a working VertexBufferObject class that creates a vertex buffer

  • wrong in my frame buffer set up code, or elsewhere. But I can't see what. The FBO is set up through the following function: unsigned int fbo_id; unsigned int depth_buffer; int m_FBOWidth, m_FBOHeight...); glBindFramebuffer(GL_FRAMEBUFFER, 0); } Here is my drawing box code, which just takes a transformation matrix and calls the appropriate functions. The current values of P is a projection matrix...I'm having trouble implementing render to texture with OpenGL 3. My issue is that after rendering to the frame buffer, it appears the rendered object becomes deformed, which may imply a bad

Data information