Comments (4)
Hmm, there's probably not a great solution to this. However, here's my idea:
batch.PushShader(custom)
.With("Wavy", 10f);
batch.Rect(new Rect(0, 0, 32, 32), Color.Red);
batch.PopShader();
It uses a fluent interface/method chaining. PushShader()
should return a struct that can be chained to set the uniforms. The uniform values will be stored/pooled in the Batcher itself through some means. The struct will merely be a reference to the Batcher and maybe some version id/index to ensure that the user is not storing the struct and using it after the initial call (this is just plain user error, though).
It's obviously not a perfect solution since any uniforms set on the shader will not be overwritten if a With()
call is not used (unless we use automatic setting like you described in your first solution). Additionally, I'm not really sure what should happen on PopShader() (i.e. should values be reset to what they were).
The main thing I want to avoid is Shader[].Set()
since ideally we don't want any graphics calls before Batcher.Render()
.
from foster.
Yeah I think I like this direction, my only concern (and maybe this is a non-issue?) is programmatically assigning values. Like if you're batching stuff from data, you can't do something like:
foreach (var (key, value) in assignments)
batch.SetShaderParameter(key, value);
Although I suppose if the struct returned with batch.PushShader
is valid until the next call you could do
var it = batch.PushShader(custom);
foreach (var (key, value) in assignments)
it.With(key, value);
Will think about this a bit! I could even just go with the first example (batch.SetShaderParameter
). That might be good enough.
from foster.
Another option is to:
- Refactor Shader to not upload parameters immediately
- Add a Material class which holds parameter data
- Draw calls take a Material class which uploads the parameters on-draw
- Batcher takes Material and makes a (pooled?) clone on-push.
(this is actually what the old foster did, if I remember correctly)
from foster.
This is now fixed as of b8ea1b5. Opted to add a Material class that is easy to Clone, and the Batcher holds an internal pool of Materials it reuses. Did require a breaking change if you use Shaders though.
from foster.
Related Issues (20)
- libFosterPlatform.dylib not built for Arm on macOS HOT 7
- A transparency bug that occurs when using an Aseprite file with multiple layers. HOT 3
- Move samples to their own repo
- Finalize/Dispose patterns HOT 4
- Room for more render performance HOT 4
- Graphics.Clear depth should be double, not int HOT 1
- Content / UserStorage APIs HOT 3
- Upgrade to .NET 8.0
- Don't run "UpdateLibs" step in build-libs.yml on pull requests
- Dynamic Sprite Font HOT 2
- Packer.CombineDuplicate incorrectly combines images when trimming HOT 1
- Get Display Size to determine if Window can fit
- App keeps running after the platform throws an error. HOT 2
- Module shutdown order HOT 3
- SDL gamepads and joysticks are not closed on shutdown HOT 2
- Add some repository tags HOT 1
- Nintendo and Sony Detection wrong (uses vendor and product instead of just vendor) HOT 10
- Drawing transparent textures HOT 6
- Add `Batcher.ImageStretch` HOT 1
- Text word wrapping HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foster.