Re: [osg-users] Custom Vertex Attributes Binding

2011-08-28 Thread Tony Horrobin
Hi Jeremy,

It turns out that in the version I was using, osg-2.8.3 there are checks in 
osg::Geometry::drawImplementation() that would prevent the geometry being drawn 
when the traditional vertex position data is not present and generic attribute 
zero is not present.  This is not the case for latest SVN and hopefully your 
version has the checks removed too.  The context created by osg for me is 3.3 
with backwards compatibility so standard attributes like gl_Vertex are present.

Cheers,

Tony

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





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


Re: [osg-users] Custom Vertex Attributes Binding

2011-08-24 Thread Tony Horrobin
Hi Jeremy,

To clarify, I used a couple of trivial shaders instead of the missing ones and 
in order to get any output I had to add the vertices.

If I set GRID_POSITION=0 the additional call is not required.  This is covered 
in the glVertexAttrib man page.

I am using osg with the fixed pipeline available.

Cheers,

Tony

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





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


Re: [osg-users] Custom Vertex Attributes Binding

2011-08-23 Thread Tony Horrobin
Hi Jeremy,

The glsl attachments have been squashed - could you attach them as .txt, please?

I believe you have to bind shader vertex attributes as PER_VERTEX as opposed to 
colours and normals which can be PER_PRIMITIVE.
Then copy the line that calls push_back() on gridCoordinates so you have 4 
calls and it should work.

I had to add:
setVertexArray(gridPositions);

to get anything at all on the screen ( otherwise there are no primitives ).

Cheers,

-Tony

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





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


Re: [osg-users] Custom Vertex Attributes Binding

2011-08-23 Thread Jeremy Moles
On Tue, 2011-08-23 at 22:27 +0200, Tony Horrobin wrote:
 Hi Jeremy,
 
 The glsl attachments have been squashed - could you attach them as .txt, 
 please?
 
 I believe you have to bind shader vertex attributes as PER_VERTEX as opposed 
 to colours and normals which can be PER_PRIMITIVE.
 Then copy the line that calls push_back() on gridCoordinates so you have 4 
 calls and it should work.
 
 I had to add:
 setVertexArray(gridPositions);

You shouldn't have to call this at all. Something is still wrong if you
need to. :( Drats...

 to get anything at all on the screen ( otherwise there are no primitives ).

 Cheers,
 
 -Tony
 
 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=42202#42202
 
 
 
 
 
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
 


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


Re: [osg-users] Custom Vertex Attributes Binding

2011-08-23 Thread Jeremy Moles
On Tue, 2011-08-23 at 22:27 +0200, Tony Horrobin wrote:
 Hi Jeremy,
 
 The glsl attachments have been squashed - could you attach them as .txt, 
 please?
 
 I believe you have to bind shader vertex attributes as PER_VERTEX as opposed 
 to colours and normals which can be PER_PRIMITIVE.
 Then copy the line that calls push_back() on gridCoordinates so you have 4 
 calls and it should work.
 
 I had to add:
 setVertexArray(gridPositions);
 
 to get anything at all on the screen ( otherwise there are no primitives ).

OH WAIT, if you weren't using the shaders, then on wonder. :) So,
scratch my first response.

As far as your binding speculation is concerned: you are probably right.
I was just hoping I could avoid some repetitive memory use for the
heightfields this way.

 Cheers,
 
 -Tony
 
 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=42202#42202
 
 
 
 
 
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
 


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


[osg-users] Custom Vertex Attributes Binding

2011-08-22 Thread Jeremy Moles
Hello everyone.

I am using custom vertex attributes but running into a strange issue. I
do not seem to be able to use:

BIND_PER_PRIMITIVE

..when using custom vertex attributes. Is this a known limitation, or is
it likely a bug/me doing something wrong? I have attached a simple
example of this failure; if you uncomment GridCoordinates, nothing is
rendered at all (nor do I receive any information via OSG_NOTIFY).

If you keep this commented out, the grid renders.

Curious...
#include osg/Geometry
#include osg/Geode
#include osg/PrimitiveSet
#include osgViewer/Viewer
#include osgViewer/ViewerEventHandlers

class Grid: public osg::Geometry {
public:
	enum {
		GRID_POSITION   = 6,
		GRID_COORDINATE = 7
	};

	Grid(const osg::Vec2s size, const osg::Vec2 gridSize = osg::Vec2(1.0f, 1.0f)):
	_size (size),
	_gridSize (gridSize) {
		setUseDisplayList(false);
	}

	bool allocate() {
		osg::Program* program = new osg::Program();
		osg::Shader*  vert= osg::Shader::readShaderFile(osg::Shader::VERTEX, vert.glsl);
		osg::Shader*  frag= osg::Shader::readShaderFile(osg::Shader::FRAGMENT, frag.glsl);
		// osg::Uniform* texture = new osg::Uniform(osg::Uniform::SAMPLER_2D, Texture);
		
		program-addShader(vert);
		program-addShader(frag);
		program-addBindAttribLocation(GridPosition, GRID_POSITION);
		program-addBindAttribLocation(GridCoordinate, GRID_COORDINATE);

		osg::Vec4Array* gridPositions   = new osg::Vec4Array();
		osg::Vec2Array* gridCoordinates = new osg::Vec2Array();

		for(short x = 0; x  _size.x(); x++) {
			for(short y = 0; y  _size.y(); y++) {
osg::Vec4 bl(x, y, 0.0f, 0.0f);
osg::Vec4 br(x + _gridSize.x(), y, 0.0f, 1.0f);
osg::Vec4 ur(x + _gridSize.x(), y + _gridSize.y(), 0.0f, 2.0f);
osg::Vec4 ul(x, y + _gridSize.y(), 0.0f, 3.0f);

gridPositions-push_back(bl);
gridPositions-push_back(br);
gridPositions-push_back(ur);
gridPositions-push_back(ul);

gridCoordinates-push_back(osg::Vec2(x, y));
			}
		}

		// GridPosition
		setVertexAttribArray(GRID_POSITION, gridPositions);
		setVertexAttribBinding(GRID_POSITION, osg::Geometry::BIND_PER_VERTEX);

		/*
		// GridCoordinates
		setVertexAttribArray(GRID_COORDINATE, gridCoordinates);
		setVertexAttribBinding(GRID_COORDINATE, osg::Geometry::BIND_PER_PRIMITIVE);
		u*/

		// Finish seting up the Geometry...
		addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, _size.x() * _size.y() * 4));

		// texture-set(0);

		osg::StateSet* state = getOrCreateStateSet();

		state-setAttributeAndModes(program);
		// state-addUniform(texture);

		return true;
	}

	virtual osg::BoundingBox computeBound() const {
		return osg::BoundingBox(
			osg::Vec3(0.0f, 0.0f, 0.0f),
			osg::Vec3(_size.x() * _gridSize.x(), _size.y() * _gridSize.y(), 0.0f)
		);
	}

private:
	osg::Vec2s _size;
	osg::Vec2  _gridSize;
};

int main(int argc, char** argv) {
	osgViewer::Viewer viewer;

	Grid* grid = new Grid(osg::Vec2s(10, 10));

	grid-allocate();

	osg::Geode* geode = new osg::Geode();

	geode-addDrawable(grid);

	viewer.setSceneData(geode);
	viewer.addEventHandler(new osgViewer::StatsHandler());

	return viewer.run();
}

varying float color;

void main() {
gl_FragColor = vec4(color, color, color, 1.0);
}

in vec4 GridPosition;
in vec2 GridCoordinate;

varying float color;

void main() {
color = GridPosition.w / 3.0;

gl_Position = gl_ModelViewProjectionMatrix * vec4(GridPosition.xyz, 
1.0);
}

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