OpenGL Context란 무엇인가?
1. 개념
OpenGL Context는 OpenGL API를 사용하여 그래픽을 렌더링하는 데 필요한 모든 정보를 가지는 데이터 구조이다. 여기에는 활성 셰이더(Active Shader), 현재 정점 배열(Current Vertex Array), 현재 프레임 버퍼(Current Framebuffer)와 같은 렌더링 파이프라인의 현재 상태(Current State) 정보가 포함된다. 또한 렌더링 프로세스에 사용되는 텍스처(Texture), 정점 버퍼(Vertex Buffer) 및 기본 프레임 버퍼(Default Framebuffer 또는 Window system-provided Framebuffer)와 같은 리소스도 포함된다.
2. 역할
OpenGL Context는 활성 셰이더 설정, 현재 정점 배열 설정 등 다양한 렌더링 옵션으로 구성된 렌더링 파이프라인의 상태와 렌더링 프로세스에서 사용되는 텍스처 및 정점 버퍼와 같은 리소스를 관리한다. OpenGL Context는 또한 응용 프로그램과 그래픽 하드웨어 간의 데이터 흐름을 제어한다. 응용 프로그램은 Context를 통해 그래픽 하드웨어가 실행할 명령을 전송하고, 그래픽 하드웨어가 처리한 렌더링 결과를 받는다.
3. 특징
OpenGL Context는 동일한 프로세스에서 여러 개를 생성할 수 있고 병렬로 사용될 수 있다. 이를 통해 여러 화면을 독립적으로 동시에 렌더링 할 수 있다. 현재 상태(Current)의 OpenGL Context는 스레드 로컬(Thread-local)하다. 즉, 하나의 프로세스는 여러 스레드(Thread)를 가지고 각 스레드는 고유한 현재 상태의 Context를 가진다.
4. 사용 방법
응용 프로그램에서 OpenGL을 사용하여 그래픽을 렌더링하려면, 먼저 OpenGL Context를 생성해야 한다. 이는 일반적으로 운영 체제에서 제공하는 함수를 호출하여 수행된다. Context가 생성되면 응용 프로그램은 OpenGL API를 사용하여 Context의 상태 및 리소스를 조작하는 명령을 실행할 수 있다. 실행되는 모든 명령은 현재 상태(Current)의 OpenGL Context에 적용된다. 그리고 현재 상태의 Context는 응용 프로그램의 창(Window)과 같이 별도의 표시 가능한 화면과 연결해야 한다.
...
// Use OpenGL core profile
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Do not use deprecated functions in OpenGL
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// Create windowed mode window with graphics context
GLFWwindow* window = glfwCreateWindow(1280, 720, "Hylene Engine", NULL, NULL);
if (window == NULL)
return 1;
glfwMakeContextCurrent(window);
...
<참고자료>
1) https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_types
OpenGL Context - OpenGL Wiki
An OpenGL context represents many things. A context stores all of the state associated with this instance of OpenGL. It represents the (potentially visible) default framebuffer that rendering commands will draw to when not drawing to a framebuffer object.
www.khronos.org
2) https://learnopengl.com/Getting-started/OpenGL
LearnOpenGL - OpenGL
OpenGL Getting-started/OpenGL Before starting our journey we should first define what OpenGL actually is. OpenGL is mainly considered an API (an Application Programming Interface) that provides us with a large set of functions that we can use to manipulate
learnopengl.com
3) The OpenGL Graphics System: A Specification - Version 4.6 (Core Profile)