Comments (5)
Thanks so much for the explanation! The solution that you posted seems great. I'll close the issue.
from sokol.
You're on the right track. You need 2 textures setup as render targets, and 2 pass objects using those textures as framebuffer. I was considering making pass render targets 'rebindable' similar to the sg_draw_state bind slots but decided against it for now for various implementation detail reasons (for instance on D3D11 the image object would need to own the RenderTargetView or DepthStencilView, not the pass object, or alternatively, the View objects would need to be created on the fly etc etc etc...), none of the solution looked very nice to me.
Also all the validation can happen in sg_create_pass() (e.g. that all render target have the sample multi-sample count, pixel format, size etc...), instead of in sg_begin_pass().
So it would basically look like this:
sg_pass pass[2];
sg_image img[2]
void init() {
....
sg_image_desc img_desc = { .render_target = true, ... };
for (int i = 0; i < 2; i++) {
img[i] = sg_make_image(&img_desc);
pass[i] = sg_make_pass(&(sg_pass_desc) { .color_attachment[0].image = img[i] });
}
...
}
void frame() {
....
// offscreen ping-pong rendering
sg_begin_pass(pass[frame_count % 2], &pass_action);
draw_state.fs_image[0] = img[(frame_count + 1) % 2];
sg_apply_draw_state(&draw_state);
sg_draw(...);
sg_end_pass();
...
}
(you'd need to handle the first frame as special case though, since the images will have undefined content initially).
from sokol.
PS: IMHO the only reason to implement a similar 'rebinding' on an existing pass like in sg_draw_state would be to avoid a combinatorial explosion, if you have many different render-target combinations for MRT rendering. But my thinking was that usually there's much fewer passes happening per frame then draw calls, and the different pass configurations should be fairly 'rigid' The only exception would be if you have hundreds of per-object dynamically rendered textures, but even then one or two pass objects per object isn't too bad, as they should be much more light-weight than for instance the texture(s) used as render target, so creating hundreds of thousands of pass objects shouldn't be too bad (but trying to render hundreds of passes each frame probably isn't a good idea).
from sokol.
PPS: here's a ping-pong-rendering sample from Oryol: the basic ideas also translate to sokol-gfx: https://github.com/floooh/oryol/blob/master/code/Samples/InfiniteSpheres/InfiniteSpheres.cc
from sokol.
Hi @mhalber, I know it's been a while but I was wondering if you managed to get this working and, if possible, if you have a working example to show. I've been trying to get a simple gaussian blur demo to work (draw image to offscreen texture, then perform ping-pong blurring and finally render to screen) but all I get is a black screen. :)
PS: @floooh it would be really great to have something like this in the sokol-samples repo. ;)
from sokol.
Related Issues (20)
- [sokol_gfx] Array of struct uniform HOT 1
- WebGPU samples currently broken. HOT 1
- Regression: swapchains with depth (not depth/stencil) buffers currently broken in Metal. HOT 2
- [sokol_app] A call to GetIntegerv in _sapp_wgl_create_context leaves the stack corrupted HOT 8
- Sampling a depth texture using `SG_IMAGESAMPLETYPE_FLOAT` in order to copy it to the main framebuffer's depth buffer HOT 2
- Crash on validation error HOT 2
- sdhc + sokol_app.h: Uniform Arrays of smaller than vec4 type lead to validation errors or silently introduce buggy behaviour HOT 5
- Will you accept a PR that allows setting minimum width/height for resizable windows? HOT 3
- Apps showcase HOT 2
- Why isn't SOKOL_NO_ENTRY supported on android? Is it impossible or just not implemented yet? HOT 1
- How to fill the new sg_swapchain struct when using SDL2? HOT 1
- support arm64-v8a - INSTALL_FAILED_NO_MATCHING_ABIS HOT 4
- Load graphical dynamic libraries on demand with dlopen HOT 6
- sokol_gfx: warnings when compiling with mingw-w64 HOT 3
- sokol_app.h: request for show/hide/focus window functions HOT 1
- Request for Tagged Releases HOT 6
- README gives no indication of what this library does HOT 1
- [sokol_gfx] Any plans to support base vertex location? HOT 12
- error: expected '(' for function-style cast or type construction, while using SG_RANGE on MacOS using c++ HOT 6
- Idea: Add flags to only initialize certain parts in sokol_app HOT 2
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 sokol.