@@ -64,8 +64,7 @@ model_render_params::model_render_params() :
64
64
Xparent_alpha(1 .0f ),
65
65
Forced_bitmap(-1 ),
66
66
Insignia_bitmap(-1 ),
67
- Replacement_textures(NULL ),
68
- Manage_replacement_textures(false ),
67
+ Replacement_textures(nullptr ),
69
68
Team_color_set(false ),
70
69
Clip_plane_set(false ),
71
70
Animated_effect(-1 ),
@@ -91,12 +90,6 @@ model_render_params::model_render_params() :
91
90
gr_init_color (&Color, 0 , 0 , 0 );
92
91
}
93
92
94
- model_render_params::~model_render_params ()
95
- {
96
- if (Manage_replacement_textures)
97
- vm_free (const_cast <int *>(Replacement_textures));
98
- }
99
-
100
93
uint model_render_params::get_model_flags () const
101
94
{
102
95
return Model_flags;
@@ -157,7 +150,7 @@ int model_render_params::get_insignia_bitmap() const
157
150
return Insignia_bitmap;
158
151
}
159
152
160
- const int * model_render_params::get_replacement_textures () const
153
+ std::shared_ptr< const model_texture_replace> model_render_params::get_replacement_textures () const
161
154
{
162
155
return Replacement_textures;
163
156
}
@@ -223,19 +216,14 @@ bool model_render_params::is_team_color_set() const
223
216
return Team_color_set;
224
217
}
225
218
226
- void model_render_params::set_replacement_textures (const int * textures)
219
+ void model_render_params::set_replacement_textures (std::shared_ptr< const model_texture_replace> textures)
227
220
{
228
- Replacement_textures = textures;
221
+ Replacement_textures = std::move ( textures) ;
229
222
}
230
223
231
224
void model_render_params::set_replacement_textures (int modelnum, const SCP_vector<texture_replace>& replacement_textures)
232
225
{
233
- auto textures = (int *)vm_malloc (MAX_REPLACEMENT_TEXTURES * sizeof (int ));
234
-
235
- for (int i = 0 ; i < MAX_REPLACEMENT_TEXTURES; i++)
236
- textures[i] = -1 ;
237
-
238
- Manage_replacement_textures = true ;
226
+ auto textures = make_shared<model_texture_replace>();
239
227
240
228
polymodel* pm = model_get (modelnum);
241
229
@@ -247,11 +235,11 @@ void model_render_params::set_replacement_textures(int modelnum, const SCP_vecto
247
235
248
236
int tnum = tmap->FindTexture (tr.old_texture );
249
237
if (tnum > -1 )
250
- textures[i * TM_NUM_TYPES + tnum] = bm_load (tr.new_texture );
238
+ (* textures) [i * TM_NUM_TYPES + tnum] = bm_load (tr.new_texture );
251
239
}
252
240
}
253
241
254
- Replacement_textures = textures;
242
+ Replacement_textures = std::move ( textures) ;
255
243
}
256
244
257
245
void model_render_params::set_insignia_bitmap (int bitmap)
@@ -1054,7 +1042,7 @@ void model_render_buffers(model_draw_list* scene, model_material *rendering_mate
1054
1042
1055
1043
int texture_maps[TM_NUM_TYPES] = { -1 };
1056
1044
size_t buffer_size = buffer->tex_buf .size ();
1057
- const int * replacement_textures = interp->get_replacement_textures ();
1045
+ const auto & replacement_textures = interp->get_replacement_textures ();
1058
1046
1059
1047
for ( size_t i = 0 ; i < buffer_size; i++ ) {
1060
1048
int tmap_num = buffer->tex_buf [i].texture ;
@@ -1081,12 +1069,12 @@ void model_render_buffers(model_draw_list* scene, model_material *rendering_mate
1081
1069
1082
1070
} else if ( !no_texturing ) {
1083
1071
// pick the texture, animating it if necessary
1084
- if ( (replacement_textures != NULL ) && (replacement_textures[rt_begin_index + TM_BASE_TYPE] == REPLACE_WITH_INVISIBLE) ) {
1072
+ if ( (replacement_textures != nullptr ) && ((* replacement_textures) [rt_begin_index + TM_BASE_TYPE] == REPLACE_WITH_INVISIBLE) ) {
1085
1073
// invisible textures aren't rendered, but we still have to skip assigning the underlying model texture
1086
1074
texture_maps[TM_BASE_TYPE] = -1 ;
1087
- } else if ( (replacement_textures != NULL ) && (replacement_textures[rt_begin_index + TM_BASE_TYPE] >= 0 ) ) {
1075
+ } else if ( (replacement_textures != nullptr ) && ((* replacement_textures) [rt_begin_index + TM_BASE_TYPE] >= 0 ) ) {
1088
1076
// an underlying texture is replaced with a real new texture
1089
- tex_replace[TM_BASE_TYPE] = texture_info (replacement_textures[rt_begin_index + TM_BASE_TYPE]);
1077
+ tex_replace[TM_BASE_TYPE] = texture_info ((* replacement_textures) [rt_begin_index + TM_BASE_TYPE]);
1090
1078
texture_maps[TM_BASE_TYPE] = model_interp_get_texture (&tex_replace[TM_BASE_TYPE], elapsed_time);
1091
1079
} else {
1092
1080
// we just use the underlying texture
@@ -1101,8 +1089,8 @@ void model_render_buffers(model_draw_list* scene, model_material *rendering_mate
1101
1089
if ( !(model_flags & MR_NO_GLOWMAPS) ) {
1102
1090
auto tglow = &tmap->textures [TM_GLOW_TYPE];
1103
1091
1104
- if ( (replacement_textures != NULL ) && (replacement_textures[rt_begin_index + TM_GLOW_TYPE] >= 0 ) ) {
1105
- tex_replace[TM_GLOW_TYPE] = texture_info (replacement_textures[rt_begin_index + TM_GLOW_TYPE]);
1092
+ if ( (replacement_textures != nullptr ) && ((* replacement_textures) [rt_begin_index + TM_GLOW_TYPE] >= 0 ) ) {
1093
+ tex_replace[TM_GLOW_TYPE] = texture_info ((* replacement_textures) [rt_begin_index + TM_GLOW_TYPE]);
1106
1094
texture_maps[TM_GLOW_TYPE] = model_interp_get_texture (&tex_replace[TM_GLOW_TYPE], elapsed_time);
1107
1095
} else if (tglow->GetTexture () >= 0 ) {
1108
1096
// shockwaves are special, their current frame has to come out of the shockwave code to get the timing correct
@@ -1115,17 +1103,17 @@ void model_render_buffers(model_draw_list* scene, model_material *rendering_mate
1115
1103
}
1116
1104
1117
1105
if (!(debug_flags & MR_DEBUG_NO_SPEC)) {
1118
- if (replacement_textures != NULL && replacement_textures[rt_begin_index + TM_SPECULAR_TYPE] >= 0 ) {
1119
- tex_replace[TM_SPECULAR_TYPE] = texture_info (replacement_textures[rt_begin_index + TM_SPECULAR_TYPE]);
1106
+ if (replacement_textures != nullptr && (* replacement_textures) [rt_begin_index + TM_SPECULAR_TYPE] >= 0 ) {
1107
+ tex_replace[TM_SPECULAR_TYPE] = texture_info ((* replacement_textures) [rt_begin_index + TM_SPECULAR_TYPE]);
1120
1108
texture_maps[TM_SPECULAR_TYPE] = model_interp_get_texture (&tex_replace[TM_SPECULAR_TYPE], elapsed_time);
1121
1109
}
1122
1110
else {
1123
1111
texture_maps[TM_SPECULAR_TYPE] = model_interp_get_texture (&tmap->textures [TM_SPECULAR_TYPE], elapsed_time);
1124
1112
}
1125
1113
}
1126
1114
1127
- if ( replacement_textures != NULL && replacement_textures[rt_begin_index + TM_SPEC_GLOSS_TYPE] >= 0 ) {
1128
- tex_replace[TM_SPEC_GLOSS_TYPE] = texture_info (replacement_textures[rt_begin_index + TM_SPEC_GLOSS_TYPE]);
1115
+ if ( replacement_textures != nullptr && (* replacement_textures) [rt_begin_index + TM_SPEC_GLOSS_TYPE] >= 0 ) {
1116
+ tex_replace[TM_SPEC_GLOSS_TYPE] = texture_info ((* replacement_textures) [rt_begin_index + TM_SPEC_GLOSS_TYPE]);
1129
1117
texture_maps[TM_SPEC_GLOSS_TYPE] = model_interp_get_texture (&tex_replace[TM_SPEC_GLOSS_TYPE], elapsed_time);
1130
1118
} else {
1131
1119
texture_maps[TM_SPEC_GLOSS_TYPE] = model_interp_get_texture (&tmap->textures [TM_SPEC_GLOSS_TYPE], elapsed_time);
@@ -1138,24 +1126,25 @@ void model_render_buffers(model_draw_list* scene, model_material *rendering_mate
1138
1126
auto ambient_map = &tmap->textures [TM_AMBIENT_TYPE];
1139
1127
auto misc_map = &tmap->textures [TM_MISC_TYPE];
1140
1128
1141
- if (replacement_textures != NULL ) {
1142
- if (replacement_textures[rt_begin_index + TM_NORMAL_TYPE] >= 0 ) {
1143
- tex_replace[TM_NORMAL_TYPE] = texture_info (replacement_textures[rt_begin_index + TM_NORMAL_TYPE]);
1129
+ if (replacement_textures != nullptr ) {
1130
+ const auto & replacement_textures_deref = *replacement_textures;
1131
+ if (replacement_textures_deref[rt_begin_index + TM_NORMAL_TYPE] >= 0 ) {
1132
+ tex_replace[TM_NORMAL_TYPE] = texture_info (replacement_textures_deref[rt_begin_index + TM_NORMAL_TYPE]);
1144
1133
norm_map = &tex_replace[TM_NORMAL_TYPE];
1145
1134
}
1146
1135
1147
- if (replacement_textures [rt_begin_index + TM_HEIGHT_TYPE] >= 0 ) {
1148
- tex_replace[TM_HEIGHT_TYPE] = texture_info (replacement_textures [rt_begin_index + TM_HEIGHT_TYPE]);
1136
+ if (replacement_textures_deref [rt_begin_index + TM_HEIGHT_TYPE] >= 0 ) {
1137
+ tex_replace[TM_HEIGHT_TYPE] = texture_info (replacement_textures_deref [rt_begin_index + TM_HEIGHT_TYPE]);
1149
1138
height_map = &tex_replace[TM_HEIGHT_TYPE];
1150
1139
}
1151
1140
1152
- if (replacement_textures [rt_begin_index + TM_AMBIENT_TYPE] >= 0 ) {
1153
- tex_replace[TM_AMBIENT_TYPE] = texture_info (replacement_textures [rt_begin_index + TM_AMBIENT_TYPE]);
1141
+ if (replacement_textures_deref [rt_begin_index + TM_AMBIENT_TYPE] >= 0 ) {
1142
+ tex_replace[TM_AMBIENT_TYPE] = texture_info (replacement_textures_deref [rt_begin_index + TM_AMBIENT_TYPE]);
1154
1143
ambient_map = &tex_replace[TM_AMBIENT_TYPE];
1155
1144
}
1156
1145
1157
- if (replacement_textures [rt_begin_index + TM_MISC_TYPE] >= 0 ) {
1158
- tex_replace[TM_MISC_TYPE] = texture_info (replacement_textures [rt_begin_index + TM_MISC_TYPE]);
1146
+ if (replacement_textures_deref [rt_begin_index + TM_MISC_TYPE] >= 0 ) {
1147
+ tex_replace[TM_MISC_TYPE] = texture_info (replacement_textures_deref [rt_begin_index + TM_MISC_TYPE]);
1159
1148
misc_map = &tex_replace[TM_MISC_TYPE];
1160
1149
}
1161
1150
}
@@ -1174,8 +1163,8 @@ void model_render_buffers(model_draw_list* scene, model_material *rendering_mate
1174
1163
1175
1164
// Check for invisible or transparent textures so they don't show up in the shadow maps - Valathil
1176
1165
if ( Rendering_to_shadow_map ) {
1177
- if ( (replacement_textures != NULL ) && (replacement_textures[rt_begin_index + TM_BASE_TYPE] >= 0 ) ) {
1178
- tex_replace[TM_BASE_TYPE] = texture_info (replacement_textures[rt_begin_index + TM_BASE_TYPE]);
1166
+ if ( (replacement_textures != nullptr ) && ((* replacement_textures) [rt_begin_index + TM_BASE_TYPE] >= 0 ) ) {
1167
+ tex_replace[TM_BASE_TYPE] = texture_info ((* replacement_textures) [rt_begin_index + TM_BASE_TYPE]);
1179
1168
texture_maps[TM_BASE_TYPE] = model_interp_get_texture (&tex_replace[TM_BASE_TYPE], elapsed_time);
1180
1169
} else {
1181
1170
texture_maps[TM_BASE_TYPE] = model_interp_get_texture (&tmap->textures [TM_BASE_TYPE], elapsed_time);
@@ -3113,6 +3102,7 @@ bool render_tech_model(tech_render_type model_type, int x1, int y1, int x2, int
3113
3102
3114
3103
// Make sure model is loaded
3115
3104
model_num = model_load (sip->pof_file , sip->n_subsystems , &sip->subsystems [0 ], 0 );
3105
+ render_info.set_replacement_textures (model_num, sip->replacement_textures );
3116
3106
3117
3107
break ;
3118
3108
0 commit comments