
JP Bridges
Members-
Posts
11 -
Joined
-
Last visited
About JP Bridges
- Birthday 06/10/1977
JP Bridges's Achievements
Newbie (1/14)
0
Reputation
-
Solved it... The Marshal.Copy static member did what I was after. JP
-
Folks, This is probably a fairly basic problem but I'm having trouble finding a solution. I've opened a file stream to read file x. The first element of file x is a structure of type y, this structure consists of your basic unmanaged elements, ints, fixed char arrays, etc. What is the best way of extracting and using the structure in managed code. I can read the correct amount of bytes from the file stream into a byte array... so I figure I have the data but in the wrong format, I'm not sure how to get this data and turn it into something I can use. JP
-
In the following function... public: Array* GraphicsStream::Read(Type*returnType, int ranks __gc[]); Does anybody have any idea what the ranks parameter does?? JP
-
Use the code tag... have a look at the help next to vB Code, it's explianed there. As for your code I don't know what's wrong. My experience with DX9 (Managed) so far has been mostly frustration, things don't seem to work unless you get them just right. The lack of documentation is terrible too. One thing you may want to try though is looking in your debug window while you are running particular function calls... often it'll flash up messages there that you'd otherwise miss. JP
-
As far as I understand you present the swap chain since that is actually your off screen surface... My drawing loop looks like this... (in C#ish lingo) pSurf = pSwapChain.GetBackBuffer(0, BackBufferType.Mono); pSurf.Device.SetRenderTarget(0, pSurf); pSurf.Device.Clear(ClearFlags.Target, Drawing.Color.Black, 0.0f, 0); pSurf.Device.BeginScene(); pSurf.Device.EndScene(); pSwapChain.Present(); pSurf device is just a pointer to the main graphics device so don't let it confuse you. JP
-
My PresentParams and device creation method call is as follows... // Basic implementation of Direct X... change this later. PresentParameters * pp = new PresentParameters; pp->Windowed = true; pp->BackBufferCount = 1; pp->BackBufferWidth = 0; pp->BackBufferHeight = 0; pp->BackBufferFormat = Format::Unknown; pp->EnableAutoDepthStencil = false; pp->DeviceWindow = this; pp->DeviceWindowHandle = this->Handle; pp->PresentFlag = PresentFlag::None; pp->FullScreenRefreshRateInHz = 0; pp->MultiSample = MultiSampleType::None; pp->PresentationInterval = PresentInterval::Default; pp->SwapEffect = SwapEffect::Discard; // Create our device based on the presentation parameters. pDev = new Microsoft::DirectX::Direct3D::Device(0, DeviceType::Hardware, this->Handle, CreateFlags::SoftwareVertexProcessing, pp); This is called from within the main applications constructor so 'this' refers to the main windows form. As far as I remember this was pretty much the bare minimum I could get away with without the Device call failing. The reason I assigned both the DeviceWindow and the DeviceWindowHandle was that I was having trouble getting the swap chain to associate with the panel. I agree that one or the other should do the job and you probably don't/shouldn't need both. If you're still having trouble feel free to email and I'll send you some source files... JP *still grumbling that MS still haven't published any significant documentation for this stuff*
-
Okay although I make no claim to tidy or well ordered code here you go... First step is of course correctly setting up a D3D device, which I assume you've done. Next you have to set up your swap chain. In the code below ViewPanel is inherited from Panel and has a swap chain associated with it. pSwapChain is a private member of ViewPanel. Void ViewPanel::InitializeSwapChain(DirectX::Direct3D::Device * pDev) { // Create a new set of presentation parameters based on our main Direct3D device. // Point the new presentation parameters at the panel, and then create a new swap chain. PresentParameters * pp = new PresentParameters(pDev->PresentationParameters); pp->DeviceWindow = this; pp->DeviceWindowHandle = this->Handle; try { pSwapChain = new SwapChain(pDev, pp); } catch(InvalidCallException * dxCatch) { Console::WriteLine(dxCatch->ToString()); } } // End METHOD InitializeSwapChain Now to test this I used the Paint event of the panel... I had to put a test in to make sure we didn't try to use the swap chain if it was marked for garbage collection because it was fairly bad karma if we did (see original post). Void ViewPanel::OnPaintBackground(Object * pObject, PaintEventArgs * pea) { DirectX::Direct3D::Surface * pSurf; // If the swap chain is marked for disposal, due to a device reset or something, then don't // do anything. if(pSwapChain->Disposed) { return; } pSurf = pSwapChain->GetBackBuffer(0, BackBufferType::Mono); pSurf->Device->SetRenderTarget(0, pSurf); pSurf->Device->Clear(ClearFlags::Target, Drawing::Color::Black, 0.0f, 0); pSurf->Device->EndScene(); pSwapChain->Present(); } // End EVENT OnPaintBackground Now the only other thing is that you have to remember to handle the Reset event for your main D3D device. When a device is reset you must re-initialise all of your swap chains again using the first method I posted. In this code I keep track of my swap chains by keeping an ArrayList of pointers to the active ViewPanels... although I'm sure there are better ways to do this. Hope this helps... JP
-
Thanks Nerseus, I called Dispose explicitly and it worked like a charm. Funny though, my instance of Line was a local variable so I would have thought that Dispose would have been called automatically when it went out of scope. I guess it took a while for the garbage collection to kick in. JP
-
Folks, Has anyody had any experience using Microsoft::DirectX::Direct3D::Line. I'm using it and drawing lines but when the D3D Device gets reset (for example when you resize the window) the Device enters an invalid state. It basically says that I must uninitialise any state blocks associated with the device before it can be reset. Now this only happens when I use Line... so I guess it's talking about state blocks associated with the line class. Here is (in a roundabout way) what I'm doing. 1. Create Device... 2. On a paint event... a) Line * pLine = new Line(device); b) Set Line States (width, etc). c) Device->BeginScene d) Line->Begin e) Line->Draw f) Line->End g) Device->EndScene h) Device->Present Now as stated this works great, until the device is reset, then it grumbles - pretty fatally. Am I using Line correctly? Does anybody know why I get errors? JP
-
Yeah thanks Steve, it's sorted. Upon a resize the D3D Device resets itself causing a chain reaction that causes the swap chains to flag themselves for disposal. The problem I had was that I wasn't handling this at the right time and it was messing things up. One of the things that did have me worried though was that this was happenning multiple times when the window was resized via dragging... and the recreation of the swap chains seemed to take forever. An hour or so passes with me trying to work out how to make it faster. Then I decide to run the application in Release mode and it runs like lightning. Moral of the story... debug mode with Managed DX (or managed stuff in general?) is VERY VERY slow, if things seem to take an unacceptably long time to run in code then, before panicking, it's well worth compiling a release version to see if you will get acceptable speeds because there is a HUGE difference. JP
-
Folks, I'm trying to get D3D views running in multiple panels of my windows forms application. I derive a class from panel and set as a member variable a SwapChain object. I then pass a valid D3D Device to this class in the constructor and steal it's present parameters (changing DeviceWindow and DeviceWindow handle to this and this->Handle respectively). This works fine and I can create multiple instances of these controls all of which display valid D3D data. I do the drawing (currently only Device::Clear) in the panels Paint event handler, this works great. However when I resize the window things go pear shaped and I get an exception thrown saying the swap chain is trying to dispose itself. Now I guess that the swap chain is destroying itself because the back buffer size no longer matches the size of the control. Which is fine. However I can't seem to handle this gracefully, I mean do I try and watch if the SwapChain::Disposed property is true, and if it is then create a whole new SwapChain, or is there a better way to do it... the documentation seems to offer no clues. Anybody? JP :confused: