0
\$\begingroup\$

I'm trying to go over some Shader code at my university, I have forgotten it, and well, Its really confusing, The documentation we have been given is really difficult to read.

Also is there any good beginner tutorials In HLSL that can walk me through the whole thing ?

void RenderScene( float updateTime )
{
    // Setup the viewport - defines which part of the back-buffer we will render to (usually all of it)
    D3D10_VIEWPORT vp;
    vp.Width  = BackBufferWidth;
    vp.Height = BackBufferHeight;
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
    g_pd3dDevice->RSSetViewports( 1, &vp );



    //************************************************
    // FIRST RENDER PASS - Render scene to texture

    // Specify that the scene texture will be the render target in this first pass (rather than the backbuffer), will share the depth/stencil buffer with the backbuffer though
    g_pd3dDevice->OMSetRenderTargets( 1, /* MISSING */ , DepthStencilView );
    /*MISSING - specify scene texture as render target (variables near top of file)*/
    // Clear the texture and the depth buffer
    g_pd3dDevice->ClearRenderTargetView( SceneRenderTarget, &AmbientColour.r );
    g_pd3dDevice->ClearDepthStencilView( DepthStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0 );

    // Prepare camera
    MainCamera->SetAspect( static_cast<TFloat32>(BackBufferWidth) / BackBufferHeight );
    MainCamera->CalculateMatrices();
    MainCamera->CalculateFrustrumPlanes();

    // Set camera and light data in shaders
    SetCamera( MainCamera );
    SetAmbientLight( AmbientColour );
    SetLights( &Lights[0] );

    // Render entities and draw on-screen text
    EntityManager.RenderAllEntities( MainCamera );

    //************************************************

I'm really not sure whats to go in OMSSetRenderTarget, it has aweird parameter that has Variable * const *variable which I try replicating with the values I have been given and it returns an error.

\$\endgroup\$
  • \$\begingroup\$ Are you sure that's HLSL? Looks like plain old C++11 to me. Maybe that's why you're having problems. \$\endgroup\$ – Pharap May 21 '17 at 0:00
1
\$\begingroup\$

If you check the online documentation of OMSetRenderTargets, then you'll see that the second argument should be of type ID3D11RenderTargetView * const * and is named ppRenderTargetViews, which is a pointer to a pointer of render target views (most likely an array of pointers to render target views).

It's clear that the intended variable is SceneRenderTarget, but without knowing the type of SceneRenderTarget (whether it's a struct or a pointer) I couldn't tell you what /*Missing*/ should be. Thankfully I can check the online documentation of ClearRenderTargetView to discover that its type is ID3D11RenderTargetView *, so I can deduce that as OMSetRenderTargets needs a ID3D11RenderTargetView * const * (a pointer to a pointer) and SceneRenderTarget is a pointer, you just need to take the address of SceneRenderTarget to have a valid argument, leaving the answer as:

g_pd3dDevice->OMSetRenderTargets( 1, &SceneRenderTarget, DepthStencilView );

(Next time you get a problem of type 'fill in the missing argument', always check the documentation to discover the expected type of the argument and what the expected argument represents.)

\$\endgroup\$
  • \$\begingroup\$ Odd I tried putting that in and it didn't work, it throws an exception. \$\endgroup\$ – RNewell122 May 21 '17 at 0:01
  • \$\begingroup\$ @RNewell122 Specifically which exception? \$\endgroup\$ – Pharap May 21 '17 at 0:02
  • \$\begingroup\$ Oh I am rather sorry, i misunderstood the const that it requires an &SceneRenderTarget instead of SceneRenderTarget \$\endgroup\$ – RNewell122 May 21 '17 at 0:08
  • \$\begingroup\$ @RNewell122 ID3D11RenderTargetView * const * means 'pointer to const pointer to ID3D11RenderTargetView', SceneRenderTarget is a ID3D11RenderTargetView * (a 'pointer to ID3D11RenderTargetView'), so &SceneRenderTarget is a 'pointer to pointer to ID3D11RenderTargetView', but the const can be added implicitly, so it still matches the signature of ID3D11RenderTargetView * const *. Is it working or is it still causing an exception? (And if it is, what is the error message?) \$\endgroup\$ – Pharap May 21 '17 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.