-
-
Notifications
You must be signed in to change notification settings - Fork 966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Native] - Implement some existing C++ methods in C# #1896
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f157fe9
Implement StrideBatch.UpdateBufferValues in c#
Jklawreszuk d91dd64
Implement fast text renderer
Jklawreszuk 23ed286
Remove predicates
Jklawreszuk a33e914
[Native] - Apply code review suggestions to FastTextRenderer
Jklawreszuk 2191454
[Native] - Fix size of VertextPositionNormalTexture span
Jklawreszuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using Stride.Core.Mathematics; | ||
using Stride.Native; | ||
using Stride.Rendering; | ||
|
||
namespace Stride.Graphics | ||
|
@@ -590,9 +589,45 @@ internal unsafe void DrawSprite(Texture texture, ref RectangleF destination, boo | |
|
||
protected override unsafe void UpdateBufferValuesFromElementInfo(ref ElementInfo elementInfo, IntPtr vertexPtr, IntPtr indexPtr, int vertexOffset) | ||
{ | ||
var vertex = (VertexPositionColorTextureSwizzle*)vertexPtr; | ||
fixed (SpriteDrawInfo* drawInfo = &elementInfo.DrawInfo) | ||
Comment on lines
590
to
593
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here with |
||
{ | ||
NativeInvoke.UpdateBufferValuesFromElementInfo(new IntPtr(drawInfo), vertexPtr, indexPtr, vertexOffset); | ||
float deltaX = 1.0f / drawInfo->TextureSize.X; | ||
float deltaY = 1.0f / drawInfo->TextureSize.Y; | ||
|
||
Vector2 rotation = new(1,0); | ||
|
||
if (Math.Abs(drawInfo->Rotation) > float.Epsilon) | ||
{ | ||
(rotation.X, rotation.Y) = MathF.SinCos(drawInfo->Rotation); | ||
} | ||
|
||
Vector2 origin = drawInfo->Origin; | ||
origin.X /= Math.Max(float.Epsilon, drawInfo->Source.Width); | ||
origin.Y /= Math.Max(float.Epsilon, drawInfo->Source.Height); | ||
|
||
for (int j = 0; j < 4; j++) | ||
{ | ||
Vector2 corner = CornerOffsets[j]; | ||
Vector2 position; | ||
position.X = (corner.X - origin.X) * drawInfo->Destination.Width; | ||
position.Y = (corner.Y - origin.Y) * drawInfo->Destination.Height; | ||
|
||
vertex->Position.X = drawInfo->Destination.X + (position.X * rotation.X) - (position.Y * rotation.Y); | ||
vertex->Position.Y = drawInfo->Destination.Y + (position.X * rotation.Y) + (position.Y * rotation.X); | ||
vertex->Position.Z = drawInfo->Depth; | ||
vertex->Position.W = 1.0f; | ||
vertex->ColorScale = drawInfo->ColorScale; | ||
vertex->ColorAdd = drawInfo->ColorAdd; | ||
|
||
corner = CornerOffsets[((j ^ (int)drawInfo->SpriteEffects) + (int)drawInfo->Orientation) % 4]; | ||
vertex->TextureCoordinate.X = (drawInfo->Source.X + corner.X * drawInfo->Source.Width) * deltaX; | ||
vertex->TextureCoordinate.Y = (drawInfo->Source.Y + corner.Y * drawInfo->Source.Height) * deltaY; | ||
|
||
vertex->Swizzle = (int)drawInfo->Swizzle; | ||
|
||
vertex++; | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 0 additions & 112 deletions
112
sources/engine/Stride.Native/FastTextRenderer/FastTextRenderer.c
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use
VertexPositionNormalTexture**
as the parameter type instead ofIntPtr
, it'll be clearer for the caller and you can move the type conversion outside the loop, it's likely already inlined by the jit but might as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually incorrect as written (and crashes when enabling the Profiler for example). It should just be
VertexPositionNormalTexture*
as I see it.I suggest something like
private int GraphicsFastTextRendererGenerateVertices(RectangleF constantInfos, RectangleF renderInfos, string text, Span<VertexPositionNormalTexture> vertexBuffer)
or maybeprivate int GraphicsFastTextRendererGenerateVertices(RectangleF constantInfos, RectangleF renderInfos, string text, ref VertexPositionNormalTexture vertexBuffer)
and iterating withvertexBuffer = ref Unsafe.Add(ref vertexBuffer, 1)
instead of pointer arithmetic if that's simpler/faster thanSpan
. I see no reason to keep a C-like signature.