Render targets

Getting back to on-topic SDL discussion, I’ve been talking about needing render targets soon for several months now. Well, I don’t need them soon anymore, I need them now. Does anyone know if any progress is being made on the implementation?

Nope, I’ve been crunching on Battle.net for the StarCraft 2 release. :slight_smile:

However, if I remember correctly there was a proposal that was decent.
Does anyone want to air it again for discussion and/or
implementation?On Thu, Apr 8, 2010 at 11:03 AM, Mason Wheeler wrote:

Getting back to on-topic SDL discussion, I’ve been talking about needing render targets soon for several months now. ?Well, I don’t need them soon anymore, I need them now. ?Does anyone know if any progress is being made on the implementation?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Well, I gave a (somewhat) formal definition of what’s needed.

Currently we have SDL_Window, an object that you can render to, either
directly (SDL_RenderLine, for example) or by copying from a texture.
SDL_Window also has another intrinsic characteristic: whatever you
render
gets displayed on screen. We also have SDL_Texture, an object that you
can
render from onto a SDL_Window.

We have three intrinsic characteristics here: 1) Object you can render
to,
2) object you can render from, and 3) object that displays its contents
on-screen. SDL_Window has #1 and #3, SDL_Texture has #2. I need an
object
that has #1 and #2, and not #3.

nfries came up with a decent API specification based on the idea. Here it is:

// Tells whether or not the renderer supports render buffer - since GL
support will require 3.0+ context
bool SDL_RendererSupportsRenderBuffer(SDL_Renderer*);
// Make a render buffer
SDL_RenderBuffer* SDL_CreateRenderBuffer(Uint32 format, int w, int h);
// Get a render buffer from a window (important for the next function)
SDL_RenderBuffer* SDL_GetWindowRenderBuffer(SDL_Window*);
// Set the target to a render buffer, by default it should be the
window’s render buffer
SDL_RenderSetTarget(SDL_RenderBuffer*);
// Blit from a buffer to another buffer or a window.
int SDL_RenderCopyBuffer(SDL_RenderBuffer* buffer, const SDL_Rect*
srcrect, const SDL_Rect* destrect);

perhaps scaling and blendmodes on RenderBuffers, too?
int SDL_SetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int
scalemode);
int SDL_GetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int*
scalemode);
int SDL_SetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int
blendmode);
int SDL_GetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int*
blendmode);

Really, though, anything else we could do for renderbuffers would just
be the same as for a texture.

Seems to me that that last part could be simplified quite a bit by having the render buffer actually contain a SDL_Texture pointer. That would eliminate the need for everything from SDL_RenderCopyBuffer on.>----- Original Message ----

From: Sam Lantinga
Subject: Re: [SDL] Render targets

Nope, I’ve been crunching on Battle.net for the StarCraft 2 release. :slight_smile:

However, if I remember correctly there was a proposal that was decent.
Does anyone want to air it again for discussion and/or
implementation?

On Thu, Apr 8, 2010 at 11:03 AM, Mason Wheeler <@Mason_Wheeler> wrote:

Getting back to on-topic SDL discussion, I’ve been talking about needing render targets soon for several months now. Well, I don’t need them soon anymore, I need them now. Does anyone know if any progress is being made on the implementation?

There was also the idea of creating SDL_TEXTUREACCESS_TARGET and
having an API like this:
SDL_SetRenderTargetWindow(SDL_WindowID)
SDL_SetRenderTargetTexture(SDL_TextureID)On Fri, Apr 9, 2010 at 5:37 AM, Mason Wheeler wrote:

Well, I gave a (somewhat) formal definition of what’s needed.

Currently we have SDL_Window, an object that you can render to, either
directly (SDL_RenderLine, for example) or by copying from a texture.
SDL_Window also has another intrinsic characteristic: whatever you
render
gets displayed on screen. ?We also have SDL_Texture, an object that you
can
render from onto a SDL_Window.

We have three intrinsic characteristics here: 1) Object you can render
to,
2) object you can render from, and 3) object that displays its contents
on-screen. ?SDL_Window has #1 and #3, SDL_Texture has #2. ?I need an
object
that has #1 and #2, and not #3.

nfries came up with a decent API specification based on the idea. ?Here it is:

// Tells whether or not the renderer supports render buffer - since GL
support will require 3.0+ context
bool SDL_RendererSupportsRenderBuffer(SDL_Renderer*);
// Make a render buffer
SDL_RenderBuffer* SDL_CreateRenderBuffer(Uint32 format, int w, int h);
// Get a render buffer from a window (important for the next function)
SDL_RenderBuffer* SDL_GetWindowRenderBuffer(SDL_Window*);
// Set the target to a render buffer, by default it should be the
window’s render buffer
SDL_RenderSetTarget(SDL_RenderBuffer*);
// Blit from a buffer to another buffer or a window.
int SDL_RenderCopyBuffer(SDL_RenderBuffer* buffer, const SDL_Rect*
srcrect, const SDL_Rect* destrect);

perhaps scaling and blendmodes on RenderBuffers, too?
int SDL_SetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int
scalemode);
int SDL_GetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int*
scalemode);
int SDL_SetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int
blendmode);
int SDL_GetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int*
blendmode);

Really, though, anything else we could do for renderbuffers would just
be the same as for a texture.

Seems to me that that last part could be simplified quite a bit by having the render buffer actually contain a SDL_Texture pointer. ?That would eliminate the need for everything from SDL_RenderCopyBuffer on.

----- Original Message ----
From: Sam Lantinga <@slouken>
Subject: Re: [SDL] Render targets

Nope, I’ve been crunching on Battle.net for the StarCraft 2 release. :slight_smile:

However, if I remember correctly there was a proposal that was decent.
Does anyone want to air it again for discussion and/or
implementation?

On Thu, Apr 8, 2010 at 11:03 AM, Mason Wheeler wrote:

Getting back to on-topic SDL discussion, I’ve been talking about needing render targets soon for several months now. ?Well, I don’t need them soon anymore, I need them now. ?Does anyone know if any progress is being made on the implementation?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

I kinda like the other idea better, but at the moment I’d be willing to settle for
whatever is faster to implement. I really do need this functionality now,
which is why I’ve been talking about it for so long.>----- Original Message ----

From: Sam Lantinga
Subject: Re: [SDL] Render targets

There was also the idea of creating SDL_TEXTUREACCESS_TARGET and
having an API like this:
SDL_SetRenderTargetWindow(SDL_WindowID)
SDL_SetRenderTargetTexture(SDL_TextureID)

On Fri, Apr 9, 2010 at 5:37 AM, Mason Wheeler <@Mason_Wheeler> wrote:

Well, I gave a (somewhat) formal definition of what’s needed.

Currently we have SDL_Window, an object that you can render to, either
directly (SDL_RenderLine, for example) or by copying from a texture.
SDL_Window also has another intrinsic characteristic: whatever you
render
gets displayed on screen. We also have SDL_Texture, an object that you
can
render from onto a SDL_Window.

We have three intrinsic characteristics here: 1) Object you can render
to,
2) object you can render from, and 3) object that displays its contents
on-screen. SDL_Window has #1 and #3, SDL_Texture has #2. I need an
object
that has #1 and #2, and not #3.

nfries came up with a decent API specification based on the idea. Here it is:

// Tells whether or not the renderer supports render buffer - since GL
support will require 3.0+ context
bool SDL_RendererSupportsRenderBuffer(SDL_Renderer*);
// Make a render buffer
SDL_RenderBuffer* SDL_CreateRenderBuffer(Uint32 format, int w, int h);
// Get a render buffer from a window (important for the next function)
SDL_RenderBuffer* SDL_GetWindowRenderBuffer(SDL_Window*);
// Set the target to a render buffer, by default it should be the
window’s render buffer
SDL_RenderSetTarget(SDL_RenderBuffer*);
// Blit from a buffer to another buffer or a window.
int SDL_RenderCopyBuffer(SDL_RenderBuffer* buffer, const SDL_Rect*
srcrect, const SDL_Rect* destrect);

perhaps scaling and blendmodes on RenderBuffers, too?
int SDL_SetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int
scalemode);
int SDL_GetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int*
scalemode);
int SDL_SetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int
blendmode);
int SDL_GetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int*
blendmode);

Really, though, anything else we could do for renderbuffers would just
be the same as for a texture.

Seems to me that that last part could be simplified quite a bit by having the render buffer actually contain a SDL_Texture pointer. That would eliminate the need for everything from SDL_RenderCopyBuffer on.

Was there any particular reason you liked the first proposal better?

The advantage of the TEXTUREACCESS_TARGET is that it’s explicitly a
texture and you can do all the normal texture things with it (specify
color blending, etc.)

Does anyone have a first pass at implementation?On Wed, Apr 14, 2010 at 6:12 AM, Mason Wheeler wrote:

I kinda like the other idea better, but at the moment I’d be willing to settle for
whatever is faster to implement. ?I really do need this functionality now,
which is why I’ve been talking about it for so long.

----- Original Message ----

From: Sam Lantinga <@slouken>
Subject: Re: [SDL] Render targets

There was also the idea of creating SDL_TEXTUREACCESS_TARGET and
having an API like this:
SDL_SetRenderTargetWindow(SDL_WindowID)
SDL_SetRenderTargetTexture(SDL_TextureID)

On Fri, Apr 9, 2010 at 5:37 AM, Mason Wheeler wrote:

Well, I gave a (somewhat) formal definition of what’s needed.

Currently we have SDL_Window, an object that you can render to, either
directly (SDL_RenderLine, for example) or by copying from a texture.
SDL_Window also has another intrinsic characteristic: whatever you
render
gets displayed on screen. ?We also have SDL_Texture, an object that you
can
render from onto a SDL_Window.

We have three intrinsic characteristics here: 1) Object you can render
to,
2) object you can render from, and 3) object that displays its contents
on-screen. ?SDL_Window has #1 and #3, SDL_Texture has #2. ?I need an
object
that has #1 and #2, and not #3.

nfries came up with a decent API specification based on the idea. ?Here it is:

// Tells whether or not the renderer supports render buffer - since GL
support will require 3.0+ context
bool SDL_RendererSupportsRenderBuffer(SDL_Renderer*);
// Make a render buffer
SDL_RenderBuffer* SDL_CreateRenderBuffer(Uint32 format, int w, int h);
// Get a render buffer from a window (important for the next function)
SDL_RenderBuffer* SDL_GetWindowRenderBuffer(SDL_Window*);
// Set the target to a render buffer, by default it should be the
window’s render buffer
SDL_RenderSetTarget(SDL_RenderBuffer*);
// Blit from a buffer to another buffer or a window.
int SDL_RenderCopyBuffer(SDL_RenderBuffer* buffer, const SDL_Rect*
srcrect, const SDL_Rect* destrect);

perhaps scaling and blendmodes on RenderBuffers, too?
int SDL_SetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int
scalemode);
int SDL_GetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int*
scalemode);
int SDL_SetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int
blendmode);
int SDL_GetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int*
blendmode);

Really, though, anything else we could do for renderbuffers would just
be the same as for a texture.

Seems to me that that last part could be simplified quite a bit by having the render buffer actually contain a SDL_Texture pointer. ?That would eliminate the need for everything from SDL_RenderCopyBuffer on.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

The guy who proposed that idea created an OpenGL patch for it, but I haven’t
tested it so I don’t know if it works or not.

http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2009-June/071148.html

As for why I like the first proposal better, it’s just sort of the way I think about
the data. A render target isn’t a texture, it’s an object that contains a texture
but also does other things. In OOP it would probably inherit from SDL_Texture,
but since this is all in C, it would have to contain a SDL_Texture (or a
SDL_Texture pointer) instead.

That texture could do all the same things that any SDL_Texture can do, but it
would have additional functionality (the ability to render to it) that a SDL_Texture
can’t do. This would mean, for example, that you can’t pass an SDL_Texture
pointer to SDL_RenderCopyBuffer or SDL_RenderSetTarget, so those routines
don’t have to check for it. Otherwise, you need special code in them to make
sure that the texture you’ve passed in uses SDL_TEXTUREACCESS_TARGET
and return an error code if it’s wrong, (which the user has to check for because
C doesn’t have exceptions) and so on. Compile-time errors that you can’t miss
are much better than runtime errors that you can.> ----- Original Message -----

From: slouken@libsdl.org (Sam Lantinga)
To: SDL Development List
Sent: Wed, April 14, 2010 11:22:44 PM
Subject: Re: [SDL] Render targets

Was there any particular reason you liked the first proposal better?

The advantage of the TEXTUREACCESS_TARGET is that it’s explicitly a
texture and you can do all the normal texture things with it (specify
color blending, etc.)

Does anyone have a first pass at implementation?

On Wed, Apr 14, 2010 at 6:12 AM, Mason Wheeler <@Mason_Wheeler> wrote:

I kinda like the other idea better, but at the moment I’d be willing to settle for
whatever is faster to implement. I really do need this functionality now,
which is why I’ve been talking about it for so long.

----- Original Message ----

From: Sam Lantinga
Subject: Re: [SDL] Render targets

There was also the idea of creating SDL_TEXTUREACCESS_TARGET and
having an API like this:
SDL_SetRenderTargetWindow(SDL_WindowID)
SDL_SetRenderTargetTexture(SDL_TextureID)

On Fri, Apr 9, 2010 at 5:37 AM, Mason Wheeler <@Mason_Wheeler> wrote:

Well, I gave a (somewhat) formal definition of what’s needed.

Currently we have SDL_Window, an object that you can render to, either
directly (SDL_RenderLine, for example) or by copying from a texture.
SDL_Window also has another intrinsic characteristic: whatever you
render
gets displayed on screen. We also have SDL_Texture, an object that you
can
render from onto a SDL_Window.

We have three intrinsic characteristics here: 1) Object you can render
to,
2) object you can render from, and 3) object that displays its contents
on-screen. SDL_Window has #1 and #3, SDL_Texture has #2. I need an
object
that has #1 and #2, and not #3.

nfries came up with a decent API specification based on the idea. Here it is:

// Tells whether or not the renderer supports render buffer - since GL
support will require 3.0+ context
bool SDL_RendererSupportsRenderBuffer(SDL_Renderer*);
// Make a render buffer
SDL_RenderBuffer* SDL_CreateRenderBuffer(Uint32 format, int w, int h);
// Get a render buffer from a window (important for the next function)
SDL_RenderBuffer* SDL_GetWindowRenderBuffer(SDL_Window*);
// Set the target to a render buffer, by default it should be the
window’s render buffer
SDL_RenderSetTarget(SDL_RenderBuffer*);
// Blit from a buffer to another buffer or a window.
int SDL_RenderCopyBuffer(SDL_RenderBuffer* buffer, const SDL_Rect*
srcrect, const SDL_Rect* destrect);

perhaps scaling and blendmodes on RenderBuffers, too?
int SDL_SetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int
scalemode);
int SDL_GetRenderBufferScaleMode(SDL_RenderBuffer* buffer, int*
scalemode);
int SDL_SetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int
blendmode);
int SDL_GetRenderBufferBlendMode(SDL_RenderBuffer* buffer, int*
blendmode);

Really, though, anything else we could do for renderbuffers would just
be the same as for a texture.

Seems to me that that last part could be simplified quite a bit by having the render buffer actually contain a SDL_Texture pointer. That would eliminate the need for everything from SDL_RenderCopyBuffer on.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

OK, just tested it. Once I managed to get everything running without any errors,
I ended up with a whole lot of nothing.

Here’s what I did:

Create a window with a GL renderer.
Create a TEXTUREACCESS_TARGET texture.
SDL_SetTargetTexture
SDL_SetRenderDrawColor($ff, $ff, $ff, $ff);
SDL_RenderFillRect on the whole thing
SDL_RenderCopy a valid texture.
SDL_SelectRenderer on the window.
SDL_RenderCopy the render target.

Intuitively, this should work. It doesn’t return any errors, either. But I ended up
with a black window, and a broken black window at that. After performing this,
nothing would appear in the SDL_Window with normal rendering commands.

I don’t know enough OpenGL to have any idea why this isn’t working, but it’s not
working.>----- Original Message ----

From: Mason Wheeler <@Mason_Wheeler>
Subject: Re: [SDL] Render targets

The guy who proposed that idea created an OpenGL patch for it, but I haven’t
tested it so I don’t know if it works or not.

http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2009-June/071148.html

----- Original Message ----
From: Sam Lantinga
Subject: Re: [SDL] Render targets

Was there any particular reason you liked the first proposal better?

The advantage of the TEXTUREACCESS_TARGET is that it’s explicitly a
texture and you can do all the normal texture things with it (specify
color blending, etc.)

Does anyone have a first pass at implementation?

I did a bit of research and found the problem, (the author missed an important
step,) and now I have a basic GL render target implementation that passes
my internal test. I’ll submit the working patch to Bugzilla in a bit…>----- Original Message ----

From: Mason Wheeler <@Mason_Wheeler>
Subject: Re: [SDL] Render targets

OK, just tested it. Once I managed to get everything running without any errors,
I ended up with a whole lot of nothing.

I don’t know enough OpenGL to have any idea why this isn’t working, but it’s not
working.

Great! :)On Thu, Apr 15, 2010 at 5:23 PM, Mason Wheeler wrote:

I did a bit of research and found the problem, (the author missed an important
step,) and now I have a basic GL render target implementation that passes
my internal test. ?I’ll submit the working patch to Bugzilla in a bit…

----- Original Message ----
From: Mason Wheeler
Subject: Re: [SDL] Render targets

OK, just tested it. ?Once I managed to get everything running without any errors,
I ended up with a whole lot of nothing.

I don’t know enough OpenGL to have any idea why this isn’t working, but it’s not
working.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

OK, it’s in.

http://bugzilla.libsdl.org/show_bug.cgi?id=983>----- Original Message ----

From: Sam Lantinga
Subject: Re: [SDL] Render targets

Great! :slight_smile:

On Thu, Apr 15, 2010 at 5:23 PM, Mason Wheeler <@Mason_Wheeler> wrote:

I did a bit of research and found the problem, (the author missed an important
step,) and now I have a basic GL render target implementation that passes
my internal test. I’ll submit the working patch to Bugzilla in a bit…

Thanks! Ryan and I are looking it over. Feel free to use it in the
meantime, as always. :)On Thu, Apr 15, 2010 at 8:52 PM, Mason Wheeler wrote:

OK, it’s in.

http://bugzilla.libsdl.org/show_bug.cgi?id=983

----- Original Message ----
From: Sam Lantinga <@slouken>
Subject: Re: [SDL] Render targets

Great! :slight_smile:

On Thu, Apr 15, 2010 at 5:23 PM, Mason Wheeler wrote:

I did a bit of research and found the problem, (the author missed an important
step,) and now I have a basic GL render target implementation that passes
my internal test. ?I’ll submit the working patch to Bugzilla in a bit…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

I just got a notification from Bugzilla that Gabriel Jacobo reworked my render target patch to apply correctly against the current head.? So now what would it take to finally get it applied?