38 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
38 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
39 procedure RenderWeaponTooltip(atype: TAmmoType); |
39 procedure RenderWeaponTooltip(atype: TAmmoType); |
40 procedure ShowWeaponTooltip(x, y: LongInt); |
40 procedure ShowWeaponTooltip(x, y: LongInt); |
41 procedure FreeWeaponTooltip; |
41 procedure FreeWeaponTooltip; |
42 procedure MakeCrossHairs; |
42 procedure MakeCrossHairs; |
|
43 procedure InitOffscreenOpenGL; |
43 |
44 |
44 procedure WarpMouse(x, y: Word); inline; |
45 procedure WarpMouse(x, y: Word); inline; |
45 procedure SwapBuffers; inline; |
46 procedure SwapBuffers; inline; |
46 |
47 |
47 implementation |
48 implementation |
48 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, |
49 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, |
49 uDebug{$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}; |
50 uDebug{$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}, glut; |
50 |
51 |
51 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple); |
52 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple); |
52 |
53 |
53 var MaxTextureSize: LongInt; |
54 var MaxTextureSize: LongInt; |
54 {$IFDEF SDL13} |
55 {$IFDEF SDL13} |
436 if not reload then |
437 if not reload then |
437 AddProgress; |
438 AddProgress; |
438 IMG_Quit(); |
439 IMG_Quit(); |
439 end; |
440 end; |
440 |
441 |
|
442 procedure CreateFramebuffer(var frame, depth, tex: GLuint); |
|
443 begin |
|
444 glGenFramebuffersEXT(1, @frame); |
|
445 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frame); |
|
446 glGenRenderbuffersEXT(1, @depth); |
|
447 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth); |
|
448 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, cScreenWidth, cScreenHeight); |
|
449 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth); |
|
450 glGenTextures(1, @tex); |
|
451 glBindTexture(GL_TEXTURE_2D, tex); |
|
452 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, cScreenWidth, cScreenHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil); |
|
453 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
454 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
455 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0); |
|
456 end; |
|
457 |
|
458 procedure DeleteFramebuffer(var frame, depth, tex: GLuint); |
|
459 begin |
|
460 glDeleteTextures(1, @tex); |
|
461 glDeleteRenderbuffersEXT(1, @depth); |
|
462 glDeleteFramebuffersEXT(1, @frame); |
|
463 end; |
|
464 |
441 procedure StoreRelease(reload: boolean); |
465 procedure StoreRelease(reload: boolean); |
442 var ii: TSprite; |
466 var ii: TSprite; |
443 ai: TAmmoType; |
467 ai: TAmmoType; |
444 i, t: LongInt; |
468 i, t: LongInt; |
445 begin |
469 begin |
509 FreeTexture(TeamsArray[t]^.Hedgehogs[i].HatTex); |
533 FreeTexture(TeamsArray[t]^.Hedgehogs[i].HatTex); |
510 TeamsArray[t]^.Hedgehogs[i].HatTex:= nil; |
534 TeamsArray[t]^.Hedgehogs[i].HatTex:= nil; |
511 end; |
535 end; |
512 end; |
536 end; |
513 end; |
537 end; |
|
538 if defaultFrame <> 0 then |
|
539 DeleteFramebuffer(defaultFrame, depthv, texv); |
514 {$IFNDEF S3D_DISABLED} |
540 {$IFNDEF S3D_DISABLED} |
515 if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then |
541 if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then |
516 begin |
542 begin |
517 glDeleteTextures(1, @texl); |
543 DeleteFramebuffer(framel, depthl, texl); |
518 glDeleteRenderbuffersEXT(1, @depthl); |
544 DeleteFramebuffer(framer, depthr, texr); |
519 glDeleteFramebuffersEXT(1, @framel); |
|
520 glDeleteTextures(1, @texr); |
|
521 glDeleteRenderbuffersEXT(1, @depthr); |
|
522 glDeleteFramebuffersEXT(1, @framer) |
|
523 end |
545 end |
524 {$ENDIF} |
546 {$ENDIF} |
525 end; |
547 end; |
526 |
548 |
527 |
549 |
671 else |
694 else |
672 AddFileLog('OpenGL Warning - unknown hardware vendor; please report'); |
695 AddFileLog('OpenGL Warning - unknown hardware vendor; please report'); |
673 {$ENDIF} |
696 {$ENDIF} |
674 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
697 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
675 *) |
698 *) |
|
699 glGetIntegerv(GL_AUX_BUFFERS, @AuxBufNum); |
676 |
700 |
677 // everyone love debugging |
701 // everyone love debugging |
678 AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER)))); |
702 AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER)))); |
679 AddFileLog(' |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR)))); |
703 AddFileLog(' |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR)))); |
680 AddFileLog(' |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION)))); |
704 AddFileLog(' |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION)))); |
681 AddFileLog(' |----- Texture Size: ' + inttostr(MaxTextureSize)); |
705 AddFileLog(' |----- Texture Size: ' + inttostr(MaxTextureSize)); |
682 AddFileLog(' \----- Extensions: ' + shortstring(pchar(glGetString(GL_EXTENSIONS)))); |
706 AddFileLog(' |----- Number of auxilary buffers: ' + inttostr(AuxBufNum)); |
|
707 AddFileLog(' \----- Extensions: '); |
|
708 AddFileLogRaw(glGetString(GL_EXTENSIONS)); |
|
709 AddFileLog(''); |
683 //TODO: don't have the Extensions line trimmed but slipt it into multiple lines |
710 //TODO: don't have the Extensions line trimmed but slipt it into multiple lines |
|
711 |
|
712 defaultFrame:= 0; |
|
713 if GameType = gmtRecord then |
|
714 begin |
|
715 if AuxBufNum > 0 then |
|
716 begin |
|
717 glDrawBuffer(GL_AUX0); |
|
718 glReadBuffer(GL_AUX0); |
|
719 AddFileLog('Using auxilary buffer for video recording.'); |
|
720 end |
|
721 else if glLoadExtension('GL_EXT_framebuffer_object') then |
|
722 begin |
|
723 CreateFramebuffer(defaultFrame, depthv, texv); |
|
724 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame); |
|
725 AddFileLog('Using framebuffer for video recording.'); |
|
726 end |
|
727 else |
|
728 begin |
|
729 glDrawBuffer(GL_BACK); |
|
730 glReadBuffer(GL_BACK); |
|
731 AddFileLog('Warning: off-screen rendering is not supported; using back buffer but it may not work.'); |
|
732 end; |
|
733 end; |
684 |
734 |
685 {$IFNDEF S3D_DISABLED} |
735 {$IFNDEF S3D_DISABLED} |
686 if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then |
736 if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then |
687 begin |
737 begin |
688 // prepare left and right frame buffers and associated textures |
738 // prepare left and right frame buffers and associated textures |
689 if glLoadExtension('GL_EXT_framebuffer_object') then |
739 if glLoadExtension('GL_EXT_framebuffer_object') then |
690 begin |
740 begin |
691 // left |
741 CreateFramebuffer(framel, depthl, texl); |
692 glGenFramebuffersEXT(1, @framel); |
742 CreateFramebuffer(framer, depthr, texr); |
693 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel); |
|
694 glGenRenderbuffersEXT(1, @depthl); |
|
695 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthl); |
|
696 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, cScreenWidth, cScreenHeight); |
|
697 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthl); |
|
698 glGenTextures(1, @texl); |
|
699 glBindTexture(GL_TEXTURE_2D, texl); |
|
700 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, cScreenWidth, cScreenHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil); |
|
701 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
703 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texl, 0); |
|
704 |
|
705 // right |
|
706 glGenFramebuffersEXT(1, @framer); |
|
707 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framer); |
|
708 glGenRenderbuffersEXT(1, @depthr); |
|
709 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthr); |
|
710 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, cScreenWidth, cScreenHeight); |
|
711 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthr); |
|
712 glGenTextures(1, @texr); |
|
713 glBindTexture(GL_TEXTURE_2D, texr); |
|
714 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, cScreenWidth, cScreenHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil); |
|
715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
717 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texr, 0); |
|
718 |
743 |
719 // reset |
744 // reset |
720 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) |
745 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame) |
721 end |
746 end |
722 else |
747 else |
723 cStereoMode:= smNone; |
748 cStereoMode:= smNone; |
724 end; |
749 end; |
725 {$ENDIF} |
750 {$ENDIF} |