/// <summary> /// Constructor. /// </summary> ///<param name="manager"></param> ///<param name="type">Type of index (16 or 32 bit).</param> /// <param name="numIndices">Number of indices to create in this buffer.</param> /// <param name="usage">Buffer usage.</param> /// <param name="useSystemMemory">Create in system memory?</param> /// <param name="useShadowBuffer">Use a shadow buffer for reading/writing?</param> public HardwareIndexBuffer( HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, bool useSystemMemory, bool useShadowBuffer ) : base( usage, useSystemMemory, useShadowBuffer ) { this.type = type; this.numIndices = numIndices; this.Manager = manager; // calc the index buffer size sizeInBytes = numIndices; if ( type == IndexType.Size32 ) { indexSize = Marshal.SizeOf( typeof( int ) ); } else { indexSize = Marshal.SizeOf( typeof( short ) ); } sizeInBytes *= indexSize; // create a shadow buffer if required if ( useShadowBuffer ) { shadowBuffer = new DefaultHardwareIndexBuffer( Manager, type, numIndices, BufferUsage.Dynamic ); } }
public GLESHardwareIndexBuffer( HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer ) : base( manager, type, numIndices, usage, false, useShadowBuffer ) { if ( type == IndexType.Size32 ) { throw new AxiomException( "32 bit hardware buffers are not allowed in OpenGL ES." ); } if ( !useShadowBuffer ) { throw new AxiomException( "Only support with shadowBuffer" ); } OpenGL.GenBuffers( 1, ref this._bufferId ); GLESConfig.GlCheckError( this ); if ( this._bufferId == 0 ) { throw new AxiomException( "Cannot create GL index buffer" ); } OpenGL.BindBuffer( All.ElementArrayBuffer, this._bufferId ); GLESConfig.GlCheckError( this ); OpenGL.BufferData( All.ElementArrayBuffer, new IntPtr( sizeInBytes ), IntPtr.Zero, GLESHardwareBufferManager.GetGLUsage( usage ) ); GLESConfig.GlCheckError( this ); }
public override HardwareVertexBuffer CreateVertexBuffer( VertexDeclaration vertexDeclaration, int numVerts, BufferUsage usage, bool useShadowBuffer ) { Contract.Requires( numVerts > 0 ); #if AXIOM_D3D_MANAGE_BUFFERS // Override shadow buffer setting; managed buffers are automatically // backed by system memory // Don't override shadow buffer if discardable, since then we use // unmanaged buffers for speed (avoids write-through overhead) if ( useShadowBuffer && ( usage & BufferUsage.Discardable ) == 0 ) { useShadowBuffer = false; // Also drop any WRITE_ONLY so we can read direct if ( usage == BufferUsage.DynamicWriteOnly ) { usage = BufferUsage.Dynamic; } else if ( usage == BufferUsage.StaticWriteOnly ) { usage = BufferUsage.Static; } } #endif var vbuf = new D3D9HardwareVertexBuffer( this, vertexDeclaration, numVerts, usage, false, useShadowBuffer ); lock ( VertexBuffersMutex ) { vertexBuffers.Add( vbuf ); } return vbuf; }
public override HardwareIndexBuffer CreateIndexBuffer( IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer ) { var buffer = new GLHardwareIndexBuffer( this, type, numIndices, usage, useShadowBuffer ); lock ( IndexBuffersMutex ) indexBuffers.Add( buffer ); return buffer; }
public IndexBuffer(Device device, BufferUsage usage) { this.device = device; this.usage = usage; Gl.glGenBuffersARB(1, out this.handle); }
public override HardwareVertexBuffer CreateVertexBuffer( VertexDeclaration vertexDeclaration, int numVerts, BufferUsage usage, bool useShadowBuffer ) { var vertexBuffer = new GLESHardwareVertexBuffer( this, vertexDeclaration, numVerts, usage, true ); lock ( VertexBuffersMutex ) { vertexBuffers.Add( vertexBuffer ); } return vertexBuffer; }
public override HardwareIndexBuffer CreateIndexBuffer( IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer ) { var indexBuffer = new GLESHardwareIndexBuffer( this, type, numIndices, usage, true ); lock ( IndexBuffersMutex ) { indexBuffers.Add( indexBuffer ); } return indexBuffer; }
public void AllocateStorage(IntPtr dataPtr, int size, BufferUsage usage) { if (size < 1) return; //if (dataPtr == IntPtr.Zero) // return; // Allocate memory for the buffer GI.BufferData(fBufferTarget, size, dataPtr, usage); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="target"></param> /// <param name="id"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> /// <param name="face"></param> /// <param name="level"></param> /// <param name="usage"></param> /// <param name="crappyCard"></param> /// <param name="writeGamma"></param> /// <param name="fsaa"></param> public GLESTextureBuffer( string basename, All targetfmt, int id, int width, int height, int format, int face, int level, BufferUsage usage, bool crappyCard, bool writeGamma, int fsaa ) : base( 0, 0, 0, Media.PixelFormat.Unknown, usage ) { _target = targetfmt; _textureId = id; _face = face; _level = level; _softwareMipmap = crappyCard; GLESConfig.GlCheckError( this ); OpenGL.BindTexture( All.Texture2D, _textureId ); GLESConfig.GlCheckError( this ); // Get face identifier _faceTarget = _target; // TODO verify who get this Width = width; Height = height; Depth = 1; _glInternalFormat = (All)format; Format = GLESPixelUtil.GetClosestAxiomFormat( _glInternalFormat ); RowPitch = Width; SlicePitch = Height * Width; sizeInBytes = PixelUtil.GetMemorySize( Width, Height, Depth, Format ); // Set up a pixel box _buffer = new PixelBox( Width, Height, Depth, Format ); if ( Width == 0 || Height == 0 || Depth == 0 ) { /// We are invalid, do not allocate a buffer return; } // Is this a render target? if ( ( (int)Usage & (int)TextureUsage.RenderTarget ) != 0 ) { // Create render target for each slice for ( int zoffset = 0; zoffset < Depth; zoffset++ ) { string name = string.Empty; name = "rtt/" + this.GetHashCode() + "/" + basename; GLESSurfaceDescription target = new GLESSurfaceDescription(); target.Buffer = this; target.ZOffset = zoffset; RenderTexture trt = GLESRTTManager.Instance.CreateRenderTexture( name, target, writeGamma, fsaa ); _sliceTRT.Add( trt ); Root.Instance.RenderSystem.AttachRenderTarget( _sliceTRT[ zoffset ] ); } } }
/// <summary> /// </summary> /// <param name="idxType"> </param> /// <param name="numIndexes"> </param> /// <param name="usage"> </param> public GLES2DefaultHardwareIndexBuffer( IndexType idxType, int numIndexes, BufferUsage usage ) : base( null, idxType, numIndexes, usage, true, false ) // always software, never shadowed { if ( idxType == IndexType.Size32 ) { throw new AxiomException( "32 bit hardware buffers are not allowed in OpenGL ES." ); } this._data = new byte[ sizeInBytes ]; this._dataPtr = BufferBase.Wrap( this._data ); }
public VertexBuffer(int _numElements, int _elementSize, BufferUsage _usage) { type = Gl.GL_ARRAY_BUFFER; numElem = _numElements; elemSize = _elementSize; usage = _usage; int[] ids = new int[1]; Gl.glGenBuffers (1, ids); id = ids[0]; }
/// <summary> /// /// </summary> /// <param name="usage"></param> /// <returns></returns> public static int ConvertEnum(BufferUsage usage) { switch(usage) { case BufferUsage.Static: case BufferUsage.StaticWriteOnly: return (int)Gl.GL_STATIC_DRAW_ARB; case BufferUsage.Dynamic: case BufferUsage.DynamicWriteOnly: default: return (int)Gl.GL_DYNAMIC_DRAW_ARB; } }
///<summary> /// Should be called by HardwareBufferManager ///</summary> public HardwarePixelBuffer(int width, int height, int depth, Axiom.Media.PixelFormat format, BufferUsage usage, bool useSystemMemory, bool useShadowBuffer) : base(usage, useSystemMemory, useShadowBuffer) { this.width = width; this.height = height; this.depth = depth; this.format = format; // Default rowPitch = width; slicePitch = height * width; sizeInBytes = height * width * depth * PixelUtil.GetNumElemBytes(format); }
public GLBufferObject(GraphicsInterface gi, BufferTarget target, BufferUsage usage, IntPtr dataPtr, int size) :base(gi) { fBufferTarget = target; // Generate the buffer ID gi.GenBufferID(out fBufferID); // Bind the buffer so subsequent calls apply to that buffer Bind(); if (size > 0) AllocateStorage(dataPtr, size, usage); Unbind(); }
public GLHardwareVertexBuffer(int vertexSize, int numVertices, BufferUsage usage, bool useShadowBuffer) : base(vertexSize, numVertices, usage, false, useShadowBuffer) { bufferID = 0; Gl.glGenBuffersARB(1, out bufferID); if(bufferID == 0) { throw new Exception("Cannot create GL vertex buffer"); } Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, bufferID); // initialize this buffer. we dont have data yet tho Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB, sizeInBytes, IntPtr.Zero, GLHelper.ConvertEnum(usage)); }
public void Define( Array controlPointArray, VertexDeclaration declaration, int width, int height, int uMaxSubdivisionLevel, int vMaxSubdivisionLevel, VisibleSide visibleSide, BufferUsage vbUsage, BufferUsage ibUsage, bool vbUseShadow, bool ibUseShadow ) { VertexBufferUsage = vbUsage; UseVertexShadowBuffer = vbUseShadow; IndexBufferUsage = ibUsage; UseIndexShadowBuffer = ibUseShadow; // Init patch builder // define the surface // NB clone the declaration to make it independent this.vertexDeclaration = (VertexDeclaration)declaration.Clone(); this.patchSurface.DefineSurface( controlPointArray, this.vertexDeclaration, width, height, PatchSurfaceType.Bezier, uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide ); }
unsafe public XnaHardwareIndexBuffer( HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, XFG.GraphicsDevice device, bool useSystemMemory, bool useShadowBuffer ) : base( manager, type, numIndices, usage, useSystemMemory, useShadowBuffer ) { _bufferType = ( type == IndexType.Size16 ) ? XFG.IndexElementSize.SixteenBits : XFG.IndexElementSize.ThirtyTwoBits; // create the buffer if (usage == BufferUsage.Dynamic || usage == BufferUsage.DynamicWriteOnly) { _xnaBuffer = new XFG.IndexBuffer(device, _bufferType, numIndices, XnaHelper.Convert(usage)); } else _xnaBuffer = new XFG.IndexBuffer(device, _bufferType, numIndices, XFG.BufferUsage.None); _bufferBytes = new byte[ sizeInBytes ]; _bufferBytes.Initialize(); }
///// <summary> ///// Generates an atomic counter buffer. ///// </summary> ///// <param name="array"></param> ///// <param name="usage"></param> ///// <returns></returns> //public static AtomicCounterBuffer GenAtomicCounterBuffer(this UnmanagedArrayBase array, BufferUsage usage) //{ // return GenIndependentBuffer(array, IndependentBufferTarget.AtomicCounterBuffer, usage) as AtomicCounterBuffer; //} ///// <summary> ///// Generates a pixel pack buffer. ///// </summary> ///// <param name="array"></param> ///// <param name="usage"></param> ///// <returns></returns> //public static PixelPackBuffer GenPixelPackBuffer(this UnmanagedArrayBase array, BufferUsage usage) //{ // return GenIndependentBuffer(array, IndependentBufferTarget.PixelPackBuffer, usage) as PixelPackBuffer; //} ///// <summary> ///// Generates a pixel unpack buffer. ///// </summary> ///// <param name="array"></param> ///// <param name="usage"></param> ///// <returns></returns> //public static PixelUnpackBuffer GenPixelUnpackBuffer(this UnmanagedArrayBase array, BufferUsage usage) //{ // return GenIndependentBuffer(array, IndependentBufferTarget.PixelUnpackBuffer, usage) as PixelUnpackBuffer; //} ///// <summary> ///// Generates a shader storage buffer. ///// </summary> ///// <param name="array"></param> ///// <param name="usage"></param> ///// <returns></returns> //public static ShaderStorageBuffer GenShaderStorageBuffer(this UnmanagedArrayBase array, BufferUsage usage) //{ // return GenIndependentBuffer(array, IndependentBufferTarget.ShaderStorageBuffer, usage) as ShaderStorageBuffer; //} ///// <summary> ///// Generates a texture buffer. ///// </summary> ///// <param name="array"></param> ///// <param name="usage"></param> ///// <returns></returns> //public static TextureBuffer GenTextureBuffer(this UnmanagedArrayBase array, BufferUsage usage) //{ // return GenIndependentBuffer(array, IndependentBufferTarget.TextureBuffer, usage) as TextureBuffer; //} ///// <summary> ///// Generates an uniform buffer. ///// </summary> ///// <param name="array"></param> ///// <param name="usage"></param> ///// <returns></returns> //public static UniformBuffer GenUniformBuffer(this UnmanagedArrayBase array, BufferUsage usage) //{ // return GenIndependentBuffer(array, IndependentBufferTarget.UniformBuffer, usage) as UniformBuffer; //} /// <summary> /// Generates an independent buffer. /// </summary> /// <param name="array"></param> /// <param name="bufferTarget"></param> /// <param name="usage"></param> /// <returns></returns> private static Buffer GenIndependentBuffer(this UnmanagedArrayBase array, IndependentBufferTarget bufferTarget, BufferUsage usage) { if (glGenBuffers == null) { InitFunctions(); } uint[] buffers = new uint[1]; glGenBuffers(1, buffers); var target = (uint)bufferTarget; glBindBuffer(target, buffers[0]); glBufferData(target, array.ByteLength, array.Header, (uint)usage); glBindBuffer(target, 0); Buffer buffer = null; switch (bufferTarget) { case IndependentBufferTarget.AtomicCounterBuffer: buffer = new AtomicCounterBuffer(buffers[0], array.Length, array.ByteLength); break; case IndependentBufferTarget.PixelPackBuffer: buffer = new PixelPackBuffer(buffers[0], array.Length, array.ByteLength); break; case IndependentBufferTarget.PixelUnpackBuffer: buffer = new PixelUnpackBuffer(buffers[0], array.Length, array.ByteLength); break; case IndependentBufferTarget.ShaderStorageBuffer: buffer = new ShaderStorageBuffer(buffers[0], array.Length, array.ByteLength); break; case IndependentBufferTarget.TextureBuffer: buffer = new TextureBuffer(buffers[0], array.Length, array.ByteLength); break; case IndependentBufferTarget.UniformBuffer: buffer = new UniformBuffer(buffers[0], array.Length, array.ByteLength); break; default: throw new NotImplementedException(); } return buffer; }
// ------------------------------------ // ------------------------------------ /// <summary> /// Creates a new PatchMesh. /// </summary> /// <remarks> /// As defined in <see cref="MeshManager.CreateBezierPatch" />. /// </remarks> public PatchMesh(string name, System.Array controlPointBuffer, VertexDeclaration declaration, int width, int height, int uMaxSubdivisionLevel, int vMaxSubdivisionLevel, VisibleSide visibleSide, BufferUsage vbUsage, BufferUsage ibUsage, bool vbUseShadow, bool ibUseShadow) : base(name) { vertexBufferUsage = vbUsage; useVertexShadowBuffer = vbUseShadow; indexBufferUsage = ibUsage; useIndexShadowBuffer = ibUseShadow; // Init patch builder // define the surface // NB clone the declaration to make it independent vertexDeclaration = (VertexDeclaration)declaration.Clone(); patchSurface.DefineSurface(controlPointBuffer, vertexDeclaration, width, height, PatchSurfaceType.Bezier, uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide); }
public IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage) : base(graphicsDevice, BufferTarget.ElementArrayBuffer, GetElementSizeInBytes(indexElementSize), indexCount, usage) { IndexElementSize = indexElementSize; switch (indexElementSize) { case IndexElementSize.EightBits: DrawElementsType = DrawElementsType.UnsignedByte; break; case IndexElementSize.SixteenBits: DrawElementsType = DrawElementsType.UnsignedShort; break; case IndexElementSize.ThirtyTwoBits: DrawElementsType = DrawElementsType.UnsignedInt; break; } }
public XnaHardwareVertexBuffer( HardwareBufferManagerBase manager, VertexDeclaration vertexDeclaration, int numVertices, BufferUsage usage, XFG.GraphicsDevice dev, bool useSystemMemory, bool useShadowBuffer ) : base( manager, vertexDeclaration, numVertices, usage, useSystemMemory, useShadowBuffer ) { _device = dev; if ( !( vertexDeclaration is XnaVertexDeclaration ) ) { throw new AxiomException ("Invalid VertexDeclaration supplied, must be created by HardwareBufferManager.CreateVertexDeclaration()" ); } if (usage == BufferUsage.Dynamic || usage == BufferUsage.DynamicWriteOnly) { _buffer = new XFG.DynamicVertexBuffer(_device, ( (XnaVertexDeclaration)vertexDeclaration ).XFGVertexDeclaration , numVertices, XnaHelper.Convert(usage)); } else _buffer = new XFG.VertexBuffer(_device, ( (XnaVertexDeclaration)vertexDeclaration ).XFGVertexDeclaration, numVertices, XnaHelper.Convert(usage)); _bufferBytes = new byte[ vertexDeclaration.GetVertexSize() * numVertices]; _bufferBytes.Initialize(); }
/// <summary> /// Constructor. /// </summary> /// <param name="type">Index type (16 or 32 bit).</param> /// <param name="numIndices">Number of indices in the buffer.</param> /// <param name="usage">Usage flags.</param> /// <param name="useShadowBuffer">Should this buffer be backed by a software shadow buffer?</param> public GLHardwareIndexBuffer(IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer) : base(type, numIndices, usage, false, useShadowBuffer) { // generate the buffer Gl.glGenBuffersARB(1, out bufferID); if(bufferID == 0) throw new Exception("Cannot create GL index buffer"); Gl.glBindBufferARB(Gl.GL_ELEMENT_ARRAY_BUFFER_ARB, bufferID); // initialize this buffer. we dont have data yet tho Gl.glBufferDataARB( Gl.GL_ELEMENT_ARRAY_BUFFER_ARB, sizeInBytes, IntPtr.Zero, GLHelper.ConvertEnum(usage)); }
public HardwareVertexBuffer( HardwareBufferManagerBase manager, VertexDeclaration vertexDeclaration, int numVertices, BufferUsage usage, bool useSystemMemory, bool useShadowBuffer ) : base( usage, useSystemMemory, useShadowBuffer ) { this.vertexDeclaration = vertexDeclaration; this.numVertices = numVertices; this.Manager = manager; // calculate the size in bytes of this buffer sizeInBytes = vertexDeclaration.GetVertexSize()*numVertices; // create a shadow buffer if required if ( useShadowBuffer ) { shadowBuffer = new DefaultHardwareVertexBuffer( this.Manager, vertexDeclaration, numVertices, BufferUsage.Dynamic ); } this.useCount = 0; }
/// <summary> /// Constructor. /// </summary> /// <param name="manager"> the HardwareBufferManager instance that created this buffer. </param> /// <param name="type"> Index type (16 or 32 bit). </param> /// <param name="numIndices"> Number of indices in the buffer. </param> /// <param name="usage"> Usage flags. </param> /// <param name="useShadowBuffer"> Should this buffer be backed by a software shadow buffer? </param> public GLHardwareIndexBuffer( HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer ) : base( manager, type, numIndices, usage, false, useShadowBuffer ) { // generate the buffer Gl.glGenBuffersARB( 1, out this._bufferId ); if ( this._bufferId == 0 ) { throw new Exception( "OGL: Cannot create GL index buffer" ); } Gl.glBindBufferARB( Gl.GL_ELEMENT_ARRAY_BUFFER_ARB, this._bufferId ); // initialize this buffer. we dont have data yet tho Gl.glBufferDataARB( Gl.GL_ELEMENT_ARRAY_BUFFER_ARB, new IntPtr( sizeInBytes ), IntPtr.Zero, GLHelper.ConvertEnum( usage ) ); LogManager.Instance.Write( "OGL: Created IndexBuffer[{0}].", this._bufferId ); }
/// <summary> /// Creates a <see cref="OneIndexBuffer"/> object directly in server side(GPU) without initializing its value. /// </summary> /// <param name="type"></param> /// <param name="length">How many indexes are there?(How many uint/ushort/bytes?)</param> /// <param name="mode"></param> /// <param name="usage"></param> /// <returns></returns> public static OneIndexBuffer Create(IndexBufferElementType type, int length, DrawMode mode, BufferUsage usage) { if (glGenBuffers == null) { glGenBuffers = OpenGL.GetDelegateFor<OpenGL.glGenBuffers>(); } if (glBindBuffer == null) { glBindBuffer = OpenGL.GetDelegateFor<OpenGL.glBindBuffer>(); } if (glBufferData == null) { glBufferData = OpenGL.GetDelegateFor<OpenGL.glBufferData>(); } int byteLength = GetSize(type) * length; uint[] buffers = new uint[1]; glGenBuffers(1, buffers); const uint target = OpenGL.GL_ELEMENT_ARRAY_BUFFER; glBindBuffer(target, buffers[0]); glBufferData(target, byteLength, IntPtr.Zero, (uint)usage); glBindBuffer(target, 0); var buffer = new OneIndexBuffer( buffers[0], mode, type, length, byteLength); return buffer; }
/// <summary> /// 生成顶点属性Buffer。描述顶点的位置或颜色或UV等各种属性。 /// <para>每个<see cref="VertexBuffer"/>仅描述其中一个属性。</para> /// <para>Vertex Buffer Object that describes vertex' property(position, color, uv coordinate, etc.).</para> /// <para>Each <see cref="VertexBuffer"/> describes only 1 property.</para> /// </summary> /// <param name="array"></param> /// <param name="config">This <paramref name="config"/> decides parameters' values in glVertexAttribPointer(attributeLocation, size, type, false, 0, IntPtr.Zero);</param> /// <param name="varNameInVertexShader">此顶点属性VBO对应于vertex shader中的哪个in变量?<para>Mapping variable's name in vertex shader.</para></param> /// <param name="usage"></param> /// <param name="instancedDivisor">0: not instanced. 1: instanced divisor is 1.</param> /// <param name="patchVertexes">How many vertexes makes a patch? No patch if <paramref name="patchVertexes"/> is 0.</param> /// <returns></returns> public static VertexBuffer GenVertexBuffer(this UnmanagedArrayBase array, VBOConfig config, string varNameInVertexShader, BufferUsage usage, uint instancedDivisor = 0, int patchVertexes = 0) { if (glGenBuffers == null) { InitFunctions(); } uint[] buffers = new uint[1]; glGenBuffers(1, buffers); const uint target = OpenGL.GL_ARRAY_BUFFER; glBindBuffer(target, buffers[0]); glBufferData(target, array.ByteLength, array.Header, (uint)usage); glBindBuffer(target, 0); var buffer = new VertexBuffer( buffers[0], config, varNameInVertexShader, array.Length, array.ByteLength, instancedDivisor, patchVertexes); return buffer; }
public GLESHardwareVertexBuffer( HardwareBufferManager mgr, int vertexSize, int numVertices, BufferUsage usage, bool useShadowBuffer ) : base( numVertices, vertexSize, usage, false, useShadowBuffer ) { if ( !useShadowBuffer ) { throw new AxiomException( "Only supported with shadowBuffer" ); } OpenGL.GenBuffers( 1, ref _bufferId ); GLESConfig.GlCheckError( this ); if ( _bufferId == 0 ) { throw new AxiomException( "Cannot create GL vertex buffer" ); } OpenGL.BindBuffer( All.ArrayBuffer, _bufferId ); GLESConfig.GlCheckError( this ); OpenGL.BufferData( All.ArrayBuffer, new IntPtr( sizeInBytes ), IntPtr.Zero, GLESHardwareBufferManager.GetGLUsage( usage ) ); GLESConfig.GlCheckError( this ); }
public GLHardwareVertexBuffer( HardwareBufferManagerBase manager, VertexDeclaration vertexDeclaration, int numVertices, BufferUsage usage, bool useShadowBuffer ) : base( manager, vertexDeclaration, numVertices, usage, false, useShadowBuffer ) { this.bufferID = 0; Gl.glGenBuffersARB( 1, out this.bufferID ); if ( this.bufferID == 0 ) { throw new Exception( "Cannot create GL vertex buffer" ); } Gl.glBindBufferARB( Gl.GL_ARRAY_BUFFER_ARB, this.bufferID ); // initialize this buffer. we dont have data yet tho Gl.glBufferDataARB( Gl.GL_ARRAY_BUFFER_ARB, new IntPtr( sizeInBytes ), IntPtr.Zero, GLHelper.ConvertEnum( usage ) ); // TAO 2.0 //Gl.glBufferDataARB( Gl.GL_ARRAY_BUFFER_ARB, sizeInBytes, IntPtr.Zero, GLHelper.ConvertEnum( usage ) ); }
/// <summary> /// Creates a <see cref="VertexBuffer"/> object(actually an array) directly in server side(GPU) without initializing its value. /// </summary> /// <param name="elementType">element's type of this 'array'.</param> /// <param name="length">How many elements are there?</param> /// <param name="config">mapping to vertex shader's 'in' type.</param> /// <param name="varNameInVertexShader">mapping to vertex shader's 'in' name.</param> /// <param name="usage"></param> /// <param name="instanceDivisor"></param> /// <param name="patchVertexes"></param> /// <returns></returns> public static VertexBuffer Create(Type elementType, int length, VBOConfig config, string varNameInVertexShader, BufferUsage usage, uint instanceDivisor = 0, int patchVertexes = 0) { if (!elementType.IsValueType) { throw new ArgumentException(string.Format("{0} must be a value type!", elementType)); } if (glGenBuffers == null) { glGenBuffers = OpenGL.GetDelegateFor<OpenGL.glGenBuffers>(); } if (glBindBuffer == null) { glBindBuffer = OpenGL.GetDelegateFor<OpenGL.glBindBuffer>(); } if (glBufferData == null) { glBufferData = OpenGL.GetDelegateFor<OpenGL.glBufferData>(); } int byteLength = Marshal.SizeOf(elementType) * length; uint[] buffers = new uint[1]; glGenBuffers(1, buffers); const uint target = OpenGL.GL_ARRAY_BUFFER; glBindBuffer(target, buffers[0]); glBufferData(target, byteLength, IntPtr.Zero, (uint)usage); glBindBuffer(target, 0); var buffer = new VertexBuffer( buffers[0], config, varNameInVertexShader, length, byteLength, instanceDivisor, patchVertexes); return buffer; }
public GLESHardwareVertexBuffer( HardwareBufferManagerBase manager, VertexDeclaration vertexDeclaration, int numVertices, BufferUsage usage, bool useShadowBuffer ) : base( manager, vertexDeclaration, numVertices, usage, false, useShadowBuffer ) { if ( !useShadowBuffer ) { throw new AxiomException( "Only supported with shadowBuffer" ); } var buffers = new int[ 1 ]; GL.GenBuffers( 1, buffers ); GLESConfig.GlCheckError( this ); this._bufferID = buffers[ 0 ]; if ( this._bufferID == 0 ) { throw new AxiomException( "Cannot create GL ES vertex buffer" ); } ( Root.Instance.RenderSystem as GLESRenderSystem ).BindGLBuffer( GLenum.ArrayBuffer, this._bufferID ); GL.BufferData( GLenum.ArrayBuffer, new IntPtr( sizeInBytes ), IntPtr.Zero, GLESHardwareBufferManager.GetGLUsage( usage ) ); GLESConfig.GlCheckError( this ); }
public DynamicIndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int indexCount, BufferUsage usage) : base(graphicsDevice, indexType, indexCount, usage, true) { }
/// <summary> /// Generates an uniform buffer. /// </summary> /// <param name="array"></param> /// <param name="usage"></param> /// <returns></returns> public static UniformBuffer GenUniformBuffer <T>(this T[] array, BufferUsage usage) where T : struct { return(GenBuffer(array, IndependentBufferTarget.UniformBuffer, usage) as UniformBuffer); }
public override Axiom.Graphics.HardwareIndexBuffer CreateIndexBuffer(IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer) { D3DHardwareIndexBuffer buffer = new D3DHardwareIndexBuffer(type, numIndices, usage, device, false, useShadowBuffer); indexBuffers.Add(buffer); return(buffer); }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="numIndices"></param> /// <param name="usage"></param> /// <param name="useShadowBuffer"></param> /// <returns></returns> public override HardwareIndexBuffer CreateIndexBuffer(IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer) { // always use shadowBuffer GLESHardwareIndexBuffer buf = new GLESHardwareIndexBuffer(this, type, numIndices, usage, true); lock ( _indexBufferLock ) { indexBuffers.Add(buf); } return(buf); }
/// <summary> /// Generates an uniform buffer. /// </summary> /// <param name="array"></param> /// <param name="usage"></param> /// <returns></returns> public static TransformFeedbackBuffer GenTransformFeedbackBuffer <T>(this T[] array, BufferUsage usage) where T : struct { return(GenBuffer(array, IndependentBufferTarget.TransformFeedbackBuffer, usage) as TransformFeedbackBuffer); }
/// <summary> /// /// </summary> /// <param name="vertexSize"></param> /// <param name="numVerts"></param> /// <param name="usage"></param> /// <returns></returns> public override HardwareVertexBuffer CreateVertexBuffer(VertexDeclaration declaration, int numVerts, BufferUsage usage) { return(CreateVertexBuffer(declaration, numVerts, usage, true)); }
/// <summary> /// Construct an ShaderStorageBuffer. /// </summary> /// <param name="hint"> /// An <see cref="BufferUsage"/> that specifies the data buffer usage hints. /// </param> public ShaderStorageBuffer(BufferUsage hint) : base(BufferTarget.ShaderStorageBuffer, hint) { }
public IndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int indexCount, BufferUsage usage) : this(graphicsDevice, SizeForType(graphicsDevice, indexType), indexCount, usage, false) { }
/// <summary> /// Generates an pixel unpack buffer. /// </summary> /// <param name="array"></param> /// <param name="usage"></param> /// <returns></returns> public static PixelUnpackBuffer GenPixelUnpackBuffer <T>(this T[] array, BufferUsage usage) where T : struct { return(GenBuffer(array, IndependentBufferTarget.PixelUnpackBuffer, usage) as PixelUnpackBuffer); }
public VertexBuffer(GraphicsDevice graphicsDevice, Type type, int vertexCount, BufferUsage bufferUsage) : this(graphicsDevice, VertexDeclaration.FromType(type), vertexCount, bufferUsage, false) { }
/// <summary> /// Generates an texture buffer. /// </summary> /// <param name="array"></param> /// <param name="usage"></param> /// <returns></returns> public static TextureBuffer GenTextureBuffer <T>(this T[] array, BufferUsage usage) where T : struct { return(GenBuffer(array, IndependentBufferTarget.TextureBuffer, usage) as TextureBuffer); }
public VertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage bufferUsage) : this(graphicsDevice, vertexDeclaration, vertexCount, bufferUsage, false) { }
protected VertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage bufferUsage, bool dynamic) { if (graphicsDevice == null) { throw new ArgumentNullException("Graphics Device Cannot Be null"); } this.GraphicsDevice = graphicsDevice; this.VertexDeclaration = vertexDeclaration; this.VertexCount = vertexCount; this.BufferUsage = bufferUsage; // Make sure the graphics device is assigned in the vertex declaration. if (vertexDeclaration.GraphicsDevice != graphicsDevice) { vertexDeclaration.GraphicsDevice = graphicsDevice; } _isDynamic = dynamic; #if DIRECTX GenerateIfRequired(); #elif PSM //Do nothing, we cannot create the storage array yet #elif !PORTABLE Threading.BlockOnUIThread(GenerateIfRequired); #endif }
/// <summary> /// Creates a <see cref="PixelUnpackBuffer"/> object directly in server side(GPU) without initializing its value. /// </summary> /// <param name="elementType"></param> /// <param name="usage"></param> /// <param name="length"></param> /// <returns></returns> public static PixelUnpackBuffer Create(Type elementType, int length, BufferUsage usage) { return(GLBuffer.Create(IndependentBufferTarget.PixelUnpackBuffer, elementType, length, usage) as PixelUnpackBuffer); }
/// <summary> /// Constructs a new <see cref="BufferDescription"/>. /// </summary> /// <param name="sizeInBytes">The desired capacity, in bytes.</param> /// <param name="usage">Indicates how the <see cref="Buffer"/> will be used.</param> /// <param name="structureByteStride">For structured buffers, this value indicates the size in bytes of a single /// structure element, and must be non-zero. For all other buffer types, this value must be zero.</param> public BufferDescription(uint sizeInBytes, BufferUsage usage, uint structureByteStride) { SizeInBytes = sizeInBytes; Usage = usage; StructureByteStride = structureByteStride; }
public override Axiom.Graphics.HardwareIndexBuffer CreateIndexBuffer(IndexType type, int numIndices, BufferUsage usage) { // call overloaded method with no shadow buffer return(CreateIndexBuffer(type, numIndices, usage, false)); }
public DynamicIndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage) : base(graphicsDevice, indexElementSize, indexCount, usage, true) { }
public override HardwareVertexBuffer CreateVertexBuffer(int vertexSize, int numVerts, BufferUsage usage, bool useShadowBuffer) { D3DHardwareVertexBuffer buffer = new D3DHardwareVertexBuffer(vertexSize, numVerts, usage, device, false, useShadowBuffer); vertexBuffers.Add(buffer); return(buffer); }
/// <summary> /// Generates an shader storage buffer. /// </summary> /// <param name="array"></param> /// <param name="usage"></param> /// <returns></returns> public static ShaderStorageBuffer GenShaderStorageBuffer <T>(this T[] array, BufferUsage usage) where T : struct { return(GenBuffer(array, IndependentBufferTarget.ShaderStorageBuffer, usage) as ShaderStorageBuffer); }
public TModelo(GraphicFactory factory, T[] vertices, int[] indices, Matrix transformation, String diffuseTextureName = null, float radius = -1, bool isDynamic = false, float dynamicMultiplier = 1, BufferUsage BufferUsage = BufferUsage.WriteOnly) { this.BufferUsage = BufferUsage; this.radius = -1; this.vertices = vertices; this.indices = indices; this.transformation = transformation; this.diffuseTextureName = diffuseTextureName; this.isDynamic = isDynamic; this.dynamicMultiplier = dynamicMultiplier; LoadModel(factory, out BatchInformations, out TextureInformations); }
public IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage bufferUsage) : this(graphicsDevice, indexElementSize, indexCount, bufferUsage, false) { }
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic) { if (graphicsDevice == null) { throw new ArgumentNullException("GraphicsDevice is null"); } this.GraphicsDevice = graphicsDevice; this.IndexElementSize = indexElementSize; this.IndexCount = indexCount; this.BufferUsage = usage; _isDynamic = dynamic; #if DIRECTX GenerateIfRequired(); #elif PSM if (indexElementSize != IndexElementSize.SixteenBits) { throw new NotImplementedException("PSS Currently only supports ushort (SixteenBits) index elements"); } _buffer = new ushort[indexCount]; #else Threading.BlockOnUIThread(GenerateIfRequired); #endif }
/// <summary> /// Generates an atomic counter buffer. /// </summary> /// <param name="array"></param> /// <param name="usage"></param> /// <returns></returns> public static AtomicCounterBuffer GenAtomicCounterBuffer <T>(this T[] array, BufferUsage usage) where T : struct { return(GenBuffer(array, IndependentBufferTarget.AtomicCounterBuffer, usage) as AtomicCounterBuffer); }
/// <summary> /// Generates an independent buffer. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <param name="target"></param> /// <param name="usage"></param> /// <returns></returns> private static GLBuffer GenBuffer <T>(this T[] array, IndependentBufferTarget target, BufferUsage usage) where T : struct { GCHandle pinned = GCHandle.Alloc(array, GCHandleType.Pinned); IntPtr header = pinned.AddrOfPinnedObject(); // same result with: IntPtr header = Marshal.UnsafeAddrOfPinnedArrayElement(array, 0); UnmanagedArrayBase unmanagedArray = new TempUnmanagedArray <T>(header, array.Length);// It's not neecessary to call Dispose() for this unmanaged array. GLBuffer buffer = GenIndependentBuffer(unmanagedArray, target, usage); pinned.Free(); return(buffer); }
/// <summary> /// Constructor. /// </summary> /// <param name="manager"> the HardwareBufferManager instance that created this buffer. </param> /// <param name="type"> Index type (16 or 32 bit). </param> /// <param name="numIndices"> Number of indices in the buffer. </param> /// <param name="usage"> Usage flags. </param> /// <param name="useShadowBuffer"> Should this buffer be backed by a software shadow buffer? </param> public GLHardwareIndexBuffer(HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, bool useShadowBuffer) : base(manager, type, numIndices, usage, false, useShadowBuffer) { // generate the buffer Gl.glGenBuffersARB(1, out this._bufferId); if (this._bufferId == 0) { throw new Exception("OGL: Cannot create GL index buffer"); } Gl.glBindBufferARB(Gl.GL_ELEMENT_ARRAY_BUFFER_ARB, this._bufferId); // initialize this buffer. we dont have data yet tho Gl.glBufferDataARB(Gl.GL_ELEMENT_ARRAY_BUFFER_ARB, new IntPtr(sizeInBytes), IntPtr.Zero, GLHelper.ConvertEnum(usage)); LogManager.Instance.Write("OGL: Created IndexBuffer[{0}].", this._bufferId); }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="numIndices"></param> /// <param name="usage"></param> /// <returns></returns> public override HardwareIndexBuffer CreateIndexBuffer(IndexType type, int numIndices, BufferUsage usage) { return(CreateIndexBuffer(type, numIndices, usage, true)); }
public GLHardwarePixelBuffer(int width, int height, int depth, PixelFormat format, BufferUsage usage) : base(width, height, depth, format, usage, false, false) { buffer = new PixelBox(width, height, depth, format); GLFormat = Gl.GL_NONE; }
protected IndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int indexCount, BufferUsage usage, bool dynamic) : this(graphicsDevice, SizeForType(graphicsDevice, indexType), indexCount, usage, dynamic) { }
/// <summary> /// /// </summary> /// <param name="vertexSize"></param> /// <param name="numVerts"></param> /// <param name="usage"></param> /// <param name="useShadowBuffer"></param> /// <returns></returns> public override HardwareVertexBuffer CreateVertexBuffer(VertexDeclaration declaration, int numVerts, BufferUsage usage, bool useShadowBuffer) { // always use shadowBuffer GLESHardwareVertexBuffer buf = new GLESHardwareVertexBuffer(this, declaration, numVerts, usage, true); lock ( _vertexBufferLock ) { vertexBuffers.Add(buf); } return(buf); }
public override HardwareVertexBuffer CreateVertexBuffer(int vertexSize, int numVerts, BufferUsage usage) { // call overloaded method with no shadow buffer return(CreateVertexBuffer(vertexSize, numVerts, usage, false)); }