Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First batch of fixes, post-4.4.0 #3484

Merged
merged 8 commits into from
Nov 8, 2023
64 changes: 39 additions & 25 deletions lib/ivis_opengl/gfx_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,33 @@ gfx_api::texture_array* gfx_api::context::loadTextureArrayFromFiles(const std::v
bool uncompressedExtractionFormat = gfx_api::is_uncompressed_format(desiredImageExtractionFormat);
std::vector<std::unique_ptr<iV_BaseImage>> defaultTextureMips;

auto getDefaultTextureMipsP = [&defaultTextureMips, &defaultTextureGenerator, textureType, maxWidth, maxHeight](size_t layer, unsigned int width, unsigned int height, size_t mipmap_levels, gfx_api::pixel_format format) -> std::vector<std::unique_ptr<iV_BaseImage>>* {
if (defaultTextureMips.empty())
{
ASSERT_OR_RETURN(nullptr, defaultTextureGenerator != nullptr, "Failed to generate default texture - no default texture generator provided");
ASSERT_OR_RETURN(nullptr, gfx_api::is_uncompressed_format(format), "Expected uncompressed extraction format, but received: %s", gfx_api::format_to_str(format));
if (defaultTextureGenerator)
{
auto pCurrentImage = defaultTextureGenerator((layer > 0) ? width : maxWidth, (layer > 0) ? height : maxHeight, gfx_api::format_channels(format));
ASSERT_OR_RETURN(nullptr, pCurrentImage != nullptr, "Failed to generate default texture");
if (layer > 0)
{
ASSERT_OR_RETURN(nullptr, pCurrentImage->width() == width && pCurrentImage->height() == height, "Failed to generate matching default texture");
}
size_t expectedMipLevels = calcMipmapLevelsForUncompressedImage(*pCurrentImage, textureType);
if (layer > 0)
{
ASSERT_OR_RETURN(nullptr, expectedMipLevels == mipmap_levels, "Failed to generate matching default texture");
}
auto miplevels = generateMipMapsFromUncompressedImage(*pCurrentImage, expectedMipLevels, textureType);
defaultTextureMips.push_back(std::move(pCurrentImage));
defaultTextureMips.insert(defaultTextureMips.end(), std::make_move_iterator(miplevels.begin()), std::make_move_iterator(miplevels.end()));
miplevels.clear();
}
}
return &defaultTextureMips;
};

std::unique_ptr<gfx_api::texture_array> texture_array = nullptr;
unsigned int width = 0;
unsigned int height = 0;
Expand All @@ -968,36 +995,23 @@ gfx_api::texture_array* gfx_api::context::loadTextureArrayFromFiles(const std::v
std::vector<std::unique_ptr<iV_BaseImage>>* pImagesForLayer = nullptr;
if (imageLoadFilename.isEmpty())
{
if (defaultTextureMips.empty())
{
ASSERT_OR_RETURN(nullptr, defaultTextureGenerator != nullptr, "Failed to generate default texture - no default texture generator provided");
ASSERT_OR_RETURN(nullptr, uncompressedExtractionFormat, "Expected uncompressed extraction format, but received: %s", gfx_api::format_to_str(desiredImageExtractionFormat));
if (defaultTextureGenerator)
{
auto pCurrentImage = defaultTextureGenerator((layer > 0) ? width : maxWidth, (layer > 0) ? height : maxHeight, gfx_api::format_channels(desiredImageExtractionFormat));
ASSERT_OR_RETURN(nullptr, pCurrentImage != nullptr, "Failed to generate default texture");
if (layer > 0)
{
ASSERT_OR_RETURN(nullptr, pCurrentImage->width() == width && pCurrentImage->height() == height, "Failed to generate matching default texture");
}
size_t expectedMipLevels = calcMipmapLevelsForUncompressedImage(*pCurrentImage, textureType);
if (layer > 0)
{
ASSERT_OR_RETURN(nullptr, expectedMipLevels == mipmap_levels, "Failed to generate matching default texture");
}
auto miplevels = generateMipMapsFromUncompressedImage(*pCurrentImage, expectedMipLevels, textureType);
defaultTextureMips.push_back(std::move(pCurrentImage));
defaultTextureMips.insert(defaultTextureMips.end(), std::make_move_iterator(miplevels.begin()), std::make_move_iterator(miplevels.end()));
miplevels.clear();
}
}
pImagesForLayer = &defaultTextureMips;
pImagesForLayer = getDefaultTextureMipsP(layer, width, height, mipmap_levels, desiredImageExtractionFormat);
ASSERT_OR_RETURN(nullptr, pImagesForLayer != nullptr, "Failed to generate matching default texture");
}
else if (uncompressedExtractionFormat || imageLoadFilename.endsWith(".png"))
{
// load into an uncompressed format
loadedImagesForLayer = loadUncompressedImageWithMips(imageLoadFilename.toUtf8(), textureType, maxWidth, maxHeight, desiredImageExtractionFormat == gfx_api::pixel_format::FORMAT_RGBA8_UNORM_PACK8);
pImagesForLayer = &loadedImagesForLayer;
if (!loadedImagesForLayer.empty())
{
pImagesForLayer = &loadedImagesForLayer;
}
else
{
// failed to load image
debug(LOG_INFO, "Using default texture generator for failed image: %s", imageLoadFilename.toUtf8().c_str());
pImagesForLayer = getDefaultTextureMipsP(layer, width, height, mipmap_levels, desiredImageExtractionFormat);
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2689,7 +2689,7 @@ int32_t gl_context::get_context_value(const context_value property)
// special-handling for MAX_VERTEX_OUTPUT_COMPONENTS
if (!gles)
{
if (GLAD_GL_VERSION_3_0)
if (GLAD_GL_VERSION_3_2)
{
glGetIntegerv(GL_MAX_VERTEX_OUTPUT_COMPONENTS, &value);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/netplay/netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4056,8 +4056,8 @@ static void NETallowJoining()

NETcloseTempSocket(i);
sync_counter.cantjoin++;
continue;
}
continue;
}

if (NETgetMessage(NETnetTmpQueue(i))->type == NET_JOIN)
Expand Down
19 changes: 11 additions & 8 deletions src/display3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,14 +1560,17 @@ bool init3DView()
batchedObjectStatusRenderer.initialize();


// vertex attributes for a single triangle that covers the screen
gfx_api::gfxFloat screenTriangleVertices[] = {
-1.f, -1.f,
3.f, -1.f,
-1.f, 3.f
};
pScreenTriangleVBO = gfx_api::context::get().create_buffer_object(gfx_api::buffer::usage::vertex_buffer, gfx_api::context::buffer_storage_hint::static_draw, "screenTriangleVertices");
pScreenTriangleVBO->upload(sizeof(screenTriangleVertices), screenTriangleVertices);
if (!pScreenTriangleVBO)
{
// vertex attributes for a single triangle that covers the screen
gfx_api::gfxFloat screenTriangleVertices[] = {
-1.f, -1.f,
3.f, -1.f,
-1.f, 3.f
};
pScreenTriangleVBO = gfx_api::context::get().create_buffer_object(gfx_api::buffer::usage::vertex_buffer, gfx_api::context::buffer_storage_hint::static_draw, "screenTriangleVertices");
pScreenTriangleVBO->upload(sizeof(screenTriangleVertices), screenTriangleVertices);
}

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ void DROID_GROUP::remove(DROID *psDroid)
}
}

intCommanderGroupChanged((type == GT_COMMAND && psCommander) ? psCommander : nullptr);

// free the group if necessary
if (refCount <= 0)
{
grpGlobalManager.erase(id);
delete this;
}

intCommanderGroupChanged((type == GT_COMMAND && psCommander) ? psCommander : nullptr);
}

// count the members of a group
Expand Down
9 changes: 9 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ static int numTile_names;
static std::unique_ptr<char[]> Tile_names = nullptr;

static std::unique_ptr<int[]> map; // 3D array pointer that holds the texturetype
static int numTile_types = 0;

static std::unique_ptr<bool[]> mapDecals; // array that tells us what tile is a decal
#define MAX_TERRAIN_TILES 0x0200 // max that we support (for now), see TILE_NUMMASK

Expand Down Expand Up @@ -436,6 +438,7 @@ static void SetGroundForTile(const char *filename, const char *nametype)
//increment the pointer to the start of the next record
pFileData = strchr(pFileData, '\n') + 1;

numTile_types = numlines;
map = std::unique_ptr<int[]> (new int[numlines * 2 * 2]());

for (i = 0; i < numlines; i++)
Expand Down Expand Up @@ -476,6 +479,12 @@ static int getTextureType(const char *textureType)
// so map[10][0][1] would be map[10*2*2 + 0*2 + 1] == map[41]
static int groundFromMapTile(int tile, int j, int k)
{
auto tileNumber = TileNumber_tile(tile);
if (tileNumber >= numTile_types)
{
debug(LOG_INFO, "Invalid ground tile number: %d", (int)tileNumber);
return 0;
}
return map[TileNumber_tile(tile) * 2 * 2 + j * 2 + k];
}

Expand Down
15 changes: 13 additions & 2 deletions src/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ bool texLoad(const char *fileName)
}
}

decalTexArr = gfx_api::context::get().loadTextureArrayFromFiles(tile_base_filepaths, gfx_api::texture_type::game_texture, mipmap_max, mipmap_max, nullptr, nullptr, "decalTexArr");
decalTexArr = gfx_api::context::get().loadTextureArrayFromFiles(tile_base_filepaths, gfx_api::texture_type::game_texture, mipmap_max, mipmap_max, [](int width, int height, int channels) -> std::unique_ptr<iV_Image> {
std::unique_ptr<iV_Image> pDefaultTexture = std::unique_ptr<iV_Image>(new iV_Image);
pDefaultTexture->allocate(width, height, channels, true);
return pDefaultTexture;
}, nullptr, "decalTexArr");
if (has_auxillary_texture_info)
{
if (has_nm)
Expand Down Expand Up @@ -412,7 +416,14 @@ bool texLoad(const char *fileName)
}
}
// flush all of the array textures
decalTexArr->flush();
if (decalTexArr)
{
decalTexArr->flush();
}
else
{
debug(LOG_FATAL, "Failed to load one or more terrain decals");
}
if (decalNormalArr) { decalNormalArr->flush(); }
if (decalSpecularArr) { decalSpecularArr->flush(); }
if (decalHeightArr) { decalHeightArr->flush(); }
Expand Down
Loading