Skip to content

Commit abf2f76

Browse files
committed
renderer: set unordered_map static and const in shader and image list functions
1 parent 33d8008 commit abf2f76

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

src/engine/renderer/tr_image.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ R_ListImages_f
153153
*/
154154
void R_ListImages_f()
155155
{
156-
std::unordered_map<GLenum, std::string> imageTypeName = {
156+
static const std::unordered_map<GLenum, std::string> imageTypeName = {
157157
{ GL_TEXTURE_2D, "2D" },
158158
{ GL_TEXTURE_3D, "3D" },
159159
{ GL_TEXTURE_CUBE_MAP, "CUBE" },
160160
};
161161

162162
typedef std::pair<const std::string, int> nameSizePair;
163-
std::unordered_map<uint32_t, nameSizePair> imageFormatNameSize = {
163+
static const std::unordered_map<uint32_t, nameSizePair> imageFormatNameSize = {
164164
// TODO: find imageDataSize multiplier
165165
{ GL_RGBA, { "RGBA", 4 } },
166166

@@ -205,7 +205,7 @@ void R_ListImages_f()
205205
{ GL_DEPTH24_STENCIL8, { "D24S8", 4 } },
206206
};
207207

208-
std::unordered_map<wrapTypeEnum_t, std::string> wrapTypeName = {
208+
static const std::unordered_map<wrapTypeEnum_t, std::string> wrapTypeName = {
209209
{ wrapTypeEnum_t::WT_REPEAT, "rept" },
210210
{ wrapTypeEnum_t::WT_CLAMP, "clmp" },
211211
{ wrapTypeEnum_t::WT_EDGE_CLAMP, "eclmp" },
@@ -316,7 +316,7 @@ void R_ListImages_f()
316316
}
317317
else
318318
{
319-
type = imageTypeName[ image->type ];
319+
type = imageTypeName.at( image->type );
320320
}
321321

322322
int imageDataSize = image->uploadWidth * image->uploadHeight * image->numLayers;
@@ -332,8 +332,8 @@ void R_ListImages_f()
332332
}
333333
else
334334
{
335-
format = imageFormatNameSize[ image->internalFormat ].first;
336-
imageDataSize *= imageFormatNameSize[ image->internalFormat ].second;
335+
format = imageFormatNameSize.at( image->internalFormat ).first;
336+
imageDataSize *= imageFormatNameSize.at( image->internalFormat ).second;
337337
}
338338

339339
if ( !wrapTypeName.count( image->wrapType.t ) )
@@ -345,7 +345,7 @@ void R_ListImages_f()
345345
}
346346
else
347347
{
348-
twrap = "t." + wrapTypeName[ image->wrapType.t ];
348+
twrap = "t." + wrapTypeName.at( image->wrapType.t );
349349
}
350350

351351
if ( !wrapTypeName.count( image->wrapType.s ) )
@@ -357,7 +357,7 @@ void R_ListImages_f()
357357
}
358358
else
359359
{
360-
swrap = "s." + wrapTypeName[ image->wrapType.s ];
360+
swrap = "s." + wrapTypeName.at( image->wrapType.s );
361361
}
362362

363363
name = image->name;

src/engine/renderer/tr_shader.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6559,14 +6559,14 @@ A second parameter will cause it to print in sorted order
65596559
*/
65606560
void R_ListShaders_f()
65616561
{
6562-
std::unordered_map<shaderType_t, std::string> shaderTypeName = {
6562+
static const std::unordered_map<shaderType_t, std::string> shaderTypeName = {
65636563
{ shaderType_t::SHADER_2D, "2D" },
65646564
{ shaderType_t::SHADER_3D_DYNAMIC, "3D_DYNAMIC" },
65656565
{ shaderType_t::SHADER_3D_STATIC, "3D_STATIC" },
65666566
{ shaderType_t::SHADER_LIGHT, "LIGHT" },
65676567
};
65686568

6569-
std::unordered_map<shaderSort_t, std::string> shaderSortName = {
6569+
static const std::unordered_map<shaderSort_t, std::string> shaderSortName = {
65706570
{ shaderSort_t::SS_BAD, "BAD" },
65716571
{ shaderSort_t::SS_PORTAL, "PORTAL" },
65726572
{ shaderSort_t::SS_DEPTH, "DEPTH" },
@@ -6592,7 +6592,7 @@ void R_ListShaders_f()
65926592
{ shaderSort_t::SS_POST_PROCESS, "POST_PROCESS" },
65936593
};
65946594

6595-
std::unordered_map<stageType_t, std::string> stageTypeName = {
6595+
static const std::unordered_map<stageType_t, std::string> stageTypeName = {
65966596
{ stageType_t::ST_COLORMAP, "COLORMAP" },
65976597
{ stageType_t::ST_GLOWMAP, "GLOWMAP" },
65986598
{ stageType_t::ST_DIFFUSEMAP, "DIFFUSEMAP" },
@@ -6689,8 +6689,26 @@ void R_ListShaders_f()
66896689
stageCount += shader->numStages;
66906690
highestShaderStageCount = std::max( highestShaderStageCount, shader->numStages );
66916691

6692-
shaderType = shaderTypeName[ shader->type ];
6693-
shaderSort = shaderSortName[ (shaderSort_t) shader->sort ];
6692+
if ( !shaderTypeName.count( shader->type ) )
6693+
{
6694+
Log::Debug( "Undocumented shader type %i for shader %s",
6695+
Util::ordinal( shader->type ), shader->name );
6696+
}
6697+
else
6698+
{
6699+
shaderType = shaderTypeName.at( shader->type );
6700+
}
6701+
6702+
if ( !shaderSortName.count( (shaderSort_t) shader->sort ) )
6703+
{
6704+
Log::Debug( "Undocumented shader sort %f for shader %s",
6705+
shader->sort, shader->name );
6706+
}
6707+
else
6708+
{
6709+
shaderSort = shaderSortName.at( (shaderSort_t) shader->sort );
6710+
}
6711+
66946712
interactLight = shader->interactLight ? "INTERACTLIGHT" : "";
66956713
shaderName = shader->name;
66966714
shaderName += shader->defaultShader ? " (DEFAULTED)" : "";
@@ -6699,7 +6717,15 @@ void R_ListShaders_f()
66996717
{
67006718
shaderStage_t *stage = shader->stages[ j ];
67016719

6702-
stageType = stageTypeName[ stage->type ];
6720+
if ( !stageTypeName.count( stage->type ) )
6721+
{
6722+
Log::Debug( "Undocumented stage type %i for shader stage %s:%d",
6723+
Util::ordinal( stage->type ), shader->name, j );
6724+
}
6725+
else
6726+
{
6727+
stageType = stageTypeName.at( stage->type );
6728+
}
67036729

67046730
lineStream.clear();
67056731
lineStream.str("");

0 commit comments

Comments
 (0)