From 0feeb79d05fecf0896a8fb67811a9dfd017d77e6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 29 Dec 2020 18:28:17 +0000 Subject: [PATCH] Added 4x4 grid of images, currently repeating each row 4 times as step towards full 4x4 rendering. --- examples/osgmultiviewOVR/Leia.cpp | 55 ++++++++++++++++-------------- examples/osgmultiviewOVR/leia.vert | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp index 5bca252c8..eb2b43647 100644 --- a/examples/osgmultiviewOVR/Leia.cpp +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -198,31 +198,32 @@ osg::ref_ptr Leia::createLeiaMesh(const osg::Vec3& origin, const osg: osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); - // left hand side - vertices->push_back(origin); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); - vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); - vertices->push_back(origin + widthVector*0.5f +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 0.0f)); - vertices->push_back(origin + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 0.0f)); + for(uint32_t row = 0; row<4; ++row) + { + for(uint32_t column = 0; column<4; ++column) + { + uint16_t base = static_cast(vertices->size()); - elements->push_back(0); - elements->push_back(1); - elements->push_back(2); - elements->push_back(2); - elements->push_back(3); - elements->push_back(0); + vertices->push_back(origin + widthVector*static_cast(column)*0.25f + heightVector*static_cast(row)*0.25f); + texcoords->push_back(osg::Vec3(0.0f, 0.0f, static_cast(column))); - // right hand side - vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); - vertices->push_back(origin + widthVector); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 1.0f)); - vertices->push_back(origin + widthVector +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); - vertices->push_back(origin + widthVector*0.5f + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 1.0f)); + vertices->push_back(origin + widthVector*static_cast(column+1)*0.25f + heightVector*static_cast(row)*0.25f); + texcoords->push_back(osg::Vec3(1.0f, 0.0f, static_cast(column))); - elements->push_back(4); - elements->push_back(5); - elements->push_back(6); - elements->push_back(6); - elements->push_back(7); - elements->push_back(4); + vertices->push_back(origin + widthVector*static_cast(column+1)*0.25f + heightVector*static_cast(row+1)*0.25f); + texcoords->push_back(osg::Vec3(1.0f, 1.0f, static_cast(column))); + + vertices->push_back(origin + widthVector*static_cast(column)*0.25f + heightVector*static_cast(row+1)*0.25f); + texcoords->push_back(osg::Vec3(0.0f, 1.0f, static_cast(column))); + + elements->push_back(base + 0); + elements->push_back(base + 1); + elements->push_back(base + 2); + elements->push_back(base + 2); + elements->push_back(base + 3); + elements->push_back(base + 0); + } + } geometry->setVertexArray(vertices); geometry->setColorArray(colors, osg::Array::BIND_OVERALL); @@ -281,7 +282,7 @@ void Leia::configure(osgViewer::View& view) const osg::Texture2DArray* color_texture = new osg::Texture2DArray; - color_texture->setTextureSize(tex_width, tex_height, 2); + color_texture->setTextureSize(tex_width, tex_height, 4); color_texture->setInternalFormat(GL_RGBA); color_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); color_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); @@ -291,7 +292,7 @@ void Leia::configure(osgViewer::View& view) const osg::Texture2DArray* depth_texture = new osg::Texture2DArray; - depth_texture->setTextureSize(tex_width, tex_height, 2); + depth_texture->setTextureSize(tex_width, tex_height, 4); depth_texture->setInternalFormat(GL_DEPTH_COMPONENT); depth_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); depth_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); @@ -341,8 +342,10 @@ void Leia::configure(osgViewer::View& view) const osg::StateSet* stateset = camera->getOrCreateStateSet(); { // set up the projection and view matrix uniforms - ifc->projectionMatrices.push_back(camera->getProjectionMatrix()); - ifc->projectionMatrices.push_back(camera->getProjectionMatrix()); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(-0.2, 0.0, 0.0)); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(-0.1, 0.0, 0.0)); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(0.1, 0.0, 0.0)); + ifc->projectionMatrices.push_back(camera->getProjectionMatrix()*osg::Matrixd::translate(0.2, 0.0, 0.0)); ifc->computeClipSpaceBound(*camera); diff --git a/examples/osgmultiviewOVR/leia.vert b/examples/osgmultiviewOVR/leia.vert index cbc189ac6..8d7858062 100644 --- a/examples/osgmultiviewOVR/leia.vert +++ b/examples/osgmultiviewOVR/leia.vert @@ -1,7 +1,7 @@ #version 330 #extension GL_OVR_multiview2 : enable -#define NUM_VIEWS 2 +#define NUM_VIEWS 4 layout(num_views = NUM_VIEWS) in;