1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

#52 fixes macOS OpenGL core profile

This commit is contained in:
FunkyFr3sh 2020-10-23 17:56:24 +02:00
parent 7229a2a34e
commit 05d665dea9
3 changed files with 60 additions and 4 deletions

View File

@ -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

View File

@ -1,6 +1,7 @@
#include <windows.h>
#include <stdio.h>
#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");

View File

@ -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)