Imagination PowerVR SDK Blog

InitView() fails due to mPrint3d.SeTextures

pvrshaman

#1

EDITED to make it clear that I added an additional shader, so there are two shader programs created in LoadShaders()



I am running the OGLES2ParallaxBumpMap application in SDK 3.0.



There is a LoadShaders() function. I have added my own shader into the application IN ADDITION to the one that is already in the example/App. So now there are two shader programs being created in load LoadShaders() I receive no error handling messages. For some reason InitView fails due to m_Print3D.SetTextures.



The error I get is :



PVRTTextureLoadFromPointer failed: glBindTexture() failed.

Exit message has been set to: "ERROR: Cannot initialise Print3D




It happens in the following block.



if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)

{

PVRShellSet(prefExitMessage, “ERROR: Cannot initialise Print3Dn”);

return false;

}




The following is my code that I added into LoadShaders(). Again, I get no error handling messages. But what I noticed is that when I comment out PVRTCreateProgram() the program does not crash (succesfully go through InitView).



I receive no error handling messages for PVRTCreateProgram() when InitView fails. I googled the error messages and saw that there could be some state issues. I am not trying to load up any additional textures. Is there some resource/state issue I have caused by trying to create another shader program?



The code I am using is the same code in the original LoadShaders() function --> OGLES2ParallaxBumpMap::LoadShaders(CPVRTString* pErrorStr)



if (PVRTShaderLoadFromFile(

media_szVertShaderBinFile, media_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &media_VertShader, pErrorStr) != PVR_SUCCESS)

{

return false;

}



if (PVRTShaderLoadFromFile(

media_szFragShaderBinFile, media_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &media_FragShader, pErrorStr) != PVR_SUCCESS)

{

return false;

}





/*

Set up and link the shader program

*/





if (PVRTCreateProgram(&media_ShaderProgram.uiId, media_VertShader, media_FragShader, media_aszAttribNames, eMediaNumAttribs, pErrorStr) != PVR_SUCCESS)

{



PVRShellSet(prefExitMessage, pErrorStr->c_str());

return false;

}





// Store the location of uniforms for later use

for (int i = 0; i < eMediaNumUniforms; ++i)

{

media_ShaderProgram.auiLoc = glGetUniformLocation(media_ShaderProgram.uiId, media_aszUniformNames);

}






#2

Hi Sir,



it’ seems that there is a problem in the Shader that you added ,you can test it with PVR Shaman to see is there is nothing wrong ?



i did a quick fast and dirty test base on the sample that you mention with two shaders and no prob at all



bool OGLES2ParallaxBumpMap::LoadShaders(CPVRTString* pErrorStr)

{

/*

Load and compile the shaders from files.

Binary shaders are tried first, source shaders

are used as fallback.

/

if (PVRTShaderLoadFromFile(

c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS) {

return false;

}



if (PVRTShaderLoadFromFile(

c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS) {

return false;

}





/


Load and compile the shaders from files.

Binary shaders are tried first, source shaders

are used as fallback.

*/

if (PVRTShaderLoadFromFile(c_szFastVsBinFile,

c_szFastVsSrcFile,

GL_VERTEX_SHADER,

GL_SGX_BINARY_IMG,

&m_uiFastVertShader,

pErrorStr) != PVR_SUCCESS) {

*pErrorStr = CPVRTString(“From file '”) + c_szFastVsBinFile +

"’ or ‘" + c_szFastVsSrcFile + "’:n" + *pErrorStr;

PVRShellSet(prefExitMessage, pErrorStr->c_str());

return false;

}



if (PVRTShaderLoadFromFile(c_szFastFsBinFile,

c_szFastFsSrcFile,

GL_FRAGMENT_SHADER,

GL_SGX_BINARY_IMG,

&m_uiFastFragShader,

pErrorStr) != PVR_SUCCESS) {

pErrorStr = CPVRTString(“From file '”) + c_szFastVsBinFile +

"’ or ‘" + c_szFastVsSrcFile + "’:n" + pErrorStr;

PVRShellSet(prefExitMessage, pErrorStr->c_str());

return false;

}

/


Set up and link the shader programs

/

const char
aszAttribs[] = { “inVertex”, “inNormal” };

if (

(PVRTCreateProgram(&m_FastShader.uiId, m_uiFastVertShader, m_uiFastFragShader, aszAttribs, 2, pErrorStr) != PVR_SUCCESS) ) {

PVRShellSet(prefExitMessage, pErrorStr->c_str());

return false;

}



/


Store the location of uniforms for later use

/

m_FastShader.uiMVPMatrixLoc = glGetUniformLocation(m_FastShader.uiId, “MVPMatrix”);

m_FastShader.uiMsLightDirLoc = glGetUniformLocation(m_FastShader.uiId, “msLightDir”);

m_FastShader.uiMsEyePosLoc = glGetUniformLocation(m_FastShader.uiId, “msEyePos”);





/


Set up and link the shader program

*/

if (PVRTCreateProgram(&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, g_aszAttribNames, eNumAttribs, pErrorStr) != PVR_SUCCESS) {

PVRShellSet(prefExitMessage, pErrorStr->c_str());

return false;

}



// Store the location of uniforms for later use

for (int i = 0;

i < eNumUniforms;

++i) {

m_ShaderProgram.auiLoc = glGetUniformLocation(m_ShaderProgram.uiId, g_aszUniformNames);

}







return true;

}








#3

Edit : I ran the my vertex and fragment shaders in PVRShaman … There were no issues.



Hi Dgu, you mentioned that you tried on two different shaders. My issue was running the code base in the LoadShaders() two time in a row (sequentially). Load 2 different shaders one after another in the same app VERSUS running one shader at at a time.



Can you confirm?



Thanks


#4

maybe you should load all your shades and bind them in the same method then or use parameters , index to load then by using function argument.

calling load shader twice is allow of course if you dont affect twice the same VBO , maybe some shaderName is passed as argument

Initview () is where rendering API are initialized,that is all , it should not be call twice manually as well .



kind regards

david


#5

Hi @Dgu. Thanks for your response. I load and bind them in the same method as mentioned in my original post.



I am aware of InitView()…and understand that it can not be called twice.


#6

in the code you provided , you use only one shader media_szFragShader right ?


#7

Thanks for responding. The code I provided loads media_szFragShader and media_szVertShaderSrcFile. As mentioned its in LoadShaders(). Before this code snipet runs there is code that loads another vertex/fragment shader pair … fo course with different variables.



I have looked in xcode where InitView fails and all shaders are loaded. I have read several other e-mails about mprint3d and it can cause some state issues. i don’t know why even there would be bind texture issue when I am not even doing that.


#8

Hello



Joe mention once :

Print3D has to change the OpenGL ES renderstate before it can render, for example enable blending if it is disabled. Print3D should revert the renderstate once it has finished rendering.

As a test, can you reset your renderstate at the start of your RenderScene() function? If this fixes the problem, then this suggests that there is a bug in Print3D's renderstate revert mechanism.

#9

Edit: I don’t know that would help anyway. I can’t get to the RenderScene() function if I can’t succeed with InitView as I have mentioned in the original post. Thanks for your help though.



Yes, I have seen that statement before … how do you specifically reset your renderstate… thats vague


#10

is it possible to see your test code ? it will be more easy by my side if it s ok with you ?


#11

many apologize , it s not clear at all for me because i dont understand why you bind twice the same &media_ShaderProgram.uiId



regardsd

avid


#12

No worries :slight_smile: … I don’t bind the same shader program twice… I have two different shader programs that I did not create … two different shader programs that I can use at run time. So when I try to load two different shaders there is a state issue lock somewhere.


#13

Here is the entire LoadShaders() method -->

I just run the same load/create shader methods twice… of course with different variables for the shader programs.



I don’t why this would produce state issues.



/!***************************************************************************

@Function LoadShaders

@Output pErrorStr A string describing the error on failure

@Return bool true if no error occurred

@Description Loads and compiles the shaders and links the shader programs

required for this training course

****************************************************************************/

bool OGLES2ParallaxBumpMap::LoadShaders(CPVRTString
pErrorStr)

{

/


Load and compile the shaders from files.

Binary shaders are tried first, source shaders

are used as fallback.

/



if (PVRTShaderLoadFromFile(

c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)

{

return false;

}



if (PVRTShaderLoadFromFile(

c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)

{

return false;

}



/


Set up and link the shader program

/



if (PVRTCreateProgram(&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, g_aszAttribNames, eNumAttribs, pErrorStr) != PVR_SUCCESS)

{

PVRShellSet(prefExitMessage, pErrorStr->c_str());

return false;

}



// Store the location of uniforms for later use

for (int i = 0; i < eNumUniforms; ++i)

{

m_ShaderProgram.auiLoc = glGetUniformLocation(m_ShaderProgram.uiId, g_aszUniformNames);

}





// OK NOW LETS DO THE SAME FLOW FOR MULTIMEDIA SHADERS/RESOURCES





if (PVRTShaderLoadFromFile(

media_szVertShaderBinFile, media_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &media_VertShader, pErrorStr) != PVR_SUCCESS)

{

return false;

}



if (PVRTShaderLoadFromFile(

media_szFragShaderBinFile, media_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &media_FragShader, pErrorStr) != PVR_SUCCESS)

{

return false;

}







/


Set up and link the shader program

*/





if (PVRTCreateProgram(&media_ShaderProgram.uiId, media_VertShader, media_FragShader, media_aszAttribNames, eMediaNumAttribs, pErrorStr) != PVR_SUCCESS)

{

NSLog(@“right here in the mist”);

PVRShellSet(prefExitMessage, pErrorStr->c_str());

return false;

}









// Store the location of uniforms for later use

for (int i = 0; i < eMediaNumUniforms; ++i)

{

media_ShaderProgram.auiLoc = glGetUniformLocation(media_ShaderProgram.uiId, media_aszUniformNames);

}





return true;

}


#14

Can someone from the IMG team comment on the state issues ( @Joe Davis )


#15

That is wierd , in the first post i sent to you i was doing the same , and it work.


#16

Hi,



Based on the information provided I suspect one of the new calls you’ve added is producing a gl error which is effecting the later Print3D call. Possibly it’ll be your glGetUniformLocation calls. You can clear the error by calling glGetError() just after your new calls. This should fix the Print3D setup problems. Obviously this is just a workaround and it would be better to fix the offending gl call. :slight_smile:



Cheers,



Scott


#17

Hi Scott,



I added a glGetError() call before the m_Print3d.setTextures.



As you predicted the error went away but it caused my program to bomb out later in RenderScene(). There is another thread where the same thing happened.



@Dgu I don’t think you ran the code base twice… load two different shaders.



IMO when you load one shader there is some state change and it can’t handle loading/creating another shader object using the way done in SDK 3.0. I noticed in SDK 3.1 there is a difference in LoadShaders().



I am somewhat shocked though because loading and creating shaders is so important. Its done in the bloom app repeatedly …


#18

As far as I can tell the render state changes that Print3D performs for its rendering are unrelated to the problem you’re experiencing. If you wish to confirm this, you should be able to remove all of Print3D from the application without it interfering with the example.



My recommendation would be to track down and fix the gl error that the addition of glGetError is clearing.


#19

i dont understand why you disagree with the code snipet that i did and made work , without to see what is going on in the render section of your code and the poor explanation of your problem, the objective was to try to help you that the goal !!!

cheers

david


#20
i dont understand why you disagree with the code snipet that i did and made work , without to see what is going on in the render section of your code and the poor explanation of your problem, the objective was to try to help you that the goal !!!

cheers
david


Hi David,

I appreciate the input you gave earlier today and there is no need to get defensive. But I think you may have jumped the gun on what I was trying to debug. I am not trying to debug "the render section" of my code as you have noted above. As I mentioned in my earlier post I could not get to the render section as I could not pass InitView(). I clearly state that this was an issue of loading/creating shaders.

Again, thanks for your inputs.