public ChunkCloudRender(Transform transformParent) { isReady = false; _cullType = CullFaceMode.Front; transform = new Transform(); transform.Position = new Vector3(transformParent.Position.X, 50, transformParent.Position.Z); transform.Rotation = new Quaternion(MathHelper.DegreesToRadians(90), 0, 0, 1); transform.Size = new Vector3(10, 10, 1); C_shader = AssetsManager.GetShader("Cloud"); C_texture = AssetsManager.GetTexture("Cloud"); CreteCloudMesh(); if (mesh != null) { if (C_shader != null) { C_shader.Use(); } C_VAO = GL.GenVertexArray(); C_IBO = GL.GenBuffer(); C_vbo = GL.GenBuffer(); C_tbo = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ElementArrayBuffer, C_IBO); GL.BufferData(BufferTarget.ElementArrayBuffer, mesh._indices.Length * sizeof(int), mesh._indices, BufferUsageHint.StaticDraw); GL.BindVertexArray(C_VAO); GL.BindBuffer(BufferTarget.ArrayBuffer, C_vbo); GL.BufferData(BufferTarget.ArrayBuffer, mesh._vertices.Length * Vector3.SizeInBytes, mesh._vertices, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(0); //Texture GL.BindBuffer(BufferTarget.ArrayBuffer, C_tbo); GL.BufferData(BufferTarget.ArrayBuffer, mesh._texCoords.Length * Vector2.SizeInBytes, mesh._texCoords, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(1); TickSystem.AddRenderItem(this); isReady = true; } }
private void SetUpGL() { _cullType = CullFaceMode.Front; IBO = GL.GenBuffer(); VAO = GL.GenVertexArray(); vbo = GL.GenBuffer(); dbo = GL.GenBuffer(); tbo = GL.GenBuffer(); nbo = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBO); GL.BufferData(BufferTarget.ElementArrayBuffer, AssetsManager.GetMesh(_mesh)._indices.Length *sizeof(int), AssetsManager.GetMesh(_mesh)._indices, BufferUsageHint.StaticDraw); GL.BindVertexArray(VAO); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); GL.BufferData(BufferTarget.ArrayBuffer, AssetsManager.GetMesh(_mesh)._vertices.Length *Vector3.SizeInBytes, AssetsManager.GetMesh(_mesh)._vertices, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(0); //Colors GL.BindBuffer(BufferTarget.ArrayBuffer, dbo); GL.BufferData(BufferTarget.ArrayBuffer, AssetsManager.GetMesh(_mesh)._Colors.Length *sizeof(float), AssetsManager.GetMesh(_mesh)._Colors, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(1); //Texture GL.BindBuffer(BufferTarget.ArrayBuffer, tbo); GL.BufferData(BufferTarget.ArrayBuffer, AssetsManager.GetMesh(_mesh)._texCoords.Length *Vector2.SizeInBytes, AssetsManager.GetMesh(_mesh)._texCoords, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(2); GL.BindBuffer(BufferTarget.ArrayBuffer, nbo); GL.BufferData(BufferTarget.ArrayBuffer, AssetsManager.GetMesh(_mesh)._Normals.Length *Vector3.SizeInBytes, AssetsManager.GetMesh(_mesh)._Normals, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(3); TickSystem.AddRenderItem(this); }
public ChunkMeshRender(Transform transformParent, Mesh mesh, Shader shader, Texture texture) { isReady = false; _cullType = CullFaceMode.Front; transform = transformParent; _Mesh = new Mesh(mesh); if (_Mesh != null) { _shader = shader; _texture = texture; shader.SetInt("texture0", 0); /*if (_shader != null) * { * _shader.Use(); * }*/ IndiceLength = _Mesh._indices.Length; IBO = GL.GenBuffer(); VAO = GL.GenVertexArray(); vbo = GL.GenBuffer(); dbo = GL.GenBuffer(); tbo = GL.GenBuffer(); nbo = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBO); GL.BufferData(BufferTarget.ElementArrayBuffer, _Mesh._indices.Length * sizeof(int), _Mesh._indices, BufferUsageHint.StreamDraw); GL.BindVertexArray(VAO); //Vertices(Vector3) GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); GL.BufferData(BufferTarget.ArrayBuffer, _Mesh._vertices.Length * Vector3.SizeInBytes, _Mesh._vertices, BufferUsageHint.StreamDraw); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(0); //Colors(Vectro4|Color) GL.BindBuffer(BufferTarget.ArrayBuffer, dbo); GL.BufferData(BufferTarget.ArrayBuffer, _Mesh._Colors.Length * Vector4.SizeInBytes, _Mesh._Colors, BufferUsageHint.StreamDraw); GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(1); //Texture(Vector2) GL.BindBuffer(BufferTarget.ArrayBuffer, tbo); GL.BufferData(BufferTarget.ArrayBuffer, _Mesh._texCoords.Length * Vector2.SizeInBytes, _Mesh._texCoords, BufferUsageHint.StreamDraw); GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(2); //Mesh Normals(Vector3) GL.BindBuffer(BufferTarget.ArrayBuffer, nbo); GL.BufferData(BufferTarget.ArrayBuffer, _Mesh._Normals.Length * Vector3.SizeInBytes, _Mesh._Normals, BufferUsageHint.StreamDraw); GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(3); isReady = true; TickSystem.AddRenderItem(this); } }