diff --git a/inc/openglshader.h b/inc/openglshader.h index 5e08d6d..72ee07f 100644 --- a/inc/openglshader.h +++ b/inc/openglshader.h @@ -1,7 +1,7 @@ #ifndef OPENGLSHADER_H #define OPENGLSHADER_H -// old +// OpenGL 2.0 const char PASSTHROUGH_VERT_SHADER_110[] = "#version 110\n" @@ -37,7 +37,7 @@ const char PASSTHROUGH_FRAG_SHADER_110[] = " gl_FragColor = texel; \n" "}\n"; -// new +// OpenGL 3.0 const char PASSTHROUGH_VERT_SHADER[] = "#version 130\n" @@ -82,4 +82,49 @@ const char PASSTHROUGH_FRAG_SHADER[] = " FragColor = texel;\n" "}\n"; +// OpenGL 3.2 (Core Profile) + +const char PASSTHROUGH_VERT_SHADER_CORE[] = + "#version 150\n" + "in vec4 VertexCoord;\n" + "in vec4 COLOR;\n" + "in vec4 TexCoord;\n" + "out vec4 COL0;\n" + "out vec4 TEX0;\n" + "uniform mat4 MVPMatrix;\n" + "\n" + "void main()\n" + "{\n" + " gl_Position = MVPMatrix * VertexCoord;\n" + " COL0 = COLOR;\n" + " TEX0.xy = TexCoord.xy;\n" + "}\n"; + + +const char PALETTE_FRAG_SHADER_CORE[] = + "#version 150\n" + "out vec4 FragColor;\n" + "uniform sampler2D SurfaceTex;\n" + "uniform sampler2D PaletteTex;\n" + "in vec4 TEX0;\n" + "\n" + "void main()\n" + "{\n" + " vec4 pIndex = texture(SurfaceTex, TEX0.xy);\n" + " FragColor = texture(PaletteTex, vec2(pIndex.r * (255.0/256.0) + (0.5/256.0), 0));\n" + "}\n"; + + +const char PASSTHROUGH_FRAG_SHADER_CORE[] = + "#version 150\n" + "out vec4 FragColor;\n" + "uniform sampler2D SurfaceTex;\n" + "in vec4 TEX0;\n" + "\n" + "void main()\n" + "{\n" + " vec4 texel = texture(SurfaceTex, TEX0.xy);\n" + " FragColor = texel;\n" + "}\n"; + #endif diff --git a/src/opengl_utils.c b/src/opengl_utils.c index 17f95cd..ad14929 100644 --- a/src/opengl_utils.c +++ b/src/opengl_utils.c @@ -1,6 +1,7 @@ #include #include #include "opengl_utils.h" +#include "dd.h" PFNWGLCREATECONTEXTPROC xwglCreateContext; PFNWGLDELETECONTEXTPROC xwglDeleteContext; @@ -209,7 +210,7 @@ void oglu_init() glEnableVertexAttribArray && glUniform2fv && glUniformMatrix4fv && glGenVertexArrays && glBindVertexArray && glGetUniformLocation; - if (g_oglu_got_version3 && glversion && glversion[0] == '2') // macOS + if (g_ddraw->wine && glversion && glversion[0] == '2') // macOS { g_oglu_got_version3 = FALSE; wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)xwglGetProcAddress("wglCreateContextAttribsARB"); diff --git a/src/render_ogl.c b/src/render_ogl.c index 3fadb51..a37ef07 100644 --- a/src/render_ogl.c +++ b/src/render_ogl.c @@ -79,8 +79,8 @@ static HGLRC ogl_create_core_context(HDC hdc) if (made_current) { - g_oglu_got_version3 = TRUE; xwglDeleteContext(g_ogl.context); + oglu_init(); return context; } else if (context) @@ -169,10 +169,20 @@ static void ogl_build_programs() if (g_ddraw->bpp == 8) { g_ogl.main_program = oglu_build_program(PASSTHROUGH_VERT_SHADER, PALETTE_FRAG_SHADER); + + if (!g_ogl.main_program) + { + g_ogl.main_program = oglu_build_program(PASSTHROUGH_VERT_SHADER_CORE, PALETTE_FRAG_SHADER_CORE); + } } else if (g_ddraw->bpp == 16) { g_ogl.main_program = oglu_build_program(PASSTHROUGH_VERT_SHADER, PASSTHROUGH_FRAG_SHADER); + + if (!g_ogl.main_program) + { + g_ogl.main_program = oglu_build_program(PASSTHROUGH_VERT_SHADER_CORE, PASSTHROUGH_FRAG_SHADER_CORE); + } } if (g_ogl.main_program)