Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DepthStencilBuffer.OpenGL.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL
4 // Copyright (c) 2011 Silicon Studio
5 using System;
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.ReferenceCounting;
8 
9 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
10 using OpenTK.Graphics.ES30;
11 #else
12 using OpenTK.Graphics.OpenGL;
13 #endif
14 
15 namespace SiliconStudio.Paradox.Graphics
16 {
17  /// <summary>
18  /// Depth stencil buffer
19  /// </summary>
20  public partial class DepthStencilBuffer
21  {
22  private bool needReadOnlySynchronization;
23  internal bool DepthMask = true;
24 
25  internal bool IsDepthBuffer { get; set; }
26  internal bool IsStencilBuffer { get; set; }
27 
28  internal DepthStencilBuffer(GraphicsDevice device, Texture2D depthTexture, bool isReadOnly) : base(device)
29  {
30  DescriptionInternal = depthTexture.Description;
31  depthTexture.AddReferenceInternal();
32  Texture = depthTexture;
33 
34  resourceId = Texture.ResourceId;
35 
36  if (Description.Format == PixelFormat.D24_UNorm_S8_UInt ||
37  Description.Format == PixelFormat.D32_Float_S8X24_UInt)
38  {
39  IsDepthBuffer = true;
40  IsStencilBuffer = true;
41  }
42  else if (Description.Format == PixelFormat.D32_Float ||
43  Description.Format == PixelFormat.D16_UNorm)
44  {
45  IsDepthBuffer = true;
46  IsStencilBuffer = false;
47  }
48  else
49  throw new NotSupportedException("The provided depth stencil format is currently not supported"); // implement composition for other formats
50 
51 
52 #if !SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
53  if (isReadOnly)
54  {
55  if (device.versionMajor < 4)
56  {
57  needReadOnlySynchronization = true;
58  throw new NotImplementedException();
59  }
60  }
61 #endif
62  }
63 
64  /// <inheritdoc/>
65  protected internal override bool OnRecreate()
66  {
67  // Dependency: wait for underlying texture to be recreated first
68  if (Texture.LifetimeState != GraphicsResourceLifetimeState.Active)
69  return false;
70 
71  base.OnRecreate();
72  resourceId = Texture.ResourceId;
73 
74  return true;
75  }
76 
77  protected override void DestroyImpl()
78  {
79  Texture.ReleaseInternal();
80 
81  resourceId = 0;
82 
83  base.DestroyImpl();
84  }
85 
86  public static bool IsReadOnlySupported(GraphicsDevice device)
87  {
88  // Since OpenGL 4.0? (need to double-check)
89  return (device.versionMajor >= 4);
90  }
91 
92  public void SynchronizeReadOnly(Graphics.GraphicsDevice context)
93  {
94  if (needReadOnlySynchronization)
95  throw new NotImplementedException();
96  }
97  }
98 }
99 
100 #endif
Same as Deferred mode, except sprites are sorted by texture prior to drawing. This can improve perfor...
GraphicsResourceLifetimeState
Describes the lifetime state of a graphics resource.
PixelFormat
Defines various types of pixel formats.
Definition: PixelFormat.cs:32