public CSharpGL.VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader) { if ((bufferName == position)) { if ((positionBufferPtr == null)) { using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw)) {// begin of using buffer.Create(this.pointCount); unsafe { var random = new Random(); var array = (vec3 *)buffer.Header.ToPointer(); 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; } } positionBufferPtr = buffer.GetBufferPtr(); }// end of using } return(positionBufferPtr); } throw new System.ArgumentException("bufferName"); }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader) { if (bufferName == strPosition) { if (positionBufferPtr == null) { using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw)) { buffer.Create(positions.Length); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < positions.Length; i++) { array[i] = positions[i] / 2 * this.lengths; } } positionBufferPtr = buffer.GetBufferPtr(); } } return(positionBufferPtr); } else { throw new ArgumentException(); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader) { if (bufferName == strPosition) { if (positionBufferPtr == null) { using (var buffer = new VertexAttributeBuffer <GlyphPosition>(varNameInShader, VertexAttributeConfig.Vec2, BufferUsage.DynamicDraw)) { buffer.Create(maxCharCount); positionBufferPtr = buffer.GetBufferPtr(); } } return(positionBufferPtr); } else if (bufferName == strUV) { if (uvBufferPtr == null) { using (var buffer = new VertexAttributeBuffer <GlyphTexCoord>(varNameInShader, VertexAttributeConfig.Vec2, BufferUsage.DynamicDraw)) { buffer.Create(maxCharCount); uvBufferPtr = buffer.GetBufferPtr(); } } return(uvBufferPtr); } else { throw new ArgumentException(); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader) { if (bufferName == position) { if (positionBufferPtr == null) { using (var buffer = new VertexAttributeBuffer <vec3>( varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw)) { buffer.Create(BigDipperModel.positions.Length); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < BigDipperModel.positions.Length; i++) { array[i] = BigDipperModel.positions[i]; } } positionBufferPtr = buffer.GetBufferPtr(); } } return(positionBufferPtr); } else if (bufferName == color) { if (colorBufferPtr == null) { using (var buffer = new VertexAttributeBuffer <vec3>( varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw)) { buffer.Create(BigDipperModel.colors.Length); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < BigDipperModel.colors.Length; i++) { array[i] = BigDipperModel.colors[i]; } } colorBufferPtr = buffer.GetBufferPtr(); } } return(colorBufferPtr); } else { throw new NotImplementedException(); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader) { if (bufferName == position) { if (!propertyBufferPtrDict.ContainsKey(bufferName)) { using (var buffer = new VertexAttributeBuffer <vec3>( varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw)) { buffer.Create(model.Positions.Length); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < model.Positions.Length; i++) { array[i] = model.Positions[i]; } } propertyBufferPtrDict.Add(bufferName, buffer.GetBufferPtr() as VertexAttributeBufferPtr); } } return(propertyBufferPtrDict[bufferName]); } else if (bufferName == color) { if (!propertyBufferPtrDict.ContainsKey(bufferName)) { using (var buffer = new VertexAttributeBuffer <vec3>( varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw)) { buffer.Create(model.Colors.Length); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < model.Colors.Length; i++) { array[i] = model.Colors[i]; } } propertyBufferPtrDict.Add(bufferName, buffer.GetBufferPtr() as VertexAttributeBufferPtr); } } return(propertyBufferPtrDict[bufferName]); } else { throw new NotImplementedException(); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public CSharpGL.VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader) { if ((bufferName == strposition)) { if ((positionBufferPtr == null)) { using (var buffer = new VertexAttributeBuffer <vec3>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw)) {// begin of using buffer.Create(this.pointPositions.Length); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < this.pointPositions.Length; i++) { array[i] = this.pointPositions[i]; } } positionBufferPtr = buffer.GetBufferPtr(); }// end of using } return(positionBufferPtr); } throw new System.ArgumentException("bufferName"); }