「MonoGame/クラスライブラリ/RenderTargetUsage列挙体」の版間の差分
imported>Administrator |
Administrator (トーク | 投稿記録) |
||
| (3人の利用者による、間の11版が非表示) | |||
| 1行目: | 1行目: | ||
RenderTargetUsage列挙体は、グラフィックデバイス([[MonoGame/クラスライブラリ/GraphicsDeviceクラス|GraphicsDeviceクラス]])に新たなレンダリングターゲット([[MonoGame/クラスライブラリ/RenderTarget2Dクラス|RenderTarget2Dクラス]])を設定したとき、そのレンダリングターゲットの[[データ]] | RenderTargetUsage列挙体は、グラフィックデバイス([[MonoGame/クラスライブラリ/GraphicsDeviceクラス|GraphicsDeviceクラス]])に新たなレンダリングターゲット([[MonoGame/クラスライブラリ/RenderTarget2Dクラス|RenderTarget2Dクラス]])を設定したとき、そのレンダリングターゲットの[[データ]]をどのように処理するかを指定するのに使用する[[列挙体]]である。 | ||
== 名前空間 == | == 名前空間 == | ||
[[MonoGame/クラスライブラリ/Microsoft.Xna.Framework.Graphics名前空間|Microsoft.Xna.Framework.Graphics名前空間]] | |||
== 構文 == | == 構文 == | ||
| 25行目: | 25行目: | ||
== 備考 == | == 備考 == | ||
=== PreserveContentsは遅い === | === PreserveContentsは遅い === | ||
PreserveContentsは[[VRAM]]容量が少ない環境では[[メインメモリ]]への保存と復元が発生するため絶望的なほど遅くなる。 | |||
[[PC]]ではまず問題になることはないようだが、一部の[[スマホ]]では絶望的な速度になるようだ。 | |||
なるべくDiscardContentsを使ったほうが良さそうだ。 | |||
=== DiscardContentsの注意点 === | === DiscardContentsの注意点 === | ||
DiscardContents設定になっていると「GraphicsDevice.SetRenderTargetするたびに破棄(初期化)される」という特徴がある。この特性があるためレンダリング系APIの呼出順序を間違えると残念なことになる。 | |||
<source lang="csharp"> | |||
GraphicsDevice.SetRenderTarget(このRenderTargetは初期化される); | |||
</source> | |||
ちなみにGraphicsDeviceが最初から持っているレンダリングターゲット([[DirectX]]でいう[[プライマリサーフェイス]]、SetRenterTarget(null))に相当するものは問答無用でDiscardContentsに設定されている。 | |||
このため、たとば以下のコードは正常に動作しない。 | |||
<source lang="csharp"> | <source lang="csharp"> | ||
protected override void Draw(GameTime gameTime) | |||
{ | |||
var gd = _graphics.GraphicsDevice; | |||
// (1)プライマリサーフェイスを塗りつぶす | |||
gd.Clear(Color.CornflowerBlue); | |||
// (2)レンダリングターゲットを切り替える | |||
gd.SetRenderTarget(new RenderTarget2D(GraphicsDevice, 128, 128)); | |||
// (3)レンダリングターゲットをプライマリサーフェイスに戻す | |||
// プライマリサーフェイスは問答無用でDiscardContents設定なので | |||
// 内容はクリアされ(1)の塗りつぶしは無かったことにされる。 | |||
// なお、(2)のレンダーターゲットは影響を受けない。 | |||
gd.SetRenderTarget(null); | |||
base.Draw(gameTime); | |||
} | |||
</source> | </source> | ||
DiscardContentsの場合は以下のような呼出順序で書かなければならない。 | DiscardContentsの場合は以下のような呼出順序で書かなければならない。 | ||
<source lang="csharp"> | <source lang="csharp"> | ||
protected override void Draw(GameTime gameTime) | |||
{ | |||
var gd = _graphics.GraphicsDevice; | |||
// (1)レンダリングターゲットを切り替える | |||
gd.SetRenderTarget(new RenderTarget2D(GraphicsDevice, 128, 128)); | |||
// (2)レンダリングターゲットをプライマリサーフェイスに戻す(と同時にまっさらになる) | |||
// (1)のレンダーターゲットは影響を受けない。 | |||
gd.SetRenderTarget(null); | |||
// (3)プライマリサーフェイスを塗りつぶす | |||
gd.Clear(Color.CornflowerBlue); | |||
base.Draw(gameTime); | |||
} | |||
</source> | </source> | ||
== 関連項目 == | == 関連項目 == | ||
* [[MonoGame/クラスライブラリ/GraphicsDeviceクラス|GraphicsDeviceクラス]] | * [[MonoGame/クラスライブラリ/GraphicsDeviceクラス|GraphicsDeviceクラス]] | ||
** [[MonoGame/クラスライブラリ/GraphicsDeviceクラス/SetRenderTargetメソッド| | ** [[MonoGame/クラスライブラリ/GraphicsDeviceクラス/SetRenderTargetメソッド|SetRenderTargetメソッド]] | ||
** [[MonoGame/クラスライブラリ/GraphicsDeviceクラス/SetRenderTargetsメソッド| | ** [[MonoGame/クラスライブラリ/GraphicsDeviceクラス/SetRenderTargetsメソッド|SetRenderTargetsメソッド]] | ||
** [[MonoGame/クラスライブラリ/GraphicsDeviceクラス/GetRenderTargetsメソッド| | ** [[MonoGame/クラスライブラリ/GraphicsDeviceクラス/GetRenderTargetsメソッド|GetRenderTargetsメソッド]] | ||
* [[MonoGame/クラスライブラリ/RenderTarget2Dクラス|RenderTarget2Dクラス]] | * [[MonoGame/クラスライブラリ/RenderTarget2Dクラス|RenderTarget2Dクラス]] | ||
* [[MonoGame/クラスライブラリ/RenderTargetCubeクラス|RenderTargetCubeクラス]] | * [[MonoGame/クラスライブラリ/RenderTargetCubeクラス|RenderTargetCubeクラス]] | ||
* [[MonoGame/クラスライブラリ/CubeMapFace列挙体|CubeMapFace列挙体]] | * [[MonoGame/クラスライブラリ/CubeMapFace列挙体|CubeMapFace列挙体]] | ||
* [[MonoGame/クラスライブラリ/RenderTargetBinding構造体|RenderTargetBinding構造体]] | * [[MonoGame/クラスライブラリ/RenderTargetBinding構造体|RenderTargetBinding構造体]] | ||
* [[MonoGame/クラスライブラリ/RenderTargetUsage列挙体|RenderTargetUsage列挙体]] | |||
[[category: MonoGame]] | [[category: MonoGame]] | ||