public static void DrawStudConnector(Matrix4 transform, LDDModder.LDD.Primitives.Connectors.Custom2DFieldConnector connector) { bool wasTexEnabled = GL.IsEnabled(EnableCap.Texture2D); GL.Enable(EnableCap.Texture2D); //GL.DepthMask(false); StudConnectionShader.Use(); StudConnectionShader.ModelMatrix.Set(transform); var cellSize = new Vector2(0.8f) * new Vector2(connector.StudWidth, connector.StudHeight); cellSize.X /= connector.ArrayWidth; cellSize.Y /= connector.ArrayHeight; StudConnectionShader.CellSize.Set(cellSize); StudConnectionShader.IsMale.Set(connector.SubType == 23); TextureManager.StudGridTexture.Bind(TextureUnit.Texture5); StudConnectionShader.Texture.Set(TextureUnit.Texture5); var items = new List <StudGridCell>(); for (int y = 0; y < connector.ArrayHeight; y++) { for (int x = 0; x < connector.ArrayWidth; x++) { var node = connector[x, y]; items.Add(new StudGridCell() { Position = new Vector3(x, y, 0), Values = new Vector3(node.Value1, node.Value2, node.Value3) }); } } var gridBuffer = new Buffer <StudGridCell>(); gridBuffer.Init(BufferTarget.ArrayBuffer, items.ToArray()); var vao = new VertexArray(); vao.Bind(); vao.BindAttribute(StudConnectionShader.Position, gridBuffer, 0); vao.BindAttribute(StudConnectionShader.Values, gridBuffer, 12); vao.DrawArrays(PrimitiveType.Points, 0, items.Count); vao.UnbindAttribute(StudConnectionShader.Position); vao.UnbindAttribute(StudConnectionShader.Values); gridBuffer.Dispose(); vao.Dispose(); StudConnectionShader.Texture.Set(TextureUnit.Texture0); TextureManager.StudGridTexture.Bind(TextureUnit.Texture0); //GL.DepthMask(true); if (!wasTexEnabled) { GL.Disable(EnableCap.Texture2D); } }
public static void ReleaseResources() { if (ColorShader != null) { ColorShader.Dispose(); ColorShader = null; } if (WireframeShader != null) { WireframeShader.Dispose(); WireframeShader = null; } if (WireframeShader2 != null) { WireframeShader2.Dispose(); WireframeShader2 = null; } if (ModelShader != null) { ModelShader.Dispose(); ModelShader = null; } if (BoundingBoxBufffer != null) { BoundingBoxBufffer.Dispose(); BoundingBoxBufffer = null; } if (StudConnectionShader != null) { StudConnectionShader.Dispose(); StudConnectionShader = null; } if (SimpleTextureShader != null) { SimpleTextureShader.Dispose(); SimpleTextureShader = null; } }
public static void InitializeMatrices(Camera camera) { var viewMatrix = camera.GetViewMatrix(); var projection = camera.GetProjectionMatrix(); WireframeShader.Use(); WireframeShader.ViewMatrix.Set(viewMatrix); WireframeShader.Projection.Set(projection); WireframeShader2.Use(); WireframeShader2.ViewMatrix.Set(viewMatrix); WireframeShader2.Projection.Set(projection); ColorShader.Use(); ColorShader.ViewMatrix.Set(viewMatrix); ColorShader.Projection.Set(projection); ModelShader.Use(); ModelShader.ViewMatrix.Set(viewMatrix); ModelShader.Projection.Set(projection); ModelShader.ViewPosition.Set(camera.Position); StudConnectionShader.Use(); StudConnectionShader.ViewMatrix.Set(viewMatrix); StudConnectionShader.Projection.Set(projection); SimpleTextureShader.Use(); SimpleTextureShader.ViewMatrix.Set(viewMatrix); SimpleTextureShader.Projection.Set(projection); if (UIRenderHelper.Freetype6Loaded) { UIRenderHelper.TextRenderer.ProjectionMatrix = projection; UIRenderHelper.TextRenderer.DrawingPrimitives.Clear(); } TextViewMatrix = viewMatrix; GL.UseProgram(0); }