/// <summary> /// Submit something to be drawn /// </summary> /// <param name="shader"></param> /// <param name="vertexArray"></param> /// <param name="transform"></param> public static void Submit(IShader shader, IVertexArray vertexArray, Matrix4x4 transform) { shader.Bind(); shader.SetMat4("u_ViewProjection", sceneData.ViewProjectionMatrix); shader.SetMat4("u_Transform", transform); vertexArray.Bind(); RenderingAPI.DrawIndexed(vertexArray); }
/// <summary> /// Draws a quad using a texture /// </summary> /// <param name="transform"></param> /// <param name="texture"></param> /// <param name="tintColor"></param> /// <param name="tillingFactor"></param> public static void DrawQuad(Transform transform, I2DTexture texture, Vector4 tintColor, float tillingFactor = 1.0f) { rendererData.TextureShader.SetVec4("u_Color", tintColor); rendererData.TextureShader.SetFloat("u_TilingFactor", tillingFactor); texture.Bind(); Matrix4x4 shaderTransform = Matrix4x4.CreateTranslation(transform.Position) * Matrix4x4.CreateScale(transform.Scale.X, transform.Scale.Y, 1.0f); rendererData.TextureShader.SetMat4("u_Transform", shaderTransform); rendererData.QuadVertexArray.Bind(); RenderingAPI.DrawIndexed(rendererData.QuadVertexArray); }
/// <summary> /// Initializes the rendering system /// </summary> /// <exception cref="InitializationException"></exception> internal static void Init() { ProfilerTimer.Profile(() => { if (initialized) { throw new InitializationException("The rendering system is already initialized!"); } RenderingAPI.Init(); Renderer2D.Init(); initialized = true; }); }
/// <summary> /// Draws a quad rotated /// </summary> /// <param name="transform"></param> /// <param name="tintColor"></param> /// <param name="texture"></param> /// <param name="tillingFactor"></param> public static void DrawRotatedQuad(Transform transform, Vector4 tintColor, I2DTexture texture, float tillingFactor = 1.0f) { //If the rotation is only 0, we will call the regular draw quad, to save performance on the rotation calculations if (transform.Rotation == 0.0f) { DrawQuad(transform, texture, tintColor, tillingFactor); return; } rendererData.TextureShader.SetVec4("u_Color", tintColor); rendererData.TextureShader.SetFloat("u_TilingFactor", tillingFactor); texture.Bind(); Matrix4x4 shaderTransform = Matrix4x4.CreateTranslation(transform.Position) * Matrix4x4.CreateRotationZ(transform.Rotation.ToRadian()) * Matrix4x4.CreateScale(transform.Scale.X, transform.Scale.Y, 1.0f); rendererData.TextureShader.SetMat4("u_Transform", shaderTransform); rendererData.QuadVertexArray.Bind(); RenderingAPI.DrawIndexed(rendererData.QuadVertexArray); }