Coder Social home page Coder Social logo

edubart / sokol_gp Goto Github PK

View Code? Open in Web Editor NEW
433.0 12.0 23.0 3.16 MB

Minimal modern efficient cross platform 2D graphics painter in C

License: MIT No Attribution

C 67.75% Makefile 0.40% GLSL 0.88% C++ 30.97%
2d sokol c graphics opengl d3d11 metal rendering

sokol_gp's People

Contributors

edubart avatar faywong avatar krychu avatar robloach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sokol_gp's Issues

Getting this to work with sokol_imgui.h

I'm trying to figure out if there is anything special I need to do to get sokol_imgui.h working with sokol_gp.h. I've got it all setup and ostensibly running in the backround without error, but not sure if the state required on the defaul sokol_gfx thread needs to be somehow handed off to sokol_gp for rendering. I'm calling the normal sokol_imgui render functions but aren't seeing any gui being drawn. Would love any help if you can offer!

sample-framebuffer yields a sokol assert failure

Hi, thanks for making this nice project available!

I've cloned the repository, ran make, and could successfully run all ./build/sample-* executables except the sample-framebuffer which outputs:

./build/sample-framebuffer 
sg_apply_pipeline: pipeline depth pixel_format doesn't match pass depth attachment pixel format
^^^^  SOKOL-GFX VALIDATION FAILED, TERMINATING ^^^^
sample-framebuffer: thirdparty/sokol_gfx.h:13735: _sg_validate_end: Assertion `0' failed.
Aborted (core dumped)

flip sgp_draw_textured_rect_ex

Hello,

I was wondering if there is a way to flip the textures drawn by sgp_draw_textured_rect_ex? I tried sending negative w,h and but does not work. Also, I don't think negative scaling will work?

Thanks

Some `sgp_draw_line()` not being rendered?

I've got a large 2D grid, where each cell draws a box and an outline like so:

int px = x * TILE_SIZE;
int py = y * TILE_SIZE;

sgp_set_color(0, 0.15f, 0.32f, 1);
sgp_draw_filled_rect(px, py, TILE_SIZE, TILE_SIZE);

sgp_set_color(1, 0.11f, 0.01f, 1);
sgp_draw_line(px, py, px + TILE_SIZE, py);
sgp_draw_line(px, py, px, py + TILE_SIZE);
sgp_draw_line(px + TILE_SIZE, py, px + TILE_SIZE, py + TILE_SIZE);
sgp_draw_line(px, py + TILE_SIZE, px + TILE_SIZE, py + TILE_SIZE);

However, depending on the projection, some of the lines will not be drawn. Transforming the projection changes which lines aren't drawn. You can see it pictured below:

Screen Shot 2023-03-21 at 5 23 15 PM

And here's a video (might be hard to tell because of the low video resolution):

Mar-21-2023.17-28-37.mp4

My code overall looks very similar to most of the example projects:

const int width = sapp_width(), height = sapp_height();

sgp_begin(width, height);
sgp_viewport(0, 0, width, height);
sgp_set_color(0.01f, 0.48f, 0.51f, 1.0f);
sgp_clear();
sgp_reset_color();

sgp_project(0, camera.width, 0, camera.height);
sgp_translate(-camera.x + camera.width * 0.5f, -camera.y + camera.height * 0.5f);

// this is where each cell is drawn

sg_pass_action pass_action = {0};
sg_begin_default_pass(&pass_action, width, height);
sgp_flush();
sgp_end();
sg_end_pass();
sg_commit();

Question about color uniform

Hello,

I am inquiring about the reason why colour is applied as a transform and not as a vertex colour? If it is done through a vertex colour, I think it will decrease draw calls dramatically.

Thanks

Metal not working?

Hi @edubart thanks for this nice lib.
Unfortunately SOKOL_METAL rendering seems broken for me while SOKOL_GLCORE33 seems to work just fine :(

Steps to reproduce:

  1. I did copy https://github.com/edubart/sokol_gp#quick-usage-example into an empty xcode macOS project as an main.m Objective-C file.
  2. Changed head of file to:
// main.m
#define SOKOL_IMPL
// #define SOKOL_GLCORE33 // This works just fine
#define SOKOL_METAL // BUG: Metal breaks with current sokol_gp plus
#include "sokol_gfx.h"
...
  1. Bug:

Screenshot 2022-02-15 at 22 42 21

How to do circle drawing right with sokol_gp?

Both line and filled variations. I have something working with multiple lines and filled triangles but it doesn't look good enough IMO. Small radii (a small number of pixels) are an issue as well as blending modes.

Anyone have thoughts on this? Should it be part of the library?

Line thickness?

Two questions:

  1. Is there a way to specify line thickness?
  2. If yes, are those lines antialiased?

Premultiplied alpha

Hi,

I'd like to extend sokol_gp to support to allow for premultiplied alpha. It seems that the easiest way to do it would be to add a new sgp_blend_mode type. Maybe SGP_BLENDMODE_BLEND_PREMULTIPLIED_ALPHA?

Thanks.

SOKOL_MALLOC/CALLOC/FREE macros are no longer supported

I'm working on a visual studio project using sokol_gfx and sokol_gp.

I am using sokol_gfx master branch after allocator-interface merge.

The first error I had was: "'SOKOL_MALLOC': identifier not found" from sokol_gp, after doing an extended search I found this error in conditional compilation at line 2625 of sokol_gfx.h: "SOKOL_MALLOC / CALLOC / FREE macros are no longer supported, please use sg_desc.allocator to override memory allocation functions ".

Is there a fix for this problem? or am I doing something wrong?

Trouble compiling the examples on macOS Monterey

Hi,

I'm having trouble compiling the examples on macOS Monterey v12.1, using Xcode v13.2.1, and using either gcc v11.2 or clang v13.

I see the make code is linking to X11 libraries, so perhaps you've only tested it on a *nix system other than macOS.

This is what I'm getting:

$ cd sokol_gp
$ make
gcc -o build/sample-rectangle samples/sample-rectangle.c -I. -Ithirdparty -Ishaders -D_GNU_SOURCE -DSOKOL_GLCORE33 -std=c99 -Wall -Wextra -Wshadow -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-function -pthread -Og -g -lX11 -lXi -lXcursor -lGL -ldl -lm
In file included from samples/sample-rectangle.c:7:
In file included from thirdparty/sokol_app.h:1676:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:523:1: error: expected identifier or '('
@Class NSString, Protocol;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:525:9: error: unknown type name 'NSString'
typedef NSString * NSExceptionName NS_TYPED_EXTENSIBLE_ENUM;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:526:9: error: unknown type name 'NSString'
typedef NSString * NSRunLoopMode NS_TYPED_EXTENSIBLE_ENUM;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:528:19: error: unknown type name 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:529:44: error: unknown type name 'NSString'
FOUNDATION_EXPORT SEL NSSelectorFromString(NSString *aSelectorName);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:531:19: error: unknown type name 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromClass(Class aClass);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:532:53: error: unknown type name 'NSString'
FOUNDATION_EXPORT Class _Nullable NSClassFromString(NSString *aClassName);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:534:19: error: unknown type name 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromProtocol(Protocol *proto) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:534:50: error: unknown type name 'Protocol'
FOUNDATION_EXPORT NSString *NSStringFromProtocol(Protocol *proto) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:535:19: error: unknown type name 'Protocol'
FOUNDATION_EXPORT Protocol * _Nullable NSProtocolFromString(NSString *namestr) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:535:61: error: unknown type name 'NSString'
FOUNDATION_EXPORT Protocol * _Nullable NSProtocolFromString(NSString *namestr) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:539:30: error: unknown type name 'NSString'
FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2) NS_NO_TAIL_CALL;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:539:53: error: format argument not an NSString
FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2) NS_NO_TAIL_CALL;
~~~~~~~~~~~~~~~~ ^ ~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:94:49: note: expanded from macro 'NS_FORMAT_FUNCTION'
#define NS_FORMAT_FUNCTION(F,A) attribute((format(NSString, F, A)))
^ ~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:540:31: error: unknown type name 'NSString'
FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0) NS_NO_TAIL_CALL;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:540:63: error: format argument not an NSString
FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0) NS_NO_TAIL_CALL;
~~~~~~~~~~~~~~~~ ^ ~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:94:49: note: expanded from macro 'NS_FORMAT_FUNCTION'
#define NS_FORMAT_FUNCTION(F,A) attribute((format(NSString, F, A)))
^ ~
In file included from samples/sample-rectangle.c:7:
In file included from thirdparty/sokol_app.h:1676:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSZone.h:9:1: error: expected identifier or '('
@Class NSString;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSZone.h:19:63: error: unknown type name 'NSString'
FOUNDATION_EXPORT void NSSetZoneName(NSZone * _Nullable zone, NSString *name)NS_SWIFT_UNAVAILABLE("Zone-based memory management is unavailable");
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSZone.h:20:19: error: unknown type name 'NSString'
FOUNDATION_EXPORT NSString *NSZoneName(NSZone * _Nullable zone) NS_SWIFT_UNAVAILABLE("Zone-based memory management is unavailable");
^
In file included from samples/sample-rectangle.c:7:
In file included from thirdparty/sokol_app.h:1676:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:10:1: error: expected identifier or '('
@Class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [sample-rectangle] Error 1

Thanks

No transparency when using the R8 pixel format

I'm on Windows using the latest sokol libs.

When rendering an image with the pixel format SG_PIXELFORMAT_R8, and while using a custom shader (shown below), I am unable to render with any transparency.

@vs vs
in vec4 coord;
out vec2 texUV;
void main() {
    gl_Position = vec4(coord.xy, 0.0, 1.0);
    texUV = coord.zw;
}
@end

@fs fs
uniform texture2D iTexChannel0;
uniform sampler iSmpChannel0;
uniform fs_params {
    vec4 iColor;
};
in vec2 texUV;
out vec4 fragColor;
void main() {
    vec4 tex_color = texture(sampler2D(iTexChannel0, iSmpChannel0), texUV) * iColor;
    fragColor = vec4(1, 1, 1, tex_color.r);
}
@end

@program text vs fs

I have the blend mode set correctly, and I'm correctly rendering other images with transparency. When using the above shader, I can even set the fragColor's alpha value to 0, and it will still render fully opaque.

Here is the image description:

    res.img = sg_make_image(&(sg_image_desc){
        .width = res.w,
        .height = res.h,
        .data.subimage[0][0].ptr = temp_bitmap,
        .data.subimage[0][0].size = (size_t)(res.w * res.h),
        .pixel_format = SG_PIXELFORMAT_R8,
    });

When rendering with the default shader, this is what is produced:
image

And when rendering with the custom shader, this is what is produced:
image

Am I doing something wrong, or is there a bug in the way that R8 images are being rendered?

`SOKOL_LOG` has been removed from `sokol_app.h`

It seems that recently SOKOL_LOG has been removed from sokol_app.h:

floooh/sokol@0574a28#diff-42747840ac0dd5aaeaa9368919646cc57e72a0bb54c03ad85c7eac18956ea584L1879-L1896

This breaks the following line of sokol_gp.h:

https://github.com/edubart/sokol_gp/blob/master/sokol_gp.h#L693

It's easy enough for me to fix this in my local copy of sokol_gp.h but it might be good to provide a real fix for any newcomers here. Perhaps sgp_desc should provider a logger configuration like sg_desc now does?

Duplicated API sgp_draw_textured_rects and sgp_draw_filled_rects ?

Initially I thought that the filled_rect API should just draw a solid color rectangle, while the textured_rect one should fill it with an image. But I discovered that filled_rect respects the sgp_set_image too! In fact the code of sgp_draw_textured_rects and sgp_draw_filled_rects seems quite similar.

Is this the wanted behavior or I am missing something? I am on linux and I compiled with SOKOL_GLCORE33.

Option to specify pixel format

Would it be possible to add the option to specify the pixel format for the pass?
I work with EDR/HDR and need non-default pixel formats.

I would need to somehow pass a new value to pip_desc.colors[0].pixel_format in _sgp_make_pipeline.

Region calculation

Hello,

If I set the projection sgp_project(-ratio, ratio, 1.0f, -1.0f);. Rendering many entities yield a lot of draw calls. I think because the region calculation in sgp_draw_filled_rects, and sgp_draw_textured_rects has a problem causing the overlap calculation to yield false positives.

Shouldn't sgp_region region = {1.0f, 1.0f, -1.0f, -1.0f};
be something like sgp_region region = {FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX};? So the min, max calculations work correctly?

Edit:
If the shapes are drawn outside the -1.0-1.0 range.

Thanks

Ability to not clear the display?

I'm trying to figure out why not calling sgp_clear() is still clearing the frame buffer. I'd like to just play with some effects like turning off the clear so that draws accumulate in the buffer, which I thought was possible by no calling clear(), but it's still clearing. Is there some other function I should not be calling? Or is it part of the default sokol_gfx pass action?

Just a thank you!

A great library thank you very much! The look back 8 commands idea is great! most importantly when combined with the region intersection detection to solve many z-fighting problems. To use it more efficiently, I organize my shapes into layers then I submit my shapes layer by layer to make most of the automatic batching.

Thinking of using it to render something like nanovg for higher level drawing (I already ported most of Raylib's 2D shapes to it but they lack anti-aliasing).

Cannot render to frame buffer

Hi,

Thanks for this excellent library, I was using sokol_gfx directly in a 2D engine and sokol_gp made my life a lot easier.

However, I can't seem to be able to render to a frame buffer. My rendering starts with a start call, which receives an optional render target:

void start(rm::RenderTarget const* target) override {
    _renderTarget = target;

    if (_renderTarget == nullptr) {
        sgp_begin(_size.width(), _size.height());
        sgp_viewport(0, 0, _size.width(), _size.height());
        sgp_project(0.0f, _size.width(), 0.0f, _size.height());

        sgp_set_color(0.0f, 0.0f, 0.0f, 1.0f);
        sgp_clear();
        sgp_reset_color();
    }
    else {
        rm::Size<long> const& size = _renderTarget->size();
        sgp_begin(size.width(), size.height());
        sgp_viewport(0, 0, size.width(), size.height());
        sgp_project(0, size.width(), 0.0f, size.height());

        sg_pass_action action = {};
        action.colors[0].action = SG_ACTION_CLEAR;
        action.colors[0].value.r = 0.0f;
        action.colors[0].value.g = 0.0f;
        action.colors[0].value.b = 0.0f;
        action.colors[0].value.a = 1.0f;
        sg_begin_pass(static_cast<SokolRenderTarget const*>(_renderTarget)->_pass, &action);
    }
}

After that, I can draw quads, textured or not:

void draw(rm::Quad const& quad, rm::Texture const* const texture, Post post) override {
    rm::Point const& position = quad.position();
    rm::Size<float> const& size = quad.size();
    rm::Point const& center = quad.center();
    rm::Vec2 const& scale = quad.scale();
    float const angle = -quad.angle();
    rm::Color const& color = quad.color();

    rm::Point const screencenter(position.x() + center.x(), position.y() + center.y());

    sgp_push_transform();
    sgp_scale_at(scale.x(), scale.y(), screencenter.x(), screencenter.y());
    sgp_rotate_at(angle, screencenter.x(), screencenter.y());

    sgp_set_color(color.r(), color.g(), color.b(), color.a());
    sgp_set_blend_mode(SGP_BLENDMODE_BLEND);

    if (texture != nullptr) {
        sgp_set_image(0, static_cast<SokolTexture const*>(texture)->_texture);
        sgp_draw_textured_rect(position.x(), position.y(), size.width(), size.height());
        sgp_reset_image(0);
    }
    else {
        sgp_draw_filled_rect(position.x(), position.y(), size.width(), size.height());
    }

    sgp_reset_blend_mode();
    sgp_reset_color();
    sgp_pop_transform();
}

And then I call present to commit the draw calls:

void present() override {
    if (_renderTarget == nullptr) {
        sg_pass_action action = {0};
        sg_begin_default_pass(&action, _size.width(), _size.height());

        sgp_flush();
        sgp_end();

        sg_end_pass();
        sg_commit();

        _platform->swapBuffers();
    }
    else {
        sgp_flush();
        sgp_end();
        sg_end_pass();

        _renderTarget = nullptr;
    }
}

When I render to the screen, I can see everything is there (it's just one textured quad), but if I render to a framebuffer, all I see when I render it to the screen is a white quad. If I set a breakpoint at draw I can see that texture is not null, and all the other values are good. I can also see that the framebuffer path is being taken in start and present.

This is how I'm creating the framebuffer:

SokolRenderTarget(long const width, long const height, Filter const filter) : rm::RenderTarget(width, height) {
    {

        sg_image_desc desc = {};
        desc.render_target = true;
        desc.width = width;
        desc.height = height;
        desc.pixel_format = SG_PIXELFORMAT_RGBA8;
        desc.min_filter = filter == rm::Texture::Filter::Nearest ? SG_FILTER_NEAREST : SG_FILTER_LINEAR;
        desc.mag_filter = desc.min_filter;
        desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE;
        desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE;
        _target = sg_make_image(&desc);
    }

    {
        sg_desc sgdesc = sg_query_desc();

        sg_image_desc desc = {};
        desc.render_target = true;
        desc.width = width;
        desc.height = height;
        desc.pixel_format = SG_PIXELFORMAT_DEPTH_STENCIL;
        desc.sample_count = sgdesc.context.sample_count;
        _depth = sg_make_image(&desc);
    }

    {
        sg_pass_desc desc = {};
        desc.color_attachments[0].image = _target;
        desc.depth_stencil_attachment.image = _depth;
        _pass = sg_make_pass(&desc);
    }
}

I followed the framebuffer example to write the code, but the example is a bit contrived in that it follows a fixed path whereas I need the flexibility to draw anything, anytime to a framebuffer, but still it looks correct to me.

Any help is greatly appreciated.

Batching draw calls with different colors

I'd like to start a discussion about ways to batch calls that use a different color. I'm trying to use the default sokol_gp pipeline to draw entites that have slight variances in color (like a particle system), and the color differences between any two objects means that the draw calls aren't batched for GP.

I can think of a few ways to potentially implement this, but I wanted to open a discussion here with @edubart about what you think would work as well.

Off the top of my head, I think doing something like supplying a texture that gets written to for colors for submitted calls could work. You could set a max size for this texture similar to setting the max vert count, and that texture is created and written to for colors. So to start maybe just something like a 64x64 texture would support 64^2 unique colors before needing to do a new call.

I think having this as an option as well would be nice โ€” the overhead of updating a texture per-frame may not be worth it for some use cases, but I think the benefits would definitely be felt by me. Interested to hear what you think!

Update to latest sokol_gfx

sokol_gp does not compile anymore with the latest sokol_gfx. Do you have plans to update sokol_gp?

I could give it a try, but I'd rather know from you how the sokol_gp public API should look like before starting to change the code to maximize the chance of the PR being accepted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.