Covellite++  Version: 2.3.0 Revision: ??? Platform: x64 Build: 23:13 04.01.2025
Кроссплатформенный фреймворк для разработки приложений на С++
Загрузка...
Поиск...
Не найдено
OpenGL.cpp
1
2#include "stdafx.h"
3#include "OpenGL.hpp"
4#include <winuser.h>
5#include <alicorn/platform/winapi-check.hpp>
6//#include <alicorn/logger.hpp>
7
8#pragma comment(lib, "opengl32.lib")
9
10namespace covellite
11{
12
13namespace api
14{
15
16namespace renderer
17{
18
19//static void GLDebugCallback(GLenum /*source*/, GLenum type, GLuint id,
20// GLenum severity, GLsizei /*length*/, const GLchar *message, const void * /*userParam*/)
21//{
22// const auto strType =
23// (type == GL_DEBUG_TYPE_ERROR) ? "ERROR" :
24// (type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR) ? "DEPRECATED BEHAVIOR" :
25// (type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR) ? "UDEFINED BEHAVIOR" :
26// (type == GL_DEBUG_TYPE_PORTABILITY) ? "PORTABILITY" :
27// (type == GL_DEBUG_TYPE_PERFORMANCE) ? "PERFORMANCE" :
28// (type == GL_DEBUG_TYPE_OTHER) ? "OTHER" :
29// (type == GL_DEBUG_TYPE_MARKER) ? "MARKER" : "UNKNOWN";
30//
31// if (severity == GL_DEBUG_SEVERITY_HIGH)
32// {
33// LOGGER(Error) << strType << ": " << message << " [" << id << "]";
34// }
35// else if (severity == GL_DEBUG_SEVERITY_MEDIUM)
36// {
37// LOGGER(Warning) << strType << ": " << message << " [" << id << "]";
38// }
39// else if (severity == GL_DEBUG_SEVERITY_LOW)
40// {
41// LOGGER(Info) << strType << ": " << message << " [" << id << "]";
42// }
43// else if (severity == GL_DEBUG_SEVERITY_NOTIFICATION)
44// {
45// LOGGER(Trace) << strType << ": " << message << " [" << id << "]";
46// }
47// else
48// {
49// LOGGER(Trace) << strType << ": " << message << " [" << id << "]";
50// }
51//}
52
53static PIXELFORMATDESCRIPTOR PixelFormatDescriptor = { 0 };
54
55OpenGL::OpenGL(const Data_t & _Data) :
56 OpenGLCommonShader(_Data, uT("OpenGL "),
57 "#version 330 core\r\n"
58 "#define COVELLITE_SHADER_DESKTOP\r\n"),
59 m_hWnd(::covellite::any_cast<HWND>(_Data.Handle)),
60 m_hDeviceContex(USING_MOCK ::GetDC(m_hWnd))
61{
62 WINAPI_CHECK (m_hDeviceContex != NULL);
63
64 PixelFormatDescriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR);
65 PixelFormatDescriptor.nVersion = 1;
66 PixelFormatDescriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
67 PixelFormatDescriptor.iPixelType = PFD_TYPE_RGBA;
68 PixelFormatDescriptor.cColorBits = 32;
69 PixelFormatDescriptor.cAlphaBits = 8;
70 PixelFormatDescriptor.cDepthBits = 32;
71 PixelFormatDescriptor.iLayerType = PFD_MAIN_PLANE;
72
73 // Игнорирование предупреждений при анализе кода (анализатор не понимает,
74 // что макрос WINAPI_CHECK вызывает исключение при нулевом значении
75 // m_hDeviceContex и последующий код не может быть выполнен).
76# pragma warning(push)
77# pragma warning(disable: 6387)
78
79 const auto PixelFormat = USING_MOCK ::ChoosePixelFormat(m_hDeviceContex,
80 &PixelFormatDescriptor);
81 WINAPI_CHECK (PixelFormat != 0);
82
83 WINAPI_CHECK USING_MOCK ::SetPixelFormat(m_hDeviceContex, PixelFormat,
84 &PixelFormatDescriptor);
85
86# pragma warning(pop)
87
88 m_hRenderContex = USING_MOCK ::wglCreateContext(m_hDeviceContex);
89 WINAPI_CHECK (m_hRenderContex != NULL);
90
91 WINAPI_CHECK USING_MOCK ::wglMakeCurrent(m_hDeviceContex, m_hRenderContex);
92
93 //glEnable(GL_DEBUG_OUTPUT);
94 //glDebugMessageCallback(&GLDebugCallback, NULL);
95 //glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
96}
97
98OpenGL::~OpenGL(void) noexcept
99{
100 USING_MOCK ::wglMakeCurrent(NULL, NULL);
101 USING_MOCK ::wglDeleteContext(m_hRenderContex);
102
103 USING_MOCK ::ReleaseDC(m_hWnd, m_hDeviceContex);
104}
105
106void OpenGL::PresentFrame(void) /*override*/
107{
108 WINAPI_CHECK USING_MOCK ::SwapBuffers(m_hDeviceContex);
109
110 OpenGLCommonShader::PresentFrame();
111}
112
113} // namespace renderer
114
115} // namespace api
116
117} // namespace covellite