shithub: cstory

Download patch

ref: 60d3cc2ed622308e479892d3defc82c021324308
parent: 8edca4fb2e1fd839918c02fce2040bdb23bb6f44
author: Clownacy <[email protected]>
date: Sun Feb 9 07:40:35 EST 2020

Update cute_spritebatch.h

--- a/external/cute_spritebatch.h
+++ b/external/cute_spritebatch.h
@@ -187,9 +187,10 @@
 // from within the `spritebatch_defrag` function, and sometimes from `spritebatch_flush`.
 
 // Called when the pixels are needed from the user. `image_id` maps to a unique image, and is *not*
-// related to `texture_id` at all. `buffer` must be filled in with `bytes_to_fill` number of bytes.
-// The user is assumed to know the width/height of the image, and can optionally verify that
-// `bytes_to_fill` matches the user's w * h * stride for this particular image.
+// related to `texture_id` at all. The `texture_id` is the value returned by this function. `buffer`
+// must be filled in with `bytes_to_fill` number of bytes. The user is assumed to know the
+// width/height of the image, and can optionally verify that `bytes_to_fill` matches the user's
+// w * h * stride for this particular image.
 typedef void (get_pixels_fn)(SPRITEBATCH_U64 image_id, void* buffer, int bytes_to_fill, void* udata);
 
 // Called with a new texture handle is needed. This will happen whenever a new atlas is created,
@@ -198,7 +199,8 @@
 typedef SPRITEBATCH_U64 (generate_texture_handle_fn)(void* pixels, int w, int h, void* udata);
 
 // Called whenever a texture handle is ready to be free'd up. This happens whenever a particular image
-// or a particular atlas has not been used for a while, and is ready to be released.
+// or a particular atlas has not been used for a while, and is ready to be released. `texture_id` is the
+// value returned by a previous call to `generate_texture_handle_fn`.
 typedef void (destroy_texture_handle_fn)(SPRITEBATCH_U64 texture_id, void* udata);
 
 // Sets all function pointers originally defined in the `config` struct when calling `spritebatch_init`.
@@ -228,7 +230,14 @@
 
 struct spritebatch_sprite_t
 {
+	// User-defined value to represent a unique sprite.
 	SPRITEBATCH_U64 image_id;
+
+	// Assigned by calling `generate_texture_handle_fn`. Does not map one-to-one with `image_id`,
+	// since a single sprite can be drawn, allocate a `texture_id`, and then not be drawn again
+	// for a long time. This would then trigger the `destroy_texture_handle_fn` and release the
+	// previously used `texture_id`. Then later, if the sprite is drawn again it will allocate a
+	// new `texture_id` by calling `generate_texture_handle_fn`.
 	SPRITEBATCH_U64 texture_id;
 
 	// User-defined sorting key, see: http://realtimecollisiondetection.net/blog/?p=86
@@ -884,6 +893,8 @@
 
 // end of hashtable.h
 
+
+#include <limits.h>
 
 int spritebatch_init(spritebatch_t* sb, spritebatch_config_t* config, void* udata)
 {
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -16,7 +16,6 @@
 #include "SDL.h"
 
 #define SPRITEBATCH_IMPLEMENTATION
-#include <limits.h>	// Needed by `cute_spritebatch.h` for `INT_MAX`
 #include "cute_spritebatch.h"
 
 #include "../../WindowsWrapper.h"
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -7,7 +7,6 @@
 #include "SDL.h"
 
 #define SPRITEBATCH_IMPLEMENTATION
-#include <limits.h>	// Needed by `cute_spritebatch.h` for `INT_MAX`
 #include "cute_spritebatch.h"
 
 #include "../../WindowsWrapper.h"