zengqh / slimdx

Automatically exported from code.google.com/p/slimdx
0 stars 0 forks source link

D3D9.Device.Get*State<> don't handle enums too well. #312

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The issue exists in GetRenderState, GetSamplerState and
GetTextureStageState (latest revision).
When generic parameter is enum (for example Direct3D9.Cull)
Convert::ChangeType throws InvalidCastException which is then caught and
enum value is returned via static_cast. This works ok, but the problem is
that throwing this exception every frame slows down things, especially
because this function is called a couple of times every frame.
I'm attaching a patch that adds following in all three methods:
if ( T::typeid->IsEnum )
{
    return safe_cast<T>(Enum::ToObject(T::typeid, static_cast<int>(value));
}
else
{
    // existing code...
}

Original issue reported on code.google.com by luke.pat...@gmail.com on 29 Jul 2008 at 2:20

Attachments:

GoogleCodeExporter commented 9 years ago
Ah, that's a better method. I'm not sure why I went with the exception method 
in the
first place.

Original comment by Mike.Popoloski on 29 Jul 2008 at 3:01

GoogleCodeExporter commented 9 years ago
Fixed.

Original comment by Mike.Popoloski on 8 Aug 2008 at 3:22

GoogleCodeExporter commented 9 years ago

Original comment by Mike.Popoloski on 8 Aug 2008 at 3:56