void updateVbo() { myIndexCount = 0; for (int i = 0; i < 8; i++) //addTriangleToVbo is recursive, so only update the roots { addTriangleToVbo(myTris[i]); } myVBO.setData(myVerts, (int)myVertCount); myIBO.setData(myIndex, (int)myIndexCount); }
public RenderCommand debugRender() { if (myVbo == null) { myVbo = new VertexBufferObject <V3>(BufferUsageHint.DynamicDraw); myIbo = new IndexBufferObject(BufferUsageHint.DynamicDraw); } uint vi = 0; uint ii = 0; V3[] verts = new V3[1024 * 1024]; uint[] index = new uint[1024 * 1024 * 2]; myNodes[0].debugRender(ref verts, ref vi, ref index, ref ii); myVbo.setData(verts, (int)vi); myIbo.setData(index, (int)ii); RenderVboCommand cmd = new RenderVboCommand(myVbo, myIbo, Color4.Blue, PrimitiveType.Quads); return(cmd); }
public void generateCommands(ref List <RenderCommand> cmds) { myVbo.setData(myVerts, (int)myVertCount); myIbo.setData(myIndexes, (int)myIndexCount); Matrix4 transform = Matrix4.CreateTranslation(new Vector3(0, myScreenSize.Y, 0)); Matrix4 scale = Matrix4.CreateScale(new Vector3(myScale, -myScale, 1)); myModelMatrix = scale * transform; //sort based on layer depth myCmdBuffer.Sort((a, b) => { int c = a.layer.CompareTo(b.layer); if (c != 0) { return(c); } return(a.index.CompareTo(b.index)); }); foreach (DrawCmd dc in myCmdBuffer) { if (dc.userRenderCommand != null) { cmds.Add(dc.userRenderCommand); } else { if (dc.elementCount > 0) { cmds.Add(new UiRenderCommand(dc, myModelMatrix, myVbo, myIbo)); } } } }
static RenderCubemapSphere() { theOrientation = Matrix4.CreateFromQuaternion(new Quaternion(0f, 0f, 0f)); List <ShaderDescriptor> shadersDesc = new List <ShaderDescriptor>(); shadersDesc.Add(new ShaderDescriptor(ShaderType.VertexShader, "GpuNoise.shaders.cube-vs.glsl")); shadersDesc.Add(new ShaderDescriptor(ShaderType.FragmentShader, "GpuNoise.shaders.cube-ps.glsl")); ShaderProgramDescriptor sd = new ShaderProgramDescriptor(shadersDesc); theShader = Renderer.resourceManager.getResource(sd) as ShaderProgram; theVBO = new VertexBufferObject <V3>(BufferUsageHint.StaticDraw); theIBO = new IndexBufferObject(BufferUsageHint.StaticDraw); int lats = 25; int longs = 25; int vertIdx = 0; V3[] verts = new V3[(lats + 1) * (longs + 1)]; ushort[] index = new ushort[lats * longs * 6]; for (int i = 0; i <= lats; i++) { float theta = (float)i * (float)Math.PI / lats; float sinTheta = (float)Math.Sin(theta); float cosTheta = (float)Math.Cos(theta); for (int j = 0; j <= longs; j++) { float phi = (float)j * (float)(Math.PI * 2) / longs; float sinPhi = (float)Math.Sin(phi); float cosPhi = (float)Math.Cos(phi); float x = cosPhi * sinTheta; float y = sinPhi * sinTheta; float z = cosTheta; // float u = 1 - (j / longs); // float v = 1- (i / lats); V3 temp = new V3(); temp.Position = new Vector3(x, y, z); verts[vertIdx++] = temp; } } int indexIdx = 0; for (int i = 0; i < lats; i++) { for (int j = 0; j < longs; j++) { ushort first = (ushort)((i * (longs + 1)) + j); ushort second = (ushort)(first + longs + 1); index[indexIdx++] = first; index[indexIdx++] = second; index[indexIdx++] = (ushort)(first + 1); index[indexIdx++] = second; index[indexIdx++] = (ushort)(second + 1); index[indexIdx++] = (ushort)(first + 1); } } theVBO.setData(verts); theIBO.setData(index); theVAO = new VertexArrayObject(); theVAO.bindVertexFormat <V3>(theShader); thePipeline = new PipelineState(); thePipeline.shaderState.shaderProgram = theShader; thePipeline.vaoState.vao = theVAO; thePipeline.generateId(); }