Skip to content
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

Framework and Platform improvements (App, Math, Graphical, Storage) #60

Merged
merged 25 commits into from
Feb 5, 2024

Conversation

Techiesplash
Copy link
Contributor

@Techiesplash Techiesplash commented Feb 4, 2024

Changes:

  • App now allows passing a preferred renderer as an optional argument, defaults to Renderers.None
  • Batcher.Text() no longer starts a new batch every whitespace character (caused many extra draw calls)
  • ShaderDefaults has been changed to use verbatim text (multiline) literals to improve maintainability
  • Reworked Ease:
    • Changed the Ease class to a struct that will automatically set up In, Out, and InOut variants of an Easer based on one or two provided, also accepts the others being specified
    • Changed default Easers to use Ease class instead, removed variants
    • Added Quartic easer (t = t^4)
  • Changes in OpenGL Platform implementation:
    • Fixed typo in Texture struct ("FoxtureTexure_OpenGL"?)
    • Optimizations:
      • Fixed mistake in texture binding in AssignAttributes that caused stateTextureSlots to not be updated (thus causing a rebind of the texture every time)
      • Now keeps track of bound ARRAY_BUFFER and does not rebind if matching (reduces rebind calls notably)
      • Now keeps track of bound ELEMENT_ARRAY_BUFFER and does not rebind if matching (reduces rebind calls notably)
    • Reformatted code:
      • DEBUGPROC arguments now aligned with source argument
      • case statements now consistently have an indent
      • Instances of i ++ changed to i++ for consistency

Additions

  • Content API added:
    • Content: Read-only file access API with default impl, virtual
    • WritableContent: derives from Readable, allows writing to files, also with default impl, virtual
    • UserStorage (static class): Accepts a WritableContent global (Creates default one at App.UserPath). This allows it to reuse working API, still allows overriding it for specialized access

API change/addition examples:

Ease:

// Generates Out and InOut automatically
Ease autoEase = new (t => t * t);
// Generates only InOut automatically
Ease partialAutoEase = new (t => t * t, t => t * t);
// Generates nothing automatically
Ease manual = new (t => t * t, t => t * t, t => t * t);

// And to access the Easers it creates
var i = autoEase.In(t);
var o = autoEase.Out(t);
var x = autoEase.InOut(t);

// Ease also includes an Apply function that invokes InOut, and clamps the input to 0-1
x = autoEase.Apply(t);

// Easers can still be defined and used the same
Ease.Easer linear = (float t) => t;

Content:

// The Content class by default uses the default C# File/Directory API
// Assign to custom content class if desired
Content content = new Content(); 
Stream read = content.OpenRead();

// Uses the default WritableContent at directory App.UserPath
// Can be changed at UserStorage.Provider
UserStorage.WriteAllText("My Text!"); 

Effect on draw calls:

Benchmark details:

  • One million frogs via FroggyMark using the default Batcher
  • Both compiled locally on Release configuration and linked to the benchmark via ProjectReference
    • NuGet packages specifically appear to be much faster? I was getting 30FPS on NuGet packages.
  • Analyzed via NVIDIA Nsight Graphics
As current (0.1.16a) With fixes
Count: 276 Count: 166
FPS: ~13 FPS: ~13
Issues: 100 Issues: 2

@Techiesplash Techiesplash changed the title Framework and Platform improvements (App, Math, Graphical) Framework and Platform improvements (App, Math, Graphical, Storage) Feb 4, 2024
@NoelFB
Copy link
Collaborator

NoelFB commented Feb 4, 2024

Hey, this looks quite good, thank you! Few small thoughts:

  • Can we keep the existing Ease methods, but they redirect to the new ones and include an [Obsolete] attribute? This way it wont break existing code.
  • All of the tabs were converted in foster_renderer_opengl.c; ideally these would be left to match the rest of the project.

@Techiesplash
Copy link
Contributor Author

I put in obsolete-marked redirects for Easers.
Indenting seems to be fixed... There's shenanigans going on with the IDE when it comes to indents.

@NoelFB
Copy link
Collaborator

NoelFB commented Feb 5, 2024

Awesome, this looks really great, thanks for all the fixes and additions! :)

@NoelFB NoelFB merged commit 6bf6134 into FosterFramework:main Feb 5, 2024
@NoelFB
Copy link
Collaborator

NoelFB commented Feb 5, 2024

Hmm I'm getting a GL (ERROR:HIGH) GL_INVALID_OPERATION error generated. <texture> is not the name of an existing texture. sometimes when I try to create a Target (Framebuffer) now in a side project of mine. Investigating, not sure if it was from these changes or something else.

@NoelFB
Copy link
Collaborator

NoelFB commented Feb 5, 2024

Yeah the error seems to occur if I create a Target, dispose it immediately, and then create another one. It re-uses the GL ID and something bad happens in fgl.glFramebufferTexture2D(GL_FRAMEBUFFER, tex->glAttachment, GL_TEXTURE_2D, tex->id, 0);. Looking into it.

@NoelFB
Copy link
Collaborator

NoelFB commented Feb 5, 2024

Fixed this - it was an issue with deleting a texture while it was bound to a slot, and now that the slot stuff is actually caching properly, it broke. Pushing a fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants