# Multiple shaderprograms and textures

**URL:** <https://forums.imgtec.com/t/multiple-shaderprograms-and-textures/424>\
**Category:** PowerVR Insider\
**Created:** [July 29, 2009, 12:30pm UTC](https://forums.imgtec.com/t/multiple-shaderprograms-and-textures/424 "2009-07-29T12:30:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hnyk](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@hnyk](https://forums.imgtec.com/u/hnyk)\
**Post date:** [July 29, 2009, 12:30pm UTC](https://forums.imgtec.com/t/multiple-shaderprograms-and-textures/424/1 "2009-07-29T12:30:26Z")

</div>

Hi  
  
I am trying to build a pipeline which includes multiple shaderprograms. Each of these shaderprograms, except the first one, will render output to texture and use previous render as a source. The first one will take a picture as a source and it is loaded to m\_uiTexture. Shaderprograms are also compiled and linked beforehand and they should work just fine so I didn't include them here. The samplers are defined beforehand so I can loop the actual rendering with minimal overhead.  
  
GLuint m\_uiTexture;  
  
GLuint framebuffer;  
  
GLuint renderbuffer;   
  
GLuint textures[2];  
  
glGenFramebuffers(1, &framebuffer);  
glGenRenderbuffers(1, &renderbuffer);  
  
glBindRenderbuffer(GL\_RENDERBUFFER, renderbuffer);  
glRenderbufferStorage(GL\_RENDERBUFFER, GL\_RGB8\_OES, 512, 512);  
  
glBindFramebuffer(GL\_FRAMEBUFFER, framebuffer);  
  
glGenTextures(2, textures);  
  
glUseProgram(m\_ShaderProgramScale.uiId);  
glActiveTexture(GL\_TEXTURE0);  
glBindTexture(GL\_TEXTURE\_2D, m\_uiTexture);  
glUniform1i(m\_ShaderProgramScale.auiLoc[eSampler], 0);  
  
glUseProgram(m\_ShaderProgramDOG.uiId);  
glActiveTexture(GL\_TEXTURE1);  
glBindTexture(GL\_TEXTURE\_2D, textures[0]);  
glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGBA, texWidth, texHeight, 0, GL\_RGBA, GL\_UNSIGNED\_BYTE, NULL);  
glUniform1i(m\_ShaderProgramDOG.auiLoc[eSampler], 1);  
  
glUseProgram(m\_ShaderProgramExtrema.uiId);  
glActiveTexture(GL\_TEXTURE2);  
glBindTexture(GL\_TEXTURE\_2D, textures[1]);  
glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGBA, texWidth, texHeight, 0, GL\_RGBA, GL\_UNSIGNED\_BYTE, NULL);  
glUniform1i(m\_ShaderProgramExtrema.auiLoc[eSampler], 2);  
  

* * *
Loop starts here
* * *
  
  
glFramebufferTexture2D(GL\_FRAMEBUFFER, GL\_COLOR\_ATTACHMENT0, GL\_TEXTURE\_2D, textures[0], 0);  
glUseProgram(m\_ShaderProgramScale.uiId);  
glDrawArrays(GL\_TRIANGLE\_STRIP, 0, 4);  
  
glFramebufferTexture2D(GL\_FRAMEBUFFER, GL\_COLOR\_ATTACHMENT0, GL\_TEXTURE\_2D, textures[1], 0);  
glUseProgram(m\_ShaderProgramDOG.uiId);  
glDrawArrays(GL\_TRIANGLE\_STRIP, 0, 4);  
  
glFramebufferTexture2D(GL\_FRAMEBUFFER, GL\_COLOR\_ATTACHMENT0, GL\_TEXTURE\_2D, textures[0], 0);  
glUseProgram(m\_ShaderProgramExtrema.uiId);  
glDrawArrays(GL\_TRIANGLE\_STRIP, 0, 4);  
  
For some reason this doesn't give the expected result. Could someone tell me why?  
  
-hnyk  
  

* * *
  
  
I have now tracked down the problem to this instruction: glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGBA, texWidth, texHeight, 0, GL\_RGBA, GL\_UNSIGNED\_BYTE, NULL);  
  
The system works fine when I load the texture from a file and then render over it, but when I try to create a blank texture with the above instruction, it doesn't work.  
  
Any ideas what is wrong and how can I fix it?  
  

* * *
  
  
Okay the problem was with texture filters and now it seems to work :)   
  
hnyk2009-08-03 11:43:45
