Permalink
Browse files

Add pixel buffers to the USE_SHADERS codepath. Turn on USE_SHADERS.

git-svn-id: svn+ssh://truffle/home/andrew/repo/memview@63 6d4121a9-3ab8-48c6-8db9-97dca464e206
  • Loading branch information...
1 parent 549b866 commit 996249651abfffbf7c30933a9355cd088bea3193 @ajclinto committed Jan 23, 2012
Showing with 65 additions and 10 deletions.
  1. +33 −5 GLImage.h
  2. +31 −5 Window.C
  3. +1 −0 Window.h
View
@@ -6,25 +6,52 @@ class GLImage {
GLImage()
: myData(0)
, myWidth(0)
- , myHeight(0) {}
+ , myHeight(0)
+ , myOwnData(false) {}
+ ~GLImage()
+ {
+ if (myOwnData)
+ delete [] myData;
+ }
void resize(int width, int height)
{
if (myWidth != width ||
myHeight != height)
{
- delete [] myData;
- myData = 0;
+ if (myOwnData)
+ {
+ delete [] myData;
+ myData = 0;
+ }
+
myWidth = width;
myHeight = height;
+
+ if (myWidth && myHeight)
+ {
+ myData = new uint32[myWidth*myHeight];
+ myOwnData = true;
+ }
}
+ }
- if (!myData)
- myData = new uint32[myWidth*myHeight];
+ // Interface to allow external ownership
+ void setSize(int width, int height)
+ {
+ myWidth = width;
+ myHeight = height;
+ myOwnData = false;
+ }
+ void setData(uint32 *data)
+ {
+ myData = data;
+ myOwnData = false;
}
int width() const { return myWidth; }
int height() const { return myHeight; }
+ size_t bytes() const { return myWidth*myHeight*sizeof(uint32); }
const uint32 *data() const { return myData; }
void fill(uint32 val)
@@ -46,6 +73,7 @@ class GLImage {
uint32 *myData;
int myWidth;
int myHeight;
+ bool myOwnData;
};
#endif
View
@@ -1,6 +1,13 @@
+#define GL_GLEXT_PROTOTYPES
+#include <GL/gl.h>
+
#include "Window.h"
#include "MemoryState.h"
+// This define causes rendering to use textures, PBOs, and to render a
+// full-screen quad. When disabled, glDrawPixels is used.
+#define USE_SHADERS
+
static const QSize theDefaultSize(800, 600);
Window::Window(int argc, char *argv[])
@@ -61,6 +68,7 @@ MemViewWidget::MemViewWidget(int argc, char *argv[],
, myHScrollBar(hscrollbar)
, myTexture(0)
, myList(0)
+ , myPixelBuffer(0)
, myStopWatch(false)
, myDragging(false)
{
@@ -109,6 +117,8 @@ MemViewWidget::initializeGL()
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glGenBuffers(1, &myPixelBuffer);
+
myList = glGenLists(1);
glNewList(myList, GL_COMPILE);
@@ -163,6 +173,16 @@ MemViewWidget::resizeGL(int width, int height)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
+
+#if defined(USE_SHADERS)
+ myImage.setSize(width, height);
+
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, myPixelBuffer);
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, myImage.bytes(), 0, GL_STREAM_DRAW);
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+#else
+ myImage.resize(width, height);
+#endif
}
void
@@ -175,15 +195,22 @@ MemViewWidget::paintGL()
myAnchor.myAbsoluteOffset;
myAnchor.myColumn += myHScrollBar->value() - myAnchor.myColumn;
+#if !defined(USE_SHADERS)
myState->fillImage(myImage, myAnchor);
-#if !defined(USE_SHADERS)
glDrawPixels(myImage.width(), myImage.height(), GL_BGRA,
GL_UNSIGNED_BYTE, myImage.data());
#else
- glTexImage2D(GL_TEXTURE_2D, 0, 3,
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, myPixelBuffer);
+
+ myImage.setData((uint32 *)
+ glMapBufferARB(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY));
+ myState->fillImage(myImage, myAnchor);
+ glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
myImage.width(), myImage.height(), 0, GL_BGRA,
- GL_UNSIGNED_BYTE, myImage.data());
+ GL_UNSIGNED_BYTE, 0);
glCallList(myList);
#endif
@@ -207,10 +234,9 @@ MemViewWidget::resizeEvent(QResizeEvent *event)
myVScrollBar->setPageStep(h);
myHScrollBar->setPageStep(w);
- myImage.resize(w, h);
- update();
QGLWidget::resizeEvent(event);
+ update();
}
}
View
@@ -81,6 +81,7 @@ private slots:
QGLShaderProgram *myProgram;
GLuint myTexture;
GLuint myList;
+ GLuint myPixelBuffer;
MemoryState::AnchorInfo myAnchor;
MemoryState *myState;

0 comments on commit 9962496

Please sign in to comment.