public void DrawToDynamicQueue(ref CoordinateSpace target, ref FillType type, ref Colour colour, ref Vertex2D[] vertices, ref int[] indices, ref ulong texture0, ref ulong texture1, ref TextureCoordinateMode texMode0, ref TextureCoordinateMode texMode1, ref float depth, ref int layer, bool validate = false) { AddToQueue(_queues.DynamicQueue.Queue, ref target, ref type, ref colour, ref vertices, ref indices, ref texture0, ref texture1, ref texMode0, ref texMode1, ref depth, ref layer, ref validate); }
private Sampler GenerateTextureSampler(TextureCoordinateMode texCoordMode, SamplerFilter samplerFilter) { //Default to linear if not supported if (samplerFilter == SamplerFilter.Anisotropic && !_components.Device.SamplerAnisotropy) { samplerFilter = SamplerFilter.MinLinear_MagLinear_MipLinear; } SamplerAddressMode samplerAddressMode = SamplerAddressMode.Wrap; switch (texCoordMode) { case TextureCoordinateMode.Mirror: samplerAddressMode = SamplerAddressMode.Mirror; break; case TextureCoordinateMode.Wrap: samplerAddressMode = SamplerAddressMode.Wrap; break; } return(_components.Factory.CreateSampler(new SamplerDescription( samplerAddressMode, samplerAddressMode, samplerAddressMode, samplerFilter, null, MAXIMUM_ANISTROPHY, 0, 0, 0, SamplerBorderColor.TransparentBlack ))); }
public void Draw(ulong stage, CoordinateSpace target, FillType type, Vertex2D[] vertices, int[] indices, Colour colour, ulong texture0, ulong texture1, TextureCoordinateMode texWrap0, TextureCoordinateMode texWrap1, float depth, int layer, bool validate = false) { var request = new DrawRequest { CoordinateSpace = target, FillType = type, Vertices = vertices, Indices = indices, Colour = colour, Texture0 = WrapTextureId(texture0), Texture1 = WrapTextureId(texture1), TextureWrap0 = texWrap0, TextureWrap1 = texWrap1, Depth = depth, Layer = layer }; Draw(stage, ref request, validate); }
public void DrawDistortion(ulong stage, CoordinateSpace target, FillType type, Vertex2D[] vertices, int[] indices, Colour colour, ulong texture0, ulong texture1, TextureCoordinateMode texWrap0, TextureCoordinateMode texWrap1, float intensity, bool validate = false) { var request = new DistortionDrawRequest { CoordinateSpace = target, FillType = type, Vertices = vertices, Indices = indices, Colour = new Colour(colour.R * intensity, colour.G * intensity, colour.B * intensity, colour.A * intensity), Texture0 = WrapTextureId(texture0), Texture1 = WrapTextureId(texture1), TextureWrap0 = texWrap0, TextureWrap1 = texWrap1 }; DrawDistortion(stage, ref request, validate); }
/// <summary> /// Descriptor for Texturing Brush /// </summary> /// <param name="texture">Texture Reference</param> /// <param name="textureMode">Wrap Texture Coordinates - Mirror or Repeat</param> /// <param name="textureScaling">Is the Texture tiled or stretched across the shape</param> /// <param name="tilingScale">When tiling, ratio between shape pixel and texture pixel sizes</param> public TextureBrush(ITexture texture, TextureCoordinateMode textureMode, TextureScaling textureScaling, Vector2 tilingScale) { Texture = texture; TextureMode = textureMode; TextureScaling = textureScaling; TilingScale = tilingScale; }
private void ConsumeNextRequest(int queue, IDrawQueue[] rawQs, int[] nextRequestToConsume, int[] indexCounter, ref ulong tex0, ref bool hastex0, ref TextureCoordinateMode tMode0, ref ulong tex1, ref bool hastex1, ref TextureCoordinateMode tMode1, bool[] activeQueuesOverAllLayers) { var currentQueueNextIndex = rawQs[queue].Data.Ordering[nextRequestToConsume[queue]]; var cTex0 = rawQs[queue].Data.Texture0[currentQueueNextIndex]; var cTex1 = rawQs[queue].Data.Texture1[currentQueueNextIndex]; if (!hastex0) { tMode0 = rawQs[queue].Data.TextureMode0[currentQueueNextIndex]; } if (!hastex1) { tMode1 = rawQs[queue].Data.TextureMode1[currentQueueNextIndex]; } if (cTex0 != 0UL) { tex0 = cTex0; hastex0 = true; } if (cTex1 != 0UL) { tex1 = cTex1; hastex1 = true; } var numIndicesInRequest = rawQs[queue].Data.NumIndices[currentQueueNextIndex]; indexCounter[queue] += numIndicesInRequest; //Advance next request to consume and ensure has not reached the end of the Queue nextRequestToConsume[queue]++; if (nextRequestToConsume[queue] >= rawQs[queue].Data.NumRequests) { //Shut this queue down activeQueuesOverAllLayers[queue] = false; } }
private void AddToQueue(IDrawQueue queue, ref CoordinateSpace target, ref FillType type, ref Colour colour, ref Vertex2D[] vertices, ref int[] indices, ref ulong texture0, ref ulong texture1, ref TextureCoordinateMode texMode0, ref TextureCoordinateMode texMode1, ref float depth, ref int layer, ref bool validate) { if (validate) { var success = queue.AddIfValid(ref target, ref type, ref colour, ref vertices, ref indices, ref texture0, ref texture1, ref texMode0, ref texMode1, ref depth, ref layer); if (!success) { throw new Yak2DException("Add draw request to dynamic draw queue queue failed. Request validation failed. Reason written to debug output"); } } else { queue.Add(ref target, ref type, ref colour, ref vertices, ref indices, ref texture0, ref texture1, ref texMode0, ref texMode1, ref depth, ref layer); } _stageIsSortedAndProcessed = false; }
public void DrawTexturedQuad(ulong drawStage, CoordinateSpace space, ulong texture, Colour colour, Vector2 position, float width, float height, float depth, int layer = 0, float rotation_clockwise_radians = 0.0f, float texcoord_min_x = 0.0f, float texcoord_min_y = 0.0f, float texcoord_max_x = 1.0f, float texcoord_max_y = 1.0f, TextureCoordinateMode textureMode = TextureCoordinateMode.Wrap) { var halfSize = 0.5f * new Vector2(width, height); _drawing.Draw(drawStage, space, FillType.Textured, new Vertex2D[] { new Vertex2D { Position = Common.RotateVectorClockwise(new Vector2(-halfSize.X, halfSize.Y), rotation_clockwise_radians) + position, TexCoord0 = new Vector2(texcoord_min_x, texcoord_min_y), TexCoord1 = new Vector2(0.0f, 0.0f), TexWeighting = 0.0f, Colour = new Colour(1.0f, 1.0f, 1.0f, 1.0f) }, new Vertex2D { Position = Common.RotateVectorClockwise(new Vector2(halfSize.X, halfSize.Y), rotation_clockwise_radians) + position, TexCoord0 = new Vector2(texcoord_max_x, texcoord_min_y), TexCoord1 = new Vector2(1.0f, 0.0f), TexWeighting = 1.0f, Colour = new Colour(1.0f, 1.0f, 1.0f, 1.0f) }, new Vertex2D { Position = Common.RotateVectorClockwise(new Vector2(-halfSize.X, -halfSize.Y), rotation_clockwise_radians) + position, TexCoord0 = new Vector2(texcoord_min_x, texcoord_max_y), TexCoord1 = new Vector2(0.0f, 1.0f), TexWeighting = 0.0f, Colour = new Colour(1.0f, 1.0f, 1.0f, 1.0f) }, new Vertex2D { Position = Common.RotateVectorClockwise(new Vector2(halfSize.X, -halfSize.Y), rotation_clockwise_radians) + position, TexCoord0 = new Vector2(texcoord_max_x, texcoord_max_y), TexCoord1 = new Vector2(1.0f, 1.0f), TexWeighting = 1.0f, Colour = new Colour(1.0f, 1.0f, 1.0f, 1.0f) }, }, new int[] { 0, 1, 2, 2, 1, 3 }, colour, texture, 0UL, textureMode, TextureCoordinateMode.None, depth, layer); }
public void Add(ref CoordinateSpace target, ref FillType type, ref Colour colour, ref Vertex2D[] vertices, ref int[] indices, ref ulong texture0, ref ulong texture1, ref TextureCoordinateMode texmode0, ref TextureCoordinateMode texmode1, ref float depth, ref int layer) { var numVertices = vertices.Length; var numIndices = indices.Length; CheckAndUpsizeSinglePropertyArrays(); CheckAndUpsizeVertexArray(numVertices); CheckAndUpsizeIndexArray(numIndices); Data.Ordering[Data.NumRequests] = Data.NumRequests; Data.Targets[Data.NumRequests] = target; Data.Types[Data.NumRequests] = type; Data.BaseColours[Data.NumRequests] = colour; Data.NumVertices[Data.NumRequests] = numVertices; Data.FirstVertexPosition[Data.NumRequests] = Data.NumVerticesUsed; Data.NumIndices[Data.NumRequests] = numIndices; Data.FirstIndexPosition[Data.NumRequests] = Data.NumIndicesUsed; Data.Texture0[Data.NumRequests] = texture0; Data.Texture1[Data.NumRequests] = texture1; Data.TextureMode0[Data.NumRequests] = texmode0; Data.TextureMode1[Data.NumRequests] = texmode1; Data.Depths[Data.NumRequests] = depth; Data.Layers[Data.NumRequests] = layer; for (var v = 0; v < numVertices; v++) { Data.Vertices[Data.NumVerticesUsed + v] = vertices[v]; } for (var i = 0; i < numIndices; i++) { Data.Indices[Data.NumIndicesUsed + i] = indices[i]; } Data.NumRequests++; Data.NumVerticesUsed += numVertices; Data.NumIndicesUsed += numIndices; }
//Helper created draw request to support creating persistent queue private InternalDrawRequest Create(FillType fill, ulong texture0, ulong texture1, TextureCoordinateMode tmode0, TextureCoordinateMode tmode1, int layer, float depth = 0.5f) { //Unsorted properties var verts = new Vertex2D[] { new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.Zero, TexWeighting = 1.0f }, new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.Zero, TexWeighting = 1.0f }, new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.Zero, TexWeighting = 1.0f }, }; var indices = new int[] { 0, 1, 2 }; var target = CoordinateSpace.Screen; var colour = Colour.White; return(new InternalDrawRequest { Colour = colour, CoordinateSpace = target, Depth = depth, FillType = fill, Indices = indices, Layer = layer, Texture0 = texture0, Texture1 = texture1, TextureMode0 = tmode0, TextureMode1 = tmode1, Vertices = verts }); }
/* * Batch boundaries are triggered by: * - Change in layer * - Change in Queue being used * - Once one of the texture slots is attempted to be set more than once * OR * - When a texture wrap mode is changed on an active texture */ //Helper adds request to queue private void Add(IDrawQueue queue, FillType fill, ulong texture0, ulong texture1, TextureCoordinateMode tmode0, TextureCoordinateMode tmode1, int layer, float depth = 1.0f) { //Unsorted properties var verts = new Vertex2D[] { new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.Zero, TexWeighting = 1.0f }, new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.Zero, TexWeighting = 1.0f }, new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.Zero, TexWeighting = 1.0f }, }; var indices = new int[] { 0, 1, 2 }; var target = CoordinateSpace.Screen; var colour = Colour.White; queue.Add(ref target, ref fill, ref colour, ref verts, ref indices, ref texture0, ref texture1, ref tmode0, ref tmode1, ref depth, ref layer); }
private void AddItem(IDrawQueue queue, TextureCoordinateMode texcoord0, TextureCoordinateMode texcoord1, FillType fill, ulong t0, ulong t1, float depth, int layer) { var space = CoordinateSpace.Screen; var colour = Colour.White; var verts = new Vertex2D[] { new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.One, TexWeighting = 0.9f }, new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.One, TexWeighting = 0.9f }, new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.One, TexWeighting = 0.9f } }; var indices = new int[] { 0, 1, 2 }; queue.Add(ref space, ref fill, ref colour, ref verts, ref indices, ref t0, ref t1, ref texcoord0, ref texcoord1, ref depth, ref layer); }
private void Draw(CoordinateSpace coordinateSpace, Colour colour, Vertex2D[] vertices, int[] indices, float depth, int layer, FillType fillType = FillType.Coloured, ulong t0 = 0UL, ulong t1 = 0UL, TextureCoordinateMode tm0 = TextureCoordinateMode.None, TextureCoordinateMode tm1 = TextureCoordinateMode.None) { _drawStageModel.DrawToDynamicQueue(ref coordinateSpace, ref fillType, ref colour, ref vertices, ref indices, ref t0, ref t1, ref tm0, ref tm1, ref depth, ref layer); }
public bool AddIfValid(ref CoordinateSpace target, ref FillType type, ref Colour colour, ref Vertex2D[] vertices, ref int[] indices, ref ulong texture0, ref ulong texture1, ref TextureCoordinateMode texmode0, ref TextureCoordinateMode texmode1, ref float depth, ref int layer) { if (vertices.Length < 3) { _frameworkMessenger.Report("Add draw request failed: Less than 3 vertices provided"); return(false); } if (indices.Length == 0) { _frameworkMessenger.Report("Add draw request failed: zero indices provided"); return(false); } if (indices.Length % 3 != 0) { _frameworkMessenger.Report(string.Concat("Add draw request failed: Number of indices ", indices.Length, " not divisible by 3")); return(false); } if (type == FillType.Coloured) { texture0 = 0UL; texture1 = 0UL; texmode0 = TextureCoordinateMode.None; texmode1 = TextureCoordinateMode.None; } else { if (texture0 == 0UL) { _frameworkMessenger.Report("Add draw request failed: No Texture0 provided for Textured Drawing"); return(false); } } if (type == FillType.DualTextured) { if (texture1 == 0UL) { _frameworkMessenger.Report("Add draw request failed: No Texture1 provided for Dual Textured Drawing"); return(false); } if (texture0 == texture1) { _frameworkMessenger.Report("Add draw request failed: Same texture provided for both textures in Dual Textured drawing. Not supported"); return(false); } if (texmode0 == TextureCoordinateMode.None) { texmode0 = TextureCoordinateMode.Wrap; } if (texmode1 == TextureCoordinateMode.None) { texmode1 = TextureCoordinateMode.Wrap; } } if (type == FillType.Textured) { if (texmode0 == TextureCoordinateMode.None) { texmode0 = TextureCoordinateMode.Wrap; } texture1 = 0UL; texmode1 = TextureCoordinateMode.None; } if (depth < 0.0f || depth > 1.0f) { _frameworkMessenger.Report("Add draw request failed: Depth out of range 0 - 1"); return(false); } if (layer < 0) { _frameworkMessenger.Report("Add draw request failed: a negative layer number is not valid"); return(false); } ; Add(ref target, ref type, ref colour, ref vertices, ref indices, ref texture0, ref texture1, ref texmode0, ref texmode1, ref depth, ref layer); return(true); }
private bool CheckIfNextInQueueShouldBeIncluded(int queue, int numQueues, IDrawQueue[] rawQs, int[] nextRequestToConsume, bool[] activeInCurrentLayer, int layer, ulong tex0, TextureCoordinateMode tMode0, bool hasTexBeenSet0, ulong tex1, TextureCoordinateMode tMode1, bool hasTexBeenSet1, bool[] activeQueuesOverAllLayers) { //Ensure queue remains valid if (!activeQueuesOverAllLayers[queue]) { return(false); } //Ensure next in queue has the highest depth var currentQueueNextIndex = rawQs[queue].Data.Ordering[nextRequestToConsume[queue]]; var currentQueueDepthIsHighest = true; var currentQueueDepth = rawQs[queue].Data.Depths[currentQueueNextIndex]; for (var n = 0; n < numQueues; n++) { if (n == queue || !activeQueuesOverAllLayers[n] || !activeInCurrentLayer[n]) //made some changes here might breaksomething { continue; } var nextIndex = rawQs[n].Data.Ordering[nextRequestToConsume[n]]; var nextDepth = rawQs[n].Data.Depths[nextIndex]; if (nextDepth > currentQueueDepth) { currentQueueDepthIsHighest = false; break; } } if (!currentQueueDepthIsHighest) { return(false); } //Now we are confirmed to be potentially consuming from the current queue, we check for reasons to end the DrawingBatch //Layer and (invalid) Texture Changing var nextLayer = rawQs[queue].Data.Layers[currentQueueNextIndex]; if (nextLayer != layer) { return(false); } var nextTexture0 = rawQs[queue].Data.Texture0[currentQueueNextIndex]; if (nextTexture0 != tex0) { if (nextTexture0 != 0UL && hasTexBeenSet0) { return(false); } } var nextTextureMode0 = rawQs[queue].Data.TextureMode0[currentQueueNextIndex]; if (nextTextureMode0 != tMode0) { if (nextTextureMode0 != TextureCoordinateMode.None && tMode0 != TextureCoordinateMode.None) { return(false); } } var nextTexture1 = rawQs[queue].Data.Texture1[currentQueueNextIndex]; if (nextTexture1 != tex1) { if (nextTexture1 != 0UL && hasTexBeenSet1) { return(false); } } var nextTextureMode1 = rawQs[queue].Data.TextureMode1[currentQueueNextIndex]; if (nextTextureMode1 != tMode1) { if (nextTextureMode1 != TextureCoordinateMode.None && tMode1 != TextureCoordinateMode.None) { return(false); } } return(true); }