2011/12/26(Mon)Direct 3D の Device の Reset に失敗する。

はてブ数 2011/12/26 19:49 プログラミング::SlimDX つーさ

ウィンドウモードで起動したアプリはAlt+Enterで何度でも切り替えられるのに、フルスクリーンで起動したアプリをウィンドウモードにしてからフルスクリーンにしようとすると、IDirect3DDevice9::ResetでD3DERR_DEVICELOST が出て復帰できない。

>> スクリーンモードを変更します。
Direct3D9: (ERROR) :Exclusive Mode has been taken by other app or other device on the same adapter. SetCooperativeLevel returns D3DERR_DEVICELOST.
Direct3D9: (ERROR) :SetCooperativeLevel returned failure. CreateDevice/Reset Failed
Direct3D9: (ERROR) :Reset failed and Reset/TestCooperativeLevel/Release are the only legal APIs to be called subsequently
Direct3D9: :Window has been subclassed; cannot restore!
Direct3D9: (ERROR) :Exclusive Mode has been taken by other app or other device on the same adapter. SetCooperativeLevel returns D3DERR_DEVICELOST.

がんばってググった結果は、Direct Inputがウィンドウをサブクラス化してしまうせいだとわかった。
Direct3Dより、DirectInputを先に初期化するだけで、この不具合は直った。

覚えておくといいなのっ

2011/12/17(Sat)すけーる・よーぴっちろーる・とらんすれーと

はてブ数 2011/12/17 3:32 プログラミング::SlimDX つーさ

コピペして使うがよい。

using System;

class MatrixLib {
/// <summary>
/// 3Dの[拡縮→回転→平行移動]変換行列を作る。
/// </summary>
/// <param name="xScale">X軸方向倍率</param>
/// <param name="yScale">Y軸方向倍率</param>
/// <param name="zScale">Z軸方向倍率</param>
/// <param name="yawRotate">ヨー角度(360.0で一周)</param>
/// <param name="pitchRotate">ピッチ角度(360.0で一周)</param>
/// <param name="rollRotate">ロール角度(360.0で一周)</param>
/// <param name="xTranslate">X軸方向移動量</param>
/// <param name="yTranslate">Y軸方向移動量</param>
/// <param name="zTranslate">Z軸方向移動量</param>
/// <returns></returns>
public static D3DMatrix Transform3D(double xScale, double yScale, double zScale, double yawRotate, double pitchRotate, double rollRotate, double xTranslate, double yTranslate, double zTranslate)
{
  D3DMatrix m = D3DMatrix.Identity;
  double cosYaw = Cos(yawRotate), sinYaw = Sin(yawRotate);
  double cosPitch = Cos(pitchRotate), sinPitch = Sin(pitchRotate);
  double cosRoll = Cos(rollRotate), sinRoll = Sin(rollRotate);

  m.M11 = (float)(xScale * (cosRoll * cosYaw + sinRoll * sinPitch * sinYaw));
  m.M12 = (float)(xScale * sinRoll * cosPitch);
  m.M13 = (float)(xScale * (sinRoll * sinPitch * cosYaw - cosRoll * sinYaw));
  m.M21 = (float)(yScale * (yScale * cosRoll * sinPitch * sinYaw - sinRoll * cosYaw));
  m.M22 = (float)(yScale * cosRoll * cosPitch);
  m.M23 = (float)(yScale * (sinRoll * sinYaw + cosRoll * sinPitch * cosYaw));
  m.M31 = (float)(zScale * cosPitch * sinYaw);
  m.M32 = (float)(zScale * -sinPitch);
  m.M33 = (float)(zScale * cosPitch * cosYaw);
  m.M41 = (float)xTranslate;
  m.M42 = (float)yTranslate;
  m.M43 = (float)zTranslate;
  m.M44 = 1f;

  return m;
}

/// <summary>
/// 2Dの[拡縮→回転→平行移動]変換行列を作る。
/// </summary>
/// <param name="scaleX">X軸方向倍率</param>
/// <param name="scaleY">Y軸方向倍率</param>
/// <param name="angle">回転角度(360.0で一周)</param>
/// <param name="transX">X軸方向平行移動</param>
/// <param name="transY">Y軸方向平行移動</param>
/// <returns>作られた行列</returns>
public static D3DMatrix Transform2D(double scaleX, double scaleY, double angle, double transX, double transY)
{
  D3DMatrix m = D3DMatrix.Identity;
  double cos = Cos(a), sin = Sin(a);
  m.M11 = (float)(cos * scaleX);
  m.M12 = (float)(sin * scaleX);
  m.M21 = (float)(-sin * scaleY);
  m.M22 = (float)(cos * scaleY);
  m.M33 = 1.0f;
  m.M41 = (float)transX;
  m.M42 = (float)transY;
  m.M44 = 1.0f;
  return m;
}

static double Sin(double a) { return Math.Sin(a / 180d * Math.PI); }
static double Cos(double a) { return Math.Cos(a / 180d * Math.PI); }
static double Tan(double a) { return Math.Tan(a / 180d * Math.PI); }
static double Asin(double d) { return Math.Asin(d) / Math.PI * 180d; }
static double Acos(double d) { return Math.Acos(d) / Math.PI * 180d; }
static double Atan(double d) { return Math.Atan(d) / Math.PI * 180d; }
static double Atan2(double y, double x) { return Math.Atan2(y, x) / Math.PI * 180d; }
}

2010/06/18(Fri)RenderStateManager.cs

はてブ数 2010/06/18 6:25 プログラミング::SlimDX つーさ
void SetRenderState<T>(RenderState state, T value);
T GetRenderState<T>(RenderState state);

SlimDXのDirect3D9のRenderState周りに関してGetとSetメソッドしかない。
なんで RenderStateManagerとかないの? ググったらGone.とか書いてあるページが出てきたけど。
正直不便。なので、Managed DirectXライクに、その辺をラップするRenderStateManagerを作ったりなど。
この辺欲しい人他にもいるんじゃないかなぁと思って公開してみるテスト。

続きを読む