Re: [osg-users] Using getGlShaderInfoLog

2010-12-15 Thread Joel Graff
J-S,

Thanks for the reply.  You told me exactly what I needed to know.

I think I had assumed to this point that the shader would be compiled once it 
was loaded and bound to the program object - it seemed the most logical way to 
manage it.  Of course, once you indicated that even compilation doesn't happen 
until the shader's called for (which makes sense, now that I think of it), I 
tried retrieving the log after calling viewer.frame() inside the viewer loop 
and it worked perfectly.

Anyway, thanks for the help!

Joel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=34886#34886





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Using getGlShaderInfoLog

2010-12-14 Thread Joel Graff
Just as a follow-up, I stumbled across a post which indicated part of the 
problem may lie in the compiler.  I should point out that I'm using OSG with 
VS2010.

I'm also starting to wonder if this has something more to do with OpenGL than 
with OSG.  I tried accessing the shader info log immediately after loading the 
shader and binding it to the program object, with the same result.  


Code:

//load shaders
osg::ref_ptrosg::Shader vertexShader1(
osg::Shader::readShaderFile (osg::Shader::VERTEX, 
C:/OpenSceneGraph/OpenSceneGraph-Data-2.8.0/myShaders/pass1.vert));

osg::ref_ptrosg::Shader geometryShader1(
osg::Shader::readShaderFile (osg::Shader::GEOMETRY, 
C:/OpenSceneGraph/OpenSceneGraph-Data-2.8.0/myShaders/test.geom));

osg::ref_ptrosg::Shader fragShader1(
osg::Shader::readShaderFile (osg::Shader::FRAGMENT, 
C:/OpenSceneGraph/OpenSceneGraph-Data-2.8.0/myShaders/pass1.frag));

//set up program
osg::ref_ptrosg::Program pass1 (new osg::Program());

pass1-addShader(vertexShader1); 
pass1-addShader(geometryShader1);
pass1-addShader(fragShader1);

pass1-addBindAttribLocation(osg_Vertex, 0);
pass1-addBindAttribLocation(osg_Normal, 2);

//create stateset
geodePass1-getOrCreateStateSet()-setAttribute(pass1);

//test info log
std::string log=;
geometryShader1-getGlShaderInfoLog(0, log);




Regardless of what's in the info log, it seems to me that it ought to return 
something, if only an empty string, but I get the error instead...

Just for reference, the error is:  Unhandled exception at 0xcdcdcdcd in 
OSG-shader.exe: 0xC005: Access violation.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=34866#34866





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Using getGlShaderInfoLog

2010-12-14 Thread Jean-Sébastien Guay

Hi Joel,


Just for reference, the error is:  Unhandled exception at 0xcdcdcdcd in 
OSG-shader.exe: 0xC005: Access violation.


This error is a general error on Windows that means something bad 
happened. Generally the something bad is a null pointer being 
dereferenced, or something like that, but the only way to know for sure 
is to build the project in debug and run it. Then the Visual Studio 
debugger will stop exactly where the error happens and you'll be able to 
pinpoint the cause.


In your case, it seems to me that two things may cause the error you're 
getting:


1. osgDB::readShaderFile() for geometryShader1 returned NULL, i.e. the 
shader file you specified did not exist / could not be read. So when you 
call geometryShader1-getGlShaderInfoLog(0, log); you're dereferencing a 
null pointer.


2. osg::Shader::getGlShaderInfoLog() requires that the context ID you 
pass (0 in your case) be current, or that the shader have been compiled 
for that context prior to the call, and that isn't the case. Again that 
might cause a null pointer dereference.


For 2, note that in OSG, unless you run specifically in single threaded 
mode, you generally don't have a graphics context current in the main 
application thread. All OpenGL work is done in other threads 
(GraphicsThread). And shaders are generally compiled only when needed, 
i.e. when rendering a frame. So if the shader was read correctly, 
eliminating problem 1, then you probably need to wait for a frame to be 
rendered before getting the shader info log. You could set a post-frame 
callback on your camera, or something like that.


In any case, building OSG and your app in debug and running it will tell 
you what's happening better than I could ever hope to.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Using getGlShaderInfoLog

2010-12-11 Thread Joel Graff
Hello,

As I've been playing with shaders in OSG, I've tried to get the shader info log 
so I can export it directly to a file (largely because it doesn't want to show 
up in the console when I have a GLSL compilation error).

In any case, I've pieced together several snippets of code across a few posts 
from the forum, but to no avail.

The code:


Code:
osgViewer::ViewerBase::Contexts* c = new osgViewer::ViewerBase::Contexts();

viewer.getContexts(*c);

unsigned int contextID;
osg::ref_ptrosg::State stat;

for (osgViewer::ViewerBase::Contexts::iterator itr=c-begin(); itr!=c-end(); 
++itr)
 stat = (*itr)-getState();

contextID = stat-getContextID();

osg::ref_ptr osg::Geode pass1 (dynamic_castosg::Geode * (FindNode(root, 
root_geodeShaderGeometry1)-getFirst()));
osg::ref_ptr osg::Program sh1 (dynamic_castosg::Program * 
(pass1-getStateSet()-getAttribute(osg::StateAttribute::PROGRAM, 0)));

std::string log;

osg::Shader* shader = sh1-getShader(0);

shader-compileShader(*(stat.get()));
bool logFound = shader-getGlShaderInfoLog(contextID, log);

if (logFound)
 std::cout  log;




I can retrieve my shader programs fine (I have 3), but i get an unhandled 
exception (access violation) at 0xcdcdcdcd when I try to call compileShader or 
getGlShaderInfoLog.  That tells me the problem isn't with my parameters, but 
with accessing the shader object itself.

I'm sure it's something simple that I've overlooked, and I imagine it's been 
covered in another post somewhere, but since my knowledge of OSG overall is 
pretty much limited to what I've tried to implement, the solution eludes me.

Any thoughts?

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=34726#34726





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org