public CSharpGL.VertexBuffer GetVertexAttributeBuffer(string bufferName, string varNameInShader) { if ((bufferName == position)) { if ((this.positionBuffer == null)) { int length = this.pointCount; VertexBuffer buffer = VertexBuffer.Create(typeof(vec3), length, VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw); unsafe { var random = new Random(); IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (vec3 *)pointer; for (int i = 0; i < this.pointCount; i++) { array[i] = (new vec3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()) - new vec3(0.5f, 0.5f, 0.5f)) * this.Lengths; } buffer.UnmapBuffer(); } this.positionBuffer = buffer; } return(positionBuffer); } else { throw new System.ArgumentException("bufferName"); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <returns></returns> public VertexBuffer GetVertexAttributeBuffer(string bufferName) { if (bufferName == position) { if (this.positionBuffer == null) { this.positionBuffer = VertexBuffer.Create(typeof(QuadPositionStruct), this.Capacity, VBOConfig.Vec2, BufferUsage.DynamicDraw); } return(this.positionBuffer); } else if (bufferName == STR) { if (this.uvBuffer == null) { this.uvBuffer = VertexBuffer.Create(typeof(QuadSTRStruct), this.Capacity, VBOConfig.Vec3, BufferUsage.DynamicDraw); } return(this.uvBuffer); } else { throw new ArgumentException(); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public VertexBuffer GetVertexAttributeBuffer(string bufferName, string varNameInShader) { if (bufferName == strPosition) { if (this.positionBuffer == null) { int length = maxCharCount; VertexBuffer buffer = VertexBuffer.Create(typeof(GlyphPosition), length, VBOConfig.Vec2, varNameInShader, BufferUsage.DynamicDraw); this.positionBuffer = buffer; } return(this.positionBuffer); } else if (bufferName == strUV) { if (this.uvBuffer == null) { int length = maxCharCount; VertexBuffer buffer = VertexBuffer.Create(typeof(GlyphTexCoord), length, VBOConfig.Vec2, varNameInShader, BufferUsage.DynamicDraw); this.uvBuffer = buffer; } return(this.uvBuffer); } else { throw new ArgumentException(); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <returns></returns> public VertexBuffer GetVertexAttributeBuffer(string bufferName) { if (bufferName == position) { if (this.positionBuffer == null) { this.positionBuffer = VertexBuffer.Create(typeof(QuadStruct), this.Capacity, VBOConfig.Vec2, BufferUsage.DynamicDraw); } return(this.positionBuffer); } else if (bufferName == uv) { if (this.colorBuffer == null) { this.colorBuffer = VertexBuffer.Create(typeof(QuadStruct), this.Capacity, VBOConfig.Vec2, BufferUsage.DynamicDraw); } return(this.colorBuffer); } else if (bufferName == textureIndex) { if (this.textureIndexBuffer == null) { this.textureIndexBuffer = VertexBuffer.Create(typeof(float), this.Capacity, VBOConfig.Float, BufferUsage.DynamicDraw); } return(this.textureIndexBuffer); } else { throw new ArgumentException(); } }
private VertexBuffer GetPositionBuffer() { bool initialized = false; vec3 max = new vec3(); vec3 min = new vec3(); int uCount = GetUCount(interval); int vCount = GetVCount(interval); int length = uCount * vCount; VertexBuffer buffer = VertexBuffer.Create(typeof(vec3), length, VBOConfig.Vec3, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (vec3 *)pointer; int index = 0; for (int uIndex = 0; uIndex < uCount; uIndex++) { for (int vIndex = 0; vIndex < vCount; vIndex++) { double u = Math.PI * uIndex / uCount; double v = Math.PI * 2 * vIndex / vCount; var position = GetPosition(u, v); if (!initialized) { max = position; min = position; initialized = true; } else { position.UpdateMax(ref max); position.UpdateMin(ref min); } array[index++] = position; } } //this.Lengths = max - min; vec3 worldPosition = max / 2.0f + min / 2.0f; for (int i = 0; i < index; i++) { array[i] = array[i] - worldPosition; } buffer.UnmapBuffer(); } return(buffer); }
private VertexBuffer GetTexCoordBuffer() { int uCount = GetUCount(interval); int length = uCount; VertexBuffer buffer = VertexBuffer.Create(typeof(float), length, VBOConfig.Float, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); int index = 0; var array = (float *)pointer; for (int uIndex = 0; uIndex < uCount; uIndex++) { array[index++] = (float)uIndex / (float)uCount; } buffer.UnmapBuffer(); } return(buffer); }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public VertexBuffer GetVertexAttributeBuffer(string bufferName, string varNameInShader) { if (bufferName == strPosition) { if (this.positionBuffer == null) { int length = 1; VertexBuffer buffer = VertexBuffer.Create(typeof(CubeModel.CubePosition), length, VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.ReadWrite); { var array = (CubeModel.CubePosition *)pointer; array[0] = CubeModel.position; } { var array = (vec3 *)pointer; for (int i = 0; i < 24; i++) { array[i] = array[i] / 2 * Lengths; } } buffer.UnmapBuffer(); } this.positionBuffer = buffer; } return(this.positionBuffer); } else if (bufferName == strColor) { if (this.colorBuffer == null) { //int length = 1; //VertexBuffer buffer = VertexBuffer.Create(typeof(CubeModel.CubeColor), length, VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw); //unsafe //{ // IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); // var array = (CubeModel.CubeColor*)pointer; // array[0] = CubeModel.color; // buffer.UnmapBuffer(); //} //this.colorBuffer = buffer; // another way to do this: this.colorBuffer = CubeModel.color.GenVertexBuffer(VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw); } return(this.colorBuffer); } else if (bufferName == strNormal) { if (this.normalBuffer == null) { //int length = 1; //VertexBuffer buffer = VertexBuffer.Create(typeof(CubeModel.CubeNormal), length, VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw); //unsafe //{ // IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); // var array = (CubeModel.CubeNormal*)pointer; // array[0] = CubeModel.normal; // buffer.UnmapBuffer(); //} //this.normalBuffer = buffer; // another way to do this: this.normalBuffer = CubeModel.normal.GenVertexBuffer(VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw); } return(this.normalBuffer); } else { return(null); } }