|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "qtofflinegl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include <traster.h></traster.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <tconvert.h></tconvert.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void swapRedBlueChannels(void *buffer, int bufferSize) // Flips The Red And Blue Bytes (WidthxHeight)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
void *b = buffer; // Pointer To The Buffer
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef x64
|
|
Toshihiro Shimizu |
890ddd |
int size = bufferSize;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pix = (UCHAR *)b;
|
|
Toshihiro Shimizu |
890ddd |
while (size > 0) {
|
|
Toshihiro Shimizu |
890ddd |
UCHAR r = *pix;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR b = *(pix + 2);
|
|
Toshihiro Shimizu |
890ddd |
*pix = b;
|
|
Toshihiro Shimizu |
890ddd |
*(pix + 2) = r;
|
|
Toshihiro Shimizu |
890ddd |
pix += 4;
|
|
Toshihiro Shimizu |
890ddd |
size--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
__asm // Assembler Code To Follow
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
mov ecx, bufferSize // Counter Set To Dimensions Of Our Memory Block
|
|
Toshihiro Shimizu |
890ddd |
mov ebx, b // Points ebx To Our Data (b)
|
|
Toshihiro Shimizu |
890ddd |
label: // Label Used For Looping
|
|
Toshihiro Shimizu |
890ddd |
mov al,[ebx+0] // Loads Value At ebx Into al
|
|
Toshihiro Shimizu |
890ddd |
mov ah,[ebx+2] // Loads Value At ebx+2 Into ah
|
|
Toshihiro Shimizu |
890ddd |
mov [ebx+2],al // Stores Value In al At ebx+2
|
|
Toshihiro Shimizu |
890ddd |
mov [ebx+0],ah // Stores Value In ah At ebx
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
add ebx,4 // Moves Through The Data By 4 Bytes
|
|
Toshihiro Shimizu |
890ddd |
dec ecx // Decreases Our Loop Counter
|
|
Toshihiro Shimizu |
890ddd |
jnz label // If Not Zero Jump Back To Label
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if defined(MACOSX)
|
|
Toshihiro Shimizu |
890ddd |
#if defined(powerpc)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void rightRotateBits(UCHAR *buf, int bufferSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UINT *buffer = (UINT *)buf;
|
|
Toshihiro Shimizu |
890ddd |
register UINT app;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < bufferSize; i++, buffer++) {
|
|
Toshihiro Shimizu |
890ddd |
app = *buffer;
|
|
Toshihiro Shimizu |
890ddd |
*buffer = app >> 8 | app << 24;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
void rightRotateBits(UCHAR *buf, int bufferSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UINT *buffer = (UINT *)buf;
|
|
Toshihiro Shimizu |
890ddd |
register UINT app;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < bufferSize; i++, buffer++) {
|
|
Toshihiro Shimizu |
890ddd |
app = *buffer;
|
|
Toshihiro Shimizu |
890ddd |
*buffer = (app >> 16 & 0x000000ff) | (app << 16 & 0x00ff0000) | (app & 0xff00ff00);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// QtOfflineGL : implem. offlineGL usando QT
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QtOfflineGL::QtOfflineGL(TDimension rasterSize, const TOfflineGL::Imp *shared)
|
|
Toshihiro Shimizu |
890ddd |
: TOfflineGL::Imp(rasterSize.lx, rasterSize.ly), m_context(0), m_oldContext(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
createContext(rasterSize, shared);
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glClearColor(0.0f,0.0f,0.0f,0.0f);
|
|
Toshihiro Shimizu |
890ddd |
glClear(GL_COLOR_BUFFER_BIT);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
doneCurrent();
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QtOfflineGL::~QtOfflineGL()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_context;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGL::createContext(TDimension rasterSize, const TOfflineGL::Imp *shared)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// Imposto il formato dei Pixel (pixelFormat)
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
32, // 32-bit color depth
|
|
Toshihiro Shimizu |
890ddd |
0, 0, 0, 0, 0, 0, // color bits ignored
|
|
Toshihiro Shimizu |
890ddd |
8, // no alpha buffer
|
|
Toshihiro Shimizu |
890ddd |
0, // shift bit ignored
|
|
Toshihiro Shimizu |
890ddd |
0, // no accumulation buffer
|
|
Toshihiro Shimizu |
890ddd |
0, 0, 0, 0, // accum bits ignored
|
|
Toshihiro Shimizu |
890ddd |
32, // 32-bit z-buffer
|
|
Toshihiro Shimizu |
890ddd |
32, // max stencil buffer
|
|
Toshihiro Shimizu |
890ddd |
0, // no auxiliary buffer
|
|
Toshihiro Shimizu |
890ddd |
PFD_MAIN_PLANE, // main layer
|
|
Toshihiro Shimizu |
890ddd |
0, // reserved
|
|
Toshihiro Shimizu |
890ddd |
0, 0, 0 // layer masks ignored
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ATTENZIONE !! SU MAC IL FORMATO E' DIVERSO (casomai possiamo mettere un ifdef)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
SPECIFICHE MAC = depth_size 24, stencil_size 8, alpha_size 1
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QGLFormat fmt;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAlphaBufferSize(8);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAlpha(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setRgba(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDepthBufferSize(32);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDepth(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setStencilBufferSize(32);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setStencil(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAccum(false);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setPlane(0);
|
|
Toshihiro Shimizu |
890ddd |
#elif MACOSX
|
|
Toshihiro Shimizu |
890ddd |
fmt = QGLFormat::defaultFormat();
|
|
Toshihiro Shimizu |
890ddd |
//printf("GL Version: %s\n",glGetString(GL_VERSION));
|
|
Toshihiro Shimizu |
890ddd |
fmt.setVersion(2, 1); /* OSX10.8 では 3.2 だめかも */
|
|
Toshihiro Shimizu |
890ddd |
#if 0
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAlphaBufferSize(8);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAlpha(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setRgba(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDepthBufferSize(32);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDepth(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setStencilBufferSize(8);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setStencil(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAccum(false);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setPlane(0);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDirectRendering(false);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
/* FIXME: ここでいう QPixmap は Level Strip のセルに相当する.
|
|
Toshihiro Shimizu |
890ddd |
QPixmap に GLContext を生成して bind できれば描画したベクタのラスタ画像がそこに反映されるはずだが
|
|
Toshihiro Shimizu |
890ddd |
QLContext の生成ができないためにうまくいかない.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
printf("QPixmap(%d, %d)\n", rasterSize.lx, rasterSize.ly);
|
|
Toshihiro Shimizu |
890ddd |
//QPixmap *m_pixmap = new QPixmap(rasterSize.lx, rasterSize.ly);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Inizializzo un contesto openGL utilizzando una QPixmap
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_context = new QOpenGLContext();
|
|
Toshihiro Shimizu |
890ddd |
//m_context = new QGLContext(fmt);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_surface = new QOffscreenSurface();
|
|
Toshihiro Shimizu |
890ddd |
m_surface->setFormat(m_context->format());
|
|
Toshihiro Shimizu |
890ddd |
//QSurfaceFormat sfmt = QGuiApplication::focusWindow()->format();
|
|
Toshihiro Shimizu |
890ddd |
m_surface->create();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
printf("create context:%p [thread:0x%x]\n", m_context, QThread::currentThreadId());
|
|
Toshihiro Shimizu |
890ddd |
//m_context->setFormat(sfmt);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Creo il contesto OpenGL - assicurandomi che sia effettivamente creato
|
|
Toshihiro Shimizu |
890ddd |
// NOTA: Se il contesto non viene creato, di solito basta ritentare qualche volta.
|
|
Toshihiro Shimizu |
890ddd |
bool ret = m_context->create();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGL::makeCurrent()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_context) {
|
|
Toshihiro Shimizu |
890ddd |
m_context->makeCurrent(m_surface);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// else
|
|
Toshihiro Shimizu |
890ddd |
// m_oldContext = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGL::doneCurrent()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_context) {
|
|
Toshihiro Shimizu |
890ddd |
m_context->doneCurrent();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGL::saveCurrentContext()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// m_oldContext = const_cast<qglcontext*>(QGLContext::currentContext());</qglcontext*>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGL::restoreCurrentContext()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// if(m_oldContext) m_oldContext->makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
// m_oldContext = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGL::getRaster(TRaster32P raster)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
glFlush();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int lx = raster->getLx();
|
|
Toshihiro Shimizu |
890ddd |
int ly = raster->getLy();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
raster->lock();
|
|
Toshihiro Shimizu |
890ddd |
glReadPixels(0, 0, lx, ly,
|
|
Toshihiro Shimizu |
890ddd |
GL_RGBA /*GL_BGRA_EXT*/, GL_UNSIGNED_BYTE,
|
|
Toshihiro Shimizu |
890ddd |
raster->getRawData());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
swapRedBlueChannels(raster->getRawData(), lx * ly);
|
|
Toshihiro Shimizu |
890ddd |
#elif MACOSX
|
|
Toshihiro Shimizu |
890ddd |
rightRotateBits(raster->getRawData(), lx * ly);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
raster->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//QGLPixelBuffer::hasOpenGLPbuffers() (statica) -> true se la scheda supporta i PBuffer
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// QtOfflineGLPBuffer : implem. offlineGL usando QT e PBuffer
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QtOfflineGLPBuffer::QtOfflineGLPBuffer(TDimension rasterSize)
|
|
Toshihiro Shimizu |
890ddd |
: TOfflineGL::Imp(rasterSize.lx, rasterSize.ly), m_context(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
createContext(rasterSize);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
Toshihiro Shimizu |
890ddd |
glClear(GL_COLOR_BUFFER_BIT);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
doneCurrent();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QtOfflineGLPBuffer::~QtOfflineGLPBuffer()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_context;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGLPBuffer::createContext(TDimension rasterSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// Imposto il formato dei Pixel (pixelFormat)
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
32, // 32-bit color depth
|
|
Toshihiro Shimizu |
890ddd |
0, 0, 0, 0, 0, 0, // color bits ignored
|
|
Toshihiro Shimizu |
890ddd |
8, // no alpha buffer
|
|
Toshihiro Shimizu |
890ddd |
0, // shift bit ignored
|
|
Toshihiro Shimizu |
890ddd |
0, // no accumulation buffer
|
|
Toshihiro Shimizu |
890ddd |
0, 0, 0, 0, // accum bits ignored
|
|
Toshihiro Shimizu |
890ddd |
32, // 32-bit z-buffer
|
|
Toshihiro Shimizu |
890ddd |
32, // max stencil buffer
|
|
Toshihiro Shimizu |
890ddd |
0, // no auxiliary buffer
|
|
Toshihiro Shimizu |
890ddd |
PFD_MAIN_PLANE, // main layer
|
|
Toshihiro Shimizu |
890ddd |
0, // reserved
|
|
Toshihiro Shimizu |
890ddd |
0, 0, 0 // layer masks ignored
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ATTENZIONE !! SU MAC IL FORMATO E' DIVERSO (casomai possiamo mettere un ifdef)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
SPECIFICHE MAC = depth_size 24, stencil_size 8, alpha_size 1
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QGLFormat fmt;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAlphaBufferSize(8);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAlpha(false);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setRgba(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDepthBufferSize(32);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDepth(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setStencilBufferSize(32);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setStencil(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAccum(false);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setPlane(0);
|
|
Toshihiro Shimizu |
890ddd |
#elif MACOSX
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAlphaBufferSize(1);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAlpha(false);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setRgba(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDepthBufferSize(24);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setDepth(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setStencilBufferSize(8);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setStencil(true);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setAccum(false);
|
|
Toshihiro Shimizu |
890ddd |
fmt.setPlane(0);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Il PixelBuffer deve essere con width ed height potenze di 2
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int sizeMax = tmax(rasterSize.lx, rasterSize.ly);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// trovo la potenza di 2 che "contiene" sizeMax e la utilizzo per il PBuffer
|
|
Toshihiro Shimizu |
890ddd |
int pBufferSize = 2;
|
|
Toshihiro Shimizu |
890ddd |
while (pBufferSize < sizeMax)
|
|
Toshihiro Shimizu |
890ddd |
pBufferSize *= 2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_context = new QGLPixelBuffer(QSize(pBufferSize, pBufferSize), fmt);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGLPBuffer::makeCurrent()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_context)
|
|
Toshihiro Shimizu |
890ddd |
m_context->makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGLPBuffer::doneCurrent()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_context)
|
|
Toshihiro Shimizu |
890ddd |
m_context->doneCurrent();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void QtOfflineGLPBuffer::getRaster(TRaster32P raster)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
glFlush();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//The image is stored using a 32-bit ARGB format (0xAARRGGBB).
|
|
Toshihiro Shimizu |
890ddd |
QImage image = m_context->toImage();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int lx = raster->getLx(), ly = raster->getLy();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static const TRaster32P emptyRaster;
|
|
Toshihiro Shimizu |
890ddd |
if (image.height() == 0 || image.width() == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// devo iniziare a leggere la Y da un certo offset
|
|
Toshihiro Shimizu |
890ddd |
// dato dalla differenza tra la y della image e la y del raster
|
|
Toshihiro Shimizu |
890ddd |
int yOffset = image.height() - ly;
|
|
Toshihiro Shimizu |
890ddd |
raster->lock();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int y = 0; y < ly; y++) {
|
|
Toshihiro Shimizu |
890ddd |
QRgb *inpPix = (QRgb *)image.scanLine(yOffset + y);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *pix = raster->pixels(ly - 1 - y);
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *endPix = pix + lx;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (; pix < endPix; ++pix) {
|
|
Toshihiro Shimizu |
890ddd |
pix->m = 255;
|
|
Toshihiro Shimizu |
890ddd |
pix->r = qRed(*inpPix);
|
|
Toshihiro Shimizu |
890ddd |
pix->g = qGreen(*inpPix);
|
|
Toshihiro Shimizu |
890ddd |
pix->b = qBlue(*inpPix);
|
|
Toshihiro Shimizu |
890ddd |
*inpPix++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
raster->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|