3
\$\begingroup\$

I basically want to have a shader run that can do something like toon shading, or grayscale the whole screen, or radial lighting.

To do this, I create a new bitmap each time the display resizes that is the size of the screen. I then use this as my drawing buffer.

I realized this creates quite a performance hit. Especially on my laptop. Is there a way to do something like this without such a performance hit?

The framework I'm using is Allegro5. This is my current implementation:

void GraphicsContext::flipDisplay()
{
    if(!m_backBuffer)
    {
        al_flip_display();
    }
    else
    {   

        setTargetToBackbuffer();
        if(m_shader)
        {
            m_shader->use();
            m_shader->setSampler(m_backBuffer,"tex");
        }
        drawSprite(m_backBuffer,0,0,0);
        if(m_shader)
        {
            m_shader->stop();
        }

        al_flip_display();
        clear();
        setTargetToBuffer();

    }

}

This way all drawing gets drawn to my bitmap, then that bitmap is blitted to the backbuffer.

I tried using single buffering display but it did not help.

Any advice for fullscreen effects? I have a game I play on my laptop that uses fullscreen film grain and it does not lag. I wonder what they do.

I know that the default shader I set gets ran through every bitmap, but I do not think I can do lighting effects this way since I cannot know which pixel on the screen I'm on.

\$\endgroup\$
3
  • \$\begingroup\$ Why not draw directly to screen or to a frame buffer? Drawing to a bitmap is causing the slowdown. \$\endgroup\$
    – Roy T.
    Aug 19, 2012 at 16:08
  • \$\begingroup\$ I cannot draw directly to screen because for the effect to work I need the final image to go through the shader. I'm using a library called Allegro5 and I'm not sure how to create / use a frame buffer. \$\endgroup\$
    – jmasterx
    Aug 19, 2012 at 16:33
  • \$\begingroup\$ If I read this correctly it looks like Allegro5 can use FBO's wiki.allegro.cc/index.php?title=Hardware_Portability but I've never used Allegro5 so I wouldn't know where to start looking. Someone else will know. I've edited your question to include this info (someone might need to approve the edit before people can see it) \$\endgroup\$
    – Roy T.
    Aug 19, 2012 at 17:59

1 Answer 1

1
\$\begingroup\$

The solution to single buffer is fine, but it should not be reallocated every time the display size changes. Make a buffer the max texture size or sufficiently large enough to cover all possible screen sizes. Then make a sub bitmap of the large buffer texture that you use for drawing. This can then be drawn to screen using your shader.

FYI, allegro 5 can set / tell you what type of display mechanism is in use, whether it is double buffer, page flipping, or triple buffer behind the scenes.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .