29 #include "hugin_config.h"
30 #if defined HAVE_EPOXY && HAVE_EPOXY
37 #include <OpenGL/glu.h>
38 #include <GLUT/glut.h>
51 #include <vigra/diff2d.hxx>
52 #include <vigra/utilities.hxx>
53 #include <vigra/error.hxx>
60 return GetTickCount();
67 gettimeofday(&tv,NULL);
68 return (
long)(tv.tv_sec*1000+(tv.tv_usec/1000));
82 #define ___NCFILE___ ((char *) __FILE__)
83 #define CHECK_GL() checkGLErrors(__LINE__, ___NCFILE___)
88 GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT,
90 GL_RGBA8, GL_RGBA16, GL_RGBA32F_ARB, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE16_ALPHA16, GL_LUMINANCE_ALPHA32F_ARB,
91 GL_RGB8, GL_RGB16, GL_RGB32F_ARB, GL_LUMINANCE8, GL_LUMINANCE16, GL_LUMINANCE32F_ARB,
93 GL_LUMINANCE, GL_RGB, GL_LUMINANCE_ALPHA, GL_RGBA
98 "GL_BYTE",
"GL_UNSIGNED_BYTE",
"GL_SHORT",
"GL_UNSIGNED_SHORT",
"GL_INT",
"GL_UNSIGNED_INT",
"GL_FLOAT",
100 "GL_RGBA8",
"GL_RGBA16",
"GL_RGBA32F_ARB",
"GL_LUMINANCE8_ALPHA8",
"GL_LUMINANCE16_ALPHA16",
"GL_LUMINANCE_ALPHA32F_ARB",
101 "GL_RGB8",
"GL_RGB16",
"GL_RGB32F_ARB",
"GL_LUMINANCE8",
"GL_LUMINANCE16",
"GL_LUMINANCE32F_ARB",
103 "GL_LUMINANCE",
"GL_RGB",
"GL_LUMINANCE_ALPHA",
"GL_RGBA"
115 "#extension GL_ARB_texture_rectangle : enable\n"
116 "uniform sampler2DRect SrcAlphaTexture;\n"
119 " float alpha = texture2DRect(SrcAlphaTexture, gl_TexCoord[0].st).a;\n"
120 " if (alpha != 0.0) discard;\n"
121 " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n"
126 GLenum errCode = glGetError();
127 if (errCode != GL_NO_ERROR)
129 while (errCode != GL_NO_ERROR)
131 const GLubyte* message = gluErrorString(errCode);
132 std::cerr <<
"nona: GL error in " << file <<
":" << line << std::endl;
136 const char* messageChar =
reinterpret_cast<const char*
>(message);
137 size_t size = strlen(messageChar);
138 LPSTR OEMmessageBuffer = (LPSTR)LocalAlloc(LPTR, (size + 1)*
sizeof(char));
139 if (OEMmessageBuffer)
141 if (CharToOemBuff(messageChar, OEMmessageBuffer, size))
143 std::cerr << OEMmessageBuffer <<
" (0x" << std::hex << errCode <<
")" << std::endl;
147 std::cerr << message <<
" (0x" << std::hex << errCode <<
")" << std::endl;
152 std::cerr << message <<
" (0x" << std::hex << errCode <<
")" << std::endl;
154 LocalFree(OEMmessageBuffer);
156 std::cerr << message <<
" (0x" << std::hex << errCode <<
")" << std::endl;
161 std::cerr <<
"Error code: 0x" << std::hex << errCode << std::endl;
163 errCode = glGetError();
170 GLint infologLength = 0;
171 GLint charsWritten = 0;
172 glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength);
173 if (infologLength > 1) {
174 char* infoLog =
new char[infologLength];
175 glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
176 cout <<
"nona: GL info log:" << endl << infoLog << endl << endl;
185 status = (GLenum) glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
187 case GL_FRAMEBUFFER_COMPLETE_EXT:
189 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
190 cerr <<
"nona: GL error: Framebuffer incomplete, incomplete attachment in: " << file <<
":" << line << endl;
192 case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
193 cerr <<
"nona: Unsupported framebuffer format in: " << file <<
":" << line << endl;
195 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
196 cerr <<
"nona: Framebuffer incomplete, missing attachment in: " << file <<
":" << line << endl;
198 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
199 cerr <<
"nona: Framebuffer incomplete, attached images must have same dimensions in: " << file <<
":" << line << endl;
201 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
202 cerr <<
"nona: Framebuffer incomplete, attached images must have same format in: " << file <<
":" << line << endl;
204 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
205 cerr <<
"nona: Framebuffer incomplete, missing draw buffer in: " << file <<
":" << line << endl;
207 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
208 cerr <<
"nona: Framebuffer incomplete, missing read buffer in: " << file <<
":" << line << endl;
216 GLhandleARB& programObject,
217 GLhandleARB& shaderObject,
222 programObject = glCreateProgramObjectARB();
223 shaderObject = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
225 glShaderSourceARB(shaderObject, 1, source, NULL);
226 glCompileShaderARB(shaderObject);
228 glGetObjectParameterivARB(shaderObject, GL_OBJECT_COMPILE_STATUS_ARB, &success);
230 cerr <<
"nona: " << programName <<
" shader program could not be compiled." << endl;
238 glAttachObjectARB(programObject, shaderObject);
239 glLinkProgramARB(programObject);
241 glGetObjectParameterivARB(programObject, GL_OBJECT_LINK_STATUS_ARB, &success);
243 cerr <<
"nona: " << programName <<
" shader program could not be linked." << endl;
254 const int maxTextureSize,
255 const long long int maxPixels,
256 vector<Rect2D>& result)
262 while (ceil(static_cast<double>(width) / numXChunks) > maxTextureSize) numXChunks++;
263 while (ceil(static_cast<double>(height) / numYChunks) > maxTextureSize) numYChunks++;
266 while ((ceil(static_cast<double>(width) / numXChunks) * ceil(static_cast<double>(height) / numYChunks))
269 if (ceil(static_cast<double>(width) / numXChunks) > ceil(static_cast<double>(height) / numYChunks)) {
278 glTexImage2D(GL_PROXY_TEXTURE_2D,
281 static_cast<int>(ceil(static_cast<double>(width) / numXChunks)),
282 static_cast<int>(ceil(static_cast<double>(height) / numYChunks)),
288 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &returnedWidth);
290 if (returnedWidth != 0)
break;
292 if (ceil(static_cast<double>(width) / numXChunks) > ceil(static_cast<double>(height) / numYChunks)) {
299 for (
int yChunk = 0, y = 0; yChunk < numYChunks; yChunk++) {
300 int yEnd = std::min<int>(height,
static_cast<int>(ceil(static_cast<double>(height) / numYChunks)) + y);
301 for (
int xChunk = 0, x = 0; xChunk < numXChunks; xChunk++) {
302 int xEnd = std::min<int>(width,
static_cast<int>(ceil(static_cast<double>(width) / numXChunks)) + x);
303 result.push_back(Rect2D(x, y, xEnd, yEnd));
320 const std::string& interpolatorGLSL,
321 const int interpolatorSize,
322 const std::string& photometricGLSL,
323 const vector<double>& invLut,
324 const vector<double>& destLut,
325 const vigra::Diff2D srcSize,
326 const void*
const srcBuffer,
327 const int srcGLInternalFormat,
const int srcGLTransferFormat,
const int srcGLFormat,
const int srcGLType,
328 const void*
const srcAlphaBuffer,
329 const int srcAlphaGLType,
330 const vigra::Diff2D destUL,
331 const vigra::Diff2D destSize,
332 void*
const destBuffer,
333 const int destGLInternalFormat,
const int destGLTransferFormat,
const int destGLFormat,
const int destGLType,
334 void*
const destAlphaBuffer,
335 const int destAlphaGLType,
336 const bool warparound)
338 long t1, t3, t5, t6, t7, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t21;
340 const int xstart = destUL.x;
341 const int xend = destUL.x + destSize.x;
342 const int ystart = destUL.y;
343 const int yend = destUL.y + destSize.y;
348 cout <<
"destStart=[" << xstart <<
", " << ystart <<
"]" << endl
349 <<
"destEnd=[" << xend <<
", " << yend <<
"]" << endl
350 <<
"destSize=[" << destSize <<
"]" << endl
351 <<
"srcSize=[" << srcSize <<
"]" << endl
352 <<
"srcBuffer=" << srcBuffer << endl
353 <<
"srcAlphaBuffer=" << srcAlphaBuffer << endl
354 <<
"destBuffer=" << destBuffer << endl
355 <<
"destAlphaBuffer=" << destAlphaBuffer << endl
356 <<
"destGLInternalFormat=" <<
XGLStringMap[destGLInternalFormat] << endl
357 <<
"destGLFormat=" <<
XGLStringMap[destGLFormat] << endl
359 <<
"srcGLInternalFormat=" <<
XGLStringMap[srcGLInternalFormat] << endl
362 <<
"srcAlphaGLType=" <<
XGLStringMap[srcAlphaGLType] << endl
363 <<
"destAlphaGLType=" <<
XGLStringMap[destAlphaGLType] << endl
365 <<
"warparound=" << warparound << endl;
368 vigra_precondition((srcSize.x % 8) == 0,
"src image width not a multiple of 8");
369 vigra_precondition((destSize.x % 8) == 0,
"dest image width not a multiple of 8");
371 vigra_precondition((reinterpret_cast<const uintptr_t>(srcBuffer) & 0x7) == 0,
"src image buffer not 8-byte aligned");
372 vigra_precondition((reinterpret_cast<const uintptr_t>(srcAlphaBuffer) & 0x7) == 0,
"src alpha image buffer not 8-byte aligned");
373 vigra_precondition((reinterpret_cast<const uintptr_t>(destBuffer) & 0x7) == 0,
"dest image buffer not 8-byte aligned");
374 vigra_precondition((reinterpret_cast<const uintptr_t>(destAlphaBuffer) & 0x7) == 0,
"dest alpha image buffer not 8-byte aligned");
376 const char*
const gpuVendor =
reinterpret_cast<const char*
>(glGetString(GL_VENDOR));
377 const bool needsAtanWorkaround = (strncmp(gpuVendor,
"ATI", 3) == 0);
380 cout <<
"needsAtanWorkaround=" << needsAtanWorkaround << endl;
382 GLint maxTextureSize;
384 glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &maxTextureSize);
387 cout <<
"Retrieving GL_MAX_RECTANGLE_TEXTURE_SIZE: " << maxTextureSize << std::endl;
389 if (glGetError() != GL_NO_ERROR || maxTextureSize < 1024)
392 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
395 cout <<
"Retrieving GL_MAX_TEXTURE_SIZE: " << maxTextureSize << std::endl;
401 GLint textureWidth=0;
402 while (textureWidth < maxTextureSize)
404 glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA32F_ARB, maxTextureSize, maxTextureSize, 0, GL_RGBA, GL_FLOAT, NULL);
405 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &textureWidth);
408 cout <<
"Testing texture size " << maxTextureSize <<
", result=" << textureWidth << std::endl;
410 if (textureWidth != maxTextureSize)
414 if (maxTextureSize < 1024)
416 cerr <<
"nona: Can't allocate texture with a size of at least 1024 pixels." << std::endl;;
422 cout <<
"maxTextureSize=" << maxTextureSize << endl;
427 long long int GpuMemoryInBytes = 512 << 20;
431 #define GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX 0x9048
432 GLint total_mem_kb = 0;
434 if (glGetError() == GL_NO_ERROR)
436 GpuMemoryInBytes = total_mem_kb * 1024ll;
441 #define TEXTURE_FREE_MEMORY_ATI 0x87FC
444 if (glGetError() == GL_NO_ERROR)
446 GpuMemoryInBytes = param[0] * 1024ll;
449 const double SourceAllocationRatio = 0.7;
451 const int bytesPerSourcePixel =
BytesPerPixel[srcGLInternalFormat]
452 + ((srcGLInternalFormat != srcGLTransferFormat) ?
BytesPerPixel[srcGLTransferFormat] : 0)
453 + ((srcAlphaBuffer != NULL) ? 1 : 0);
454 const long long int maxSourcePixels =
static_cast<long long int>(GpuMemoryInBytes * SourceAllocationRatio) / bytesPerSourcePixel;
456 vector<Rect2D> sourceChunks;
457 makeChunks(srcSize.x, srcSize.y, maxTextureSize, maxSourcePixels, sourceChunks);
459 const long long int actualSourcePixels = sourceChunks[0].area();
460 const long long int gpuMemoryRemaining = GpuMemoryInBytes - (actualSourcePixels * bytesPerSourcePixel);
465 const int bytesPerDestPixel = 16 + 16 + 8
466 + ((
XGLMap[destGLTransferFormat] != GL_RGBA32F_ARB) ?
BytesPerPixel[destGLTransferFormat] : 0)
467 + ((destAlphaBuffer != NULL) ? 1 : 0);
468 const long long int maxDestPixels = gpuMemoryRemaining / bytesPerDestPixel;
470 vector<Rect2D> destChunks;
471 makeChunks(destSize.x, destSize.y, maxTextureSize, maxDestPixels, destChunks);
473 const long long int totalGpuMemoryUsed = (sourceChunks[0].area() * bytesPerSourcePixel) + (destChunks[0].area() * bytesPerDestPixel);
474 vigra_assert(totalGpuMemoryUsed <= GpuMemoryInBytes,
475 "failed to subdivide source and dest images into pieces small enough to fit in gpu memory.");
479 cout <<
"Source chunks:" << endl;
480 for (vector<Rect2D>::iterator rI = sourceChunks.begin(); rI != sourceChunks.end(); ++rI) {
481 cout <<
" " << *rI << endl;
483 cout <<
"Dest chunks:" << endl;
484 for (vector<Rect2D>::iterator rI = destChunks.begin(); rI != destChunks.end(); ++rI) {
485 cout <<
" " << *rI << endl;
487 cout <<
"Total GPU memory used: " << totalGpuMemoryUsed << endl;
491 const int TextureFetchesPerInterpolatorPass = 16;
492 vector<Rect2D> interpolatorChunks;
493 makeChunks(interpolatorSize, interpolatorSize, TextureFetchesPerInterpolatorPass, TextureFetchesPerInterpolatorPass, interpolatorChunks);
496 cout <<
"Interpolator chunks:" << endl;
497 for (vector<Rect2D>::iterator rI = interpolatorChunks.begin(); rI != interpolatorChunks.end(); ++rI) {
498 cout <<
" " << *rI << endl;
501 bool allInterpolatorChunksAreEqual =
true;
502 const Rect2D& firstInterpolatorChunk = interpolatorChunks.front();
503 for (vector<Rect2D>::iterator rI = ++(interpolatorChunks.begin()); rI != interpolatorChunks.end(); ++rI) {
504 if (rI->width() != firstInterpolatorChunk.width()
505 || rI->height() != firstInterpolatorChunk.height()) {
506 allInterpolatorChunksAreEqual =
false;
513 std::ostringstream oss;
514 oss << std::setprecision(20) << std::showpoint;
515 oss <<
"#version 110" << endl
516 <<
"#extension GL_ARB_texture_rectangle : enable" << endl
517 <<
"uniform sampler2DRect SrcTexture;" << endl
518 <<
"float sinh(in float x) { return (exp(x) - exp(-x)) / 2.0; }" << endl
519 <<
"float cosh(in float x) { return (exp(x) + exp(-x)) / 2.0; }" << endl;
524 if (needsAtanWorkaround) {
525 oss <<
"float atan2_xge0(const in float y, const in float x) {" << endl
526 <<
" if (abs(y) > x) {" << endl
527 <<
" return sign(y) * (" << (
M_PI/2.0) <<
" - atan(x, abs(y)));" << endl
528 <<
" } else {" << endl
529 <<
" return atan(y, x);" << endl
532 <<
"float atan2_safe(const in float y, const in float x) {" << endl
533 <<
" if (x >= 0.0) return atan2_xge0(y, x);" << endl
534 <<
" else return (sign(y) * " <<
M_PI <<
") - atan2_xge0(y, -x);" << endl
536 <<
"float atan_safe(const in float yx) {" << endl
537 <<
" if (abs(yx) > 1.0) {" << endl
538 <<
" return sign(yx) * (" << (
M_PI/2.0) <<
" - atan(1.0/abs(yx)));" << endl
539 <<
" } else {" << endl
540 <<
" return atan(yx);" << endl
544 oss <<
"float atan2_xge0(const in float y, const in float x) {" << endl
545 <<
" return atan(y, x);" << endl
547 <<
"float atan2_safe(const in float y, const in float x) {" << endl
548 <<
" return atan(y, x);" << endl
550 <<
"float atan_safe(const in float yx) {" << endl
551 <<
" return atan(yx);" << endl
555 oss <<
"void main(void)" << endl
557 <<
" float discardA = 1.0;" << endl
558 <<
" float discardB = 0.0;" << endl
560 <<
" src = src * discardA + vec2(-1000.0, -1000.0) * discardB;" << endl
561 <<
" gl_FragColor = vec4(src.s, 0.0, 0.0, src.t);" << endl
564 std::string coordXformKernelSourceString = oss.str();
565 const char* coordXformKernelSource = coordXformKernelSourceString.c_str();
567 cout << coordXformKernelSource;
569 GLhandleARB coordXformProgramObject;
570 GLhandleARB coordXformShaderObject;
572 coordXformProgramObject,
573 coordXformShaderObject,
574 &coordXformKernelSource);
580 static bool createdAlphaShader =
false;
581 static GLhandleARB alphaCompositeProgramObject;
582 static GLhandleARB alphaCompositeShaderObject;
583 static GLint srcAlphaTextureParam;
584 if (!createdAlphaShader
585 && (srcGLInternalFormat == srcGLTransferFormat)
586 && (srcAlphaBuffer != NULL)) {
589 alphaCompositeProgramObject,
590 alphaCompositeShaderObject,
592 srcAlphaTextureParam = glGetUniformLocationARB(alphaCompositeProgramObject,
"SrcAlphaTexture");
593 createdAlphaShader =
true;
599 oss << std::setprecision(20) << std::showpoint;
600 oss <<
"#version 110" << endl
601 <<
"#extension GL_ARB_texture_rectangle : enable" << endl
602 <<
"uniform sampler2DRect CoordTexture;" << endl
603 <<
"uniform sampler2DRect SrcTexture;" << endl
604 <<
"uniform sampler2DRect AccumTexture;" << endl
605 <<
"uniform vec2 SrcUL;" << endl
606 <<
"uniform vec2 SrcLR;" << endl
607 <<
"uniform vec2 KernelUL;" << endl
608 <<
"uniform vec2 KernelWH;" << endl
609 <<
"float w(const in float i, const in float f) {" << endl
612 <<
"void main(void)" << endl
614 <<
" vec2 src = texture2DRect(CoordTexture, gl_TexCoord[0].st).sq;" << endl
615 <<
" vec4 accum = texture2DRect(AccumTexture, gl_TexCoord[0].st);" << endl
630 oss <<
" src -= SrcUL;" << endl
631 <<
" vec2 t = floor(src) + " << (1.5 - (interpolatorSize / 2)) <<
";" << endl
632 <<
" vec2 f = fract(src);" << endl
633 <<
" vec2 k = vec2(0.0, 0.0);" << endl
637 if (allInterpolatorChunksAreEqual) {
638 oss <<
" for (float ky = 0.0; ky < " <<
static_cast<double>(firstInterpolatorChunk.height()) <<
"; ky += 1.0) {" << endl;
640 oss <<
" for (float ky = 0.0; ky < KernelWH.t; ky += 1.0) {" << endl;
643 oss <<
" k.t = ky + KernelUL.t;" << endl
644 <<
" float wy = w(k.t, f.t);" << endl;
646 if (allInterpolatorChunksAreEqual) {
647 oss <<
" for (float kx = 0.0; kx < " <<
static_cast<double>(firstInterpolatorChunk.width()) <<
"; kx += 1.0) {" << endl;
649 oss <<
" for (float kx = 0.0; kx < KernelWH.s; kx += 1.0) {" << endl;
653 oss <<
" k.s = kx + KernelUL.s;" << endl
654 <<
" float wx = w(k.s, f.s);" << endl
655 <<
" vec2 ix = t + k;" << endl
656 <<
" vec4 sp = texture2DRect(SrcTexture, ix);" << endl
657 <<
" float weight = wx * wy * sp.a;" << endl
658 <<
" accum += sp * weight;" << endl
679 <<
" gl_FragColor = accum;" << endl
683 std::string interpolatorKernelSourceString = oss.str();
684 const char* interpolatorKernelSource = interpolatorKernelSourceString.c_str();
686 cout << interpolatorKernelSource;
688 GLhandleARB interpolatorProgramObject;
689 GLhandleARB interpolatorShaderObject;
691 interpolatorProgramObject,
692 interpolatorShaderObject,
693 &interpolatorKernelSource);
695 GLint coordTextureParam = glGetUniformLocationARB(interpolatorProgramObject,
"CoordTexture");
696 GLint accumTextureParam = glGetUniformLocationARB(interpolatorProgramObject,
"AccumTexture");
697 GLint srcTextureParam = glGetUniformLocationARB(interpolatorProgramObject,
"SrcTexture");
698 GLint srcULParam = glGetUniformLocationARB(interpolatorProgramObject,
"SrcUL");
699 GLint srcLRParam = glGetUniformLocationARB(interpolatorProgramObject,
"SrcLR");
700 GLint kernelULParam = glGetUniformLocationARB(interpolatorProgramObject,
"KernelUL");
701 GLint kernelWHParam = glGetUniformLocationARB(interpolatorProgramObject,
"KernelWH");
706 oss << std::setprecision(20) << std::showpoint;
707 oss <<
"#version 120" << endl
708 <<
"#extension GL_ARB_texture_rectangle : enable" << endl
709 <<
"uniform sampler2DRect NormTexture;" << endl
710 <<
"uniform sampler2DRect CoordTexture;" << endl;
712 if (!invLut.empty()) {
713 oss <<
"uniform sampler2DRect InvLutTexture;" << endl;
716 if (!destLut.empty()) {
717 oss <<
"uniform sampler2DRect DestLutTexture;" << endl;
720 oss <<
"void main(void)" << endl
722 <<
" // Normalization" << endl
723 <<
" vec4 n = texture2DRect(NormTexture, gl_TexCoord[0].st);" << endl
724 <<
" vec4 p = vec4(0.0, 0.0, 0.0, 0.0);" << endl
725 <<
" if (n.a >= 0.2) p = n / n.a;" << endl
727 <<
" // Photometric" << endl
730 <<
" gl_FragColor = p;" << endl
734 std::string normalizationPhotometricKernelSourceString = oss.str();
735 const char* normalizationPhotometricKernelSource = normalizationPhotometricKernelSourceString.c_str();
737 cout << normalizationPhotometricKernelSource;
739 GLhandleARB normalizationPhotometricProgramObject;
740 GLhandleARB normalizationPhotometricShaderObject;
742 normalizationPhotometricProgramObject,
743 normalizationPhotometricShaderObject,
744 &normalizationPhotometricKernelSource);
746 GLint normTextureParam = glGetUniformLocationARB(normalizationPhotometricProgramObject,
"NormTexture");
747 GLint normCoordTextureParam = glGetUniformLocationARB(normalizationPhotometricProgramObject,
"CoordTexture");
749 float *invLutTextureData = NULL;
750 GLuint invLutTexture;
751 GLint invLutTextureParam;
752 if (!invLut.empty()) {
753 invLutTextureData =
new float[invLut.size() * 2];
754 for (
int i = 0; i < invLut.size(); ++i) {
755 invLutTextureData[2*i] = invLut[i];
756 invLutTextureData[2*i+1] = ((i + 1) < invLut.size()) ? invLut[i+1] : invLut[i];
758 invLutTextureParam = glGetUniformLocationARB(normalizationPhotometricProgramObject,
"InvLutTexture");
759 glGenTextures(1, &invLutTexture);
760 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, invLutTexture);
761 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
762 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
763 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
764 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
765 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA32F_ARB, invLut.size(), 1, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, invLutTextureData);
769 float *destLutTextureData = NULL;
770 GLuint destLutTexture;
771 GLint destLutTextureParam;
772 if (!destLut.empty()) {
773 destLutTextureData =
new float[destLut.size() * 2];
774 for (
int i = 0; i < destLut.size(); ++i) {
775 destLutTextureData[2*i] = destLut[i];
776 destLutTextureData[2*i+1] = ((i + 1) < destLut.size()) ? destLut[i+1] : destLut[i];
778 destLutTextureParam = glGetUniformLocationARB(normalizationPhotometricProgramObject,
"DestLutTexture");
779 glGenTextures(1, &destLutTexture);
780 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, destLutTexture);
781 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
782 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
783 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
784 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
785 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA32F_ARB, destLut.size(), 1, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, destLutTextureData);
793 cout <<
"gpu shader program compile time = " << ((t21 - t1)/1000.0) << endl;
797 glPixelStorei(GL_PACK_ALIGNMENT, 8);
798 glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
800 const float borderColor[] = {0.0, 0.0, 0.0, 0.0};
802 glClearColor(0.0, 0.0, 0.0, 0.0);
804 GLuint framebuffers[5];
805 glGenFramebuffersEXT(5, framebuffers);
806 GLuint srcFB = framebuffers[0];
807 GLuint coordFB = framebuffers[1];
808 GLuint accumFB = framebuffers[2];
809 GLuint destFB = framebuffers[3];
810 GLuint destAlphaFB = framebuffers[4];
812 const int viewportWidth = std::max<int>(destChunks[0].width(), sourceChunks[0].width());
813 const int viewportHeight = std::max<int>(destChunks[0].height(), sourceChunks[0].height());
814 glMatrixMode(GL_PROJECTION);
816 gluOrtho2D(0.0, viewportWidth, 0.0, viewportHeight);
817 glMatrixMode(GL_MODELVIEW);
819 glViewport(0, 0, viewportWidth, viewportHeight);
821 const int destOdd = (destChunks[0].height() & 1);
824 glGenTextures(1, &coordTexture);
825 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, coordTexture);
826 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
827 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
828 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
829 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
830 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB, destChunks[0].width(), destChunks[0].height() + destOdd, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, NULL);
834 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, coordFB);
836 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, coordTexture, 0);
843 GLuint accumTextures[2];
844 glGenTextures(2, accumTextures);
846 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, accumTextures[0]);
847 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
848 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
849 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
850 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
851 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB, destChunks[0].width(), destChunks[0].height() + destOdd, 0, GL_RGBA, GL_FLOAT, NULL);
854 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, accumTextures[1]);
855 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
856 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
857 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
858 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
859 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB, destChunks[0].width(), destChunks[0].height() + destOdd, 0, GL_RGBA, GL_FLOAT, NULL);
863 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, accumFB);
864 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, accumTextures[0], 0);
865 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, accumTextures[1], 0);
871 const int sourceOdd = (sourceChunks[0].height() & 1);
873 glGenTextures(1, &srcTexture);
874 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcTexture);
875 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
876 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
877 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
878 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
879 glTexParameterfv(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_BORDER_COLOR, borderColor);
880 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,
XGLMap[srcGLInternalFormat], sourceChunks[0].width(), sourceChunks[0].height() + sourceOdd, 0,
XGLMap[srcGLFormat],
XGLMap[srcGLType], NULL);
883 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, srcFB);
884 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, srcTexture, 0);
890 GLuint srcAlphaTexture;
891 if (srcAlphaBuffer != NULL) {
893 glGenTextures(1, &srcAlphaTexture);
894 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcAlphaTexture);
895 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
896 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
897 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
898 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
899 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_ALPHA, sourceChunks[0].width(), sourceChunks[0].height() + sourceOdd, 0, GL_ALPHA,
XGLMap[srcAlphaGLType], NULL);
903 GLuint srcTransferTexture;
904 if (srcGLInternalFormat != srcGLTransferFormat) {
907 glGenTextures(1, &srcTransferTexture);
908 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcTransferTexture);
909 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
910 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
911 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
912 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
913 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,
XGLMap[srcGLTransferFormat], sourceChunks[0].width(), sourceChunks[0].height() + sourceOdd, 0,
XGLMap[srcGLFormat],
XGLMap[srcGLType], NULL);
919 if (
XGLMap[destGLTransferFormat] != GL_RGBA32F_ARB) {
923 glGenTextures(1, &destTexture);
924 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, destTexture);
925 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
926 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
927 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
928 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
929 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,
XGLMap[destGLInternalFormat], destChunks[0].width(), destChunks[0].height() + destOdd, 0,
XGLMap[destGLFormat],
XGLMap[destGLType], NULL);
931 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, destFB);
932 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, destTexture, 0);
938 GLuint destAlphaTexture;
939 if (destAlphaBuffer != NULL) {
942 glGenTextures(1, &destAlphaTexture);
943 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, destAlphaTexture);
944 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
945 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
946 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
947 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
948 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, destChunks[0].width(), destChunks[0].height() + destOdd, 0, GL_ALPHA,
XGLMap[destAlphaGLType], NULL);
951 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, destAlphaFB);
952 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, destAlphaTexture, 0);
962 cout <<
"gpu shader texture/framebuffer setup time = " << ((
getms()-t21)/1000.0) << endl;
966 int destChunkNumber = 0;
967 for (vector<Rect2D>::iterator dI = destChunks.begin(); dI != destChunks.end(); ++dI, ++destChunkNumber) {
974 glUseProgramObjectARB(coordXformProgramObject);
975 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, coordFB);
976 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
978 glPolygonMode(GL_FRONT, GL_FILL);
980 glTexCoord2f(xstart + dI->left(), ystart + dI->top()); glVertex2f(0.0, 0.0);
981 glTexCoord2f(xstart + dI->right(), ystart + dI->top()); glVertex2f(dI->width(), 0.0);
982 glTexCoord2f(xstart + dI->right(), ystart + dI->bottom()); glVertex2f(dI->width(), dI->height());
983 glTexCoord2f(xstart + dI->left(), ystart + dI->bottom()); glVertex2f(0.0, dI->height());
991 cout <<
"gpu dest chunk=" << *dI <<
" coord image render time = " << ((t4-t3)/1000.0) << endl;
996 for (vector<Rect2D>::iterator sI = sourceChunks.begin(); sI != sourceChunks.end(); ++sI) {
998 if (destChunkNumber == 0 || sourceChunks.size() > 1) {
1003 glPixelStorei(GL_UNPACK_ROW_LENGTH, srcSize.x);
1004 glPixelStorei(GL_UNPACK_SKIP_PIXELS, sI->left());
1005 glPixelStorei(GL_UNPACK_SKIP_ROWS, sI->top());
1008 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, srcFB);
1009 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
1010 glClear(GL_COLOR_BUFFER_BIT);
1012 if (srcGLInternalFormat == srcGLTransferFormat) {
1014 glActiveTexture(GL_TEXTURE0);
1015 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcTexture);
1016 glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, sI->width(), sI->height(),
XGLMap[srcGLFormat],
XGLMap[srcGLType], srcBuffer);
1023 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" src upload = " << ((t6-t5)/1000.0) << endl;
1026 if (srcAlphaBuffer != NULL) {
1028 glUseProgramObjectARB(alphaCompositeProgramObject);
1030 glActiveTexture(GL_TEXTURE0);
1031 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcAlphaTexture);
1032 glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, sI->width(), sI->height(), GL_ALPHA, XGLMap[srcAlphaGLType], srcAlphaBuffer);
1033 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1034 glUniform1iARB(srcAlphaTextureParam, 0);
1041 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" src alpha upload = " << ((t7-t6)/1000.0) << endl;
1044 glPolygonMode(GL_FRONT, GL_FILL);
1046 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
1047 glTexCoord2f(sI->width(), 0.0); glVertex2f(sI->width(), 0.0);
1048 glTexCoord2f(sI->width(), sI->height()); glVertex2f(sI->width(), sI->height());
1049 glTexCoord2f(0.0, sI->height()); glVertex2f(0.0, sI->height());
1056 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" src+alpha render = " << ((
getms()-t7)/1000.0) << endl;
1062 glUseProgramObjectARB(0);
1065 glActiveTexture(GL_TEXTURE0);
1066 glEnable(GL_TEXTURE_RECTANGLE_ARB);
1067 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcTransferTexture);
1068 glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, sI->width(), sI->height(),
XGLMap[srcGLFormat],
XGLMap[srcGLType], srcBuffer);
1069 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1076 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" src upload = " << ((t6-t5)/1000.0) << endl;
1079 if (srcAlphaBuffer != NULL) {
1081 glActiveTexture(GL_TEXTURE1);
1082 glEnable(GL_TEXTURE_RECTANGLE_ARB);
1083 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcAlphaTexture);
1084 glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, sI->width(), sI->height(), GL_ALPHA, XGLMap[srcAlphaGLType], srcAlphaBuffer);
1085 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1092 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" src alpha upload = " << ((t7- t6)/1000.0) << endl;
1095 glPolygonMode(GL_FRONT, GL_FILL);
1097 glMultiTexCoord2f(GL_TEXTURE0, 0.0, 0.0); glMultiTexCoord2f(GL_TEXTURE1, 0.0, 0.0); glVertex2f(0.0, 0.0);
1098 glMultiTexCoord2f(GL_TEXTURE0, sI->width(), 0.0); glMultiTexCoord2f(GL_TEXTURE1, sI->width(), 0.0); glVertex2f(sI->width(), 0.0);
1099 glMultiTexCoord2f(GL_TEXTURE0, sI->width(), sI->height()); glMultiTexCoord2f(GL_TEXTURE1, sI->width(), sI->height()); glVertex2f(sI->width(), sI->height());
1100 glMultiTexCoord2f(GL_TEXTURE0, 0.0, sI->height()); glMultiTexCoord2f(GL_TEXTURE1, 0.0, sI->height()); glVertex2f(0.0, sI->height());
1104 glActiveTexture(GL_TEXTURE0);
1105 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1106 glActiveTexture(GL_TEXTURE1);
1107 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1113 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" src+alpha render = " << ((
getms()-t7)/1000.0) << endl;
1117 glPolygonMode(GL_FRONT, GL_FILL);
1122 glColor4f(0.0, 0.0, 0.0, 1.0);
1123 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
1124 glTexCoord2f(sI->width(), 0.0); glVertex2f(sI->width(), 0.0);
1125 glTexCoord2f(sI->width(), sI->height()); glVertex2f(sI->width(), sI->height());
1126 glTexCoord2f(0.0, sI->height()); glVertex2f(0.0, sI->height());
1130 glActiveTexture(GL_TEXTURE0);
1131 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1138 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" src render = " << ((t7-t6)/1000.0) << endl;
1149 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, accumFB);
1150 glUseProgramObjectARB(interpolatorProgramObject);
1154 glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
1155 glClear(GL_COLOR_BUFFER_BIT);
1158 glUniform2fARB(srcULParam, sI->left(), sI->top());
1160 glUniform2fARB(srcLRParam, sI->right(), sI->bottom());
1163 glActiveTexture(GL_TEXTURE0);
1164 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, coordTexture);
1165 glUniform1iARB(coordTextureParam, 0);
1166 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1169 glActiveTexture(GL_TEXTURE1);
1170 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcTexture);
1171 glUniform1iARB(srcTextureParam, 1);
1172 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1175 glActiveTexture(GL_TEXTURE2);
1176 glUniform1iARB(accumTextureParam, 2);
1177 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1181 for (vector<Rect2D>::iterator iI = interpolatorChunks.begin(); iI != interpolatorChunks.end(); ++iI, ++pass) {
1182 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, (pass & 1) ? accumTextures[0] : accumTextures[1]);
1185 glUniform2fARB(kernelULParam, iI->left(), iI->top());
1187 glUniform2fARB(kernelWHParam, iI->width(), iI->height());
1190 glDrawBuffer((pass & 1) ? GL_COLOR_ATTACHMENT1_EXT : GL_COLOR_ATTACHMENT0_EXT);
1196 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" interpolation chunk=" << *iI <<
" setup = " << ((t10-t9)/1000.0) << endl;
1199 glPolygonMode(GL_FRONT, GL_FILL);
1201 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
1202 glTexCoord2f(dI->width(), 0.0); glVertex2f(dI->width(), 0.0);
1203 glTexCoord2f(dI->width(), dI->height()); glVertex2f(dI->width(), dI->height());
1204 glTexCoord2f(0.0, dI->height()); glVertex2f(0.0, dI->height());
1213 cout <<
"gpu dest chunk=" << *dI <<
" source chunk=" << *sI <<
" interpolation chunk=" << *iI <<
" render = " << ((t11-t10)/1000.0) << endl;
1221 glUseProgramObjectARB(normalizationPhotometricProgramObject);
1223 glActiveTexture(GL_TEXTURE0);
1224 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, (pass & 1) ? accumTextures[0] : accumTextures[1]);
1225 glUniform1iARB(normTextureParam, 0);
1226 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1229 glActiveTexture(GL_TEXTURE1);
1230 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, coordTexture);
1231 glUniform1iARB(normCoordTextureParam, 1);
1232 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1235 if (!invLut.empty()) {
1236 glActiveTexture(GL_TEXTURE2);
1237 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, invLutTexture);
1238 glUniform1iARB(invLutTextureParam, 2);
1239 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1243 if (!destLut.empty()) {
1244 glActiveTexture(GL_TEXTURE3);
1245 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, destLutTexture);
1246 glUniform1iARB(destLutTextureParam, 3);
1247 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1251 glDrawBuffer((pass & 1) ? GL_COLOR_ATTACHMENT1_EXT : GL_COLOR_ATTACHMENT0_EXT);
1257 cout <<
"gpu dest chunk=" << *dI <<
" normalization setup = " << ((t12-t11)/1000.0) << endl;
1260 glPolygonMode(GL_FRONT, GL_FILL);
1262 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
1263 glTexCoord2f(dI->width(), 0.0); glVertex2f(dI->width(), 0.0);
1264 glTexCoord2f(dI->width(), dI->height()); glVertex2f(dI->width(), dI->height());
1265 glTexCoord2f(0.0, dI->height()); glVertex2f(0.0, dI->height());
1273 cout <<
"gpu dest chunk=" << *dI <<
" normalization render = " << ((t13-t12)/1000.0) << endl;
1280 glPixelStorei(GL_PACK_ROW_LENGTH, destSize.x);
1281 glPixelStorei(GL_PACK_SKIP_PIXELS, dI->left());
1282 glPixelStorei(GL_PACK_SKIP_ROWS, dI->top());
1284 if (
XGLMap[destGLTransferFormat] == GL_RGBA32F_ARB) {
1286 glReadBuffer((pass & 1) ? GL_COLOR_ATTACHMENT0_EXT : GL_COLOR_ATTACHMENT1_EXT);
1288 glReadPixels(0, 0, dI->width(), dI->height(),
XGLMap[destGLFormat],
XGLMap[destGLType], destBuffer);
1295 cout <<
"gpu dest chunk=" << *dI <<
" rgb readback = " << ((t14-t13)/1000.0) << endl;
1300 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
1301 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, destFB);
1302 glUseProgramObjectARB(0);
1304 glActiveTexture(GL_TEXTURE0);
1305 glEnable(GL_TEXTURE_RECTANGLE_ARB);
1306 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, (pass & 1) ? accumTextures[0] : accumTextures[1]);
1307 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1314 cout <<
"gpu dest chunk=" << *dI <<
" dest rgb disassembly setup = " << ((t14-t13)/1000.0) << endl;
1317 glPolygonMode(GL_FRONT, GL_FILL);
1319 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
1320 glTexCoord2f(dI->width(), 0.0); glVertex2f(dI->width(), 0.0);
1321 glTexCoord2f(dI->width(), dI->height()); glVertex2f(dI->width(), dI->height());
1322 glTexCoord2f(0.0, dI->height()); glVertex2f(0.0, dI->height());
1326 glActiveTexture(GL_TEXTURE0);
1327 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1334 cout <<
"gpu dest chunk=" << *dI <<
" dest rgb disassembly render = " << ((t15-t14)/1000.0) << endl;
1337 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
1340 glReadPixels(0, 0, dI->width(), dI->height(),
XGLMap[destGLFormat],
XGLMap[destGLType], destBuffer);
1347 cout <<
"gpu dest chunk=" << *dI <<
" rgb readback = " << ((t16-t15)/1000.0) << endl;
1351 if (destAlphaBuffer != NULL) {
1353 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, destAlphaFB);
1354 glUseProgramObjectARB(0);
1356 glActiveTexture(GL_TEXTURE0);
1357 glEnable(GL_TEXTURE_RECTANGLE_ARB);
1358 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, (pass & 1) ? accumTextures[0] : accumTextures[1]);
1359 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1366 cout <<
"gpu dest chunk=" << *dI <<
" dest alpha disassembly setup = " << ((t17-t16)/1000.0) << endl;
1369 glPolygonMode(GL_FRONT, GL_FILL);
1371 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
1372 glTexCoord2f(dI->width(), 0.0); glVertex2f(dI->width(), 0.0);
1373 glTexCoord2f(dI->width(), dI->height()); glVertex2f(dI->width(), dI->height());
1374 glTexCoord2f(0.0, dI->height()); glVertex2f(0.0, dI->height());
1378 glActiveTexture(GL_TEXTURE0);
1379 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1386 cout <<
"gpu dest chunk=" << *dI <<
" dest alpha disassembly render = " << ((t18-t17)/1000.0) << endl;
1390 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
1393 glReadPixels(0, 0, dI->width(), dI->height(), GL_ALPHA,
XGLMap[destAlphaGLType], destAlphaBuffer);
1400 cout <<
"gpu dest chunk=" << *dI <<
" alpha readback = " << ((t19-t18)/1000.0) << endl;
1410 glDeleteTextures(2, accumTextures);
1411 glDeleteTextures(1, &coordTexture);
1412 glDeleteTextures(1, &srcTexture);
1413 glDeleteTextures(1, &srcAlphaTexture);
1414 glDeleteTextures(1, &srcTransferTexture);
1415 glDeleteTextures(1, &destTexture);
1416 glDeleteTextures(1, &destAlphaTexture);
1418 if (!invLut.empty()) {
1419 glDeleteTextures(1, &invLutTexture);
1420 delete [] invLutTextureData;
1423 if (!destLut.empty()) {
1424 glDeleteTextures(1, &destLutTexture);
1425 delete [] destLutTextureData;
1428 glDeleteFramebuffersEXT(5, framebuffers);
1430 glUseProgramObjectARB(0);
1431 glDeleteObjectARB(coordXformShaderObject);
1432 glDeleteObjectARB(coordXformProgramObject);
1433 glDeleteObjectARB(interpolatorShaderObject);
1434 glDeleteObjectARB(interpolatorProgramObject);
1435 glDeleteObjectARB(normalizationPhotometricShaderObject);
1436 glDeleteObjectARB(normalizationPhotometricProgramObject);
1438 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1439 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1440 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1446 cout <<
"gpu destruct time = " << ((t20-t19)/1000.0) << endl;
1447 cout <<
"gpu total time = " << ((t20-t1)/1000.0) << endl;
void SetGPUDebugMessages(const bool doPrint)
bool transformImageGPUIntern(const std::string &coordXformGLSL, const std::string &interpolatorGLSL, const int interpolatorSize, const std::string &photometricGLSL, const vector< double > &invLut, const vector< double > &destLut, const vigra::Diff2D srcSize, const void *const srcBuffer, const int srcGLInternalFormat, const int srcGLTransferFormat, const int srcGLFormat, const int srcGLType, const void *const srcAlphaBuffer, const int srcAlphaGLType, const vigra::Diff2D destUL, const vigra::Diff2D destSize, void *const destBuffer, const int destGLInternalFormat, const int destGLTransferFormat, const int destGLFormat, const int destGLType, void *const destAlphaBuffer, const int destAlphaGLType, const bool warparound)