14#ifdef SCL_PLATFORM_WINDOWS
19HGLRC glInitialiseContext(HDC hDC)
22 int pixel_format_attribs[] = {
23 WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
24 WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
25 WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
26 WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
27 WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
28 WGL_COLOR_BITS_ARB, 32,
29 WGL_DEPTH_BITS_ARB, 32,
30 WGL_STENCIL_BITS_ARB, 8,
35 PIXELFORMATDESCRIPTOR pfd = { 0 };
36 pfd.nSize =
sizeof(PIXELFORMATDESCRIPTOR);
38 pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL;
42 INT pixel_format = ChoosePixelFormat(hDC, &pfd);
43 SCL_CORE_ASSERT(pixel_format,
"Failed to find a suitable pixel format.");
44 DescribePixelFormat(hDC, pixel_format,
sizeof(PIXELFORMATDESCRIPTOR), &pfd);
45 SCL_CORE_ASSERT(SetPixelFormat(hDC, pixel_format, &pfd),
"Failed to set the pixel format.");
48 HGLRC hTmpGLRC = wglCreateContext(hDC);
49 SCL_CORE_ASSERT(hTmpGLRC,
"Failed to create temporery OpenGL rendering context.");
50 SCL_CORE_ASSERT(wglMakeCurrent(hDC, hTmpGLRC),
"Failed to activate temporery OpenGL rendering context.");
53 glewExperimental =
true;
54 GLenum glew_init_status = glewInit();
55 SCL_CORE_ASSERT(glew_init_status == GLEW_OK,
"Failed to initialize OpenGL glew.\nError log:\n{}", (
const char *)glewGetErrorString(glew_init_status));
56 SCL_CORE_ASSERT(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader,
"Your hardware not supported. No shaders support.");
60 wglChoosePixelFormatARB(hDC, pixel_format_attribs,
nullptr, 1, &pixel_format, &num_formats);
63 int context_attribs[] = {
64 WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
65 WGL_CONTEXT_MINOR_VERSION_ARB, 6,
66 WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
70 SCL_CORE_ASSERT(wglMakeCurrent(
nullptr,
nullptr),
"Falied to deactivate temporery rendering context.");
71 SCL_CORE_ASSERT(wglDeleteContext(hTmpGLRC),
"Failed to delete temporary rendering context.");
73 HGLRC hGLRC = wglCreateContextAttribsARB(hDC,
nullptr, context_attribs);
75 SCL_CORE_ASSERT(wglMakeCurrent(hDC, hGLRC),
"Failed to set rendering context to main window.");
104 this->ClearColor = ClearColor;
110 this->IsWireframe = IsWireframe;
111 glPolygonMode(GL_FRONT_AND_BACK, IsWireframe ? GL_LINE : GL_FILL);
116 this->CullingMode = CullingMode;
129 this->IsVSync = IsVSync;
130#ifdef SCL_PLATFORM_WINDOWS
131 wglSwapIntervalEXT(IsVSync);
175static void APIENTRY glDebugOutput(UINT Source, UINT Type, UINT Id, UINT Severity,
176 INT Length,
const CHAR *Message,
const VOID *UserParam);
180#ifdef SCL_PLATFORM_WINDOWS
182 hDC = GetDC(hAppWnd);
183 hGLRC = glInitialiseContext(hDC);
189 glClearColor(0, 0, 0, 0);
190 glEnable(GL_DEPTH_TEST);
193 glEnable(GL_PRIMITIVE_RESTART);
198 glEnable(GL_DEBUG_OUTPUT);
199 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
200 glDebugMessageCallback(glDebugOutput,
nullptr);
201 glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0,
nullptr, GL_TRUE);
209#ifdef SCL_PLATFORM_WINDOWS
210 application &app = application::Get();
211 const window &win = app.GetWindow();
215 SCL_CORE_SUCCES(
"Windows OpenGL render context initialised successfully.");
221 wglMakeCurrent(
nullptr,
nullptr);
222 wglDeleteContext(hGLRC);
223 ReleaseDC(*hWnd, hDC);
238 GetGLPrimitiveType(VertexArray->GetType()),
239 VertexArray->GetIndexBuffer()->GetCount(),
243 VertexArray->Unbind();
249 glDrawElementsInstanced(
250 GetGLPrimitiveType(VertexArray->GetType()),
251 VertexArray->GetIndexBuffer()->GetCount(),
256 VertexArray->Unbind();
271static void APIENTRY glDebugOutput(UINT Source, UINT Type, UINT Id, UINT Severity,
272 INT Length,
const CHAR *Message,
const VOID *UserParam)
275 static CHAR Buf[10000] {};
278 if (Id == 131169 || Id == 131185 || Id == 131218 || Id == 131204)
281 len += sprintf_s(Buf + len, 10000,
"OpenGL debug message (Id - %i):\n%s.\n", Id, Message);
284 case GL_DEBUG_SOURCE_API: len += sprintf_s(Buf + len, 10000,
"Source: API\n");
break;
285 case GL_DEBUG_SOURCE_WINDOW_SYSTEM: len += sprintf_s(Buf + len, 10000,
"Source: Window System\n");
break;
286 case GL_DEBUG_SOURCE_SHADER_COMPILER: len += sprintf_s(Buf + len, 10000,
"Source: Shader Compiler\n");
break;
287 case GL_DEBUG_SOURCE_THIRD_PARTY: len += sprintf_s(Buf + len, 10000,
"Source: Third Party\n");
break;
288 case GL_DEBUG_SOURCE_APPLICATION: len += sprintf_s(Buf + len, 10000,
"Source: Application\n");
break;
289 case GL_DEBUG_SOURCE_OTHER: len += sprintf_s(Buf + len, 10000,
"Source: Other\n");
break;
291 len += sprintf_s(Buf + len, 10000,
"\n");
295 case GL_DEBUG_TYPE_ERROR: len += sprintf_s(Buf + len, 10000,
"Type: Error");
break;
296 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: len += sprintf_s(Buf + len, 10000,
"Type: Deprecated Behaviour");
break;
297 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: len += sprintf_s(Buf + len, 10000,
"Type: Undefined Behaviour");
break;
298 case GL_DEBUG_TYPE_PORTABILITY: len += sprintf_s(Buf + len, 10000,
"Type: Portability");
break;
299 case GL_DEBUG_TYPE_PERFORMANCE: len += sprintf_s(Buf + len, 10000,
"Type: Performance");
break;
300 case GL_DEBUG_TYPE_MARKER: len += sprintf_s(Buf + len, 10000,
"Type: Marker");
break;
301 case GL_DEBUG_TYPE_PUSH_GROUP: len += sprintf_s(Buf + len, 10000,
"Type: Push Group");
break;
302 case GL_DEBUG_TYPE_POP_GROUP: len += sprintf_s(Buf + len, 10000,
"Type: Pop Group");
break;
303 case GL_DEBUG_TYPE_OTHER: len += sprintf_s(Buf + len, 10000,
"Type: Other");
break;
308 case GL_DEBUG_SEVERITY_HIGH:
311 case GL_DEBUG_SEVERITY_MEDIUM:
312 case GL_DEBUG_SEVERITY_LOW:
315 case GL_DEBUG_SEVERITY_NOTIFICATION:
#define SCL_CORE_ASSERT(expr,...)
void DrawIndices(const shared< vertex_array > &VertexArray) override
static GLenum GetGLShaderVariableType(shader_variable_type Type)
const vec4 & GetClearColor() const override
void DrawIndicesInstanced(const shared< vertex_array > &VertexArray, int InstanceCount) override
void SetClearColor(const vec4 &ClearColor) override
void SetCullingMode(render_cull_face_mode CullingMode) override
void SetWireframeMode(bool IsWireframe) override
render_cull_face_mode GetCullingMode() const override
bool GetWireframeMode() const override
bool GetVSync() const override
void SwapBuffers() override
static GLenum GetGLPrimitiveType(mesh_type MeshType)
void CreateContext(const HWND &hAppWnd, int W, int H, bool VSync)
void SetVSync(bool VSync)
static const int MESH_RESTART_INDEX
const data & GetWindowData() const
const window_handle & GetHandle() const
#define SCL_CORE_SUCCES(...)
#define SCL_CORE_WARN(...)
#define SCL_CORE_INFO(...)
#define SCL_CORE_ERROR(...)
std::shared_ptr< T > shared
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.
Vertex array interfaces implementation module.