/// <summary> /// internal. /// </summary> /// <param name="Device"></param> /// <param name="A"></param> public static void drawArrayLined(OpenGlDevice Device, xyArray A) { if (Entity.Compiling) { PolygonMode P = Device.PolygonMode; MeshCreator.MeshdrawLined(Device, A); Device.PolygonMode = P; return; } if (Device.RenderKind == RenderKind.SnapBuffer) { MeshCreator.MeshdrawLined(Device, A); return; } int MPosition = Device.Shader.Position.handle; if (MPosition >= 0) { GL.EnableVertexAttribArray(MPosition); xyf[] Array = (A.ToFloatArray()); GL.VertexAttribPointer(MPosition, 2, VertexAttribPointerType.Float, false, 0, ref Array[0].x); GL.DrawArrays(PrimitiveType.LineStrip, 0, Array.Length); GL.DisableVertexAttribArray(MPosition); } }
/// <summary> /// compiles the <see cref="DrawAction"/> draw and returns a meshContainer. /// The <b>progs</b> of this is a list of <see cref="Mesh"/>. /// This method is called from <see cref="Entity.Compile(OpenGlDevice)"/>. /// </summary> /// <param name="Device"><see cref="OpenGlDevice"/> in which will be drawn.</param> /// <param name="Draw">the <see cref="DrawAction"/>, which is used to produce a <see cref="MeshContainer"/></param> /// <returns></returns> public static MeshContainer Compile(OpenGlDevice Device, DrawAction Draw) { Device.PushMatrix(); MeshListCurrent = new MeshContainer(); bool Compiling = Entity.Compiling; if (Compiling) { MeshCreator.Push(); } bool SaveCompiling = Entity.Compiling; Entity.Compiling = true; RenderKind SaveRenderKind = Device.RenderKind; Device.RenderKind = RenderKind.Render; MeshIndices.Clear(); Draw(Device); Renew(); Entity.Compiling = SaveCompiling; Device.RenderKind = SaveRenderKind; Device.PopMatrix(); MeshContainer Result = MeshListCurrent; if (Compiling) { MeshCreator.Pop(); } return(Result); }
/// <summary> /// internal. /// </summary> internal static void MeshdrawTriangles2d(OpenGlDevice Device, List <IndexType> Indices, xyf[] Points, xyf[] Texture) { float dir = 1; for (int i = 0; i < Indices.Count; i += 3) { xy A = new xy(Points[Indices[i + 1]].x - Points[Indices[i]].x, Points[Indices[i + 1]].y - Points[Indices[i]].y); xy B = new xy(Points[Indices[i + 2]].x - Points[Indices[i]].x, Points[Indices[i + 2]].y - Points[Indices[i]].y); double F = A & B; if (System.Math.Abs(F) > 0.0001) { if (F < 0) { dir = 1; } else { dir = -1; } break; } } int ID = MeshVertices.Count; for (int i = 0; i < Indices.Count; i++) { MeshIndices.Add((IndexType)(Indices[i] + ID)); } if (MeshVertices.Count + Points.Length > IndexType.MaxValue) { int CT = (MeshVertices.Count + Points.Length); MeshIndices = new List <IndexType>(); Renew(); throw new Exception("Points count to large " + CT.ToString()); } for (int i = 0; i < Points.Length; i++) { MeshVertices.Add(Device.ModelMatrix * new xyz(Points[i].x, Points[i].y, 0).toXYZF()); } xyzf NP = Device.ModelMatrix * new xyzf(0, 0, 0); xyzf N = Device.ModelMatrix * new xyzf(0, 0, dir) - NP; for (int i = 0; i < Points.Length; i++) { MeshNormals.Add(N); } if (Texture != null) { MeshTextureCoords.AddRange(Texture); } MeshMode = PolygonMode.Fill; if (Entity.Compiling) { if (Device.RenderKind == RenderKind.SnapBuffer) { MeshCreator.Renew(); } } }
/// <summary> /// Internal. /// </summary> internal static void CheckCompiling() { if (Entity.Compiling) { MeshCreator.CheckMeshCreator(); } }
private void setTexture(Texture value) { int Active = GL.GetInteger(GetPName.TextureBinding2D); if (RenderKind == Drawing3d.RenderKind.SnapBuffer) { return; } //if (value == _texture) // return; if (Entity.Compiling) { if (MeshCreator.HasTexture) { MeshCreator.Renew(); } MeshCreator.Texture = value; } _texture = value; if ((value == null)) { GL.BindTexture(TextureTarget.Texture2D, 0); GL.Disable(EnableCap.Texture2D); if (Shader != null) { Field C = Shader.getvar("Texture0Enabled"); if (C != null) { C.SetValue(0); } C = Shader.getvar("Texture1Enabled"); if (C != null) { C.SetValue(0); } } return; } if ((value.Handle == 0) && (value.Bitmap == null)) { return; } if (value.Handle == 0) { GL.ActiveTexture(TextureUnit.Texture0 + value.Index); RegisterTexture(value); GL.ActiveTexture(TextureUnit.Texture0); } if ((Shader != null) && (Shader.Using)) { value.SetAttributes(Shader); } }
/// <summary> /// internal. /// </summary> internal static void MeshPaintEntity(OpenGlDevice Device, Entity Entity) { MeshCreator.Renew(); Entity._Ondraw(Device); for (int i = 0; i < Entity.Children.Count; i++) { MeshPaintEntity(Device, Entity.Children[i]); } }
private void drawLetter(Font F, byte b, String s, xyz Start, int iD, OpenGlDevice Device) { if (F.Compiled[b] == null) { CompileChar = b; CompileFont = F; MeshCreator.Push(); bool SaveRegSnap = Selector.RegisterSnap; Selector.RegisterSnap = false; F.Compiled[b] = MeshCreator.Compile(this, Compiledraw); Selector.RegisterSnap = SaveRegSnap; MeshCreator.Pop(); } if (F.Compiled[b] == null) { throw new Exception("Compile error of " + (char)(b)); } if (RenderKind == RenderKind.SnapBuffer) { Object Handle = null; if ((RenderKind == RenderKind.SnapBuffer)) { Handle = Selector.RegisterSnapItem(new TextSnappItem(F, s, iD, Start, ModelMatrix * new xyz(0, 0, 0))); if (F.GlyphInfo[b].BlackBoxY < 0.1) // blank { drawBox(new xyz(0, 0, 0), new xyz(F.GlyphInfo[b].Deltax, 1, 1)); } else { drawBox(new xyz(0, 0, 0), new xyz(F.GlyphInfo[b].Deltax, F.GlyphInfo[b].BlackBoxY, 1)); } if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } } return; } if (Entity.Compiling) { MeshContainer M = F.Compiled[b] as MeshContainer; for (int i = 0; i < M.Progs.Count; i++) { Mesh E = (M.Progs[i] as Mesh).Clone() as Mesh; E.Transform(ModelMatrix); MeshCreator.MeshListCurrent.Progs.Add(E); } return; } F.Compiled[b].Paint(this); }
/// <summary> /// compiles ato an entiy. The draw method describes outfit. /// </summary> /// <param name="Draw">Method, which drsws some thing.</param> /// <returns></returns> public Entity Compile(DrawAction Draw) { bool SaveCompiling = Entity.Compiling; Entity.Compiling = true; Entity Result = MeshCreator.Compile(this, Draw); Entity.Compiling = SaveCompiling; return(Result); }
private void CheckCompiling(Color value, ref Color MaterialColor) { if (Entity.Compiling) { if (MeshCreator.Material.Emission != value) { MeshCreator.Renew(); MeshCreator.Material = FMaterial; } } }
/// <summary> /// is the main method of this object. See also <see cref="Entity.CompileDraw(OpenGlDevice)"/>. /// </summary> /// <param name="Device">Device in which it willl be compiled.</param> /// <param name="Draw">a event, which holds the drawings.</param> public static MeshContainer CreateMeshes(OpenGlDevice Device, DrawAction Draw) { // sollte nur von compilesnapbuffer aufgerufen werden !!!! und erstellt die triangles bool Compiling = Entity.Compiling; if (Compiling) { MeshCreator.Push(); } bool SaveCompiling = Entity.Compiling; // Entity.Compiling = true; // Checken braucht es wegen line snap if (Selector.StoredSnapItems.Count == 0) { Selector.StoredSnapItems.Add(null); // braucht es nicht } MeshListCurrent = new MeshContainer(); // braucht es nicht MeshIndices.Clear(); // braucht es wahrscheinlich nicht RenderKind R = Device.RenderKind;// wieder heraus Draw(Device); Renew(); Device.RenderKind = R; Entity.Compiling = SaveCompiling; MeshContainer Result = MeshListCurrent; // MeshListCurrent.MySnapItem = new MeshSnapItem(MeshListCurrent); Device.RenderKind = RenderKind.SnapBuffer; TriangleList TL = new TriangleList(); for (int i = 0; i < MeshListCurrent.Progs.Count; i++) { if (MeshListCurrent.Progs[i] is Mesh) { Mesh M = MeshListCurrent.Progs[i] as Mesh; M.getTriangles(TL); } } TriangleArrays TA = TL.ToArrays(); Device.RenderKind = R; if (Compiling) { MeshCreator.Pop(); } return(Result); }
MeshContainer DoCompile(OpenGlDevice Device) { Device.PushMatrix(); Device.ModelMatrix = Matrix.identity; if (Mesh != null) { Mesh.Dispose(); } MeshContainer M = MeshCreator.Compile(Device, CompileDraw); Device.PopMatrix(); return(M); }
void _drawPolyPolyCurve(Loxy L, Loca Loca, int id) { Object Handle = null; if (PolygonMode == PolygonMode.Fill) { if ((RenderKind == RenderKind.SnapBuffer)) { Handle = Selector.RegisterSnapItem(getSI(id, Loca, L, -1)); } drawFilledArray2d(this, L); if ((RenderKind == RenderKind.SnapBuffer)) { MeshCreator.Renew(); Selector.UnRegisterSnapItem(Handle); } return; } if ((RenderKind == RenderKind.SnapBuffer)) { SnappItem S = (getSI(id, Loca, L, -1)); Handle = Selector.RegisterSnapItem(S); } { for (int i = 0; i < L.Count; i++) { //IndexType[] Indices = new IndexType[L[i].Count]; //for (int k = 0;k < L[i].Count; k++) //{ // Indices[k] = k; //} //xyzf[] Points = new xyzf[L[i].Count]; //for (int k = 0; k < L[i].Count; k++) //{ // Points[k] = new xyzf((float)L[i][k].X, (float)L[i][k].y, 0f); //} //Primitives3d.drawTriangles(this,Indices, Points, null, null, null); ////if ((RenderKind == RenderKind.SnapBuffer)) //// Selector.ToSnapBuffer((uint)i); Primitives2d.drawArrayLined(this, L[i]); } } if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } }
private void setEmission(Color value) { FMaterial.Emission = value; if (Entity.Compiling) { if (MeshCreator.HasEmission) { MeshCreator.Renew(); } MeshCreator.Emission = value; } else if ((Shader != null) && (Shader.Using)) { Field A = Shader.getvar("Emission"); if (A != null) { A.Update(); } } }
/// <summary> /// internal. /// </summary> internal static void MeshdrawLined(OpenGlDevice Device, xyzf[] A) { int ID = MeshVertices.Count; for (int i = 0; i < A.Length; i++) { MeshIndices.Add((IndexType)(i + ID)); } for (int i = 0; i < A.Length; i++) { MeshVertices.Add(((Device.ModelMatrix * A[i]))); } // MeshVertices.Add((( A[i]))); MeshMode = PolygonMode.Line; if (Entity.Compiling) { if (Device.RenderKind == RenderKind.SnapBuffer) { MeshCreator.Renew(); } } }
/// <summary> /// internal. /// </summary> internal static void MeshdrawLined(OpenGlDevice Device, xyzArray A) { PolygonMode Save = Device.PolygonMode; int ID = MeshVertices.Count; for (int i = 0; i < A.Count; i++) { MeshIndices.Add((IndexType)(i + ID)); } for (int i = 0; i < A.Count; i++) { MeshVertices.Add(((Device.ModelMatrix * A[i]).toXYZF())); } MeshMode = PolygonMode.Line; Device._PolygonMode = Save; // verursacht ein renew falls fill MeshCreator.Renew(); if (Entity.Compiling) { if (Device.RenderKind == RenderKind.SnapBuffer) { MeshCreator.Renew(); } } }
/// <summary> /// overrides the draw method . /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { int StoredObject = -1; if (Selector.WriteToSnap) { CompiledMesh C = this as CompiledMesh; if (C != null) { StoredObject = C.SnapObject; } Device.Selector.SetObjectNumber(StoredObject); } Entity.CurrentEntity = this; if (Compiling) { MeshCreator.AddProg(this); return; } float PW = Device.PenWidth; PenStyles PS = Device.PenStyle; Material Save = Device.Material; if (Mode == PolygonMode.Line) { Device.PenWidth = PenWidth; Device.PenStyle = PenStyle; Device.Emission = PenColor; } else { Device.Material = Material; } PolygonMode SavePolygonMode = Device.PolygonMode; Device.PolygonMode = Mode; if ((VAO >= 0) && (Device.RenderKind == RenderKind.Render)) { OpenGlDevice.CheckError(); Field C = null; if (Colors != null) { C = Device.Shader.getvar("ColorEnabled"); if (C != null) { C.SetValue(1); } } GL.BindVertexArray(VAO); if (!TesselateOn) { GL.DrawElements(Primitives, VBOIndices.IndexArray.Length, DrawElementsType.UnsignedInt, 0); OpenGlDevice.CheckError(); } else { GLShader SaveShader = Device.Shader; Device.Shader = Device.TesselationtShader; if (FieldResolutionFactor == null) { FieldResolutionFactor = Device.Shader.getvar("ResolutionFactor"); } if (FieldDispFactor == null) { FieldDispFactor = Device.Shader.getvar("gDispFactor"); } if (FieldEyePos == null) { FieldEyePos = Device.Shader.getvar("gEyeWorldPos"); } if (FieldDispFactor != null) { FieldDispFactor.SetValue((float)TessDispFactor); } if (FieldEyePos != null) { FieldEyePos.SetValue(Device.Camera.Position); } Device.texture = TessDisplacementMap; //GL.ActiveTexture(TextureUnit.Texture0 + 1); //GL.BindTexture(TextureTarget.Texture2D, TessDisplacementMap.Handle); if (Texture != null) { Device.texture = Texture; } if (FieldResolutionFactor != null) { FieldResolutionFactor.SetValue((float)TessResolutionFactor); } GL.DrawElements(BeginMode.Patches, VBOIndices.IndexArray.Length, DrawElementsType.UnsignedInt, 0); TessDisplacementMap.Hide(); Device.Shader = SaveShader; Device.texture = null; } GL.BindVertexArray(0); if (Colors != null) { if (C != null) { C.SetValue(0); } } } else { if (Primitives == BeginMode.Quads) { DrawQuads(Device); } else { Texture SaveTexture = Device.texture; Device.texture = Texture; Device.drawMesh(Indices, VBOPosition.xyzPoints, VBONormals.xyzPoints, VBOTexture.xyPoints, VBOColors.xyzPoints); Device.texture = SaveTexture; } } Device.PolygonMode = SavePolygonMode; if (Mode == PolygonMode.Line) { Device.PenWidth = PW; Device.PenStyle = PS; Device.Emission = Color.Black; } Device.Material = Save; }
void DrawQuads(OpenGlDevice Device) { object SnapHandle = null; if (Device.RenderKind == RenderKind.SnapBuffer) { MeshSnappItem SI = new MeshSnappItem(this); SnapHandle = Device.Selector.RegisterSnapItem(SI); MeshCreator.MeshdrawTriangles(Device, QuadsToTriangle(Indices), Position, Normals, TextureCoords); } int MPosition = Device.Shader.Position.handle; if (MPosition >= 0) { GL.EnableVertexAttribArray(MPosition); } GL.VertexAttribPointer(MPosition, 3, VertexAttribPointerType.Float, false, 0, ref Position[0]); int THandle = Device.Shader.Texture.handle; if ((THandle >= 0) && (Texture != null)) { GL.EnableVertexAttribArray(THandle); } int NHandle = Device.Shader.Normal.handle; if ((NHandle >= 0) && (Normals != null)) { GL.EnableVertexAttribArray(NHandle); } Field C = Device.Shader.getvar("ColorEnabled"); if (C != null) { C.SetValue(0); } int CHandle = Device.Shader.Color.handle; if ((CHandle >= 0) && (Colors != null)) { if (C != null) { C.SetValue(1); } GL.EnableVertexAttribArray(CHandle); } if ((MPosition >= 0) && (Position.Length > 0)) { GL.VertexAttribPointer(MPosition, 3, VertexAttribPointerType.Float, false, 0, ref Position[0].x); if ((Colors != null) && (Colors.Length == Position.Length) && (CHandle >= 0)) { GL.VertexAttribPointer(CHandle, 3, VertexAttribPointerType.Float, false, 0, ref Colors[0].x); } if ((Texture != null) && (TextureCoords.Length > 0) && (THandle >= 0)) { GL.VertexAttribPointer(THandle, 2, VertexAttribPointerType.Float, false, 0, ref TextureCoords[0].x); } if ((NHandle >= 0) && (Normals != null) && (Normals.Length == Position.Length)) { GL.VertexAttribPointer(NHandle, 3, VertexAttribPointerType.Float, false, 0, ref Normals[0].x); } } // Draw: GL.DrawElements(PrimitiveType.Quads, Indices.Length, DrawElementsType.UnsignedInt, ref Indices[0]); OpenGlDevice.CheckError(); // Attribute freigeben if (MPosition >= 0) { GL.DisableVertexAttribArray(MPosition); } if (NHandle >= 0) { GL.DisableVertexAttribArray(NHandle); } if ((THandle >= 0)) { GL.DisableVertexAttribArray(THandle); } if ((CHandle >= 0)) { GL.DisableVertexAttribArray(CHandle); } if (C != null) { C.SetValue(0); } if (Device.RenderKind == RenderKind.SnapBuffer) { Device.Selector.UnRegisterSnapItem(SnapHandle); } }
/// <summary> /// calls recursively the <see cref="CustomEntity.OnDraw(OpenGlDevice)"/>method of the members in the <see cref="Children"/>list. /// </summary> /// <param name="Device"></param> public void Paint(OpenGlDevice Device) { if ((!Visible) && (Device.RenderKind != RenderKind.SnapBuffer)) { return; } double SaveOpacity = Device.Translucent; OpenGlDevice.CheckError(); if (Device.RenderKind == RenderKind.Render) { if ((Pattern != null) && (Texture == null)) { Texture = GetPatternTexture(Device);// ActivatePattern(Device); } } OpenGlDevice.CheckError(); Entity SaveCurrent = CurrentEntity; if (HasTexture) { Device.texture = Texture; } if (HasMaterial) { Device.Material = Material; } if (HasOpacity) { Device.Translucent = System.Math.Min(Opacity, Device.Translucent); } CurrentEntity = this; if (Device.OutFitChanged) { setMesh(null); } if (Device.RenderKind == RenderKind.Render) { if (Invalid) { Device.invalid = true; } } if (((Mesh == null) || (Invalid)) && (CompileEnable) && (!Compiling) && (Device.RenderKind == RenderKind.Render)) { Compile(Device); // sollte nicht bei refreshSnapBuffer auf gerufen werden } Invalid = false; if (Device.Selector.CreateSnap) // kommt vonRefreshMeshBuffer { if (SnappEnable) { MeshCreator.CreateMeshes(Device, CompileMeshDraw); // Entity wird gedrawt im snap items mode } return; // eventuell Children interndraw braucht nicht aufgerufen werden!!! } if (HasTransformation) { Device.PushMatrix(); Device.MulMatrix(Transformation); } if ((Mesh != null))// && (Device.RenderKind == RenderKind.Render)) { Mesh.internDraw(Device); base.OnDraw(Device); } else { if (Mesh != null) { Mesh.Paint(Device); } else { internDraw(Device); // bei snap wird im createsnap registriert } } if (Mesh == null) { for (int i = 0; i < Children.Count; i++) { if (Children[i].Visible) { Children[i].Paint(Device); } } } CurrentEntity = SaveCurrent; if (HasTransformation) { Device.PopMatrix(); } if (HasOpacity) { Device.Translucent = SaveOpacity; } if (Entity.Compiling) { MeshCreator.CheckMeshCreator(); } OpenGlDevice.CheckError(); if (Device.RenderKind == RenderKind.Render) { Invalid = false; } }
/// <summary> /// overrides the <b>Compile</b> method. /// </summary> /// <param name="Device">device, in which it will be drawn.</param> public override void Compile(OpenGlDevice Device) { setMesh(MeshCreator.CreateMeshes(Device, _Ondraw)); }