Skip to content

Commit

Permalink
Try pragma for macos opengl deprecation errors, to demote to warnings…
Browse files Browse the repository at this point in the history
… again
  • Loading branch information
jvbsl committed Jul 15, 2023
1 parent 038f99f commit bd7f507
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions overlay_gl/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
#include <time.h>
#include <unistd.h>

#define DO_PRAGMA(x) _Pragma (#x)
#define PUSH_PRAGMA(type, additional) \
DO_PRAGMA(GCC diagnostic push) \
DO_PRAGMA(GCC diagnostic type additional)

#define PUSH_PRAGMA_WARNING(x) \
PUSH_PRAGMA(warning, x)
#define POP_PRAGMA() \
DO_PRAGMA(GCC diagnostic pop)

#if defined(TARGET_UNIX)
# define GLX_GLXEXT_LEGACY
# define GL_GLEXT_PROTOTYPES
Expand Down Expand Up @@ -66,7 +76,9 @@ typedef struct _Context {
GLXDrawable draw;
#elif defined(TARGET_MAC)
CGLContextObj cglctx;
PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
NSOpenGLContext *nsctx;
POP_PRAGMA()
#endif

unsigned int uiWidth, uiHeight;
Expand Down Expand Up @@ -120,7 +132,10 @@ FDEF(glXSwapBuffers);
FDEF(glXGetProcAddressARB);
FDEF(glXGetProcAddress);
#elif defined(TARGET_MAC)
PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
FDEF(CGLFlushDrawable);
POP_PRAGMA()

FDEF(CGDisplayHideCursor);
FDEF(CGDisplayShowCursor);
#endif
Expand Down Expand Up @@ -167,13 +182,17 @@ static void newContext(Context *ctx) {
strcat(ctx->saName.sun_path, "/.MumbleOverlayPipe");
}

PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
ods("OpenGL Version %s, Vendor %s, Renderer %s, Shader %s", glGetString(GL_VERSION), glGetString(GL_VENDOR),
glGetString(GL_RENDERER), glGetString(GL_SHADING_LANGUAGE_VERSION));
POP_PRAGMA()

const char *vsource = vshader;
const char *fsource = fshader;
char buffer[8192];
GLint l;

PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(vs, 1, &vsource, NULL);
Expand All @@ -190,6 +209,7 @@ static void newContext(Context *ctx) {
glLinkProgram(ctx->uiProgram);

glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &ctx->maxVertexAttribs);
POP_PRAGMA()
ctx->vertexAttribStates = calloc((size_t) ctx->maxVertexAttribs, sizeof(GLboolean));
}

Expand Down Expand Up @@ -230,6 +250,7 @@ static bool sendMessage(Context *ctx, struct OverlayMsg *om) {
}

static void regenTexture(Context *ctx) {
PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
if (ctx->texture != ~0U) {
glDeleteTextures(1, &ctx->texture);
}
Expand All @@ -244,6 +265,7 @@ static void regenTexture(Context *ctx) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei) ctx->uiWidth, (GLsizei) ctx->uiHeight, 0, GL_BGRA,
GL_UNSIGNED_BYTE, ctx->a_ucTexture);
POP_PRAGMA()
}

static void drawOverlay(Context *ctx, unsigned int width, unsigned int height) {
Expand Down Expand Up @@ -372,12 +394,16 @@ static void drawOverlay(Context *ctx, unsigned int width, unsigned int height) {
struct OverlayMsgBlit *omb = &ctx->omMsg.omb;
ods("BLIT %d %d %d %d", omb->x, omb->y, omb->w, omb->h);
if ((ctx->a_ucTexture != NULL) && (ctx->texture != ~0U)) {
PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
glBindTexture(GL_TEXTURE_2D, ctx->texture);
POP_PRAGMA()

if ((omb->x == 0) && (omb->y == 0) && (omb->w == ctx->uiWidth) && (omb->h == ctx->uiHeight)) {
ods("Optimzied fullscreen blit");
PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei) ctx->uiWidth, (GLsizei) ctx->uiHeight, 0,
GL_BGRA, GL_UNSIGNED_BYTE, ctx->a_ucTexture);
POP_PRAGMA()
} else {
// allocate temporary memory
unsigned int x = omb->x;
Expand All @@ -397,8 +423,11 @@ static void drawOverlay(Context *ctx, unsigned int width, unsigned int height) {
}

// copy temporary texture to opengl
PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
glTexSubImage2D(GL_TEXTURE_2D, 0, (GLint) x, (GLint) y, (GLint) w, (GLint) h, GL_BGRA,
GL_UNSIGNED_BYTE, ptr);
POP_PRAGMA()

free(ptr);
}
}
Expand Down Expand Up @@ -439,18 +468,23 @@ static void drawOverlay(Context *ctx, unsigned int width, unsigned int height) {
ods("Lost texture");
regenTexture(ctx);
} else {
PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
glBindTexture(GL_TEXTURE_2D, ctx->texture);
GLfloat bordercolor[4];
glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bordercolor);
POP_PRAGMA()

if (bordercolor[0] != fBorder[0] || bordercolor[1] != fBorder[1] || bordercolor[2] != fBorder[2]
|| bordercolor[3] != fBorder[3]) {
ods("Texture was hijacked! Texture will be regenerated.");
regenTexture(ctx);
}
}

PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
glBindTexture(GL_TEXTURE_2D, ctx->texture);
glPushMatrix();
POP_PRAGMA()

float w = (float) (ctx->uiWidth);
float h = (float) (ctx->uiHeight);
Expand All @@ -465,6 +499,7 @@ static void drawOverlay(Context *ctx, unsigned int width, unsigned int height) {
float xmx = right / w;
float ymx = bottom / h;

PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
GLfloat vertex[] = { left, bottom, left, top, right, top,

left, bottom, right, top, right, bottom };
Expand All @@ -478,6 +513,7 @@ static void drawOverlay(Context *ctx, unsigned int width, unsigned int height) {
glDrawArrays(GL_TRIANGLES, 0, 6);

glPopMatrix();
POP_PRAGMA()
}

static void drawContext(Context *ctx, int width, int height) {
Expand All @@ -498,6 +534,7 @@ static void drawContext(Context *ctx, int width, int height) {
ctx->timeT = t;
}

PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
GLuint program;
GLint viewport[4];
int i;
Expand Down Expand Up @@ -629,9 +666,11 @@ static void drawContext(Context *ctx, int width, int height) {
if (vbobound != 0) {
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
POP_PRAGMA()

drawOverlay(ctx, (unsigned int) width, (unsigned int) height);

PUSH_PRAGMA_WARNING("-Wdeprecated-declarations")
if (bound != 0) {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, bound);
}
Expand Down Expand Up @@ -663,6 +702,7 @@ static void drawContext(Context *ctx, int width, int height) {
// drain opengl error queue
while (glGetError() != GL_NO_ERROR)
;
POP_PRAGMA()
}

#if defined(TARGET_UNIX)
Expand Down

0 comments on commit bd7f507

Please sign in to comment.