From b321f0c6fd37e253abc47f0c87426668a9697220 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Fri, 17 Jun 2011 19:14:36 +1000 Subject: [PATCH] Freesans.c -> Freesans.h rename --- Projects/CodeBlocks/SleepyHead.depend | 8 +-- src/graphs/{freesans.c => freesans.h} | 0 src/graphs/gl_pbuffer.cpp | 73 +++++++++++++++++++++++++++ src/graphs/gl_pbuffer.h | 14 +++-- src/graphs/graph.cpp | 70 ++++++++++++++++++++++--- src/version.h | 12 ++--- 6 files changed, 154 insertions(+), 23 deletions(-) rename src/graphs/{freesans.c => freesans.h} (100%) diff --git a/Projects/CodeBlocks/SleepyHead.depend b/Projects/CodeBlocks/SleepyHead.depend index 61585839..c6514fed 100644 --- a/Projects/CodeBlocks/SleepyHead.depend +++ b/Projects/CodeBlocks/SleepyHead.depend @@ -8309,7 +8309,7 @@ 1308026543 D -1308271423 /home/mark/projects/git/sleepyhead/src/version.h +1308301986 /home/mark/projects/git/sleepyhead/src/version.h 1308003040 ent of cb2ab33... Linux wx2.8 & wx2.9 builds fixed @@ -8362,7 +8362,7 @@ "sleeplib/profiles.h" "sleeplib/machine_loader.h" -1308271422 source:/home/mark/projects/git/sleepyhead/src/graphs/graph.cpp +1308291326 source:/home/mark/projects/git/sleepyhead/src/graphs/graph.cpp "freetype-gl/font-manager.h" "freetype-gl/texture-font.h" "graph.h" @@ -11062,7 +11062,7 @@ "freetype-gl/vector.h" -1308243123 /home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.h +1308281312 /home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.h @@ -11071,7 +11071,7 @@ -1308260282 source:/home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.cpp +1308284539 source:/home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.cpp "gl_pbuffer.h" diff --git a/src/graphs/freesans.c b/src/graphs/freesans.h similarity index 100% rename from src/graphs/freesans.c rename to src/graphs/freesans.h diff --git a/src/graphs/gl_pbuffer.cpp b/src/graphs/gl_pbuffer.cpp index 48c17f45..87bbc6de 100644 --- a/src/graphs/gl_pbuffer.cpp +++ b/src/graphs/gl_pbuffer.cpp @@ -313,5 +313,78 @@ void pBufferGLX::UseBuffer(bool b) } #elif defined(__DARWIN__) || defined(__WXMAC__) +pBufferAGL::pBufferAGL(int width, int height) +:pBuffer(),m_width(width),m_height(height) +{ + GLint attribs[] = { + AGL_RGBA, + AGL_DOUBLEBUFFER, + AGL_ACCELERATED, + AGL_NO_RECOVERY, + AGL_DEPTH_SIZE, 24, + AGL_NONE + }; + display2 = CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()); + + display = GetMainDevice(); + wxRect windowRect = { 100, 100, 100 + width, 100 + height }; + WindowRef window; + + pixelFormat = aglChoosePixelFormat( display2, 1, attribs ); + pbContext = aglCreateContext( pixelFormat, NULL ); + aglDestroyPixelFormat(pixelFormat); + + aglCreatePBuffer( width, height, GL_TEXTURE_2D,GL_RGBA, 0, &pbuffer ); + + // bind pbuffer + virtualScreen = aglGetVirtualScreen( pbContext ); + aglSetCurrentContext( pbContext ); + aglSetPBuffer( pbContext, pbuffer, 0, 0, virtualScreen ); + // draw into pbuffer + + drawPBuffer(); + + + // window pixelformat and context setup and creation + pixelFormat = aglChoosePixelFormat( &display, 1, attribs ); + context = aglCreateContext( pixelFormat, NULL ); + aglDestroyPixelFormat( pixelFormat ); + aglSetCurrentContext( context ); + + // window creation + CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &windowRect, &window); + + //Alternative Rendering Destinations 111 + SetWindowTitleWithCFString( window, CFSTR("AGL PBuffer Texture") ); + ActivateWindow(window, true); + ShowWindow(window); + // bind context to window + aglSetDrawable( context, GetWindowPort(window) ); + aglUpdateContext( context ); + // initialize window context & draw window + GLuint texid; + init( context, pbuffer, &texid ); + drawWindow( context, texid ); + // stub event loop +} + + +} +pBufferAGL::~pBufferAGL() +{ + aglSetCurrentContext( NULL ); + aglDestroyContext( context ); + aglDestroyContext( pbContext ); + aglDestroyPBuffer( pbuffer ); + +} +void pBufferAGL::UseBuffer(bool b) +{ + if (b) { + wglMakeCurrent(hdc, hGlRc); + } else { + wglMakeCurrent(saveHdc, saveHglrc); + } +} #endif diff --git a/src/graphs/gl_pbuffer.h b/src/graphs/gl_pbuffer.h index f2b06315..cbe324e4 100644 --- a/src/graphs/gl_pbuffer.h +++ b/src/graphs/gl_pbuffer.h @@ -92,12 +92,16 @@ protected: class pBufferAGL:public pBuffer { public: - pBufferAGL(int width, int height){}; - virtual ~pBufferAGL(){}; - virtual void UseBuffer(bool b){}; + pBufferAGL(int width, int height); + virtual ~pBufferAGL(); + virtual void UseBuffer(bool b); protected: - - virtual bool InitGLStuff(){}; + AGLPixelFormat pixelFormat; + AGLPbuffer pbuffer; + AGLContext context, pbContext; + long virtualScreen; + GDHandle display2; + GDHandle display; }; #endif diff --git a/src/graphs/graph.cpp b/src/graphs/graph.cpp index a256787f..a0ea527c 100644 --- a/src/graphs/graph.cpp +++ b/src/graphs/graph.cpp @@ -23,7 +23,7 @@ License: LGPL #include "sleeplib/profiles.h" -#include "freesans.c" +#include "freesans.h" //#include @@ -1003,6 +1003,48 @@ pBuffer *pbuffer=NULL; wxBitmap * gGraphWindow::RenderBitmap(int width,int height) { + // I can't get FBO buffers to work properly + // Fonts screw up and the first read is corrupted. + // pBuffers are faster anyway.. + + // shared_context->SetCurrent(*this); + /*GLuint fbo; + glGenFramebuffersEXT(1, &fbo); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + + GLuint depthbuffer,colorbuffer; + //glGenRenderbuffersEXT(1, &depthbuffer); + glGenRenderbuffersEXT(1, &colorbuffer); + + //glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer); + //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height); + + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorbuffer); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height); + + + //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, colorbuffer); + + + GLuint img; + glGenTextures(1, &img); + glBindTexture(GL_TEXTURE_2D, img); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + + + + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0); + + GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + + //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); */ + + + + if (!pbuffer) { try { #if defined(__WXMSW__) @@ -1019,24 +1061,33 @@ wxBitmap * gGraphWindow::RenderBitmap(int width,int height) } } + + if (pbuffer) { pbuffer->UseBuffer(true); } // Move this bitmap code to pBuffer // glClearColor(1,1,0,1); - glClear(GL_COLOR_BUFFER_BIT); - + //glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + //glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // Can't use font's in multiple contexts Render(width,height); - void* pixels = malloc(3 * width * height); // must use malloc - glPixelStorei(GL_PACK_ALIGNMENT, 1); - //glDrawBuffer(GL_BACK_LEFT); - //glReadBuffer(GL_FRONT); - glReadBuffer( GL_BACK_LEFT ); +// GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); + +// glBindTexture(GL_TEXTURE_2D, img); + void* pixels = malloc(3 * width * height); // must use malloc + //glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + + //glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + //glReadBuffer(GL_FRONT); + //glReadBuffer(GL_BACK_LEFT ); + //glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); // Put the image into a wxImage @@ -1048,6 +1099,9 @@ wxBitmap * gGraphWindow::RenderBitmap(int width,int height) wxBitmap *bmp=new wxBitmap(image); + // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); +// glDeleteFramebuffersEXT(1, &fbo); + //glDeleteRenderbuffersEXT(1, &depthbuffer); if (pbuffer) { //delete pbuffer; } diff --git a/src/version.h b/src/version.h index c2200227..b1f74558 100644 --- a/src/version.h +++ b/src/version.h @@ -16,14 +16,14 @@ namespace AutoVersion{ //Standard Version Type static const long _MAJOR = 0; static const long _MINOR = 7; - static const long _BUILD = 6467; - static const long _REVISION = 18579; + static const long _BUILD = 6509; + static const long _REVISION = 18811; //Miscellaneous Version Types - static const long _BUILDS_COUNT = 7630; - #define _RC_FILEVERSION 0,7,6467,18579 - #define _RC_FILEVERSION_STRING "0, 7, 6467, 18579\0" - static const char _FULLVERSION_STRING[] = "0.7.6467.18579"; + static const long _BUILDS_COUNT = 7751; + #define _RC_FILEVERSION 0,7,6509,18811 + #define _RC_FILEVERSION_STRING "0, 7, 6509, 18811\0" + static const char _FULLVERSION_STRING[] = "0.7.6509.18811"; //These values are to keep track of your versioning state, don't modify them. static const long _BUILD_HISTORY = 0;