Ejemplo n.º 1
0
        protected void Init(IntPtr dataPointer)
        {
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            if (GraphicsDevice.IsOpenGLES2 &&
                ((Description.BufferFlags & BufferFlags.ConstantBuffer) == BufferFlags.ConstantBuffer ||
                 Description.Usage == GraphicsResourceUsage.Dynamic))
            {
                if (dataPointer != IntPtr.Zero)
                {
                    // Special case: ConstantBuffer are faked with a byte array on OpenGL ES 2.0.
                    unsafe
                    {
                        Utilities.CopyMemory(StagingData, dataPointer, Description.SizeInBytes);
                    }
                }
                return;
            }
#endif
            switch (Description.Usage)
            {
            case GraphicsResourceUsage.Default:
            case GraphicsResourceUsage.Immutable:
                bufferUsageHint = BufferUsageHint.StaticDraw;
                break;

            case GraphicsResourceUsage.Dynamic:
            case GraphicsResourceUsage.Staging:
                bufferUsageHint = BufferUsageHint.DynamicDraw;
                break;

            default:
                throw new ArgumentOutOfRangeException("description.Usage");
            }

            using (var creationContext = GraphicsDevice.UseOpenGLCreationContext())
            {
                // If we're on main context, unbind VAO before binding context.
                // It will be bound again on next draw.
                if (!creationContext.UseDeviceCreationContext)
                {
                    GraphicsDevice.UnbindVertexArrayObject();
                }

                GL.GenBuffers(1, out resourceId);
                GL.BindBuffer(bufferTarget, resourceId);
                GL.BufferData(bufferTarget, (IntPtr)Description.SizeInBytes, dataPointer, bufferUsageHint);
                GL.BindBuffer(bufferTarget, 0);
            }
        }