Direct3D8Renderer for CEGUI 7.1

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

MarkR
Quite a regular
Quite a regular
Posts: 64
Joined: Thu Jul 15, 2010 06:55

Direct3D8Renderer for CEGUI 7.1

Postby MarkR » Sat Jul 31, 2010 12:31

Hi,

for all those D3D Freaks out there:

I'm currently implementing a Renderer for D3D8, as D3D8 support is officially cancelled for the 7.x series.
It's basically a straight-ahead down-port of the D3D9 Renderer, however as the ScissorRect functionality isn't implemented in D3D8, CE gave me the hint to check the Irrlicht Renderer, as the same functionality is implemented there by modifying the viewport / projection matrix.

I tried to convert the code there to D3D8 and it seems to work - except that nothing is drawn on the screen.

I'm quite sure, that I missed something important in the viewport / projection matrix modification in Direct3D8GeometryBuffer::draw(), but I just can't see, what's wrong... Anyone, who might shed some light on this?


Best regards
- Mark


Code: Select all

void Direct3D8GeometryBuffer::draw() const
{
    // Set up clipping for this buffer
    //
    // This is done via viewport & projection manipulation because DirectX 8
    // has no scissoring facilities.  This has the unfortunate side effect of
    // being much more expensive to set up.
    D3DVIEWPORT8 target_vp;
    d_device->GetViewport(&target_vp);

    D3DXMATRIX proj;
    d_device->GetTransform(D3DTS_PROJECTION, &proj);
    const Size csz(d_clipRect.getSize());
    const Size tsz(static_cast<float>(target_vp.Width),
                   static_cast<float>(target_vp.Height));

    // set modified projection 'scissor' matix that negates scale and
    // translation that would be done by setting the viewport to the clip area.
    float m_00 = tsz.d_width / csz.d_width;
    float m_11 = tsz.d_height / csz.d_height;
    float m_30 = 1.0f * (tsz.d_width + 2.0f *
            (target_vp.X -
                (d_clipRect.d_left + csz.d_width * 0.5f))) / csz.d_width;
    float m_31 = -(tsz.d_height + 2.0f *
            (target_vp.Y -
                (d_clipRect.d_top + csz.d_height * 0.5f))) / csz.d_height;

    D3DXMATRIX scsr(
        m_00, 0.0f, 0.0f, 0.0f,
        0.0f, m_11, 0.0f, 0.0f,
        0.0f, 0.0f, 1.0f, 0.0f,
        m_30, m_31, 0.0f, 1.0f);
   
    D3DXMATRIX scproj;
    d_functions.D3DXMatrixMultiply(&scproj, &scsr, &proj);
    d_device->SetTransform(D3DTS_PROJECTION, &scproj);

    // set new viewport for the clipping area
    D3DVIEWPORT8 vp;
    vp.X = static_cast<DWORD>(d_clipRect.d_left);
    vp.Y = static_cast<DWORD>(d_clipRect.d_top);
    vp.Width = static_cast<DWORD>(d_clipRect.getWidth());
    vp.Height = static_cast<DWORD>(d_clipRect.getHeight());
    vp.MinZ = 0.0f;
    vp.MaxZ = 1.0f;
    d_device->SetViewport(&vp);

    // apply the transformations we need to use.
    if (!d_matrixValid)
        updateMatrix();

    d_device->SetTransform(D3DTS_WORLD, &d_matrix);

    d_owner.setupRenderingBlendMode(d_blendMode);

    const int pass_count = d_effect ? d_effect->getPassCount() : 1;
    for (int pass = 0; pass < pass_count; ++pass)
    {
        // set up RenderEffect
        if (d_effect)
            d_effect->performPreRenderFunctions(pass);

        // draw the batches
        size_t pos = 0;
        BatchList::const_iterator i = d_batches.begin();
        for ( ; i != d_batches.end(); ++i)
        {
            d_device->SetTexture(0, (*i).first);
            d_device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, (*i).second / 3,
                                    &d_vertices[pos], sizeof(D3DVertex));
            pos += (*i).second;
        }
    }

    // clean up RenderEffect
    if (d_effect)
        d_effect->performPostRenderFunctions();

    // restore original projection matrix and viewport.
    d_device->SetTransform(D3DTS_PROJECTION, &proj);
    d_device->SetViewport(&target_vp);
}

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Direct3D8Renderer for CEGUI 7.1

Postby CrazyEddie » Sat Jul 31, 2010 20:04

Your code didn't look horrible to me, so I retro-fitted the vp/projection clipper part into the D3D9 renderer and it worked ok there (don't know if you'd tried that yourself already) - so there should be nothing wrong with the code itself.

Did you try rendering with no clipping? Just to be sure that the basic rendering part is working ok?

CE.

MarkR
Quite a regular
Quite a regular
Posts: 64
Joined: Thu Jul 15, 2010 06:55

Re: Direct3D8Renderer for CEGUI 7.1

Postby MarkR » Sun Aug 01, 2010 12:58

No, I didn't check that before...
I couldn't imagine that the problem could be somewhere else, as the D3D8 code is basically a `cat $DX9FILENAME | tr 9 8 > $DX8FILENAME`

However, I finally found out :roll:
STDMETHOD(SetRenderTarget)(THIS_ DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget) PURE;
vs
STDMETHOD(SetRenderTarget)(THIS_ IDirect3DSurface8* pRenderTarget,IDirect3DSurface8* pNewZStencil) PURE;

so d_device->SetRenderTarget(0, d_surface) has two completely different meanings on d3d8 and d3d9 -.-

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Direct3D8Renderer for CEGUI 7.1

Postby CrazyEddie » Sun Aug 01, 2010 18:43

Yay for interface consistency! :)

So, does this mean you managed to get it working in the end?

CE

MarkR
Quite a regular
Quite a regular
Posts: 64
Joined: Thu Jul 15, 2010 06:55

Re: Direct3D8Renderer for CEGUI 7.1

Postby MarkR » Sun Aug 01, 2010 22:02

Well, after fiddling around with it a little bit more, yes.
I needed however to disable the clipping again, as the didn't work with the ItemListbox / ListboxItem.
But then again, I don't really care about this, since it works good enough for me, even without clipping ;-)

If you're interested in the D3D8 code, I could send the new files to you, but as stated before, it's just more or less stupid Copy&Paste + Search&Replace - except for the stupid SetRenderTarget issue :D

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Direct3D8Renderer for CEGUI 7.1

Postby CrazyEddie » Mon Aug 02, 2010 18:00

Cool.

I think it might be useful to make the code available;, that way others could use it (so long as they understand the current limitations, and such),

CE.

MarkR
Quite a regular
Quite a regular
Posts: 64
Joined: Thu Jul 15, 2010 06:55

Re: Direct3D8Renderer for CEGUI 7.1

Postby MarkR » Mon Aug 02, 2010 18:59

Check your PMs ;-)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Direct3D8Renderer for CEGUI 7.1

Postby CrazyEddie » Tue Aug 03, 2010 18:16

Message received, thanks :)

CE.

adamix
Just popping in
Just popping in
Posts: 1
Joined: Tue Aug 31, 2010 14:05

Re: Direct3D8Renderer for CEGUI 7.1

Postby adamix » Tue Aug 31, 2010 14:25

Can someone give me Direct3D8Renderer for cegui v7.x ?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Direct3D8Renderer for CEGUI 7.1

Postby CrazyEddie » Thu Sep 02, 2010 08:22

I have two (yes, two!) versions of the D3D8 renderer. The first is the original version made by MarkR, and I also have an alternative version (that I still have to look at) from ReGeX. I need to get around to dealing with these properly, and then something will be made available 'semi-officially'. In the mean time, if neither of the the original authors do not/can not help you you out with a link, contact me and I'll see what I can come up with.

CE


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 15 guests