Skip to content

Commit

Permalink
Fixed debugging in several contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
nshtengauer committed Dec 10, 2024
1 parent 961f293 commit dad31b8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
projectName=grapl
version=2.3.0
version=2.3.1

# Versions
kotlinVersion=2.0.0
Expand Down
2 changes: 1 addition & 1 deletion modules/core/kotlin/com/huskerdev/grapl/GraplInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.huskerdev.grapl
// Generated with gradle
class GraplInfo {
companion object {
const val VERSION = "2.3.0"
const val VERSION = "2.3.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.huskerdev.grapl.gl.GLProfile
class WGLContext(
context: Long,
val dc: Long,
val hwnd: Long,
majorVersion: Int,
minorVersion: Int,
profile: GLProfile,
Expand All @@ -28,7 +29,7 @@ class WGLContext(
): LongArray
@Suppress("unused") @JvmStatic private external fun nGetCurrentContext(): LongArray
@Suppress("unused") @JvmStatic private external fun nSetCurrentContext(dc: Long, rc: Long): Boolean
@Suppress("unused") @JvmStatic private external fun nDeleteContext(rc: Long)
@Suppress("unused") @JvmStatic private external fun nDeleteContext(rc: Long, dc: Long, hwnd: Long)
@Suppress("unused") @JvmStatic private external fun nHasFunction(name: String): Boolean
@Suppress("unused") @JvmStatic private external fun nBindDebugCallback(callbackClass: Class<GLContext>)

Expand All @@ -53,10 +54,10 @@ class WGLContext(
nSetCurrentContext(0L, 0L)

private fun fromJNI(array: LongArray) = WGLContext(
array[0], array[1],
array[2].toInt(), array[3].toInt(),
if(array[4].toInt() == 1) GLProfile.CORE else GLProfile.COMPATIBILITY,
array[5].toInt() == 1
array[0], array[1], array[2],
array[3].toInt(), array[4].toInt(),
if(array[5].toInt() == 1) GLProfile.CORE else GLProfile.COMPATIBILITY,
array[6].toInt() == 1
)

init {
Expand All @@ -68,7 +69,7 @@ class WGLContext(
nSetCurrentContext(dc, handle)

override fun delete() =
nDeleteContext(handle)
nDeleteContext(handle, dc, hwnd)

override fun hasFunction(name: String) =
nHasFunction(name)
Expand Down
34 changes: 20 additions & 14 deletions modules/gl/native/win/gl-win-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,19 @@ jni_win_context(void, nInitFunctions)(JNIEnv* env, jobject) {
ReleaseDC(hwnd, dc);
DestroyWindow(hwnd);
}
}


jni_win_context(jlongArray, nCreateContext)(JNIEnv* env, jobject, jboolean isCore, jlong shareRc, jint majorVersion, jint minorVersion, jboolean debug) {
GLint context_attributes[] = {
WGL_CONTEXT_PROFILE_MASK_ARB, isCore ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
WGL_CONTEXT_MAJOR_VERSION_ARB, (majorVersion == -1) ? 1 : majorVersion,
WGL_CONTEXT_MINOR_VERSION_ARB, (minorVersion == -1) ? 0 : minorVersion,
WGL_CONTEXT_FLAGS_ARB, debug ? WGL_CONTEXT_DEBUG_BIT_ARB : 0,
0
};

// Create window with ARB pixel attributes
// Create invisible window
HWND hwnd = CreateWindow(
L"grapl-gl", L"",
WS_OVERLAPPEDWINDOW,
Expand All @@ -94,7 +105,7 @@ jni_win_context(void, nInitFunctions)(JNIEnv* env, jobject) {
NULL, NULL,
GetModuleHandle(NULL),
NULL);
dc = GetDC(hwnd);
HDC dc = GetDC(hwnd);

int pixel_format_arb;
UINT pixel_formats_count;
Expand All @@ -114,18 +125,8 @@ jni_win_context(void, nInitFunctions)(JNIEnv* env, jobject) {
checkError("wglChoosePixelFormatARB");
if (!SetPixelFormat(dc, pixel_format_arb, NULL))
checkError("SetPixelFormat (wgl)");
}


jni_win_context(jlongArray, nCreateContext)(JNIEnv* env, jobject, jboolean isCore, jlong shareRc, jint majorVersion, jint minorVersion, jboolean debug) {
GLint context_attributes[] = {
WGL_CONTEXT_PROFILE_MASK_ARB, isCore ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
WGL_CONTEXT_MAJOR_VERSION_ARB, (majorVersion == -1) ? 1 : majorVersion,
WGL_CONTEXT_MINOR_VERSION_ARB, (minorVersion == -1) ? 0 : minorVersion,
WGL_CONTEXT_FLAGS_ARB, debug ? WGL_CONTEXT_DEBUG_BIT_ARB : 0,
0
};

// Create context
HGLRC rc;
if (!(rc = wglCreateContextAttribsARB(dc, (HGLRC)shareRc, context_attributes)))
checkError("wglCreateContextAttribsARB");
Expand All @@ -136,6 +137,7 @@ jni_win_context(jlongArray, nCreateContext)(JNIEnv* env, jobject, jboolean isCor
return createLongArray(env, {
(jlong) rc,
(jlong) dc,
(jlong) hwnd,
(jlong) details.major,
(jlong) details.minor,
(jlong) details.isCore,
Expand Down Expand Up @@ -205,6 +207,7 @@ jni_win_context(jlongArray, nCreateContextForWindow)(JNIEnv* env, jobject,
return createLongArray(env, {
(jlong) rc,
(jlong) dc,
(jlong) hwnd,
(jlong) details.major,
(jlong) details.minor,
(jlong) details.isCore,
Expand All @@ -219,6 +222,7 @@ jni_win_context(jlongArray, nGetCurrentContext)(JNIEnv* env, jobject) {
return createLongArray(env, {
(jlong) _wglGetCurrentContext(),
(jlong) _wglGetCurrentDC(),
(jlong) WindowFromDC(_wglGetCurrentDC()),
(jlong) details.major,
(jlong) details.minor,
(jlong) details.isCore,
Expand All @@ -233,8 +237,10 @@ jni_win_context(jboolean, nSetCurrentContext)(JNIEnv* env, jobject, jlong dc, jl
);
}

jni_win_context(void, nDeleteContext)(JNIEnv* env, jobject, jlong rc) {
jni_win_context(void, nDeleteContext)(JNIEnv* env, jobject, jlong rc, jlong dc, jlong hwnd) {
_wglDeleteContext((HGLRC)rc);
ReleaseDC((HWND)hwnd, (HDC)dc);
DestroyWindow((HWND)hwnd);
}

jni_win_context(jboolean, nHasFunction)(JNIEnv* env, jobject, jstring _name) {
Expand Down
1 change: 0 additions & 1 deletion modules/gl/native/win/gl-win.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ extern wglSwapIntervalEXTPtr wglSwapIntervalEXT;
GL variables
*/
static HMODULE libGL;
static HDC dc = nullptr;

/*
Functions
Expand Down

0 comments on commit dad31b8

Please sign in to comment.