| | 210 | |
| | 211 | |
| | 212 | //////////////////////////////////////////////////////////////////////// |
| | 213 | // |
| | 214 | // Wrap Drawable |
| | 215 | class DrawableObject : public GLObject |
| | 216 | { |
| | 217 | public: |
| | 218 | |
| | 219 | DrawableObject(osg::Drawable* drawable): _drawable(drawable) {} |
| | 220 | |
| | 221 | void apply(osg::RenderInfo& renderInfo) |
| | 222 | { |
| | 223 | _drawable->draw(renderInfo); |
| | 224 | |
| | 225 | if (renderInfo.getState()->checkGLErrors("Drawable")) |
| | 226 | { |
| | 227 | throw "OpenGL error"; |
| | 228 | } |
| | 229 | } |
| | 230 | |
| | 231 | osg::ref_ptr<osg::Drawable> _drawable; |
| | 232 | }; |
| | 233 | |
| | 234 | ///////////////////////////////////////////////////////////////////////// |
| | 235 | // |
| | 236 | // Geometry test |
| | 237 | class GeometryTest : public GLMemoryTest |
| | 238 | { |
| | 239 | public: |
| | 240 | |
| | 241 | enum GLObjectType |
| | 242 | { |
| | 243 | VERTEX_ARRAY, |
| | 244 | DISPLAY_LIST, |
| | 245 | VERTEX_BUFFER_OBJECT |
| | 246 | }; |
| | 247 | |
| | 248 | |
| | 249 | GeometryTest(GLObjectType type, int width=64, int height=64): |
| | 250 | _glObjectType(type), |
| | 251 | _width(width), |
| | 252 | _height(height) {} |
| | 253 | |
| | 254 | virtual GLObject* allocate() |
| | 255 | { |
| | 256 | unsigned int numVertices = _width * _height; |
| | 257 | osg::Vec3Array* vertices = new osg::Vec3Array(numVertices); |
| | 258 | for(unsigned int j=0; j<_height; ++j) |
| | 259 | { |
| | 260 | for(unsigned i=0; i<_width; ++i) |
| | 261 | { |
| | 262 | (*vertices)[i+j*_width].set(float(i),float(j),0.0f); |
| | 263 | } |
| | 264 | } |
| | 265 | |
| | 266 | unsigned int numIndices = (_width-1) * (_height-1) * 4; |
| | 267 | osg::DrawElementsUShort* quads = new osg::DrawElementsUShort(GL_QUADS); |
| | 268 | quads->reserve(numIndices); |
| | 269 | for(unsigned int j=0; j<_height-1; ++j) |
| | 270 | { |
| | 271 | for(unsigned i=0; i<_width-1; ++i) |
| | 272 | { |
| | 273 | quads->push_back(i + j*_width); |
| | 274 | quads->push_back(i+1 + j*_width); |
| | 275 | quads->push_back(i+1 + (j+1)*_width); |
| | 276 | quads->push_back(i + (j+1)*_width); |
| | 277 | } |
| | 278 | } |
| | 279 | |
| | 280 | osg::Geometry* geometry = new osg::Geometry; |
| | 281 | geometry->setVertexArray(vertices); |
| | 282 | geometry->addPrimitiveSet(quads); |
| | 283 | |
| | 284 | switch(_glObjectType) |
| | 285 | { |
| | 286 | case(VERTEX_ARRAY): |
| | 287 | geometry->setUseDisplayList(false); |
| | 288 | geometry->setUseVertexBufferObjects(false); |
| | 289 | break; |
| | 290 | case(DISPLAY_LIST): |
| | 291 | geometry->setUseDisplayList(true); |
| | 292 | geometry->setUseVertexBufferObjects(false); |
| | 293 | break; |
| | 294 | case(VERTEX_BUFFER_OBJECT): |
| | 295 | geometry->setUseDisplayList(false); |
| | 296 | geometry->setUseVertexBufferObjects(true); |
| | 297 | break; |
| | 298 | } |
| | 299 | |
| | 300 | return new DrawableObject(geometry); |
| | 301 | } |
| | 302 | |
| | 303 | |
| | 304 | protected: |
| | 305 | |
| | 306 | GLObjectType _glObjectType; |
| | 307 | int _width; |
| | 308 | int _height; |
| | 309 | }; |
| | 310 | |
| | 332 | |
| | 333 | while(arguments.read("--geometry",width,height)) { tests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,width,height)); } |
| | 334 | while(arguments.read("--geometry")) { tests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,64,64)); } |
| | 335 | |
| | 336 | while(arguments.read("--geometry-vbo",width,height)) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,width,height)); } |
| | 337 | while(arguments.read("--geometry-vbo")) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,64,64)); } |
| | 338 | |
| | 339 | while(arguments.read("--geometry-va",width,height)) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,width,height)); } |
| | 340 | while(arguments.read("--geometry-va")) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,64,64)); } |