private VertexBuffer GetPositionBuffer(string varNameInShader)
{
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, varNameInShader, 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;
}