public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { ObjVNFMesh mesh = this.mesh; ushort[] values = new ushort[3]; var index = 0; var array = new Face[mesh.faces.Length]; foreach (var face in mesh.faces) { int i = 0; foreach (var vertexIndex in face.VertexIndexes()) { if (vertexIndex > ushort.MaxValue) { throw new Exception(string.Format("Not support model size greater than {0} vertexes!", ushort.MaxValue)); } values[i++] = (ushort)vertexIndex; } array[index++] = new Face(values[0], values[1], values[2]); i = 0; } AdjacentFace[] adjacentFaces = array.CalculateAdjacentFaces(); IndexBuffer buffer = adjacentFaces.GenIndexBuffer(IndexBufferElementType.UShort, BufferUsage.StaticDraw); this.drawCmd = new DrawElementsCmd(buffer, DrawMode.TrianglesAdjacency); } yield return(this.drawCmd); }
/// <summary> /// /// </summary> protected override void DoInitialize() { base.DoInitialize(); IPickableRenderMethod renderUnit = this.pickingRenderUnitBuilder.ToRenderMethod(this.RenderUnit.Model); var pickerList = new List <PickerBase>(); foreach (var vao in renderUnit.VertexArrayObjects) { IDrawCommand cmd = vao.DrawCommand; if (cmd is DrawArraysCmd) //|| cmd is MultiDrawArraysCmd) { //I don't know what will happen during picking if 'overlap' exists in glMultiDrawArrays(..). I don't care either, because that is a problem that should be solved in modeling stage. VertexBuffer positionBuffer = vao.VertexAttributes[0].Buffer; // according to base.DoInitialize(), this is the position buffer of the only vertex attribute. pickerList.Add(new DrawArraysPicker(this, positionBuffer, cmd as DrawArraysCmd)); } else if (cmd is DrawElementsCmd) //|| cmd is MultiDrawElementsCmd) { //I don't know what will happen during picking if 'overlap' exists in glMultiDrawElements(..). I don't care either, because that is a problem that should be solved in modeling stage. VertexBuffer positionBuffer = vao.VertexAttributes[0].Buffer; // according to base.DoInitialize(), this is the position buffer of the only vertex attribute. pickerList.Add(new DrawElementsPicker(this, positionBuffer, cmd as DrawElementsCmd)); } else { throw new NotImplementedException(string.Format("`{0}` is a IDrawCommand type that has not been supported for `IPickable`.", cmd.GetType())); } } this.picker = pickerList.ToArray(); this.PickingRenderUnit = renderUnit; }
public virtual bool Init(YamLikeCommand cmd) { if (cmd.SubCommand == null || cmd.SubCommand.Count == 0) { return(false); } List <IDrawCommand> tmp = new List <IDrawCommand>(); foreach (var c in cmd.SubCommand) { IDrawCommand drawingCmd = CommandDrawingFactoryEx.create(c); if (drawingCmd == null) { continue; } tmp.Add(drawingCmd); } if (tmp.Count == 0) { return(false); } this.Commands.AddRange(tmp); return(true); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { int uCount = GetUCount(interval); int vCount = GetVCount(interval); int length = (uCount + 1) * vCount + (vCount + 1 + 1) * uCount; int index = 0; var array = new uint[length]; // vertical lines. for (int i = 0; i < vCount; i++) { for (int j = 0; j < uCount; j++) { array[index++] = (uint)(i + j * vCount); } array[index++] = uint.MaxValue;// primitive restart index. } // horizontal lines. for (int i = 0; i < uCount; i++) { for (int j = 0; j < vCount; j++) { array[index++] = (uint)(j + i * vCount); } array[index++] = (uint)(0 + i * vCount); array[index++] = uint.MaxValue;// primitive restart index. } IndexBuffer buffer = array.GenIndexBuffer(BufferUsage.StaticDraw); this.drawCmd = new DrawElementsCmd(buffer, DrawMode.LineStrip); } yield return(this.drawCmd); }
/// <summary> /// VAO是用来管理VBO的。可以进一步减少DrawCall。 /// <para>VAO is used to reduce draw-call.</para> /// </summary> /// <param name="drawCommand">index buffer pointer that used to invoke draw command.</param> /// <param name="shaderProgram">shader program that <paramref name="vertexAttributes"/> bind to.</param> /// <param name="vertexAttributes">给出此VAO要管理的所有VBO。<para>All VBOs that are managed by this VAO.</para></param> public VertexArrayObject(IDrawCommand drawCommand, ShaderProgram shaderProgram, params VertexShaderAttribute[] vertexAttributes) { if (drawCommand == null) { throw new ArgumentNullException("drawCommand"); } // Zero vertex attribute is allowed in GLSL. //if (vertexAttributeBuffers == null || vertexAttributeBuffers.Length == 0) //{ // throw new ArgumentNullException("vertexAttributeBuffers"); //} this.DrawCommand = drawCommand; this.VertexAttributes = vertexAttributes; glGenVertexArrays(1, ids); glBindVertexArray(this.Id); // this vertex array object will record all stand-by actions. foreach (var item in vertexAttributes) { VertexBuffer buffer = item.Buffer; buffer.Standby(shaderProgram, item.VarNameInVertexShader); } glBindVertexArray(0); // this vertex array object has recorded all stand-by actions. }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (drawCmd == null) { drawCmd = new DrawArraysCmd(DrawMode.TriangleFan, vertsData.Length); } yield return(drawCmd); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { this.drawCommand = new DrawArraysCmd(DrawMode.Points, count, 0, count); } yield return(this.drawCommand); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { this.drawCmd = new DrawArraysCmd(DrawMode.Triangles, positions.Length); } yield return(this.drawCmd); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { this.drawCommand = new DrawArraysCmd(DrawMode.Points, this.positions.Length); } yield return(this.drawCommand); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { this.drawCommand = new DrawArraysCmd(DrawMode.LineLoop, array.Length); } yield return(this.drawCommand); }
protected override void DoInitialize() { base.DoInitialize(); { string folder = System.Windows.Forms.Application.StartupPath; var bitmap = new Bitmap(System.IO.Path.Combine(folder, @"heightmap.png")); var storage = new TexImageBitmap(bitmap); var texture = new Texture(storage); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT)); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT)); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT)); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR)); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); texture.Initialize(); texture.TextureUnitIndex = 0; bitmap.Dispose(); this.displacementMap = texture; } { string folder = System.Windows.Forms.Application.StartupPath; var bitmap = new Bitmap(System.IO.Path.Combine(folder, @"diffuse.png")); var storage = new TexImageBitmap(bitmap); var texture = new Texture(storage); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT)); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT)); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT)); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR)); texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR)); texture.Initialize(); texture.TextureUnitIndex = 1; bitmap.Dispose(); this.colorMap = texture; } { var light = new DirectionalLight(); light.Color = new vec3(1, 1, 1); light.AmbientIntensity = 1.0f; light.DiffuseIntensity = 0.01f; light.direction = new vec3(1, 1, 0); this.directionalLight = light; } { RenderMethod method = this.RenderUnit.Methods[0]; foreach (var vao in method.VertexArrayObjects) { IDrawCommand cmd = vao.DrawCommand; cmd.Mode = DrawMode.Patches; } var polygonModeState = new PolygonModeState(CSharpGL.PolygonMode.Fill); method.StateList.Add(polygonModeState); this.PolygonMode = polygonModeState; } }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { this.drawCmd = new DrawArraysCmd(DrawMode.Quads, 4); } yield return(this.drawCmd); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { this.drawCommand = new DrawArraysCmd(DrawMode.Patches, 3); } yield return(this.drawCommand); }
private void RenderForPicking(PickingEventArgs arg, ControlMode controlMode, IDrawCommand tmpCmd) { if (!this.IsInitialized) { this.Initialize(); } this.polygonModeState.Mode = arg.GeometryType.GetPolygonMode(); ShaderProgram program = this.PickingRenderUnit.Program; // 绑定shader program.Bind(); { mat4 projection = arg.Scene.Camera.GetProjectionMatrix(); mat4 view = arg.Scene.Camera.GetViewMatrix(); mat4 model = this.GetModelMatrix(); program.glUniform("MVP", projection * view * model); } this.polygonModeState.On(); this.lineWidthState.On(); this.pointSizeState.On(); PrimitiveRestartState restart = null; var hasIndexBuffer = tmpCmd as IHasIndexBuffer; if (hasIndexBuffer != null) { restart = this.GetPrimitiveRestartState(hasIndexBuffer.IndexBufferObject.ElementType); } if (restart != null) { restart.On(); } { var pickable = this as IPickable; uint baseId = pickable.PickingBaseId; foreach (var vao in this.PickingRenderUnit.VertexArrayObjects) { program.glUniform("pickingBaseId", (int)(baseId)); vao.Draw(controlMode, tmpCmd); baseId += (uint)vao.VertexAttributes[0].Buffer.Length; } } if (restart != null) { restart.Off(); } this.pointSizeState.Off(); this.lineWidthState.Off(); this.polygonModeState.Off(); // 解绑shader program.Unbind(); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { IndexBuffer indexBuffer = indexes.GenIndexBuffer(BufferUsage.StaticDraw); this.drawCommand = new DrawElementsCmd(indexBuffer, DrawMode.Quads); } yield return(this.drawCommand); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { int instanceCount = 100;// render 100 instances. this.drawCmd = new DrawArraysInstancedCmd(DrawMode.Triangles, 6, instanceCount); } yield return(this.drawCmd); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.command == null) { int vertexCount = positions.Length; this.command = new DrawArraysCmd(DrawMode.Triangles, vertexCount); } yield return(this.command); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { IndexBuffer buffer = adjacentFaceData.GenIndexBuffer(IndexBufferElementType.UShort, BufferUsage.StaticDraw); this.drawCmd = new DrawElementsCmd(buffer, DrawMode.TrianglesAdjacency); } yield return(this.drawCmd); }
internal virtual void Enqueue(IDrawCommand cmd) { if (!_open) { throw new MononokeGraphicsException("All Draw calls must be executed in the Render events."); } cmd.Graphic = _currentGraphicComponent; _currentGraphicComponent.Entity.Layer.AddDrawCommand(cmd); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { IndexBuffer buffer = cubeIndices.GenIndexBuffer(BufferUsage.StaticDraw); this.drawCmd = new DrawElementsCmd(buffer, DrawMode.Triangles); } yield return(this.drawCmd); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { var indexBuffer = this.section.Indexbuffer.GenIndexBuffer(BufferUsage.StaticDraw); this.drawCommand = new DrawElementsCmd(indexBuffer, DrawMode.Triangles); } yield return(this.drawCommand); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { Face[] faces = Teapot.faceData; IndexBuffer buffer = faces.GenIndexBuffer(IndexBufferElementType.UShort, BufferUsage.StaticDraw); this.drawCmd = new DrawElementsCmd(buffer, DrawMode.Triangles); } yield return(this.drawCmd); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.command == null) { const int firstVertex = 0; const int vertexCount = 3; this.command = new DrawArraysCmd(DrawMode.Triangles, firstVertex, vertexCount); } yield return(this.command); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { // indexes in GPU side. IndexBuffer indexBuffer = indexes.GenIndexBuffer(BufferUsage.StaticDraw); this.drawCommand = new DrawElementsCmd(indexBuffer, DrawMode.Triangles); // GL_TRIANGLES. } yield return(this.drawCommand); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { int uCount = GetUCount(interval); DrawArraysCmd buffer = new DrawArraysCmd(DrawMode.Points, 0, uCount); this.drawCmd = buffer; } yield return(this.drawCmd); }
/// <summary> /// /// </summary> /// <returns></returns> public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { var drawCmd = new DrawArraysCmd(DrawMode.Quads, this.Capacity * 4); // note: use IDrawCommand.Draw(ControlMode.Random) to enable this property. drawCmd.VertexCount = 0; this.drawCmd = drawCmd; } yield return(this.drawCmd); }
public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.command == null) { //IndexBuffer indexBuffer = indexes.GenIndexBuffer(IndexBufferElementType.UShort, BufferUsage.StaticDraw); //this.command = new DrawElementsCmd(indexBuffer, DrawMode.Triangles); IndexBuffer indexBuffer = adjacentIndexes.GenIndexBuffer(IndexBufferElementType.UShort, BufferUsage.StaticDraw); this.command = new DrawElementsCmd(indexBuffer, DrawMode.TrianglesAdjacency); } yield return(this.command); }
/// <summary> /// /// </summary> /// <param name="drawCmd"></param> public void SetTarget(IDrawCommand drawCmd) { if (drawCmd == null) { throw new ArgumentNullException(); } this.controller = drawCmd.CreateController(); UpdateUI(this.controller); this.Text = string.Format("{0}", this.controller); }
/// <summary> /// /// </summary> /// <returns></returns> public IEnumerable <IDrawCommand> GetDrawCommand() { if (this.drawCmd == null) { int primCount = 1; int frameCount = 1; var drawCmd = new DrawArraysCmd(DrawMode.Quads, 0, this.Capacity * 4, primCount, frameCount); // note: use ZeroIndexBuffer.Draw(ControlMode.Random) to enable this property. drawCmd.RenderingVertexCount = 0; this.drawCmd = drawCmd; } yield return(this.drawCmd); }
/// <summary> /// 执行一次渲染的过程。 /// <para>Execute rendering command.</para> /// </summary> /// <param name="tmpDrawCommand">render by a temporary index buffer</param> public void Draw(IDrawCommand tmpDrawCommand = null) { this.Bind(); if (tmpDrawCommand != null) { tmpDrawCommand.Draw(); } else { this.DrawCommand.Draw(); } this.Unbind(); }