@@ -315,7 +315,7 @@ r_init(CmdLine *cmdln)
315
315
r_ogl_state->wglCreateContextAttribsARB = (wgl_create_context_attribs_arb*)wglGetProcAddress (" wglCreateContextAttribsARB" );
316
316
r_ogl_state->wglChoosePixelFormatARB = (wgl_choose_pixel_format_arb*)wglGetProcAddress (" wglChoosePixelFormatARB" );
317
317
318
- ReleaseDC ( r_ogl_state->fake_window , fake_dc) ;
318
+ r_ogl_state->fake_window_dc = fake_dc;
319
319
320
320
if (!ok) {
321
321
char buffer[256 ] = {0 };
@@ -349,7 +349,7 @@ r_init(CmdLine *cmdln)
349
349
#define WGL_SAMPLES_ARB 0x2042
350
350
351
351
internal void
352
- r_ogl_initialize_window (OS_Handle handle)
352
+ r_ogl_initialize_window (OS_Handle handle, R_OGL_Window* window )
353
353
{
354
354
// - dmylo: map os window handle -> hwnd
355
355
HWND hwnd = {0 };
@@ -381,19 +381,18 @@ r_ogl_initialize_window(OS_Handle handle)
381
381
DescribePixelFormat (window_dc, suggested_format_index, sizeof (PIXELFORMATDESCRIPTOR), &suggested_format);
382
382
SetPixelFormat (window_dc, suggested_format_index, &suggested_format);
383
383
384
- ReleaseDC (hwnd, window_dc) ;
384
+ window-> dc = window_dc;
385
385
}
386
386
387
387
internal void
388
- r_ogl_initialize (OS_Handle handle)
388
+ r_ogl_initialize (OS_Handle handle, R_OGL_Window *window )
389
389
{
390
390
// - dmylo: map os window handle -> hwnd
391
391
HWND hwnd = {0 };
392
392
{
393
393
W32_Window *w32_layer_window = w32_window_from_os_window (handle);
394
394
hwnd = w32_hwnd_from_window (w32_layer_window);
395
395
}
396
- HDC window_dc = GetDC (hwnd);
397
396
398
397
// Create a modern context with the first window DC
399
398
int attribs[] =
@@ -408,9 +407,8 @@ r_ogl_initialize(OS_Handle handle)
408
407
0
409
408
};
410
409
411
- HGLRC glrc = r_ogl_state->wglCreateContextAttribsARB (window_dc, 0 , attribs);
412
- bool ok = wglMakeCurrent (window_dc, glrc);
413
- ReleaseDC (hwnd, window_dc);
410
+ HGLRC glrc = r_ogl_state->wglCreateContextAttribsARB (window->dc , 0 , attribs);
411
+ bool ok = wglMakeCurrent (window->dc , glrc);
414
412
415
413
if (!ok) {
416
414
char buffer[256 ] = {0 };
@@ -424,8 +422,10 @@ r_ogl_initialize(OS_Handle handle)
424
422
425
423
// - dmylo: Now that we have a modern context, cleanup the fake context and the fake window.
426
424
wglDeleteContext (r_ogl_state->fake_glrc );
425
+ ReleaseDC (r_ogl_state->fake_window , r_ogl_state->fake_window_dc );
427
426
DestroyWindow (r_ogl_state->fake_window );
428
427
r_ogl_state->fake_glrc = 0 ;
428
+ r_ogl_state->fake_window_dc = 0 ;
429
429
r_ogl_state->fake_window = 0 ;
430
430
431
431
// - dmylo: Load function pointers.
@@ -452,7 +452,6 @@ r_ogl_initialize(OS_Handle handle)
452
452
// buffers
453
453
gl.GenBuffers (1 , &r_ogl_state->instance_scratch_buffer_64kb );
454
454
gl.BindBuffer (GL_ARRAY_BUFFER, r_ogl_state->instance_scratch_buffer_64kb );
455
- gl.BufferData (GL_ARRAY_BUFFER, KB (64 ), 0 , GL_STREAM_DRAW);
456
455
457
456
// vao
458
457
gl.GenVertexArrays (1 , &r_ogl_state->rect_vao );
@@ -465,7 +464,6 @@ r_ogl_initialize(OS_Handle handle)
465
464
// uniforms
466
465
gl.GenBuffers (1 , &r_ogl_state->rect_uniform_buffer );
467
466
gl.BindBuffer (GL_UNIFORM_BUFFER, r_ogl_state->rect_uniform_buffer );
468
- gl.BufferData (GL_UNIFORM_BUFFER, sizeof (R_OGL_Uniforms_Rect), 0 , GL_STREAM_DRAW);
469
467
r_ogl_state->rect_uniform_block_index = gl.GetUniformBlockIndex (r_ogl_state->rect_shader , " Globals" );
470
468
}
471
469
@@ -479,7 +477,6 @@ r_ogl_initialize(OS_Handle handle)
479
477
// uniforms
480
478
gl.GenBuffers (1 , &r_ogl_state->blur_uniform_buffer );
481
479
gl.BindBuffer (GL_UNIFORM_BUFFER, r_ogl_state->blur_uniform_buffer );
482
- gl.BufferData (GL_UNIFORM_BUFFER, sizeof (R_OGL_Uniforms_BlurPass), 0 , GL_STREAM_DRAW);
483
480
r_ogl_state->blur_uniform_block_index = gl.GetUniformBlockIndex (r_ogl_state->blur_shader , " Globals" );
484
481
r_ogl_state->blur_direction_uniform_location = gl.GetUniformLocation (r_ogl_state->blur_shader , " u_direction" );
485
482
}
@@ -541,14 +538,14 @@ r_window_equip(OS_Handle handle)
541
538
window->generation += 1 ;
542
539
}
543
540
544
- r_ogl_initialize_window (handle);
541
+ r_ogl_initialize_window (handle, window );
545
542
546
543
// - dmylo: we delay OpenGL state initialization to the first time a window
547
544
// is created, because we need a window with a modern context to load
548
545
// the functions we need.
549
546
if (!r_ogl_state->initialized )
550
547
{
551
- r_ogl_initialize (handle);
548
+ r_ogl_initialize (handle, window );
552
549
r_ogl_state->initialized = true ;
553
550
just_initialized = true ;
554
551
}
@@ -572,13 +569,21 @@ r_window_equip(OS_Handle handle)
572
569
}
573
570
574
571
r_hook void
575
- r_window_unequip (OS_Handle window , R_Handle equip_handle)
572
+ r_window_unequip (OS_Handle window_handle , R_Handle equip_handle)
576
573
{
577
574
ProfBeginFunction ();
578
575
OS_MutexScopeW (r_ogl_state->device_rw_mutex )
579
576
{
577
+ // - dmylo: map os window handle -> hwnd
578
+ HWND hwnd = {0 };
579
+ {
580
+ W32_Window *w32_layer_window = w32_window_from_os_window (window_handle);
581
+ hwnd = w32_hwnd_from_window (w32_layer_window);
582
+ }
583
+
580
584
R_OGL_Window *window = r_ogl_window_from_handle (equip_handle);
581
585
window->generation += 1 ;
586
+ ReleaseDC (hwnd, window->dc );
582
587
SLLStackPush (r_ogl_state->first_free_window , window);
583
588
}
584
589
ProfEnd ();
@@ -840,9 +845,7 @@ r_window_begin_frame(OS_Handle window_handle, R_Handle window_equip)
840
845
}
841
846
842
847
// - dmylo: bind main context to the window.
843
- HDC window_dc = GetDC (hwnd);
844
- bool ok = wglMakeCurrent (window_dc, r_ogl_state->glrc );
845
- ReleaseDC (hwnd, window_dc);
848
+ bool ok = wglMakeCurrent (window->dc , r_ogl_state->glrc );
846
849
847
850
// - dmylo: get resolution
848
851
Rng2F32 client_rect = os_client_rect_from_window (window_handle);
@@ -928,7 +931,7 @@ r_window_end_frame(OS_Handle window_handle, R_Handle window_equip)
928
931
ProfBeginFunction ();
929
932
OS_MutexScopeW (r_ogl_state->device_rw_mutex )
930
933
{
931
- R_OGL_Window *wnd = r_ogl_window_from_handle (window_equip);
934
+ R_OGL_Window *window = r_ogl_window_from_handle (window_equip);
932
935
933
936
// //////////////////////////
934
937
// - dmylo: finalize, by writing staging buffer out to window framebuffer
@@ -942,28 +945,20 @@ r_window_end_frame(OS_Handle window_handle, R_Handle window_equip)
942
945
gl.Disable (GL_CULL_FACE);
943
946
gl.Disable (GL_BLEND);
944
947
945
- Vec2S32 resolution = wnd ->last_resolution ;
948
+ Vec2S32 resolution = window ->last_resolution ;
946
949
gl.Viewport (0 , 0 , (F32)resolution.x , (F32)resolution.y );
947
950
948
951
gl.UseProgram (r_ogl_state->finalize_shader );
949
952
950
953
gl.ActiveTexture (GL_TEXTURE0);
951
- gl.BindTexture (GL_TEXTURE_2D, wnd ->stage_color );
954
+ gl.BindTexture (GL_TEXTURE_2D, window ->stage_color );
952
955
gl.TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
953
956
gl.TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
954
957
955
958
gl.DrawArrays (GL_TRIANGLE_STRIP, 0 , 4 );
956
959
}
957
960
958
- HWND hwnd = {0 };
959
- {
960
- W32_Window *w32_layer_window = w32_window_from_os_window (window_handle);
961
- hwnd = w32_hwnd_from_window (w32_layer_window);
962
- }
963
- HDC window_dc = GetDC (hwnd);
964
-
965
- SwapBuffers (window_dc);
966
- ReleaseDC (hwnd, window_dc);
961
+ SwapBuffers (window->dc );
967
962
}
968
963
ProfEnd ();
969
964
}
@@ -1045,19 +1040,6 @@ r_window_submit(OS_Handle window, R_Handle window_equip, R_PassList *passes)
1045
1040
gl.BufferData (GL_ARRAY_BUFFER, batches->byte_count , dst_ptr, GL_STREAM_DRAW);
1046
1041
1047
1042
temp_end (temp);
1048
-
1049
- // - dmylo: Equivalent mapping code, much slower on nvidia driver, likely forcing GPU synchronization
1050
- // instead of providing a new driver-managed buffer for some reason.
1051
- //
1052
- // gl.BindBuffer(GL_ARRAY_BUFFER, buffer);
1053
- // U8* dst_ptr = (U8*)gl.MapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
1054
- // U64 off = 0;
1055
- // for(R_BatchNode *batch_n = batches->first; batch_n != 0; batch_n = batch_n->next)
1056
- // {
1057
- // MemoryCopy(dst_ptr+off, batch_n->v.v, batch_n->v.byte_count);
1058
- // off += batch_n->v.byte_count;
1059
- // }
1060
- // gl.UnmapBuffer(GL_ARRAY_BUFFER);
1061
1043
}
1062
1044
1063
1045
for (U32 i = 0 ; i < 8 ; i++) {
@@ -1109,22 +1091,13 @@ r_window_submit(OS_Handle window, R_Handle window_equip, R_PassList *passes)
1109
1091
uniforms.xform_scale .y = length_2f32 (xform_2x2_col1);
1110
1092
}
1111
1093
1094
+ // dmylo: uniform
1112
1095
GLuint uniform_buffer = r_ogl_state->rect_uniform_buffer ;
1113
1096
{
1114
- gl.BindBuffer (GL_UNIFORM_BUFFER, uniform_buffer);
1097
+ gl.BindBufferBase (GL_UNIFORM_BUFFER, 0 , uniform_buffer);
1115
1098
gl.BufferData (GL_UNIFORM_BUFFER, sizeof (uniforms), &uniforms, GL_STREAM_DRAW);
1116
-
1117
- // dmylo: Equivalent mapping code, much slower on nvidia driver, likely forcing GPU synchronization
1118
- // instead of providing a new driver-managed buffer for some reason.
1119
- //
1120
- // U8* dst_ptr = (U8*)gl.MapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY);
1121
- // MemoryCopy((U8 *)dst_ptr, &uniforms, sizeof(uniforms));
1122
- // gl.UnmapBuffer(GL_UNIFORM_BUFFER);
1123
1099
}
1124
-
1125
- // dmylo: bind uniform buffer
1126
1100
gl.UniformBlockBinding (r_ogl_state->rect_shader , r_ogl_state->rect_uniform_block_index , 0 );
1127
- gl.BindBufferBase (GL_UNIFORM_BUFFER, 0 , uniform_buffer);
1128
1101
1129
1102
// dmylo: activate and bind texture
1130
1103
gl.ActiveTexture (GL_TEXTURE0);
@@ -1194,10 +1167,7 @@ r_window_submit(OS_Handle window, R_Handle window_equip, R_PassList *passes)
1194
1167
gl.Disable (GL_STENCIL_TEST);
1195
1168
gl.Disable (GL_SCISSOR_TEST);
1196
1169
gl.Disable (GL_CULL_FACE);
1197
-
1198
- // dmylo: blending
1199
- gl.Enable (GL_BLEND);
1200
- gl.BlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1170
+ gl.Disable (GL_BLEND);
1201
1171
1202
1172
Vec2S32 resolution = wnd->last_resolution ;
1203
1173
gl.Viewport (0 , 0 , (F32)resolution.x , (F32)resolution.y );
@@ -1223,10 +1193,9 @@ r_window_submit(OS_Handle window, R_Handle window_equip, R_PassList *passes)
1223
1193
1224
1194
GLuint uniform_buffer = r_ogl_state->blur_uniform_buffer ;
1225
1195
{
1226
- gl.BindBuffer (GL_UNIFORM_BUFFER, uniform_buffer);
1196
+ gl.BindBufferBase (GL_UNIFORM_BUFFER, 0 , uniform_buffer);
1227
1197
gl.BufferData (GL_UNIFORM_BUFFER, sizeof (uniforms), &uniforms, GL_STREAM_DRAW);
1228
1198
gl.UniformBlockBinding (r_ogl_state->blur_shader , r_ogl_state->blur_uniform_block_index , 0 );
1229
- gl.BindBufferBase (GL_UNIFORM_BUFFER, 0 , uniform_buffer);
1230
1199
}
1231
1200
1232
1201
// dmylo: Horizontal pass
0 commit comments