Frame Buffer Object testing

This commit is contained in:
Mark Watkins 2011-06-18 01:59:04 +10:00
parent 48796f14ba
commit 5407fda324
8 changed files with 317 additions and 233 deletions

View File

@ -8300,7 +8300,7 @@
<map> <map>
"tinyxml/tinyxml.h" "tinyxml/tinyxml.h"
1308302313 /home/mark/projects/git/sleepyhead/src/graphs/graph.h 1308311237 /home/mark/projects/git/sleepyhead/src/graphs/graph.h
"gl_pbuffer.h" "gl_pbuffer.h"
<wx/glcanvas.h> <wx/glcanvas.h>
<wx/geometry.h> <wx/geometry.h>
@ -8309,7 +8309,7 @@
1308026543 D 1308026543 D
1308306194 /home/mark/projects/git/sleepyhead/src/version.h 1308326231 /home/mark/projects/git/sleepyhead/src/version.h
1308003040 ent of cb2ab33... Linux wx2.8 & wx2.9 builds fixed 1308003040 ent of cb2ab33... Linux wx2.8 & wx2.9 builds fixed
<wx/dcbuffer.h> <wx/dcbuffer.h>
@ -8341,7 +8341,7 @@
"preferences.h" "preferences.h"
"tinyxml/tinyxml.h" "tinyxml/tinyxml.h"
1308271319 source:/home/mark/projects/git/sleepyhead/src/SleepyHeadMain.cpp 1308313128 source:/home/mark/projects/git/sleepyhead/src/SleepyHeadMain.cpp
"wx_pch.h" "wx_pch.h"
"version.h" "version.h"
<wx/app.h> <wx/app.h>
@ -8362,7 +8362,7 @@
"sleeplib/profiles.h" "sleeplib/profiles.h"
"sleeplib/machine_loader.h" "sleeplib/machine_loader.h"
1308304488 source:/home/mark/projects/git/sleepyhead/src/graphs/graph.cpp 1308313179 source:/home/mark/projects/git/sleepyhead/src/graphs/graph.cpp
"freetype-gl/font-manager.h" "freetype-gl/font-manager.h"
"freetype-gl/texture-font.h" "freetype-gl/texture-font.h"
"graph.h" "graph.h"
@ -11062,7 +11062,7 @@
<string.h> <string.h>
"freetype-gl/vector.h" "freetype-gl/vector.h"
1308306186 /home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.h 1308311222 /home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.h
<wx/log.h> <wx/log.h>
<GL/glew.h> <GL/glew.h>
<GL/wglew.h> <GL/wglew.h>
@ -11072,10 +11072,13 @@
<Cocoa/Cocoa.h> <Cocoa/Cocoa.h>
<GL/gl.h> <GL/gl.h>
<GL/glx.h> <GL/glx.h>
<wx/bitmap.h>
1308304655 source:/home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.cpp 1308314362 source:/home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.cpp
"gl_pbuffer.h" "gl_pbuffer.h"
<GL/glu.h>
<wx/utils.h> <wx/utils.h>
<wx/glcanvas.h>
1305166122 /opt/mingw/usr/i686-pc-mingw32/include/wx-2.8/wx/treectrl.h 1305166122 /opt/mingw/usr/i686-pc-mingw32/include/wx-2.8/wx/treectrl.h
"wx/defs.h" "wx/defs.h"

View File

@ -16,13 +16,13 @@
<File name="../../src/SleepyHeadMain.h" open="1" top="0" tabpos="2"> <File name="../../src/SleepyHeadMain.h" open="1" top="0" tabpos="2">
<Cursor position="2035" topLine="47" /> <Cursor position="2035" topLine="47" />
</File> </File>
<File name="../../src/graphs/gl_pbuffer.cpp" open="1" top="1" tabpos="5"> <File name="../../src/graphs/gl_pbuffer.cpp" open="1" top="0" tabpos="5">
<Cursor position="7612" topLine="222" /> <Cursor position="3" topLine="0" />
</File> </File>
<File name="../../src/graphs/gl_pbuffer.h" open="1" top="0" tabpos="6"> <File name="../../src/graphs/gl_pbuffer.h" open="1" top="0" tabpos="6">
<Cursor position="644" topLine="58" /> <Cursor position="401" topLine="0" />
</File> </File>
<File name="../../src/graphs/graph.cpp" open="1" top="0" tabpos="3"> <File name="../../src/graphs/graph.cpp" open="1" top="1" tabpos="3">
<Cursor position="2743" topLine="83" /> <Cursor position="2743" topLine="83" />
</File> </File>
<File name="../../src/graphs/graph.h" open="1" top="0" tabpos="4"> <File name="../../src/graphs/graph.h" open="1" top="0" tabpos="4">
@ -58,7 +58,7 @@
<File name="../../src/libs/freetype-gl/vector.h" open="0" top="0" tabpos="20"> <File name="../../src/libs/freetype-gl/vector.h" open="0" top="0" tabpos="20">
<Cursor position="0" topLine="0" /> <Cursor position="0" topLine="0" />
</File> </File>
<File name="../../src/libs/freetype-gl/vertex-buffer.cpp" open="1" top="0" tabpos="7"> <File name="../../src/libs/freetype-gl/vertex-buffer.cpp" open="0" top="0" tabpos="7">
<Cursor position="3098" topLine="91" /> <Cursor position="3098" topLine="91" />
</File> </File>
<File name="../../src/libs/freetype-gl/vertex-buffer.h" open="0" top="0" tabpos="18"> <File name="../../src/libs/freetype-gl/vertex-buffer.h" open="0" top="0" tabpos="18">

View File

@ -825,7 +825,6 @@ Daily::Daily(wxWindow *win,Profile *p)
gwSizer->Add(SPO2,1,wxEXPAND); gwSizer->Add(SPO2,1,wxEXPAND);
gwSizer->Layout();
//fgSizer->Add(G_AHI,1,wxEXPAND); //fgSizer->Add(G_AHI,1,wxEXPAND);
//fgSizer->Add(TAP,1,wxEXPAND); //fgSizer->Add(TAP,1,wxEXPAND);
//fgSizer->Add(TAP_IAP,1,wxEXPAND); //fgSizer->Add(TAP_IAP,1,wxEXPAND);
@ -839,7 +838,10 @@ Daily::Daily(wxWindow *win,Profile *p)
//EVT_SCROLLWIN_THUMBTRACK(Daily::OnWinScroll) //EVT_SCROLLWIN_THUMBTRACK(Daily::OnWinScroll)
//this->Connect(GraphWindow->GetId(),wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEventHandler(Daily::OnWinScroll)); //this->Connect(GraphWindow->GetId(),wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEventHandler(Daily::OnWinScroll));
Refresh(); // Important. Don't change the order of the next two lines. Refresh(true); // Important. Don't change the order of the next two lines.
Update();
// gwSizer->Layout();
ResetDate(); ResetDate();
} }

View File

@ -5,8 +5,20 @@ Author: Mark Watkins <jedimark64@users.sourceforge.net>
License: GPL License: GPL
*/ */
#include "gl_pbuffer.h" #include "gl_pbuffer.h"
#include <GL/glu.h>
#include <wx/utils.h> #include <wx/utils.h>
#include <wx/glcanvas.h>
long roundup2(long v)
{
int j;
for (int i=4;i<32;i++) { // min size 16x16.. probably a usless size.
j=1 << i;
if (j >= v) break;
}
return j;
}
pBuffer::pBuffer() pBuffer::pBuffer()
{ {
@ -18,6 +30,112 @@ pBuffer::pBuffer(int width, int height)
pBuffer::~pBuffer() pBuffer::~pBuffer()
{ {
} }
wxBitmap *pBuffer::Snapshot(int width, int height)
{
glDrawBuffer(GL_BACK_LEFT);
void* pixels = malloc(3 * width * height); // must use malloc
glReadBuffer(GL_BACK_LEFT);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
// Put the image into a wxImage
wxImage image(width, height, true);
image.SetData((unsigned char*) pixels);
image = image.Mirror(false);
wxBitmap *bmp=new wxBitmap(image);
return bmp;
}
FBO::FBO(int width, int height)
:pBuffer()
{
//wxGLContext a((wxGLCanvas *)NULL,(wxGLContext *)NULL);
int m=MAX(width,height);
//int j=roundup2(m) << 2;
m_width=width; //roundup2(width) << 2;
m_height=height; //roundup2(height) << 2;
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
// create texture to render to.
glGenTextures(1, &img);
glBindTexture(GL_TEXTURE_2D, img);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0);
m_depth_buffer=true;
m_color_buffer=true; //false;
if (m_depth_buffer) {
glGenRenderbuffersEXT(1, &depthbuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_width, m_height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer);
}
if (m_color_buffer) {
glGenRenderbuffersEXT(1, &colorbuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorbuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, m_width, m_height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, colorbuffer);
}
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
//if (status!=GL_FRAMEBUFFER_COMPLETE_EXT) {
GLenum err = glGetError();
if (err!=GL_NO_ERROR) {
wxString a((char *)gluErrorString(status),wxConvUTF8);
throw GLException(wxT("glCheckFramebufferStatusEXT failed")+a);
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
FBO::~FBO()
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &fbo);
if (m_depth_buffer)
glDeleteRenderbuffersEXT(1, &depthbuffer);
if (m_color_buffer)
glDeleteRenderbuffersEXT(1, &colorbuffer);
}
void FBO::UseBuffer(bool b)
{
if (b) {
// glBindTexture(GL_TEXTURE_2D, img);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
} else {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
}
wxBitmap *FBO::Snapshot(int width,int height)
{
//width=m_width;
//height=m_height;
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
void* pixels = malloc(3 * width * height); // must use malloc
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
wxImage image(width, height, true);
image.SetData((unsigned char*) pixels);
image = image.Mirror(false);
wxBitmap *bmp=new wxBitmap(image);
return bmp;
}
#if defined(__WXMSW__) #if defined(__WXMSW__)

View File

@ -39,9 +39,12 @@ License: GPL
#include <GL/glx.h> #include <GL/glx.h>
#endif #endif
#define MIN(a,b) (a<b) ? a : b; #define MIN(a,b) (((a)<(b)) ? (a) : (b));
#define MAX(a,b) (a<b) ? b : a; #define MAX(a,b) (((a)<(b)) ? (b) : (a));
#include <wx/bitmap.h>
long roundup2(long v);
class GLException { class GLException {
public: public:
@ -56,12 +59,30 @@ public:
pBuffer(int width, int height); pBuffer(int width, int height);
virtual ~pBuffer(); virtual ~pBuffer();
virtual void UseBuffer(bool b) {}; virtual void UseBuffer(bool b) {};
int Width() { return m_width; };
int Height() { return m_height; };
virtual wxBitmap *Snapshot(int width, int height);
protected: protected:
int m_width; int m_width;
int m_height; int m_height;
}; };
class FBO:public pBuffer
{
public:
FBO(int width, int height);
virtual ~FBO();
virtual void UseBuffer(bool b);
virtual wxBitmap *Snapshot(int width, int height);
protected:
GLuint depthbuffer,colorbuffer;
GLuint img;
GLuint fbo;
bool m_depth_buffer;
bool m_color_buffer;
};
#if defined(__WXMSW__) #if defined(__WXMSW__)
class pBufferWGL:public pBuffer class pBufferWGL:public pBuffer
{ {

View File

@ -23,7 +23,7 @@ License: GPL
#include "sleeplib/profiles.h" #include "sleeplib/profiles.h"
#include "graphs/freesans.h" #include "graphs/freesans.h" // Remember to compress this..
//#include <wx/dcbuffer.h> //#include <wx/dcbuffer.h>
@ -1002,108 +1002,48 @@ pBuffer *pbuffer=NULL;
wxBitmap * gGraphWindow::RenderBitmap(int width,int height) wxBitmap * gGraphWindow::RenderBitmap(int width,int height)
{ {
// I can't get FBO buffers to work properly wxBitmap *bmp;
// 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) { if (!pbuffer) {
try { try {
wxSize res=wxGetDisplaySize();
pbuffer=new FBO(res.GetWidth(),res.GetHeight());
/*
#if defined(__WXMSW__) #if defined(__WXMSW__)
pbuffer=new pBufferWGL(width,height); pbuffer=new pBufferWGL(width,height);
#elif defined(__WXMAC__) || defined(__WXDARWIN__) #elif defined(__WXMAC__) || defined(__WXDARWIN__)
pbuffer=new pBufferAGL(width,height); throw GLException(wxT("Macintrash"));
//pbuffer=new pBufferAGL(width,height);
#elif defined(__UNIX__) #elif defined(__UNIX__)
pbuffer=new pBufferGLX(width,height); pbuffer=new pBufferGLX(width,height);
#endif #endif
*/
} catch(GLException e) { } catch(GLException e) {
// Should log already if failed.. // Should log already if failed..
wxLogDebug(wxT("pBuffers not implemented or functional on this platform.. Trying FBO"));
pbuffer=NULL;
}
}
if (!pbuffer) {
try {
pbuffer=new FBO(width,height);
} catch(GLException e) {
wxLogError(wxT("No offscreen rendering capabilities detected on this machine."));
pbuffer=NULL; pbuffer=NULL;
return NULL; return NULL;
} }
} }
if (pbuffer) { if (pbuffer) {
pbuffer->UseBuffer(true); pbuffer->UseBuffer(true);
}
// Move this bitmap code to pBuffer
// glClearColor(1,1,0,1);
//glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
// Can't use font's in multiple contexts // Can't use font's in multiple contexts
Render(width,height); Render(width,height);
//glDrawBuffer(GL_BACK_LEFT); bmp=pbuffer->Snapshot(width,height);
// 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
wxImage image(width, height, true);
image.SetData((unsigned char*) pixels);
image = image.Mirror(false);
glFlush(); glFlush();
pbuffer->UseBuffer(false);
} else bmp=NULL;
wxBitmap *bmp=new wxBitmap(image);
// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
// glDeleteFramebuffersEXT(1, &fbo);
//glDeleteRenderbuffersEXT(1, &depthbuffer);
if (pbuffer) {
//delete pbuffer;
}
return bmp; return bmp;
} }
@ -1180,7 +1120,7 @@ void gGraphWindow::OnPaint(wxPaintEvent& event)
SwapBuffers(); // Dump to screen. SwapBuffers(); // Dump to screen.
//event.Skip(); event.Skip();
} }
void gGraphWindow::OnSize(wxSizeEvent& event) void gGraphWindow::OnSize(wxSizeEvent& event)
{ {

View File

@ -30,8 +30,8 @@ extern wxColor *wxLIGHT_YELLOW;
extern wxColor *wxDARK_GREEN; extern wxColor *wxDARK_GREEN;
extern wxColor *wxDARK_GREY; extern wxColor *wxDARK_GREY;
#define MIN(a,b) (a<b) ? a : b; //#define MIN(a,b) (((a)<(b)) ? (a) : (b));
#define MAX(a,b) (a<b) ? b : a; //#define MAX(a,b) (((a)<(b)) ? (b) : (a));
class Point3D class Point3D
{ {

View File

@ -4,7 +4,7 @@
namespace AutoVersion{ namespace AutoVersion{
//Date Version Types //Date Version Types
static const char _DATE[] = "17"; static const char _DATE[] = "18";
static const char _MONTH[] = "06"; static const char _MONTH[] = "06";
static const char _YEAR[] = "2011"; static const char _YEAR[] = "2011";
static const char _UBUNTU_VERSION_STYLE[] = "11.06"; static const char _UBUNTU_VERSION_STYLE[] = "11.06";
@ -16,14 +16,14 @@ namespace AutoVersion{
//Standard Version Type //Standard Version Type
static const long _MAJOR = 0; static const long _MAJOR = 0;
static const long _MINOR = 7; static const long _MINOR = 7;
static const long _BUILD = 6516; static const long _BUILD = 6592;
static const long _REVISION = 18844; static const long _REVISION = 19276;
//Miscellaneous Version Types //Miscellaneous Version Types
static const long _BUILDS_COUNT = 7759; static const long _BUILDS_COUNT = 7932;
#define _RC_FILEVERSION 0,7,6516,18844 #define _RC_FILEVERSION 0,7,6592,19276
#define _RC_FILEVERSION_STRING "0, 7, 6516, 18844\0" #define _RC_FILEVERSION_STRING "0, 7, 6592, 19276\0"
static const char _FULLVERSION_STRING[] = "0.7.6516.18844"; static const char _FULLVERSION_STRING[] = "0.7.6592.19276";
//These values are to keep track of your versioning state, don't modify them. //These values are to keep track of your versioning state, don't modify them.
static const long _BUILD_HISTORY = 0; static const long _BUILD_HISTORY = 0;