/// <summary> /// Override from Panel. /// </summary> public override void Initialize() { base.Initialize(); // base class already has added the center panel at this point, so lets create the borders renderOp2.vertexData = new VertexData(); // 8 * 4, cant resuse vertices because they might not share same tex coords renderOp2.vertexData.vertexCount = 32; renderOp2.vertexData.vertexStart = 0; // get a reference to the vertex declaration VertexDeclaration decl = renderOp2.vertexData.vertexDeclaration; // Position and texture coords each have their own buffers to allow // each to be edited separately with the discard flag decl.AddElement(POSITION, 0, VertexElementType.Float3, VertexElementSemantic.Position); decl.AddElement(TEXCOORDS, 0, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0); // position buffer HardwareVertexBuffer buffer = HardwareBufferManager.Instance.CreateVertexBuffer( decl.GetVertexSize(POSITION), renderOp2.vertexData.vertexCount, BufferUsage.StaticWriteOnly); // bind position VertexBufferBinding binding = renderOp2.vertexData.vertexBufferBinding; binding.SetBinding(POSITION, buffer); // texcoord buffer buffer = HardwareBufferManager.Instance.CreateVertexBuffer( decl.GetVertexSize(TEXCOORDS), renderOp2.vertexData.vertexCount, BufferUsage.StaticWriteOnly); // bind texcoords binding = renderOp2.vertexData.vertexBufferBinding; binding.SetBinding(TEXCOORDS, buffer); renderOp2.operationType = OperationType.TriangleList; renderOp2.useIndices = true; // index data renderOp2.indexData = new IndexData(); // 8 * 3 * 2 = 8 vertices, 3 indices per tri, 2 tris renderOp2.indexData.indexCount = 48; renderOp2.indexData.indexStart = 0; /* Each cell is * 0-----2 | /| | / | |/ | | 1-----3 */ // create a new index buffer renderOp2.indexData.indexBuffer = HardwareBufferManager.Instance.CreateIndexBuffer( IndexType.Size16, renderOp2.indexData.indexCount, BufferUsage.StaticWriteOnly); // lock this bad boy IntPtr data = renderOp2.indexData.indexBuffer.Lock(BufferLocking.Discard); int index = 0; unsafe { short *idxPtr = (short *)data.ToPointer(); for (short cell = 0; cell < 8; cell++) { short val = (short)(cell * 4); idxPtr[index++] = val; idxPtr[index++] = (short)(val + 1); idxPtr[index++] = (short)(val + 2); idxPtr[index++] = (short)(val + 2); idxPtr[index++] = (short)(val + 1); idxPtr[index++] = (short)(val + 3); } } // unlock the buffer renderOp2.indexData.indexBuffer.Unlock(); // create new seperate object for the panels since they have a different material borderRenderable = new BorderRenderable(this); }
/// <summary> /// Override from Panel. /// </summary> public override void Initialize() { var init = !isInitialized; base.Initialize(); // superclass will handle the interior panel area if ( init ) { // base class already has added the center panel at this point, so lets create the borders this.renderOp2.vertexData = new VertexData(); // 8 * 4, cant resuse vertices because they might not share same tex coords this.renderOp2.vertexData.vertexCount = 32; this.renderOp2.vertexData.vertexStart = 0; // get a reference to the vertex declaration var decl = this.renderOp2.vertexData.vertexDeclaration; // Position and texture coords each have their own buffers to allow // each to be edited separately with the discard flag decl.AddElement( POSITION, 0, VertexElementType.Float3, VertexElementSemantic.Position ); decl.AddElement( TEXCOORDS, 0, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 ); // position buffer var buffer = HardwareBufferManager.Instance.CreateVertexBuffer( decl.Clone( POSITION ), this.renderOp2.vertexData.vertexCount, BufferUsage.StaticWriteOnly ); // bind position var binding = this.renderOp2.vertexData.vertexBufferBinding; binding.SetBinding( POSITION, buffer ); // texcoord buffer buffer = HardwareBufferManager.Instance.CreateVertexBuffer( decl.Clone( TEXCOORDS ), this.renderOp2.vertexData.vertexCount, BufferUsage.StaticWriteOnly, true ); // bind texcoords binding = this.renderOp2.vertexData.vertexBufferBinding; binding.SetBinding( TEXCOORDS, buffer ); this.renderOp2.operationType = OperationType.TriangleList; this.renderOp2.useIndices = true; // index data this.renderOp2.indexData = new IndexData(); // 8 * 3 * 2 = 8 vertices, 3 indices per tri, 2 tris this.renderOp2.indexData.indexCount = 48; this.renderOp2.indexData.indexStart = 0; /* Each cell is 0-----2 | /| | / | |/ | 1-----3 */ // create a new index buffer this.renderOp2.indexData.indexBuffer = HardwareBufferManager.Instance.CreateIndexBuffer( IndexType.Size16, this.renderOp2.indexData. indexCount, BufferUsage.StaticWriteOnly ); // lock this bad boy var data = this.renderOp2.indexData.indexBuffer.Lock( BufferLocking.Discard ); var index = 0; #if !AXIOM_SAFE_ONLY unsafe #endif { var idxPtr = data.ToShortPointer(); for ( short cell = 0; cell < 8; cell++ ) { var val = (short)( cell*4 ); idxPtr[ index++ ] = val; idxPtr[ index++ ] = (short)( val + 1 ); idxPtr[ index++ ] = (short)( val + 2 ); idxPtr[ index++ ] = (short)( val + 2 ); idxPtr[ index++ ] = (short)( val + 1 ); idxPtr[ index++ ] = (short)( val + 3 ); } } // unlock the buffer this.renderOp2.indexData.indexBuffer.Unlock(); // create new seperate object for the panels since they have a different material this.borderRenderable = new BorderRenderable( this ); isInitialized = true; } }