@@ -389,15 +389,23 @@ static glm_worldmodel_req_t* GLM_NextBatchRequest(model_t* model, float alpha, i
389
389
glm_brushmodel_drawcall_t * drawcall = & drawcalls [current_drawcall ];
390
390
float mvMatrix [16 ];
391
391
392
+ glm_brushmodel_drawcall_type desired_type = alpha == 0.0f ? opaque_world : alpha_surfaces ;
393
+
392
394
R_GetModelviewMatrix (mvMatrix );
393
395
394
396
// If user has switched off caustics (or no texture), ignore
395
397
if (caustics ) {
396
398
caustics &= ((R_ProgramCustomOptions (r_program_brushmodel ) & DRAW_CAUSTIC_TEXTURES ) == DRAW_CAUSTIC_TEXTURES );
397
399
}
398
400
399
- // See if previous batch has same texture & matrix, if so just continue
400
- if (drawcall -> batch_count ) {
401
+ if (drawcall -> type != desired_type ) {
402
+ drawcall = GL_FlushWorldModelBatch ();
403
+ drawcall -> type = desired_type ;
404
+ }
405
+ else if (drawcall -> batch_count && drawcall -> type == opaque_world ) {
406
+ // See if previous request has same texture & matrix, if so just continue
407
+ // as long as drawcall is not alpha as such requests must be drawn in the
408
+ // predetermined order.
401
409
req = & drawcall -> worldmodel_requests [drawcall -> batch_count - 1 ];
402
410
403
411
if (allow_duplicate && model == req -> model && req -> samplerMappingCount == num_textures && req -> firstTexture == first_texture && drawcall -> batch_count < MAX_WORLDMODEL_BATCH && isAlphaTested == req -> isAlphaTested ) {
@@ -765,12 +773,12 @@ void GLM_DrawBrushModel(entity_t* ent, qbool polygonOffset, qbool caustics)
765
773
glm_worldmodel_req_t * req = NULL ;
766
774
model_t * model = ent -> model ;
767
775
768
- if (GLM_DuplicatePreviousRequest (model , 1.0f , model -> last_texture_chained - model -> first_texture_chained + 1 , model -> first_texture_chained , polygonOffset , caustics )) {
776
+ if (GLM_DuplicatePreviousRequest (model , ent -> alpha , model -> last_texture_chained - model -> first_texture_chained + 1 , model -> first_texture_chained , polygonOffset , caustics )) {
769
777
return ;
770
778
}
771
779
772
780
if (model -> drawflat_chain ) {
773
- req = GLM_NextBatchRequest (model , 1.0f , 0 , 0 , false, false, false, false);
781
+ req = GLM_NextBatchRequest (model , ent -> alpha , 0 , 0 , false, false, false, false);
774
782
775
783
req = GLM_DrawFlatChain (req , model -> drawflat_chain );
776
784
@@ -788,10 +796,10 @@ void GLM_DrawBrushModel(entity_t* ent, qbool polygonOffset, qbool caustics)
788
796
continue ;
789
797
}
790
798
791
- req = GLM_NextBatchRequest (model , 1.0f , 1 , i , polygonOffset , caustics , false, tex -> isAlphaTested );
799
+ req = GLM_NextBatchRequest (model , ent -> alpha , 1 , i , polygonOffset , caustics , false, tex -> isAlphaTested );
792
800
tex = R_TextureAnimation (ent , tex );
793
801
if (!GLM_AssignTexture (i , tex )) {
794
- req = GLM_NextBatchRequest (model , 1.0f , 1 , i , polygonOffset , caustics , false, tex -> isAlphaTested );
802
+ req = GLM_NextBatchRequest (model , ent -> alpha , 1 , i , polygonOffset , caustics , false, tex -> isAlphaTested );
795
803
GLM_AssignTexture (i , tex );
796
804
}
797
805
@@ -842,12 +850,15 @@ static void GL_SortDrawCalls(glm_brushmodel_drawcall_t* drawcall)
842
850
}
843
851
}
844
852
845
- qsort (drawcall -> worldmodel_requests , drawcall -> batch_count , sizeof (drawcall -> worldmodel_requests [0 ]), GL_DrawCallComparison );
853
+ // Translucent bmodels are put into requests based on their distance from view and sorting here will break that order.
854
+ if (drawcall -> type == opaque_world ) {
855
+ qsort (drawcall -> worldmodel_requests , drawcall -> batch_count , sizeof (drawcall -> worldmodel_requests [0 ]), GL_DrawCallComparison );
856
+ }
846
857
847
858
for (i = 0 ; i < drawcall -> batch_count ; ++ i ) {
848
859
glm_worldmodel_req_t * thisReq = & drawcall -> worldmodel_requests [i ];
849
860
850
- drawcall -> calls [i ].alpha = thisReq -> alpha ;
861
+ drawcall -> calls [i ].alpha = thisReq -> alpha == 0.0f ? 1.0f : thisReq -> alpha ;
851
862
drawcall -> calls [i ].flags = thisReq -> flags ;
852
863
memcpy (drawcall -> calls [i ].modelMatrix , thisReq -> mvMatrix , sizeof (drawcall -> calls [i ].modelMatrix ));
853
864
drawcall -> calls [i ].samplerBase = thisReq -> samplerMappingBase ;
0 commit comments