File: gl_context.h

package info (click to toggle)
cen64 0.3%2Bgit20180227-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,460 kB
  • sloc: ansic: 23,713; asm: 772; cpp: 663; makefile: 14
file content (49 lines) | stat: -rw-r--r-- 1,168 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// os/winapi/gl_context.h: WinAPI GL context definitions.
//
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
// Copyright (C) 2015, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//

#ifndef CEN64_OS_WINAPI_GL_CONTEXT
#define CEN64_OS_WINAPI_GL_CONTEXT
#include "gl_common.h"
#include "gl_display.h"
#include "gl_screen.h"
#include "gl_window.h"
#include <stddef.h>

#define CEN64_GL_CONTEXT_BAD (NULL)
typedef HGLRC cen64_gl_context;

//
// Creates a cen64_gl_context and binds it to the cen64_gl_window.
//
static inline cen64_gl_context cen64_gl_context_create(cen64_gl_window window) {
  cen64_gl_context c;

  if ((c = wglCreateContext(window->hdc)) == NULL)
    return CEN64_GL_CONTEXT_BAD;

  if (wglMakeCurrent(window->hdc, c) != TRUE) {
    wglDeleteContext(c);
    c = CEN64_GL_CONTEXT_BAD;
  }

  return c;
}

//
// Unbinds the cen64_gl_context from the window and releases the context.
//
static inline void cen64_gl_context_destroy(
  cen64_gl_context context, cen64_gl_window window) {
  wglMakeCurrent(NULL, NULL);
  wglDeleteContext(context);
}

#endif