예제 #1
0
 /// <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 <float>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
             {
                 float[] positions = model.GetPositions();
                 //List<vec3> pos = new List<vec3>();
                 //for (int i = 0; i < positions.Length; i += 3)
                 //{
                 //    pos.Add(new vec3(positions[i], positions[i + 1], positions[i + 2]));
                 //}
                 //IBoundingBox box = pos.Move2Center();
                 //vec3 lengths = box.MaxPosition - box.MinPosition;
                 buffer.Create(positions.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < positions.Length; i++)
                     {
                         array[i] = positions[i];
                     }
                 }
                 positionBufferPtr = buffer.GetBufferPtr();
             }
         }
         return(positionBufferPtr);
     }
     else if (bufferName == strColor)
     {
         if (colorBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <float>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
             {
                 float[] normals = model.GetNormals();
                 buffer.Create(normals.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < normals.Length; i++)
                     {
                         array[i] = normals[i];
                     }
                 }
                 colorBufferPtr = buffer.GetBufferPtr();
             }
         }
         return(colorBufferPtr);
     }
     else if (bufferName == strNormal)
     {
         if (normalBufferPtr == null)
         {
             using (var buffer = new VertexAttributeBuffer <float>(varNameInShader, VertexAttributeConfig.Vec3, BufferUsage.StaticDraw))
             {
                 float[] normals = model.GetNormals();
                 buffer.Create(normals.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < normals.Length; i++)
                     {
                         array[i] = normals[i];
                     }
                 }
                 normalBufferPtr = buffer.GetBufferPtr();
             }
         }
         return(normalBufferPtr);
     }
     else
     {
         return(null);
     }
 }