Changes to bring in minimal functionality of the OSX port. Still needs virtual function definitions before GL functions can be called properly.

This commit is contained in:
Gregory Pierce 2002-12-30 07:09:35 +00:00
parent 64d68e7894
commit 1e74408a5f
7 changed files with 98 additions and 107 deletions

View File

@ -1,13 +1,12 @@
/*
* RenderingContext.cpp
* lwjgl
* lwjglOSX
*
* Created by Gregory Pierce on Wed Sep 04 2002.
* Created by Gregory Pierce on Sat Dec 28 2002.
* Copyright (c) 2002 __MyCompanyName__. All rights reserved.
*
*/
#include "RenderingContext.h"
RenderingContext::RenderingContext()
@ -16,68 +15,4 @@ RenderingContext::RenderingContext()
RenderingContext::~RenderingContext()
{
}
/*
** OpenGL Setup
*/
//GetWindowPort(win)
bool RenderingContext::setupAGL( AGLDrawable pAGLDrawable )
{
AGLPixelFormat fmt;
GLboolean ok;
GLint attrib[] = { AGL_RGBA, AGL_NONE };
/* Choose an rgb pixel format */
fmt = aglChoosePixelFormat(NULL, 0, attrib);
if(fmt == NULL)
{
return false;
}
/* Create an AGL context */
aglContext = aglCreateContext(fmt, NULL);
if(aglContext == NULL)
{
return false;
}
/* Attach the window to the context */
ok = aglSetDrawable(aglContext, pAGLDrawable );
if(!ok)
{
return false;
}
/* Make the context the current context */
ok = aglSetCurrentContext(aglContext);
if(!ok)
{
return false;
}
/* Pixel format is no longer needed */
aglDestroyPixelFormat(fmt);
return true;
}
void RenderingContext::destroy(void)
{
cleanupAGL();
// cleanup the window
//
DisposeWindow( windowPtr );
}
/*
** OpenGL Cleanup
*/
void RenderingContext::cleanupAGL()
{
aglSetCurrentContext(NULL);
aglSetDrawable(aglContext, NULL);
aglDestroyContext(aglContext);
}

View File

@ -1,29 +1,26 @@
/*
* RenderingContext.h
* lwjgl
* lwjglOSX
*
* Created by Gregory Pierce on Wed Sep 04 2002.
* Created by Gregory Pierce on Sat Dec 28 2002.
* Copyright (c) 2002 __MyCompanyName__. All rights reserved.
*
*/
#pragma once
#include <Carbon/Carbon.h>
#include <AGL/agl.h>
#include <DrawSprocket/DrawSprocket.h>
#include <OpenGL/gl.h>
class RenderingContext
{
AGLContext aglContext;
Rect rect;
WindowPtr windowPtr;
public:
AGLContext aglContext;
WindowPtr windowPtr;
Rect rect;
RenderingContext();
~RenderingContext();
void RenderingContext::cleanupAGL(void);
void RenderingContext::destroy(void);
bool RenderingContext::setupAGL( AGLDrawable pAGLDrawable );
};
};

View File

@ -33,11 +33,11 @@
#include <AGL/agl.h>
#include <OpenGL/gl.h>
#include <JavaVM/jni.h>
#include "RenderingContext.h"
#include "org_lwjgl_Display.h"
#include "RenderingContext.h"
RenderingContext * renderingContext;
RenderingContext * renderingContext;
/*
@ -61,38 +61,37 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate
{
#ifdef _DEBUG
printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp);
#endif
renderingContext = new RenderingContext();
#endif
InitCursor();
SetRect( &renderingContext->rect, 0, 0, width, height );
renderingContext->windowPtr = NewCWindow( NULL, &renderingContext->rect, "LWJGL", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L );
Rect rect;
SetRect( &rect, 0, 0, width, height );
WindowPtr windowPtr = NewCWindow( NULL, &rect, "LWJGL", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L );
/*
CreateNewWindow( kDocumentWindowClass,
kWindowStandardDocumentAttributes |
kWindowStandardHandlerAttribute,
&rect,
&windowPtr );
*/
SetPortWindowPort( windowPtr );
SetPortWindowPort( renderingContext->windowPtr );
if ( windowPtr == NULL )
if ( renderingContext->windowPtr == NULL )
{
printf("Failed to create a window\n");
return 1;
return JNI_TRUE;
}
ShowWindow( windowPtr );
/*
pAGLContext = setupAGL( attrib, (AGLDrawable) windowPtr);
if(ctx == NULL)
{
return 1;
}
*/
ShowWindow( renderingContext->windowPtr );
jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I");
env->SetStaticIntField(clazz, fid_handle, (jint) windowPtr );
env->SetStaticIntField(clazz, fid_handle, (jint) renderingContext->windowPtr );
return 0;
return JNI_TRUE;
}
/*
@ -105,7 +104,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy
{
// cleanup the AGL context
//
renderingContext->destroy();
aglSetCurrentContext(NULL);
aglSetDrawable(renderingContext->aglContext, NULL);
aglDestroyContext(renderingContext->aglContext);
// cleanup the window
//
DisposeWindow( renderingContext->windowPtr );
#ifdef _DEBUG

View File

@ -71,7 +71,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_Sys_createDirectBuffer
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
(JNIEnv * env, jclass clazz)
{
return 0L;
return 0L;
}
/*
@ -82,6 +82,7 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime
(JNIEnv * env, jclass clazz)
{
return 0L;
}
/*

View File

@ -60,8 +60,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs
globalClassLock = env->NewGlobalRef(clazz);
}
fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;");
fid_readBufferAddress = env->GetStaticFieldID(clazz, "readBufferAddress", "I");
//fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;");
//fid_readBufferAddress = env->GetStaticFieldID(clazz, "readBufferAddress", "I");
}

View File

@ -69,7 +69,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nCreate
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNumButtons(JNIEnv *env, jclass clazz) {
return (jint)NUM_BUTTONS;
return (jint)2;
}
/*

View File

@ -41,7 +41,9 @@
#include "extgl.h"
#include "org_lwjgl_opengl_BaseGL.h"
#include "RenderingContext.h"
extern RenderingContext * renderingContext;
/*
* Class: org_lwjgl_opengl_BaseGL
@ -51,7 +53,42 @@
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
(JNIEnv * env, jobject obj, jint colorBits, jint alphaBits, jint depthBits, jint stencilBits)
{
return JNI_TRUE;
AGLPixelFormat fmt;
GLboolean ok;
GLint attrib[] = { AGL_RGBA, AGL_NONE };
/* Choose an rgb pixel format */
fmt = aglChoosePixelFormat(NULL, 0, attrib);
if(fmt == NULL)
{
return JNI_FALSE;
}
/* Create an AGL context */
renderingContext->aglContext = aglCreateContext(fmt, NULL);
if( renderingContext->aglContext == NULL)
{
return JNI_FALSE;
}
/* Attach the window to the context */
ok = aglSetDrawable(renderingContext->aglContext, GetWindowPort(renderingContext->windowPtr) );
if(!ok)
{
return JNI_FALSE;
}
/* Make the context the current context */
ok = aglSetCurrentContext(renderingContext->aglContext);
if(!ok)
{
return JNI_FALSE;
}
/* Pixel format is no longer needed */
aglDestroyPixelFormat(fmt);
return JNI_TRUE;
}
/*
@ -62,6 +99,13 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy
(JNIEnv * env, jobject obj)
{
// clear out the current rendering context
//
aglSetCurrentContext( NULL );
// destroy the context
//
aglDestroyContext( renderingContext->aglContext );
}
/*
@ -71,6 +115,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jobject obj)
{
// swap the rendering buffer
//
aglSwapBuffers( renderingContext->aglContext );
}
/*
@ -81,6 +128,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jo
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nMakeCurrent
(JNIEnv * env, jobject obj)
{
// make the current context the one we have stored
//
aglSetCurrentContext( renderingContext->aglContext );
}
/*
@ -91,4 +141,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nMakeCurrent
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nReleaseContext
(JNIEnv *, jobject)
{
// release the context
//
aglSetCurrentContext( NULL );
}