Re: Multiple windows and multithreading

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: mikegi (mikegi_at_prestige.net)
Date: 03/03/04


Date: Tue, 2 Mar 2004 23:24:52 -0500


> Unfortunately, I have to build-in my new code into existed and
> old enough application. The application have a following data
> processing algorithm: there is some data source (recording of
> the aircraft parameters during flight) and there are many
> representations of the data. Each representation is in separate
> window in separate thread (don't ask me why).

[I'm talking out of my rear end here since I have never written a
multithreaded Direct3d app, but anyway ...]

I'd try creating a small set of routines that manage the d3d device:

CreateD3DDevice -- This function is called from WinMain. It creates the d3d
device with a back buffer sized to the full screen. It also creates a mutex
or critical section to manage access to the device.

GetD3DDevice -- This is called at the beginning of each window's render
proc. It waits on the mutex/CS created in InitD3D then returns the device.

ReleaseD3DDevice -- This is called at the end of the window's render proc.
It releases the mutex/CS so that another thread can get access to the
device.

DestroyD3DDevice -- Called just before WinMain exits. It does
device->Release() and closes the mutex.

> Can I, for example, create swap chain sized to screen dimensions
> for current mode? But how to tell DirectX not to scale back buffer
> contents, when they drawed in the window. Use viewport? Is there
> any example of such a technique?

I use the following code at the beginning of the rendering proc in my app to
handle window resizing. I create the device with a full screen-sized back
buffer.

  //------------------ Adjust viewport if necessary ---------------------

  D3DVIEWPORT8 vp;

  device->GetViewport( &vp );

  if( vp.X != 0 || vp.Y != 0 ||
      vp.Width != (UINT)cxClient || vp.Height != (UINT)cyClient )
   {
    vp.X = 0;
    vp.Y = 0;
    vp.Width = cxClient;
    vp.Height = cyClient;

    device->SetViewport( &vp );
   }

  //------------------------- Render scene ------------------------------

  [... rendering crap ...]

  //-------------------------- Display it -------------------------------

  RECT rc;

  rc.left = 0;
  rc.top = 0;
  rc.right = cxClient;
  rc.bottom = cyClient;

  device->Present( &rc, &rc, hwnd, NULL );

It would be smarter to call GetD3DDevice with cxClient and cyClient. By
funneling all viewport requests through a single point you could eliminate
the GetViewport call.



Relevant Pages

  • Re: In window mode, pD3DDevice->SetViewport?
    ... the back buffer is always stretchblit to ... // Holds Our Window Handle ... HINSTANCE hInstance; // Holds The Instance Of The Application ... void ReSizeD3DScene(int width, int height) // Resize And Initialize The ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: opengl program to load a bmp runtime error (using freeglut 2.4)
    ... but when i do ./a.out the following error appears and no window ... // Do the buffer Swap ... int gltIsExtSupported(const char *extension) ... GLint gltWriteTGA ...
    (comp.graphics.api.opengl)
  • Scenario to make recv(MSG_WAITALL) stuck
    ... Below is a scenario how to make recvwith MSG_WAITALL flag get stuck. ... Let's the size of the receive buffer is SOBUF_SIZE. ... TCP window probes. ... partial SOBUF_SIZE request. ...
    (freebsd-net)
  • Re: Scenario to make recv(MSG_WAITALL) stuck
    ... Below is a scenario how to make recvwith MSG_WAITALL flag get stuck. ... Let's the size of the receive buffer is SOBUF_SIZE. ... TCP window probes. ... partial SOBUF_SIZE request. ...
    (freebsd-net)
  • Re: A mailslot question
    ... the same problem exists whether you use a single buffer or multiple ... buffers - if you have a bug in your code it will leak memory or else ... processing of a mail slot messages by consuming additional system resources ... the right window dynamically. ...
    (microsoft.public.win32.programmer.kernel)