Not per application, unless you mean per API use (callback for a
surface is kept in the surface, different surfaces could have
different callbacks and data).
Also, now that I think of it, there are multiple ways to implement
mixing of total replacement of implementations and simple addition to
the current one using these callbacks (all depending on if we put
current implementations in a callback itself and if we call that when
the actual callbacks ask for it, or if we keep current code where it
is and make a default callback just do nothing, etc).
An example usage follows: say I want to tie my usage of OpenGL
texture objects with SDL’s surfaces, using an SDL surface as the
overall representation of a texture and stuffing the texture name in a
segment pointed to by the userdata field. Problem is, without
callbacks, I would need to create new functions that call SDL’s API
functions just to handle things like creating and destroying the
surface while also handling the userdata field’s contents. In
addition, a call to one of SDL’s API functions for surfaces
independently can undermine my intended usage of these surfaces, not
allocating or unallocating the userdata field’s contents or handling
anything related to it. Per surface callbacks would solve this as
they would be called on creation, removal, and any changes or steps
affecting their state by SDL’s API internally. It would mean that I
can handle the surface and the userdata field in real time as an API
call affecting the surface occurs, potentially changing the behavior
of the API call; it would mean I can ‘transparently’ add stuff to
SDL’s API instead of building new (and probably less complete (for
instance)) things over it.
Code that uses SDL’s surface API would still do so in the same way
(except for surface allocation when a non-default callback is desired,
minor difference there (what if we allow establishing the default
callback to be used later when creating surfaces for just this
case?)), but internally the callbacks would be replacing or adding to
implementations of the API call. Struct fields (except for the new
callback function pointer field) would remain the same and should be
used as expected.
Also, has anyone found a usage for the SDL_Surface struct’s userdata
field without implementing a new API over SDL’s current one? I
haven’t.On 4/29/14, Alex Barry <alex.barry at gmail.com> wrote:
Not to criticize, but here’s a question; why not just build another
rendering backend for the things that don’t exist?
The reason I say that is you are basically asking for the ability to
override the default renderers on a per-application basis, which doesn’t
make sense in terms of an open-source product. If you are trying to build
a different renderer (since you mention OpenGL in use with surfaces), why
not let everyone use it as an optional backend? Also, if you want to use
SDL_Surface and OpenGL together, why not just use a SDL_Renderer?
Also, you need to be more specific on what the callback(s?) would be used
for. Do you callbacks for pre- and post- function calls for absolutely all
functions that relate to SDL_Surface? I don’t think you realize that this
means a lot of refactoring in the code, especially if all SDL_Surface
functions need to only function if the callback function returns a specific
value.
For improving your use-case some more, trying describing a specific
situation, rather than generalizing (and possibly confusing) everyone. For
instance, you mention “BEFORE a specific API function…” - which API
functions, and why do they need callbacks like you describe?
I’m curious about what you mean, but if it is acceptable to the full SDL
community, they may be relying on the person suggesting the change to try
writing a patch rather than making an open suggestion for someone else to
implement. Good luck
On Tue, Apr 29, 2014 at 8:01 AM, Charles Swain <@Charles_Swain>wrote:
Just realized that there is a better way to describe possible use cases.
Everything that could be done with a surface. This includes the
functionality provided by SDL’s current API, and much more. By adding
in calls to these callbacks and corresponding circumstances for BEFORE
a specific API function performs its desired action and making
continued execution of the API function dependent on the return value
of the callback (specific values depending on the circumstance can be
reserved for indicating that some section or step or most of the
function is to be skipped because the callback already handled it or
wants it ignored), SDL’s API’s implementation can be replaced from the
inside by things such as another software renderer or hardware
accelerated rendering such as OpenGL. In fact, we could move the
implementation of SDL’s current API’s internals into a callback,
changing the current API functions into front ends for standardized
callback calls. You could even string multiple callback functions
together, if their implementations are non-conflicting, by making the
actual callback call the other callbacks (after it swaps the current
user-data pointer with a callback specific pointer as necessary,
keeping the pointers between callback calls in a struct or segment
pointed to by the user-data field).
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org