diff --git a/src/celengine/dds.cpp b/src/celengine/dds.cpp index 4b55c46898..820fc053e6 100644 --- a/src/celengine/dds.cpp +++ b/src/celengine/dds.cpp @@ -89,55 +89,47 @@ GLvoid *decompressDXTc(GLsizei width, GLsizei height, GLenum format, int transpa // decompress a DXTc image // get pixel size of decompressed image => fixed RGBA int pixelsize = 4; -/* if (format==COMPRESSED_RGB_S3TC_DXT1_EXT) - pixelsize = 3;*/ // TODO: check with the size of the input data stream if the stream is in fact decompressed // alloc memory - GLvoid *pixels = malloc(((width+3)&~3)*((height+3)&~3)*pixelsize); + GLvoid *pixels = malloc(((width + 3) & ~3) * ((height + 3) & ~3) * pixelsize); // decompress loop int blocksize = 0; - switch (format) { - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - blocksize = 8; - break; - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - blocksize = 16; - break; +#define DDS_MAX_BLOCK_SIZE 16 + switch (format) + { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + blocksize = 8; + break; + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + blocksize = 16; + break; } - uintptr_t *block = (uintptr_t *)malloc(sizeof(blocksize)); - for (int y=0; y(block), blocksize); - switch(format) { - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - DecompressBlockDXT1(x, y, width, (uint8_t*)block, transparent0, simpleAlpha, complexAlpha, (uint32_t *)pixels); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - DecompressBlockDXT3(x, y, width, (uint8_t*)block, transparent0, simpleAlpha, complexAlpha, (uint32_t *)pixels); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - DecompressBlockDXT5(x, y, width, (uint8_t*)block, transparent0, simpleAlpha, complexAlpha, (uint32_t *)pixels); - break; + in.read(block, blocksize); + switch(format) + { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + DecompressBlockDXT1(x, y, width, (uint8_t*)block, transparent0, simpleAlpha, complexAlpha, (uint32_t *)pixels); + break; + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + DecompressBlockDXT3(x, y, width, (uint8_t*)block, transparent0, simpleAlpha, complexAlpha, (uint32_t *)pixels); + break; + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + DecompressBlockDXT5(x, y, width, (uint8_t*)block, transparent0, simpleAlpha, complexAlpha, (uint32_t *)pixels); + break; } } } - free(block); return pixels; } @@ -262,10 +254,10 @@ Image* LoadDDSImage(const fs::path& filename) tmp = decompressDXTc(nw, nh, format, transparent0, &simpleAlpha, &complexAlpha, in); if (tmp != nullptr) { - pixels = malloc(4*ddsd.width*ddsd.height); + pixels = malloc(4 * ddsd.width * ddsd.height); // crop for (int y=0; ygetActiveObserver()->getFOV() / height * 4.0f; + float pickTolerance = sim->getActiveObserver()->getFOV() / height * this->pickTolerance; if (resizeSplit != nullptr) { @@ -2181,6 +2181,16 @@ void CelestiaCore::setSafeAreaInsets(int left, int top, int right, int bottom) safeAreaInsets = { left, top, right, bottom }; } +float CelestiaCore::getPickTolerance() const +{ + return pickTolerance; +} + +void CelestiaCore::setPickTolerance(float newPickTolerance) +{ + pickTolerance = newPickTolerance; +} + // Return true if anything changed that requires re-rendering. Otherwise, we // can skip rendering, keep the GPU idle, and save power. bool CelestiaCore::viewUpdateRequired() const diff --git a/src/celestia/celestiacore.h b/src/celestia/celestiacore.h index 7736d7fe16..895f457819 100644 --- a/src/celestia/celestiacore.h +++ b/src/celestia/celestiacore.h @@ -286,6 +286,8 @@ class CelestiaCore // : public Watchable int getDistanceToScreen() const; void setDistanceToScreen(int); void setSafeAreaInsets(int left, int top, int right, int bottom); + float getPickTolerance() const; + void setPickTolerance(float); void setFOVFromZoom(); void setZoomFromFOV(); @@ -467,6 +469,8 @@ class CelestiaCore // : public Watchable int screenDpi{ 96 }; int distanceToScreen{ 400 }; + float pickTolerance { 4.0f }; + unique_ptr viewportEffect { nullptr }; bool isViewportEffectUsed { false };