624 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel required |
627 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel required |
625 SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer has to be 16 bit only |
628 SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer has to be 16 bit only |
626 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // try to prefer hardware rendering |
629 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // try to prefer hardware rendering |
627 end; |
630 end; |
628 |
631 |
|
632 {$IFDEF GL2} |
|
633 function CompileShader(shaderFile: string; shaderType: GLenum): GLuint; |
|
634 var |
|
635 shader: GLuint; |
|
636 f: Textfile; |
|
637 source, line: AnsiString; |
|
638 sourceA: Pchar; |
|
639 lengthA: GLint; |
|
640 compileResult: GLint; |
|
641 logLength: GLint; |
|
642 log: PChar; |
|
643 begin |
|
644 Assign(f, Pathz[ptShaders] + '/' + shaderFile); |
|
645 filemode:= 0; // readonly |
|
646 Reset(f); |
|
647 if IOResult <> 0 then |
|
648 begin |
|
649 AddFileLog('Unable to load ' + shaderFile); |
|
650 halt(-1); |
|
651 end; |
|
652 |
|
653 source:=''; |
|
654 while not eof(f) do |
|
655 begin |
|
656 ReadLn(f, line); |
|
657 source:= source + line + #10; |
|
658 end; |
|
659 |
|
660 CloseFile(f); |
|
661 |
|
662 writeln('Compiling shader: ' + Pathz[ptShaders] + '/' + shaderFile); |
|
663 |
|
664 sourceA:=PChar(source); |
|
665 lengthA:=Length(source); |
|
666 |
|
667 shader:=glCreateShader(shaderType); |
|
668 glShaderSource(shader, 1, @sourceA, @lengthA); |
|
669 glCompileShader(shader); |
|
670 glGetShaderiv(shader, GL_COMPILE_STATUS, @compileResult); |
|
671 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, @logLength); |
|
672 |
|
673 if logLength > 1 then |
|
674 begin |
|
675 GetMem(log, logLength); |
|
676 glGetShaderInfoLog(shader, logLength, nil, log); |
|
677 writeln('========== Compiler log =========='); |
|
678 writeln(log); |
|
679 writeln('==================================='); |
|
680 FreeMem(log, logLength); |
|
681 end; |
|
682 |
|
683 if compileResult <> GL_TRUE then |
|
684 begin |
|
685 writeln('Shader compilation failed, halting'); |
|
686 halt(-1); |
|
687 end; |
|
688 |
|
689 CompileShader:= shader; |
|
690 end; |
|
691 |
|
692 function CompileProgram(shaderName: string): GLuint; |
|
693 var |
|
694 program_: GLuint; |
|
695 vs, fs: GLuint; |
|
696 linkResult: GLint; |
|
697 logLength: GLint; |
|
698 log: PChar; |
|
699 begin |
|
700 program_:= glCreateProgram(); |
|
701 vs:= CompileShader(shaderName + '.vs', GL_VERTEX_SHADER); |
|
702 fs:= CompileShader(shaderName + '.fs', GL_FRAGMENT_SHADER); |
|
703 glAttachShader(program_, vs); |
|
704 glAttachShader(program_, fs); |
|
705 glLinkProgram(program_); |
|
706 glDeleteShader(vs); |
|
707 glDeleteShader(fs); |
|
708 |
|
709 glGetProgramiv(program_, GL_LINK_STATUS, @linkResult); |
|
710 glGetProgramiv(program_, GL_INFO_LOG_LENGTH, @logLength); |
|
711 |
|
712 if logLength > 1 then |
|
713 begin |
|
714 GetMem(log, logLength); |
|
715 glGetProgramInfoLog(program_, logLength, nil, log); |
|
716 writeln('========== Compiler log =========='); |
|
717 writeln(log); |
|
718 writeln('==================================='); |
|
719 FreeMem(log, logLength); |
|
720 end; |
|
721 |
|
722 if linkResult <> GL_TRUE then |
|
723 begin |
|
724 writeln('Linking program failed, halting'); |
|
725 halt(-1); |
|
726 end; |
|
727 |
|
728 CompileProgram:= program_; |
|
729 end; |
|
730 {$ENDIF} |
|
731 |
629 procedure SetupOpenGL; |
732 procedure SetupOpenGL; |
630 //var vendor: shortstring = ''; |
733 //var vendor: shortstring = ''; |
631 var buf: array[byte] of char; |
734 var buf: array[byte] of char; |
632 begin |
735 begin |
633 buf[0]:= char(0); // avoid compiler hint |
736 buf[0]:= char(0); // avoid compiler hint |
680 AddFileLog(' |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR)))); |
783 AddFileLog(' |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR)))); |
681 AddFileLog(' |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION)))); |
784 AddFileLog(' |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION)))); |
682 AddFileLog(' |----- Texture Size: ' + inttostr(MaxTextureSize)); |
785 AddFileLog(' |----- Texture Size: ' + inttostr(MaxTextureSize)); |
683 AddFileLog(' \----- Extensions: ' + shortstring(pchar(glGetString(GL_EXTENSIONS)))); |
786 AddFileLog(' \----- Extensions: ' + shortstring(pchar(glGetString(GL_EXTENSIONS)))); |
684 //TODO: don't have the Extensions line trimmed but slipt it into multiple lines |
787 //TODO: don't have the Extensions line trimmed but slipt it into multiple lines |
|
788 |
|
789 {$IFDEF GL2} |
|
790 Load_GL_VERSION_2_0; |
|
791 Shader:= CompileProgram('default'); |
|
792 glUseProgram(Shader); |
|
793 glUniform1i(glGetUniformLocation(Shader, 'tex'), 0); |
|
794 {$ENDIF} |
685 |
795 |
686 {$IFNDEF S3D_DISABLED} |
796 {$IFNDEF S3D_DISABLED} |
687 if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then |
797 if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then |
688 begin |
798 begin |
689 // prepare left and right frame buffers and associated textures |
799 // prepare left and right frame buffers and associated textures |