Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Porting "Fullscreen" Shaders  (Read 1517 times)

0 Members and 1 Guest are viewing this topic.

cwkx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Porting "Fullscreen" Shaders
« on: March 16, 2012, 02:25:15 pm »
Hi,

I'm porting some work to SFML - I need to apply fullscreen shaders to the entire window render area, instead of just a texture rectangle. I see you can draw shaders by specifying vertices, but after trying:

Code: [Select]

const SF::Vertex vertices[] = { SF::Vertex(SF::Vector2f(-1.0f, 1.0f)), SF::Vertex(SF::Vector2f(1.0f, 1.0f)), SF::Vertex(SF::Vector2f(1.0f, -1.0f)), SF::Vertex(SF::Vector2f(-1.0f, -1.0f)) };
target.draw(&vertices[0], 4, SF::PrimitiveType::Quads, states);


1. I found it doesn't use normalized coords - how can I therefore draw to the entire window render area efficiently (do I really have to recreate 4 vertices from the app size each frame)?

2. I need to use "uniform mat4" for several of my shaders. Do I just do it manually with glUniformMatrix4fv(..., 1, GL_FALSE, &viewMatrix[0][0]); ?

3. I was looking at the code, I noticed setParameter is called in the update loop, which implicitly does: GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str()); - isn't this slow when you have quite a lot of parameters? What about providing a int getFastParamID(...)  to call in init, then instead of having strings force users who don't care about optimizations to do setParameter(getID("name"), ...) - but this allows users who do care about performance to just send the private GLint from the init - do you think this'll make much difference? (I don't know much about the framework/principles/conventions in SFML yet though so may have missed something)

4. (Offtopic) Is there an easy way to use subpixel font rendering/expose it from freetype? - I haven't looked into this yet.

- P.S. Thanks so much for keeping SFML lightweight! :wink:  I was very happy to see the output size, with static linking, so small.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Porting "Fullscreen" Shaders
« Reply #1 on: March 16, 2012, 05:53:21 pm »
Quote
1. I found it doesn't use normalized coords - how can I therefore draw to the entire window render area efficiently (do I really have to recreate 4 vertices from the app size each frame)?

Yes. Why is it a problem?

Quote
2. I need to use "uniform mat4" for several of my shaders. Do I just do it manually with glUniformMatrix4fv(..., 1, GL_FALSE, &viewMatrix[0][0]); ?

SFML provides support for SFML types. Therefore you can send a sf::Transform (as a mat4), but not a raw matrix. I guess doing it manually would work, although it is not the recommended usage.

Quote
3. I was looking at the code, I noticed setParameter is called in the update loop, which implicitly does: GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str()); - isn't this slow when you have quite a lot of parameters?

Try, and come back with results ;)
My philosophy for SFML is to make it simple, and then only optimize where it is really necessary.
But my guess is that it wouldn't make a big difference.

Quote
4. (Offtopic) Is there an easy way to use subpixel font rendering/expose it from freetype? - I haven't looked into this yet.

Easy way, most likely, but "public"/"official", no :)
Laurent Gomila - SFML developer

cwkx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Porting "Fullscreen" Shaders
« Reply #2 on: March 16, 2012, 06:28:34 pm »
Thanks for the quick reply!

1. Sorry, there's no problem with this at all - I just thought their may have been "GetScreenVertices()" or something - but setting vertices each frame works well:

Code: [Select]
const SF::Vertex vertices[] = { SF::Vertex(SF::Vector2f(0.0f, app.getSize().y)), SF::Vertex(SF::Vector2f(app.getSize().x, app.getSize().y)), SF::Vertex(SF::Vector2f(app.getSize().x, 0.0f)), SF::Vertex(SF::Vector2f(0.0f, 0.0f)) };

Simple is good for this library and its intentions :)

Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Porting "Fullscreen" Shaders
« Reply #3 on: March 16, 2012, 07:50:19 pm »
Do you actually rename namespace sf to SF in your code? :shock: :lol:
Laurent Gomila - SFML developer

cwkx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Porting "Fullscreen" Shaders
« Reply #4 on: March 17, 2012, 11:37:56 am »
Haha yeah ;) namespace SF = sf; to be consistent with the previous work - thankfully that's the only major change in style though now that your using lowercase camelCase :)

 

anything