void texture2DArray() { if(!Has_Texture_Array) { Log::error("Texture 2d array not supported.\n"); return; } // Create a 2x2 vertices quad facing the camera mQuad2DArrayTex = makeGrid( vec3(0,0,0), 10.0f, 10.0f, 2, 2 ); // Rotate plane toward the user mQuad2DArrayTex->transform( mat4::getRotation(90, 1,0,0), false ); // Texture coordinates to be animated in updateScene() mTexCoords_2DArray = new ArrayFloat3; mTexCoords_2DArray->resize( 2*2 ); mQuad2DArrayTex->setTexCoordArray(0, mTexCoords_2DArray.get()); // Create the effect used by the actor ref<Effect> fx_2darray = new Effect; fx_2darray->shader()->enable(EN_DEPTH_TEST); // Add and position the actor in the scene Actor* act_2darray = sceneManager()->tree()->addActor( mQuad2DArrayTex.get(), fx_2darray.get(), new Transform ); act_2darray->transform()->setLocalAndWorldMatrix( mat4::getTranslation(+6,+6,-6) ); // Load a 3D image, VL considers 3D images equivalent to an array of 2D images. ref<Image> img_volume = loadImage("/volume/VLTest.dat"); m2DArraySize = img_volume->depth(); // Create the 2D texture array and bind it to unit #0 ref<Texture> texture_2darray = new Texture; texture_2darray->prepareTexture2DArray( img_volume.get(), TF_RGBA, mMipmappingOn ); texture_2darray->getTexParameter()->setMagFilter(TPF_LINEAR); texture_2darray->getTexParameter()->setMinFilter(TPF_LINEAR_MIPMAP_LINEAR); fx_2darray->shader()->gocTextureSampler(0)->setTexture( texture_2darray.get() ); // IMPORTANT // We need a GLSL program that uses 'sampler2DArray()' to access the 1D and 2D texture arrays! GLSLProgram* glsl = fx_2darray->shader()->gocGLSLProgram(); glsl->attachShader( new GLSLFragmentShader("/glsl/texture_2d_array.fs") ); // Bind the sampler to unit #0 glsl->gocUniform("sampler0")->setUniformI(0); }
void texture1DArray() { if(!Has_Texture_Array) { Log::error("Texture 1d array not supported.\n"); return; } // Load a 2D texture, VL considers 2D images equivalent to arrays of 1D images. ref<Image> img_holebox = loadImage("/images/holebox.tif"); m1DArraySize = img_holebox->height(); // Create a grid with img_holebox->height() slices mQuad1DArrayTex = makeGrid( vec3(0,0,0), 10, 10, 2, img_holebox->height() ); mQuad1DArrayTex->transform( mat4::getRotation(90, 1,0,0), false ); // Texture coordinates to be animated in updateScene() mTexCoords_1DArray = new ArrayFloat2; mTexCoords_1DArray->resize( 2 * img_holebox->height() ); mQuad1DArrayTex->setTexCoordArray(0, mTexCoords_1DArray.get()); // Create the effect used by the actor ref<Effect> fx_1darray = new Effect; fx_1darray->shader()->enable(EN_DEPTH_TEST); // Add and position the actor in the scene Actor* act_1darray = sceneManager()->tree()->addActor( mQuad1DArrayTex.get(), fx_1darray.get(), new Transform ); act_1darray->transform()->setLocalAndWorldMatrix( mat4::getTranslation(+6,-6,-6) ); // Create the 1D texture array and bind it to unit #0 ref<Texture> texture_1darray = new Texture; texture_1darray->prepareTexture1DArray( img_holebox.get(), TF_RGBA, mMipmappingOn ); texture_1darray->getTexParameter()->setMagFilter(TPF_LINEAR); texture_1darray->getTexParameter()->setMinFilter(TPF_LINEAR_MIPMAP_LINEAR); fx_1darray->shader()->gocTextureSampler(0)->setTexture( texture_1darray.get() ); // IMPORTANT // We need a GLSL program that uses 'sampler1DArray()' to access the 1D and 2D texture arrays! GLSLProgram* glsl = fx_1darray->shader()->gocGLSLProgram(); glsl->attachShader( new GLSLFragmentShader("/glsl/texture_1d_array.fs") ); glsl->gocUniform("sampler0")->setUniformI(0); }