3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL
5 using System.Runtime.InteropServices;
7 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
8 using OpenTK.Graphics.ES30;
9 using RenderbufferStorage = OpenTK.Graphics.ES30.RenderbufferInternalFormat;
11 #if SILICONSTUDIO_PLATFORM_IOS
12 using ExtTextureFormatBgra8888 = OpenTK.Graphics.ES30.All;
13 using ImgTextureCompressionPvrtc = OpenTK.Graphics.ES30.All;
14 using OesPackedDepthStencil = OpenTK.Graphics.ES30.All;
15 #elif SILICONSTUDIO_PLATFORM_ANDROID
16 using ExtTextureFormatBgra8888 = OpenTK.Graphics.ES20.ExtTextureFormatBgra8888;
17 using OesCompressedEtc1Rgb8Texture = OpenTK.Graphics.ES20.OesCompressedEtc1Rgb8Texture;
21 using OpenTK.Graphics.OpenGL;
25 namespace SiliconStudio.
Paradox.Graphics
34 internal SamplerState BoundSamplerState;
36 public PixelInternalFormat InternalFormat {
get; set; }
37 public PixelFormatGl FormatGl {
get; set; }
38 public PixelType
Type {
get; set; }
39 public TextureTarget
Target {
get; set; }
40 public int DepthPitch {
get; set; }
41 public int RowPitch {
get; set; }
43 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
44 public IntPtr StagingData {
get; set; }
47 public virtual void Recreate(DataBox[] dataBoxes = null)
49 throw new NotImplementedException();
53 protected override void DestroyImpl()
55 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
56 if (StagingData != IntPtr.Zero)
58 Marshal.FreeHGlobal(StagingData);
59 StagingData = IntPtr.Zero;
63 using (GraphicsDevice.UseOpenGLCreationContext())
67 GL.DeleteBuffers(1, ref resourceId);
71 GL.DeleteTextures(1, ref resourceId);
87 if (cachedRenderTarget == null)
92 return cachedRenderTarget;
95 protected static void ConvertDepthFormat(GraphicsDevice graphicsDevice,
PixelFormat requestedFormat, out RenderbufferStorage depthFormat, out RenderbufferStorage stencilFormat)
100 switch (requestedFormat)
102 case PixelFormat.D16_UNorm:
103 depthFormat = RenderbufferStorage.DepthComponent16;
105 #if !SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
106 case PixelFormat.D24_UNorm_S8_UInt:
107 depthFormat = RenderbufferStorage.Depth24Stencil8;
109 case PixelFormat.D32_Float:
110 depthFormat = RenderbufferStorage.DepthComponent32;
112 case PixelFormat.D32_Float_S8X24_UInt:
113 depthFormat = RenderbufferStorage.Depth32fStencil8;
116 case PixelFormat.D24_UNorm_S8_UInt:
117 if (graphicsDevice.HasPackedDepthStencilExtension)
119 depthFormat = RenderbufferStorage.Depth24Stencil8;
123 depthFormat = graphicsDevice.HasDepth24 ? RenderbufferStorage.DepthComponent24 : RenderbufferStorage.DepthComponent16;
124 stencilFormat = RenderbufferStorage.StencilIndex8;
127 case PixelFormat.D32_Float:
128 case PixelFormat.D32_Float_S8X24_UInt:
129 throw new NotSupportedException(
"Only 16 bits depth buffer or 24-8 bits depth-stencil buffer is supported on OpenGLES2");
132 throw new NotImplementedException();
137 protected static void ConvertPixelFormat(GraphicsDevice graphicsDevice,
PixelFormat inputFormat, out PixelInternalFormat internalFormat, out PixelFormatGl
format, out PixelType type, out
int pixelSize, out
bool compressed)
143 case PixelFormat.R8G8B8A8_UNorm:
144 internalFormat = PixelInternalFormat.Rgba;
145 format = PixelFormatGl.Rgba;
146 type = PixelType.UnsignedByte;
149 case PixelFormat.D16_UNorm:
150 internalFormat = PixelInternalFormat.Rgba;
151 format = PixelFormatGl.Rgba;
152 type = PixelType.UnsignedByte;
155 case PixelFormat.A8_UNorm:
156 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
157 internalFormat = PixelInternalFormat.Alpha;
158 format = PixelFormatGl.Alpha;
160 internalFormat = PixelInternalFormat.R8;
161 format = PixelFormatGl.Red;
163 type = PixelType.UnsignedByte;
166 case PixelFormat.R8_UNorm:
167 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
168 internalFormat = PixelInternalFormat.Luminance;
169 format = PixelFormatGl.Luminance;
171 internalFormat = PixelInternalFormat.R8;
172 format = PixelFormatGl.Red;
174 type = PixelType.UnsignedByte;
177 case PixelFormat.B8G8R8A8_UNorm:
178 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
179 if (!graphicsDevice.HasExtTextureFormatBGRA8888)
180 throw new NotSupportedException();
183 #if SILICONSTUDIO_PLATFORM_IOS
184 internalFormat = PixelInternalFormat.Rgba;
186 internalFormat = (PixelInternalFormat)ExtTextureFormatBgra8888.BgraExt;
188 format = (PixelFormatGl)ExtTextureFormatBgra8888.BgraExt;
190 internalFormat = PixelInternalFormat.Rgba;
191 format = PixelFormatGl.Bgra;
193 type = PixelType.UnsignedByte;
196 #if !SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
197 case PixelFormat.R32_UInt:
198 internalFormat = PixelInternalFormat.R32ui;
199 format = PixelFormatGl.RedInteger;
200 type = PixelType.UnsignedInt;
203 case PixelFormat.R16G16B16A16_Float:
204 internalFormat = PixelInternalFormat.Rgba16f;
205 format = PixelFormatGl.Rgba;
206 type = PixelType.HalfFloat;
209 case PixelFormat.R32_Float:
210 internalFormat = PixelInternalFormat.R32f;
211 format = PixelFormatGl.Red;
212 type = PixelType.Float;
215 case PixelFormat.R32G32_Float:
216 internalFormat = PixelInternalFormat.Rg32f;
217 format = PixelFormatGl.Rg;
218 type = PixelType.Float;
221 case PixelFormat.R32G32B32_Float:
222 internalFormat = PixelInternalFormat.Rgb32f;
223 format = PixelFormatGl.Rgb;
224 type = PixelType.Float;
227 case PixelFormat.R32G32B32A32_Float:
228 internalFormat = PixelInternalFormat.Rgba32f;
229 format = PixelFormatGl.Rgba;
230 type = PixelType.Float;
235 internalFormat = PixelInternalFormat.DepthComponent32f;
236 format = PixelFormatGl.DepthComponent;
237 type = PixelType.Float;
241 #if SILICONSTUDIO_PLATFORM_ANDROID
242 case PixelFormat.ETC1:
244 internalFormat = (PixelInternalFormat)OesCompressedEtc1Rgb8Texture.Etc1Rgb8Oes;
245 format = (PixelFormatGl)OesCompressedEtc1Rgb8Texture.Etc1Rgb8Oes;
248 type = PixelType.UnsignedByte;
250 #elif SILICONSTUDIO_PLATFORM_IOS
251 case PixelFormat.PVRTC_4bpp_RGB:
252 internalFormat = (PixelInternalFormat)ImgTextureCompressionPvrtc.CompressedRgbPvrtc4Bppv1Img;
253 format = (PixelFormatGl)ImgTextureCompressionPvrtc.CompressedRgbPvrtc4Bppv1Img;
256 type = PixelType.UnsignedByte;
258 case PixelFormat.PVRTC_2bpp_RGB:
259 internalFormat = (PixelInternalFormat)ImgTextureCompressionPvrtc.CompressedRgbPvrtc2Bppv1Img;
260 format = (PixelFormatGl)ImgTextureCompressionPvrtc.CompressedRgbPvrtc2Bppv1Img;
263 type = PixelType.UnsignedByte;
265 case PixelFormat.PVRTC_4bpp_RGBA:
266 internalFormat = (PixelInternalFormat)ImgTextureCompressionPvrtc.CompressedRgbaPvrtc4Bppv1Img;
267 format = (PixelFormatGl)ImgTextureCompressionPvrtc.CompressedRgbaPvrtc4Bppv1Img;
270 type = PixelType.UnsignedByte;
272 case PixelFormat.PVRTC_2bpp_RGBA:
273 internalFormat = (PixelInternalFormat)ImgTextureCompressionPvrtc.CompressedRgbaPvrtc2Bppv1Img;
274 format = (PixelFormatGl)ImgTextureCompressionPvrtc.CompressedRgbaPvrtc2Bppv1Img;
277 type = PixelType.UnsignedByte;
281 throw new InvalidOperationException(
"Unsupported texture format");
285 private bool IsFlippedTexture()
287 return GraphicsDevice.BackBuffer.Texture ==
this || GraphicsDevice.DepthStencilBuffer.Texture ==
this;
GraphicsResourceUsage
Identifies expected resource use during rendering. The usage directly reflects whether a resource is ...
The type of the serialized type will be passed as a generic arguments of the serializer. Example: serializer of A becomes instantiated as Serializer{A}.
ViewType
Defines how a view is selected from a resource.
Same as Deferred mode, except sprites are sorted by texture prior to drawing. This can improve perfor...
Creates a render target buffer.
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
PixelFormat
Defines various types of pixel formats.