GLSL shader fun!

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

On my hardware this ends up being about a 200-400 FPS increase in testsprite2:

SDL_RENDER_OPENGL_SHADERS=0 ./testsprite2
OpenGL shaders: DISABLED
3051.84 frames per second

./testsprite2
OpenGL shaders: ENABLED
3428.22 frames per second

Woot! :slight_smile:

I also noticed there’s not a single example of using shaders with SDL
that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

See ya!–
? ? -Sam Lantinga, Founder and CEO, Galaxy Gameworks

1 Like

Great work Sam! Congratulations!

What do you think about adding OpenCL support as well?

In environments where OpenCL hardware is available, SDL can get better
optimizations than
using processor vector extensions, most likely.–
Paulo

On Wed, Feb 9, 2011 at 7:39 AM, Sam Lantinga wrote:

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

On my hardware this ends up being about a 200-400 FPS increase in
testsprite2:

SDL_RENDER_OPENGL_SHADERS=0 ./testsprite2
OpenGL shaders: DISABLED
3051.84 frames per second

./testsprite2
OpenGL shaders: ENABLED
3428.22 frames per second

Woot! :slight_smile:

I also noticed there’s not a single example of using shaders with SDL
that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

See ya!

-Sam Lantinga, Founder and CEO, Galaxy Gameworks

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

I’m not planning on doing it myself, but I’m happy to accept patches. :)On Tue, Feb 8, 2011 at 11:53 PM, Paulo Pinto wrote:

Great work Sam! Congratulations!

What do you think about adding OpenCL support as well?

In environments where OpenCL hardware is available, SDL can get better
optimizations than
using processor vector extensions, most likely.


Paulo

On Wed, Feb 9, 2011 at 7:39 AM, Sam Lantinga <@slouken> wrote:

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

On my hardware this ends up being about a 200-400 FPS increase in
testsprite2:

SDL_RENDER_OPENGL_SHADERS=0 ./testsprite2
OpenGL shaders: DISABLED
3051.84 frames per second

./testsprite2
OpenGL shaders: ENABLED
3428.22 frames per second

Woot! :slight_smile:

I also noticed there’s not a single example of using shaders with SDL
that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

See ya!

-Sam Lantinga, Founder and CEO, Galaxy Gameworks

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


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

I got a modest speed up with testsprite (using the 1.2 API) as well:

SDL_RENDER_OPENGL_SHADERS=0 ./testsprite
1329.16 frames per second

SDL_RENDER_OPENGL_SHADERS=1 ./testsprite
1354.20 frames per secondOn Tue, Feb 8, 2011 at 10:39 PM, Sam Lantinga <@slouken> wrote:

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

On my hardware this ends up being about a 200-400 FPS increase in
testsprite2:

SDL_RENDER_OPENGL_SHADERS=0 ./testsprite2
OpenGL shaders: DISABLED
3051.84 frames per second

./testsprite2
OpenGL shaders: ENABLED
3428.22 frames per second

Woot! :slight_smile:

I also noticed there’s not a single example of using shaders with SDL
that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

See ya!

-Sam Lantinga, Founder and CEO, Galaxy Gameworks


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

I might try to have a look at it.

It is always a good excuse to learn OpenCL :)On Wed, Feb 9, 2011 at 10:42 AM, Sam Lantinga wrote:

I’m not planning on doing it myself, but I’m happy to accept patches. :slight_smile:

On Tue, Feb 8, 2011 at 11:53 PM, Paulo Pinto <@Paulo_Pinto> wrote:

Great work Sam! Congratulations!

What do you think about adding OpenCL support as well?

In environments where OpenCL hardware is available, SDL can get better
optimizations than
using processor vector extensions, most likely.


Paulo

On Wed, Feb 9, 2011 at 7:39 AM, Sam Lantinga wrote:

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

On my hardware this ends up being about a 200-400 FPS increase in
testsprite2:

SDL_RENDER_OPENGL_SHADERS=0 ./testsprite2
OpenGL shaders: DISABLED
3051.84 frames per second

./testsprite2
OpenGL shaders: ENABLED
3428.22 frames per second

Woot! :slight_smile:

I also noticed there’s not a single example of using shaders with SDL
that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

See ya!

-Sam Lantinga, Founder and CEO, Galaxy Gameworks

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


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


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

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

Hmm? Doesn’t SDL already use shaders internally for GL rendering? I see
plenty of references to them in sdl_renderer_gl.

I also noticed there’s not a single example of using shaders with SDL

that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

Interesting example, but once you do that how do you get an SDL_Texture out
of it?>----- Original Message ----

From: Sam Lantinga
Subject: [SDL] GLSL shader fun!

Cool!

Shouldn’t/couldn’t this code be in some common (SDL1.3) helper function?

/* Check for shader support */

–AndreasOn 2/8/11 10:39 PM, Sam Lantinga wrote:

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

On my hardware this ends up being about a 200-400 FPS increase in testsprite2:

SDL_RENDER_OPENGL_SHADERS=0 ./testsprite2
OpenGL shaders: DISABLED
3051.84 frames per second

./testsprite2
OpenGL shaders: ENABLED
3428.22 frames per second

Woot! :slight_smile:

I also noticed there’s not a single example of using shaders with SDL
that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

See ya!

SDL used to use ARB shaders, and I’ve pulled them out and updated them with
a more powerful GLSL framework.

SDL’s internal shader support is just that - it’s not intended to be used
outside of the API. If you’re using shaders directly, you shouldn’t be
using the rendering API.On Wed, Feb 9, 2011 at 6:03 AM, Mason Wheeler wrote:

----- Original Message ----

From: Sam Lantinga <@slouken>
Subject: [SDL] GLSL shader fun!

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

Hmm? Doesn’t SDL already use shaders internally for GL rendering? I see
plenty of references to them in sdl_renderer_gl.

I also noticed there’s not a single example of using shaders with SDL

that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

Interesting example, but once you do that how do you get an SDL_Texture out
of it?


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

Seriously, if you keep trying to use the rendering API and mixing it with
your own OpenGL, you’re going to be frustrated. Just don’t do it. :)On Wed, Feb 9, 2011 at 10:04 AM, Sam Lantinga <@slouken> wrote:

SDL used to use ARB shaders, and I’ve pulled them out and updated them with
a more powerful GLSL framework.

SDL’s internal shader support is just that - it’s not intended to be used
outside of the API. If you’re using shaders directly, you shouldn’t be
using the rendering API.

On Wed, Feb 9, 2011 at 6:03 AM, Mason Wheeler wrote:

----- Original Message ----

From: Sam Lantinga <@slouken>
Subject: [SDL] GLSL shader fun!

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

Hmm? Doesn’t SDL already use shaders internally for GL rendering? I see
plenty of references to them in sdl_renderer_gl.

I also noticed there’s not a single example of using shaders with SDL

that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

Interesting example, but once you do that how do you get an SDL_Texture
out
of it?


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

Same thing as the rotation thing I was talking about earlier. The vast majority
of my textures won’t require any special shading, but there are some specific
cases where I will require certain effects, particularly HSL transforms, that
can’t be done without the use of a shader. I’d really prefer not to have to
throw out a very good, simple solution for the 99% case (the SDL rendering API)
just to be able to support the 1% case.________________________________
From: slouken@libsdl.org (slouken)
Subject: Re: [SDL] GLSL shader fun!

Seriously, if you keep trying to use the rendering API and mixing it with your
own OpenGL, you’re going to be frustrated. Just don’t do it. :slight_smile:

On Wed, Feb 9, 2011 at 10:04 AM, Sam Lantinga wrote:

SDL used to use ARB shaders, and I’ve pulled them out and updated them with a
more powerful GLSL framework.

SDL’s internal shader support is just that - it’s not intended to be used
outside of the API. If you’re using shaders directly, you shouldn’t be using
the rendering API.

On Wed, Feb 9, 2011 at 6:03 AM, Mason Wheeler <@Mason_Wheeler> wrote:

----- Original Message ----

From: Sam Lantinga
Subject: [SDL] GLSL shader fun!

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

Hmm? Doesn’t SDL already use shaders internally for GL rendering? I see
plenty of references to them in sdl_renderer_gl.

I also noticed there’s not a single example of using shaders with SDL

that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

Interesting example, but once you do that how do you get an SDL_Texture out
of it?


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

Okay, fair enough. :)On Wed, Feb 9, 2011 at 11:08 AM, Mason Wheeler wrote:

Same thing as the rotation thing I was talking about earlier. The vast
majority of my textures won’t require any special shading, but there are
some specific cases where I will require certain effects, particularly HSL
transforms, that can’t be done without the use of a shader. I’d really
prefer not to have to throw out a very good, simple solution for the 99%
case (the SDL rendering API) just to be able to support the 1% case.


From: Sam Lantinga <@slouken>


Subject: Re: [SDL] GLSL shader fun!

Seriously, if you keep trying to use the rendering API and mixing it with
your own OpenGL, you’re going to be frustrated. Just don’t do it. :slight_smile:

On Wed, Feb 9, 2011 at 10:04 AM, Sam Lantinga <@slouken> wrote:

SDL used to use ARB shaders, and I’ve pulled them out and updated them
with a more powerful GLSL framework.

SDL’s internal shader support is just that - it’s not intended to be used
outside of the API. If you’re using shaders directly, you shouldn’t be
using the rendering API.

On Wed, Feb 9, 2011 at 6:03 AM, Mason Wheeler wrote:

----- Original Message ----

From: Sam Lantinga <@slouken>
Subject: [SDL] GLSL shader fun!

I just added GLSL shaders to the OpenGL rendering implementation!
You can disable them by setting the SDL_HINT_RENDER_OPENGL_SHADERS
hint in your application, or the SDL_RENDER_OPENGL_SHADERS environment
variable.

Hmm? Doesn’t SDL already use shaders internally for GL rendering? I see
plenty of references to them in sdl_renderer_gl.

I also noticed there’s not a single example of using shaders with SDL

that has full source code, so I added one:
http://hg.libsdl.org/SDL/file/default/test/testshader.c

Interesting example, but once you do that how do you get an SDL_Texture
out
of it?


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


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


-Sam Lantinga, Founder and CEO, Galaxy Gameworks