BOOST_FIXTURE_TEST_CASE(switch_texture_type_repeatedly, ImagesFixture) { for (int i = 0; i < 10; ++i) images[i] = std::make_shared<MockImage>(TextureFormat(i % 4)); for (int i = 0; i < 10; ++i) { updateSwitcher(images[i]); auto& node = dynamic_cast<MockTextureNode&>(*textureNode); BOOST_CHECK_EQUAL(node.image, images[i].get()); BOOST_CHECK_EQUAL(node.format, images[i]->getFormat()); BOOST_CHECK(node.swapped || i == 0); node.swapped = false; BOOST_CHECK(switcher.switchedTextureNodes || i == 0); switcher.switchedTextureNodes = false; } }
Texture::Texture(const std::string& file) { SDL_Surface* surface = LoadImageFileSurface2d(file); m_width = surface->w; m_height = surface->h; MutableTextureStorage2d( m_hTexture, m_width, m_height, surface->format->BytesPerPixel, TextureFormat( file, surface->format->BytesPerPixel, surface->format->Rmask ), surface->pixels ); FreeImageSurface(surface); }
float fuzzyCompare (const FuzzyCompareParams& params, const ConstPixelBufferAccess& ref, const ConstPixelBufferAccess& cmp, const PixelBufferAccess& errorMask) { DE_ASSERT(ref.getWidth() == cmp.getWidth() && ref.getHeight() == cmp.getHeight()); DE_ASSERT(errorMask.getWidth() == ref.getWidth() && errorMask.getHeight() == ref.getHeight()); if (!isFormatSupported(ref.getFormat()) || !isFormatSupported(cmp.getFormat())) throw InternalError("Unsupported format in fuzzy comparison", DE_NULL, __FILE__, __LINE__); int width = ref.getWidth(); int height = ref.getHeight(); de::Random rnd (667); // Filtered TextureLevel refFiltered(TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8), width, height); TextureLevel cmpFiltered(TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8), width, height); // Kernel = {0.15, 0.7, 0.15} vector<float> kernel(3); kernel[0] = kernel[2] = 0.1f; kernel[1]= 0.8f; int shift = (int)(kernel.size() - 1) / 2; switch (ref.getFormat().order) { case TextureFormat::RGBA: separableConvolve<4, 4>(refFiltered, ref, shift, shift, kernel, kernel); break; case TextureFormat::RGB: separableConvolve<4, 3>(refFiltered, ref, shift, shift, kernel, kernel); break; default: DE_ASSERT(DE_FALSE); } switch (cmp.getFormat().order) { case TextureFormat::RGBA: separableConvolve<4, 4>(cmpFiltered, cmp, shift, shift, kernel, kernel); break; case TextureFormat::RGB: separableConvolve<4, 3>(cmpFiltered, cmp, shift, shift, kernel, kernel); break; default: DE_ASSERT(DE_FALSE); } int numSamples = 0; float errSum = 0.0f; // Clear error mask to green. clear(errorMask, Vec4(0.0f, 1.0f, 0.0f, 1.0f)); ConstPixelBufferAccess refAccess = refFiltered.getAccess(); ConstPixelBufferAccess cmpAccess = cmpFiltered.getAccess(); for (int y = 1; y < height-1; y++) { for (int x = 1; x < width-1; x += params.maxSampleSkip > 0 ? (int)rnd.getInt(0, params.maxSampleSkip) : 1) { float err = deFloatMin(compareToNeighbor<4>(params, rnd, readUnorm8<4>(refAccess, x, y), cmpAccess, x, y), compareToNeighbor<4>(params, rnd, readUnorm8<4>(cmpAccess, x, y), refAccess, x, y)); err = deFloatPow(err, params.errExp); errSum += err; numSamples += 1; // Build error image. float red = err * 500.0f; float luma = toGrayscale(cmp.getPixel(x, y)); float rF = 0.7f + 0.3f*luma; errorMask.setPixel(Vec4(red*rF, (1.0f-red)*rF, 0.0f, 1.0f), x, y); } } // Scale error sum based on number of samples taken errSum *= (float)((width-2) * (height-2)) / (float)numSamples; return errSum; }