Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Oct 11, 2020
2 parents 5d1401c + 2a6abbc commit fb4b2d7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
72 changes: 32 additions & 40 deletions src/celengine/dds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<height; y+=4) {
for (int x=0; x<width; x+=4) {
if (!in.good()) {
free(block);
char block[DDS_MAX_BLOCK_SIZE]; // enough to hold DXT1/3/5 blocks
for (int y = 0; y < height; y += 4)
{
for (int x = 0; x < width; x += 4)
{
if (!in.good())
{
free(pixels);
return nullptr;
}
in.read(reinterpret_cast<char*>(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;
}

Expand Down Expand Up @@ -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; y<ddsd.height; y++)
memcpy((char *)pixels+y*ddsd.width*4, (char *)tmp+y*nw*4, ddsd.width*4);
memcpy((char *)pixels + y * ddsd.width * 4, (char *)tmp + y * nw * 4, ddsd.width * 4);
free(tmp);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/celengine/galaxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ bool Galaxy::pick(const Ray3d& ray,
double& distanceToPicker,
double& cosAngleToBoundCenter) const
{
if (form == nullptr)
return false;

if (!isVisible())
return false;

Expand Down
12 changes: 11 additions & 1 deletion src/celestia/celestiacore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void CelestiaCore::mouseButtonUp(float x, float y, int button)
setViewChanged();

// Four pixel tolerance for picking
float pickTolerance = sim->getActiveObserver()->getFOV() / height * 4.0f;
float pickTolerance = sim->getActiveObserver()->getFOV() / height * this->pickTolerance;

if (resizeSplit != nullptr)
{
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/celestia/celestiacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ class CelestiaCore // : public Watchable<CelestiaCore>
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();
Expand Down Expand Up @@ -467,6 +469,8 @@ class CelestiaCore // : public Watchable<CelestiaCore>
int screenDpi{ 96 };
int distanceToScreen{ 400 };

float pickTolerance { 4.0f };

unique_ptr<ViewportEffect> viewportEffect { nullptr };
bool isViewportEffectUsed { false };

Expand Down

0 comments on commit fb4b2d7

Please sign in to comment.