void CubeMapTextureGLTest::subImageBuffer() { constexpr UnsignedByte zero[4*4*4] = {}; constexpr UnsignedByte subData[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; CubeMapTexture texture; texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8, ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), zero)); texture.setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i(1), BufferImage2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), subData, BufferUsage::StaticDraw)); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES BufferImage2D image(ColorFormat::RGBA, ColorType::UnsignedByte); texture.image(CubeMapTexture::Coordinate::PositiveX, 0, image, BufferUsage::StaticRead); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i(4)); const auto imageData = image.buffer().data<UnsignedByte>(); CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()), (std::vector<UnsignedByte>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), TestSuite::Compare::Container); #endif }
void CubeMapTextureGLTest::subImageBuffer() { CubeMapTexture texture; texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8, ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), Zero)); texture.setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i(1), BufferImage2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), Data, BufferUsage::StaticDraw)); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES BufferImage2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data<UnsignedByte>(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i(4)); CORRADE_COMPARE_AS(imageData, Containers::ArrayReference<const UnsignedByte>{SubDataComplete}, TestSuite::Compare::Container); #endif }
void CubeMapTextureGLTest::subImage() { CubeMapTexture texture; texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8, ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(4), Zero)); texture.setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i(1), ImageReference2D(ColorFormat::RGBA, ColorType::UnsignedByte, Vector2i(2), Data)); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES Image2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {ColorFormat::RGBA, ColorType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i(4)); CORRADE_COMPARE_AS( Containers::ArrayReference<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()), Containers::ArrayReference<const UnsignedByte>{SubDataComplete}, TestSuite::Compare::Container); #endif }
CubeMap::CubeMap(const std::string& prefix, Object3D* parent, SceneGraph::DrawableGroup3D<>* group): Object3D(parent), SceneGraph::Drawable3D<>(this, group) { CubeMapResourceManager* resourceManager = CubeMapResourceManager::instance(); /* Cube mesh */ if(!(cube = resourceManager->get<Mesh>("cube"))) { Mesh* mesh = new Mesh; Buffer* buffer = new Buffer; Buffer* indexBuffer = new Buffer; Trade::MeshData3D cubeData = Primitives::Cube::solid(); MeshTools::flipFaceWinding(*cubeData.indices()); MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *cubeData.indices()); MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw, *cubeData.positions(0)); mesh->setPrimitive(cubeData.primitive()) ->addVertexBuffer(buffer, 0, CubeMapShader::Position()); resourceManager->set("cube-buffer", buffer, ResourceDataState::Final, ResourcePolicy::Resident); resourceManager->set("cube-index-buffer", indexBuffer, ResourceDataState::Final, ResourcePolicy::Resident); resourceManager->set(cube.key(), mesh, ResourceDataState::Final, ResourcePolicy::Resident); } /* Cube map texture */ if(!(texture = resourceManager->get<CubeMapTexture>("texture"))) { CubeMapTexture* cubeMap = new CubeMapTexture; cubeMap->setWrapping(CubeMapTexture::Wrapping::ClampToEdge) ->setMagnificationFilter(CubeMapTexture::Filter::Linear) ->setMinificationFilter(CubeMapTexture::Filter::Linear, CubeMapTexture::Mipmap::Linear); Resource<Trade::AbstractImporter> importer = resourceManager->get<Trade::AbstractImporter>("tga-importer"); /* Configure texture storage using size of first image */ importer->openFile(prefix + "+x.tga"); Trade::ImageData2D* image = importer->image2D(0); Vector2i size = image->size(); cubeMap->setStorage(Math::log2(size.min())+1, CubeMapTexture::InternalFormat::RGB8, size); cubeMap->setSubImage(CubeMapTexture::PositiveX, 0, {}, image); delete image; importer->openFile(prefix + "-x.tga"); image = importer->image2D(0); cubeMap->setSubImage(CubeMapTexture::NegativeX, 0, {}, image); delete image; importer->openFile(prefix + "+y.tga"); image = importer->image2D(0); cubeMap->setSubImage(CubeMapTexture::PositiveY, 0, {}, image); delete image; importer->openFile(prefix + "-y.tga"); image = importer->image2D(0); cubeMap->setSubImage(CubeMapTexture::NegativeY, 0, {}, image); delete image; importer->openFile(prefix + "+z.tga"); image = importer->image2D(0); cubeMap->setSubImage(CubeMapTexture::PositiveZ, 0, {}, image); delete image; importer->openFile(prefix + "-z.tga"); image = importer->image2D(0); cubeMap->setSubImage(CubeMapTexture::NegativeZ, 0, {}, image); delete image; cubeMap->generateMipmap(); resourceManager->set(texture.key(), cubeMap, ResourceDataState::Final, ResourcePolicy::Manual); } /* Shader */ if(!(shader = resourceManager->get<AbstractShaderProgram, CubeMapShader>("shader"))) resourceManager->set<AbstractShaderProgram>(shader.key(), new CubeMapShader, ResourceDataState::Final, ResourcePolicy::Manual); }