3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL
5 using System.Runtime.InteropServices;
6 using SiliconStudio.Core;
7 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
8 using OpenTK.Graphics.ES30;
9 using BufferUsageHint = OpenTK.Graphics.ES30.BufferUsage;
11 using OpenTK.Graphics.OpenGL;
14 namespace SiliconStudio.
Paradox.Graphics
16 public partial class Buffer
18 internal BufferTarget bufferTarget;
19 internal BufferUsageHint bufferUsageHint;
21 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
23 internal IntPtr StagingData {
get; set; }
34 protected Buffer(GraphicsDevice device, BufferDescription description,
BufferFlags bufferFlags,
PixelFormat viewFormat, IntPtr dataPointer)
37 Description = description;
39 ViewFormat = viewFormat;
41 Recreate(dataPointer);
44 public void Recreate(IntPtr dataPointer)
48 bufferTarget = BufferTarget.ArrayBuffer;
52 bufferTarget = BufferTarget.ElementArrayBuffer;
57 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
59 StagingData = Marshal.AllocHGlobal(Description.SizeInBytes);
61 bufferTarget = BufferTarget.UniformBuffer;
66 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
68 StagingData = Marshal.AllocHGlobal(Description.SizeInBytes);
76 protected internal override bool OnRecreate()
84 Recreate(IntPtr.Zero);
90 protected override void Destroy()
92 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
93 if (StagingData != IntPtr.Zero)
95 Marshal.FreeHGlobal(StagingData);
96 StagingData = IntPtr.Zero;
100 using (GraphicsDevice.UseOpenGLCreationContext())
102 GL.DeleteBuffers(1, ref resourceId);
110 protected void Init(IntPtr dataPointer)
112 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
116 if (dataPointer != IntPtr.Zero)
121 Utilities.CopyMemory(StagingData, dataPointer, Description.SizeInBytes);
127 switch (Description.Usage)
129 case GraphicsResourceUsage.Default:
130 case GraphicsResourceUsage.Immutable:
131 bufferUsageHint = BufferUsageHint.StaticDraw;
133 case GraphicsResourceUsage.Dynamic:
134 case GraphicsResourceUsage.Staging:
135 bufferUsageHint = BufferUsageHint.DynamicDraw;
138 throw new ArgumentOutOfRangeException(
"description.Usage");
141 using (var creationContext = GraphicsDevice.UseOpenGLCreationContext())
145 if (!creationContext.UseDeviceCreationContext)
146 GraphicsDevice.UnbindVertexArrayObject();
148 GL.GenBuffers(1, out resourceId);
149 GL.BindBuffer(bufferTarget, resourceId);
150 GL.BufferData(bufferTarget, (IntPtr)Description.SizeInBytes, dataPointer, bufferUsageHint);
151 GL.BindBuffer(bufferTarget, 0);
ComponentBase.Destroy() event.
GraphicsResourceUsage
Identifies expected resource use during rendering. The usage directly reflects whether a resource is ...
SiliconStudio.Paradox.Graphics.Buffer Buffer
PixelFormat
Defines various types of pixel formats.