0

I have to implement multiple features in one opengl program. For example, to deal with one whole image file, we have 3 features:

(1). YUV->RGB

(2). image filter

(3). RGB->YUV

then just one vertex shader and 3 fragment shaders will be OK. I have implemented these 3 shaders one by one, and the function work for each, but I don't know how to link them like a pipe together? Can somebody help, thanks.

I have googled 2 ways may work for my case:

1. Use glUseProgram() to switch between shaders, but it will only make effect for the last fragment shader. 

2. Write a complicated fragment shader to embody all these features. But I don't know how, seems impossible.

1 Answer 1

1

Use FBOs (Frame Buffer Objects) to ping-pong draw calls. For example when applying some image filters. Draw texture to FBO using first image filter shader. Then you may use second shader (another filter) to draw content of FBO (texture) to framebuffer.

If you need more than two processing shaders use two FBOs and ping-pong draw calls between them in background until processing is done.

Sign up to request clarification or add additional context in comments.

2 Comments

Great! I have done it, though performance is not good as I imagined before. Thanks.
Try to tune up your shaders a lot of performance could be lost/gained there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.