Advertisement Jump to content
Sign in to follow this  
DwarvesH

SharpDX changing device size/parameters

This topic is 1875 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently researching SharpDX and I'm making slow progress because of the multitude of name changes from DirectX, but I am having real problems simply resizing the Device. I am using the DirectX9 version.

 

The only way I managed to Resize the device was by calling device.Reset(pp) with appropriate presentation parameters, but only if I called dispose on all the other resources that I have created and recreating them after the Reset.

 

There are no OnLostDevice/OnResetDevice methods anywhere in SharpDX. I thought that SharpDX was a fully auto-generated wrapper + some extra utility classes + the toolkit similar to XNA. I can comfortably code raw DirectX or DXUT (or XNA) but I have no idea how to manage the lifetime of objects in SharpDX...

 

And after changing the size, I will also need to update fullscreen, presentation interval, remove default depth buffers,etc...

 

There is literally zero documentation of SharpDX out there!

 

 

Share this post


Link to post
Share on other sites
Advertisement

Where is your code snippet that shows exactly what you are doing and where do you expect things working and where they are not working? What is the equivalent of the C++ code you are trying to replicate in SharpDX and you know for sure that it is working?

 

I don't know much about d3d9, but if you have a working C++ code/sample, the translation should not be much too difficult (apart for some change in naming, but you should be able to link to the generated documentation on sharpdx.org).

 

Whenever there is a Release() in C++, there should be a Dispose() for the same resource in C#. For  DeviceLost /ResetDevice, I don't know which  method you are referring in the original C++ API but when calling reset (or other methods), you can have a SharpDXException that will contain a ResultCode.DeviceLost or DeviceNotReset.

Edited by xoofx

Share this post


Link to post
Share on other sites

Thank you for the answer. It was my fault actually. I was looking for OnLostDevice/OnResetDevice, but lost under the new names for everything I was actually looking at classes that do not have these members. Using the correct classes fixed the issue.

 

But I have a new issue.

 

I'm trying to create a minimal rapid prototyping framework/shader playground using SharpDX and I'm laying down the foundation right now. I was adapting very basic and unstructured tutorials to a more robust minimal framework and everything was going fine until I started using the Color structure from SharpDX.

 

The tutorial declared a simple vertex format using this:

var vertexElems = new[] {
        		new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
        		new VertexElement(0, 16, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
				VertexElement.VertexDeclarationEnd
        	};

Basically the entire vertex is a set of two float4 representing a position and color, and a vertex was defined as two consecutive Vector4 in an array (position followed by color):

new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),

I am trying to give a structure to this, so I started using:

var vertexElems = new[] {
        		new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
        		new VertexElement(0, 12, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
				VertexElement.VertexDeclarationEnd
        	};

I am using a structure that has position and color:

struct VertexPosCol {
        public Vector3 Position;
        public Color Color;

        public VertexPosCol(Vector3 pos, Color col) {
            Position = pos;
            Color = col;
        }
...

And now I can define a full vertex in an array:

 new VertexPosCol(new Vector3(-1.0f, -1.0f, -1.0f), new Color(1.0f, 0.0f, 0.0f, 1.0f)),

The problem is that while these two vertices are meant to be the same, they are not. The RGB order is not correct. I checked and checked the code over again, so It must be one of two things: I did something very stupid and I'm not noticing it or Color is not the right structure to use under SharpDX. ColorBGRA seems to behave the way I want it to.

 

Is this the correct solution? Using ColorBGRA exclusively? Will this work under all setups and display modes?

Share this post


Link to post
Share on other sites

Is this the correct solution? Using ColorBGRA exclusively? Will this work under all setups and display modes?

 

If you check documentation of DeclarationType on SharpDX (which is generated from msdn pages), it is said explicitly: DeclarationType.Color = "Four-component, packed, unsigned bytes mapped to 0 to 1 range. Input is a ColorBGRA and is expanded to RGBA order."

Edited by xoofx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!