void Opcode::Register(Context *context) // ---------------------------------------------------------------------------- // If the opcode defines a shape, enter that shape in symbol table // ---------------------------------------------------------------------------- { if (Tree *shape = this->Shape()) { IFTRACE(opcodes) std::cerr << "Opcode " << this->OpID() << " for " << shape << "\n"; Save<TreePosition> savePos(Tree::NOWHERE, Tree::BUILTIN); static Name_p opcodeName = new Name("opcode"); Infix *decl = new Infix("->", shape, new Prefix(opcodeName, new Name(this->OpID()))); context->Enter(decl); decl->right->SetInfo<Opcode> (this); } else { IFTRACE(opcodes) std::cerr << "Opcode " << this->OpID() << "\n"; } }
void UpdateApplication::check(bool show) // ---------------------------------------------------------------------------- // Check for update // ---------------------------------------------------------------------------- { // This method starts the "check for update" algorithm which is // asynchronous. // If 'show' is true, a progress dialog may be shown during the check, and // a dialog is shown at the end to tell if update is available or not. // If 'show' is false, no interaction with the user occurs // until the algorithm detects that an update is available. RECORD(ALWAYS, "Check for update"); IFTRACE(update) debug() << "Checking for update (interactive: " << show << ")\n"; this->show = show; if (show && state != Idle) { // Already running. Just show the progress dialog. progress->show(); return; } if (edition.isEmpty()) { showNoUpdateAvailable(); return; } if (!manager) manager = new QNetworkAccessManager(); progress->setLabelText(tr("Checking for update")); if (show) progress->show(); // The URL where to get update information from. Redirects to a .ini file. #ifdef CFG_LIBRE_EDITION QUrl url("http://www.taodyne.com/taopresentations/2.0/update"); #else QUrl url("http://www.taodyne.com/taopresentations/2.0-libre/update"); #endif IFTRACE(update) debug() << "Downloading: '" << +url.toString() << "'\n"; state = WaitingForUpdate; // Create and send HTTP request request.setUrl(url); reply = manager->get(request); connectSignals(reply); }
Tree *FontParsingAction::DoText(Text *what) // ---------------------------------------------------------------------------- // Text specifies a font family (optionally a foundry) // ---------------------------------------------------------------------------- // We keep the first family that leads to an exact match { if (!exactMatch) { text family, style; text desc = what->value; IFTRACE(fontparsing) std::cerr << "Parsing font description: '" << desc << "'\n"; size_t slash = desc.find('/'); if (slash != std::string::npos) { // Parse string as "family/style" family = desc.substr(0, slash); style = desc.substr(slash + 1, std::string::npos); int size = font.pointSize(); IFTRACE(fontparsing) std::cerr << " Requesting font: family='" << family << "' style='" << style << "' size=" << size << "\n"; font = QFontDatabase().font(+family, +style, size); } else { // Font workaround for QTBUG-736 (apparently still not fixed in 4.6) // http://bugreports.qt.nokia.com/browse/QTBUG-736 family = what->value; if (family == "Times") family = "Times New Roman"; IFTRACE(fontparsing) std::cerr << " Requesting font: family='" << family << "'\n"; font.setFamily(+family); } QPair<QString, QString> key(+family, +style); if (!exactMatchCache.contains(key)) { exactMatchCache[key] = font.exactMatch(); IFTRACE(fontparsing) std::cerr << " Caching exact match flag\n"; } exactMatch = exactMatchCache[key]; IFTRACE(fontparsing) { std::cerr << " Returned font: family='" << +font.family() #if QT_VERSION > 0x040800 << "' style='" << +font.styleName() #endif << "' size=" << font.pointSize() << "\n" << " Exact match: " << exactMatch << "\n"; } }
void PointCloudVBO::delBuffers() // ---------------------------------------------------------------------------- // Release VBO(s) // ---------------------------------------------------------------------------- { IFTRACE(pointcloud) debug() << "Releasing VBO #" << vbo << "\n"; GL.DeleteBuffers(1, &vbo); if (colorVbo) { IFTRACE(pointcloud) debug() << "Releasing VBO #" << colorVbo << "\n"; GL.DeleteBuffers(1, &colorVbo); } }
void PointCloudVBO::checkGLContext() // ---------------------------------------------------------------------------- // Do what's needed if GL context has changed // ---------------------------------------------------------------------------- { if (QGLContext::currentContext() != context) { IFTRACE(pointcloud) debug() << "GL context changed\n"; // Re-create VBO(s) genPointBuffer(); if (colored()) genColorBuffer(); if (optimized) { IFTRACE(pointcloud) debug() << "GL context changed on optimized cloud\n"; XL_ASSERT(file != "" || nbRandom != 0); if (file != "") { IFTRACE(pointcloud) debug() << "Reloading file\n"; text f = file; clear(); loadData(f, sep, xi, yi, zi, colorScale, ri, gi, bi, ai); } else if (nbRandom != 0) { IFTRACE(pointcloud) debug() << "Re-creating random points\n"; unsigned n = nbRandom; clear(); randomPoints(n, coloredRandom); } optimized = false; XL_ASSERT(!dirty); } else updateVbo(); context = QGLContext::currentContext(); } }
void UpdateApplication::startDownload() // ---------------------------------------------------------------------------- // Start downloading the URL of the Tao file // ---------------------------------------------------------------------------- { IFTRACE(update) debug() << "Downloading: '" << +url.toString() << "'\n"; XL_ASSERT(!reply); XL_ASSERT(!url.isEmpty()); progress->setLabelText(tr("Downloading %1 %2...").arg(appName()) .arg(remoteVer())); progress->show(); state = Downloading; downloadTime.start(); request.setUrl(url); reply = manager->get(request); connect(reply, SIGNAL(metaDataChanged()), this, SLOT(processReply())); connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished())); connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64))); }
void Marble::Draw() // ---------------------------------------------------------------------------- // Apply marble material // ---------------------------------------------------------------------------- { checkGLContext(); uint prg_id = 0; if(pgm) prg_id = pgm->programId(); if(prg_id) { IFTRACE(materials) debug() << "Apply marble material" << "\n"; // Set shader tao->SetShader(prg_id); // Set uniform values GL.Uniform(uniforms["noiseMap"], unit); GL.Uniform(uniforms["scale"], scale); GL.Uniform3fv(uniforms["first_color"], 1, first_color); GL.Uniform3fv(uniforms["second_color"], 1, second_color); GL.Uniform(uniforms["unit"], (GL.ActiveTextureUnitIndex() - GL_TEXTURE0)); if(tao->isGLExtensionAvailable("GL_EXT_gpu_shader4")) { GLint lightsmask = GL.LightsMask(); GL.Uniform(uniforms["lights"], lightsmask); } } }
Activity *MouseFocusTracker::Click(uint /*button*/, uint /*count*/, int x, int y) // ---------------------------------------------------------------------------- // Track focus when mouse click // ---------------------------------------------------------------------------- { uint current = ObjectAtPoint(x, widget->height() - y); IFTRACE(widgets) std::cerr << "MouseFocusTracker::Click Focus " << current << std::endl; if (current != previous) { if (current > 0) { // Forward 'focus-in' to current item widget->focusId = current; } else if (previous > 0) { // Forward 'focus-out' to previous item widget->focusId = 0; } widget->updateGL(); } previous = current; return next; }
void PointCloudVBO::genPointBuffer() // ---------------------------------------------------------------------------- // Allocate new VBO for point coordinates // ---------------------------------------------------------------------------- { GL.GenBuffers(1, &vbo); IFTRACE(pointcloud) debug() << "Allocated VBO #" << vbo << " for point coordinates\n"; }
PreviewThread::~PreviewThread() // ---------------------------------------------------------------------------- // Stop the monitor thread // ---------------------------------------------------------------------------- { IFTRACE(preview) debug() << "Stopping\n"; quit(); wait(100); }
void UndoCommand::undo() // ---------------------------------------------------------------------------- // Reverts a change to the document. // ---------------------------------------------------------------------------- { IFTRACE(undo) std::cerr << "Undo " << +id << " " << +text() << "\n"; if (repo) repo->revert(+id); }
void PointCloudVBO::genColorBuffer() // ---------------------------------------------------------------------------- // Allocate new VBO for colors // ---------------------------------------------------------------------------- { XL_ASSERT(colored()); GL.GenBuffers(1, &colorVbo); IFTRACE(pointcloud) debug() << "Allocated VBO #" << colorVbo << " for colors\n"; }
UpdateApplication::~UpdateApplication() // ---------------------------------------------------------------------------- // Destructor // ---------------------------------------------------------------------------- { IFTRACE(update) debug() << "Destructor\n"; // FIXME crash on MacOSX // delete progress; }
Marble::Marble(uint unit, float scale) // ---------------------------------------------------------------------------- // Construction // ---------------------------------------------------------------------------- : Material(&context), unit(unit), scale(scale) { IFTRACE(materials) debug() << "Create marble material" << "\n"; checkGLContext(); }
void UpdateApplication::networkError(QNetworkReply::NetworkError err) // ---------------------------------------------------------------------------- // Handle network error // ---------------------------------------------------------------------------- { IFTRACE(update) debug() << "Network error " << err << ": " << +reply->errorString() << "\n"; state = (state == WaitingForUpdate) ? NetworkErrorCheck : NetworkErrorDownload; }
void PointCloudVBO::updateVbo() // ---------------------------------------------------------------------------- // Take into account a change in point data // ---------------------------------------------------------------------------- { XL_ASSERT(!optimized); if (QThread::currentThread() != qApp->thread()) { // OpenGL functions may be called only from the main thread, which // owns the GL context IFTRACE(pointcloud) debug() << "Not updating VBO (not main thread)\n"; return; } IFTRACE(pointcloud) debug() << "Updating VBO #" << vbo << " (" << size() << " points)\n"; GL.BindBuffer(GL_ARRAY_BUFFER, vbo); GL.BufferData(GL_ARRAY_BUFFER, size()*sizeof(Point), &points[0].x, GL_STATIC_DRAW); GL.BindBuffer(GL_ARRAY_BUFFER, 0); if (colored()) { if (colorVbo == 0) genColorBuffer(); IFTRACE(pointcloud) debug() << "Updating VBO #" << colorVbo << " (" << size() << " colors)\n"; GL.BindBuffer(GL_ARRAY_BUFFER, colorVbo); GL.BufferData(GL_ARRAY_BUFFER, size()*sizeof(Color), &colors[0].r, GL_STATIC_DRAW); GL.BindBuffer(GL_ARRAY_BUFFER, 0); } dirty = false; }
void Shading::checkGLContext() // ---------------------------------------------------------------------------- // Re-create context-dependent resources if GL context has changed // ---------------------------------------------------------------------------- { tao->makeGLContextCurrent(); if (*pcontext != QGLContext::currentContext()) { IFTRACE(shading) debug() << "Context has changed" << "\n"; *pcontext = QGLContext::currentContext(); createShaders(); } }
int main(int argc, char **argv) // ---------------------------------------------------------------------------- // Parse the command line and run the compiler phases // ---------------------------------------------------------------------------- { #if CONFIG_USE_SBRK char *low_water = (char *) sbrk(0); #endif text cmd, end = ""; // Make sure debug function is linked in... debug(NULL); // Initialize basic XL syntax from syntax description file ReadContext("xl.syntax", gContext); // Initialize the C translator XLInitCTrans(); for (cmd = gOptions.Parse(argc, argv); cmd != end; cmd = gOptions.ParseNext()) { XLParser parser (cmd.c_str(), &gContext); XLTree *tree = parser.Parse(); IFTRACE(source) { std::cout << *tree << "\n"; } IFTRACE(parse) { XLTree::outputDebug = true; std::cout << *tree << "\n"; } XL2C(tree); } #if CONFIG_USE_SBRK IFTRACE(timing) fprintf(stderr, "Total memory usage: %ldK\n", long ((char *) malloc(1) - low_water) / 1024); #endif return 0; }
void NameOpcode::Register(Context *context) // ---------------------------------------------------------------------------- // For name rewrites, create the name, assign to variable, enter it // ---------------------------------------------------------------------------- { IFTRACE(opcodes) std::cerr << "Opcode " << this->OpID() << " is a name\n"; context->Define(toDefine, toDefine); toDefine->SetInfo<Opcode> (this); #ifndef INTERPRETER_ONLY if (MAIN->options.optimize_level > 1) MAIN->compiler->EnterGlobal(toDefine, &toDefine); #endif }
Activity *MouseFocusTracker::MouseMove(int x, int y, bool active) // ---------------------------------------------------------------------------- // Track focus as mouse moves // ---------------------------------------------------------------------------- { if (active) return next; IFTRACE(widgets) std::cerr << "MouseFocusTracker::MouseMove " << x << ", " << y << std::endl; uint current = ObjectAtPoint(x, widget->height() - y); widget->shapeAction("mouseover", current, x, y); previous = current; return next; }
void UndoCommand::redo() // ---------------------------------------------------------------------------- // Applies a change to the document. // ---------------------------------------------------------------------------- { if (firstRedo) { // Kludge: The action was already applied when UndoCommand object is // created. Since Qt always calls redo() when the command is pushed // onto the undo stack, we just ignore the first invocation. firstRedo = false; return; } IFTRACE(undo) std::cerr << "Redo " << +id << " " << +text() << "\n"; if (repo) repo->cherryPick(+id); }
UpdateApplication::UpdateApplication() // ---------------------------------------------------------------------------- // Constructor // ---------------------------------------------------------------------------- : state(Idle), file(NULL), progress(NULL), dialogTitle(QString(tr("Tao3D Update"))), downloadIcon(loadIcon(":/images/download.png")), checkmarkIcon(loadIcon(":images/checkmark.png")), connectionErrorIcon(loadIcon(":/images/not_connected.png")), reply(NULL), manager(NULL), code(-1) { // download.png from http://www.iconfinder.com/icondetails/2085/128 // Author: Alexandre Moore // License: LGPL // // checkmark.png from http://www.iconfinder.com/icondetails/3207/128 // Author: Everaldo Coelho // License: LGPL // not_connected.png is a merge from: // // - Red cross from http://www.iconfinder.com/icondetails/3206/128 // Author: Everaldo Coelho // License: LGPL // - Earth from http://www.iconfinder.com/icondetails/17829/128 // Author: Everaldo Coelho // License: LGPL resetRequest(); progress = new QProgressDialog(TaoApp->windowWidget()); progress->setFixedSize(500, 100); connect(progress, SIGNAL(canceled()), this, SLOT(cancel())); progress->setWindowTitle(dialogTitle); IFTRACE(update) debug() << "Current version: edition='" << +edition << "' version=" << version << " target='" << +target << "'" << " User-Agent='" << +userAgent() << "'\n"; }
bool PointCloudVBO::optimize() // ---------------------------------------------------------------------------- // Optimize point cloud data // ---------------------------------------------------------------------------- { if (optimized || dontOptimize()) return optimized; if (useVbo()) { if (dirty) updateVbo(); nbPoints = points.size(); points.clear(); optimized = true; IFTRACE(pointcloud) debug() << "Cloud optimized\n"; } return true; }
void UpdateApplication::processReply() // ---------------------------------------------------------------------------- // Called as we receive new headers // ---------------------------------------------------------------------------- { // Hande redirections code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (code >= 300 && code < 400) { // Get redirect URL url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if (!url.isValid()) { // Not yet received return; } // In case URL is relative url = reply->url().resolved(url); IFTRACE(update) debug() << "Redirected to: '" << +url.toString() << "'\n"; request.setUrl(url); reply->deleteLater(); reply = manager->get(request); connect(reply, SIGNAL(metaDataChanged()), this, SLOT(processReply())); connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished())); connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64))); } else if (code == 200 && state == Downloading) { if (!createFile()) { progress->hide(); cancel(); } } }
PreviewThread::PreviewThread(uint timeInterval, uint maxWidth, uint maxHeight) // ---------------------------------------------------------------------------- // Start preview-save thread by saving // ---------------------------------------------------------------------------- : mutex(), path(), image(), nextSave(), timeInterval(timeInterval), maxWidth(maxWidth), maxHeight(maxHeight) { IFTRACE(preview) debug() << "Starting preview thread (" << timeInterval << " ms)\n"; // Ready the thread to receive events moveToThread(this); connect(this, SIGNAL(imageAvailable()), this, SLOT(savePreview())); // Configure the timer nextSave.setSingleShot(true); nextSave.setInterval(timeInterval); connect(&nextSave, SIGNAL(timeout()), this, SLOT(savePreview())); start(); // Wait until a preview is posted to save }
void UpdateApplication::cancel() // ---------------------------------------------------------------------------- // Cancel check for update or download // ---------------------------------------------------------------------------- { IFTRACE(update) debug() << "Cancel\n"; if (file) { file->remove(); delete file; file = NULL; } state = Idle; if (reply) { reply->abort(); reply->deleteLater(); reply = NULL; } resetRequest(); }
void Marble::createShaders() // ---------------------------------------------------------------------------- // Create shader programs // ---------------------------------------------------------------------------- { if(!failed) { delete pgm; IFTRACE(materials) debug() << "Create marble shader" << "\n"; pgm = new QGLShaderProgram(*pcontext); bool ok = false; // Basic vertex shader static string vSrc = "/********************************************************************************\n" "** \n" "** Copyright (C) 2011 Taodyne. \n" "** All rights reserved. \n" "** Contact: Taodyne ([email protected]) \n" "** \n" "** This file is part of the Tao3D application, developped by Taodyne.\n" "** It can be only used in the software and these modules. \n" "** \n" "** If you have questions regarding the use of this file, please contact \n" "** Taodyne at [email protected]. \n" "** \n" "********************************************************************************/\n" "varying vec3 viewDir;" "varying vec3 normal;" "uniform int unit;" "uniform float scale;" "void main()" "{" " /* Compute position */" " gl_Position = ftransform();" " /* Compute texture coordinates */" " if(unit == 0)" " gl_TexCoord[0] = (scale * gl_TextureMatrix[0] * gl_MultiTexCoord0);" " else if(unit == 1)" " gl_TexCoord[0] = (scale * gl_TextureMatrix[1] * gl_MultiTexCoord1);" " else if(unit == 2)" " gl_TexCoord[0] = (scale * gl_TextureMatrix[2] * gl_MultiTexCoord2);" " else if(unit == 3)" " gl_TexCoord[0] = (scale * gl_TextureMatrix[3] * gl_MultiTexCoord3);" " /* Compute world position and normal */" " normal = gl_NormalMatrix * gl_Normal;" " viewDir = -vec3(gl_ModelViewMatrix * gl_Vertex);" "}"; static string fSrc; if(tao->isGLExtensionAvailable("GL_EXT_gpu_shader4")) { // If the extension is available, use this fragment shader // to handle multiple lights fSrc = "/********************************************************************************\n" "** \n" "** Copyright (C) 2011 Taodyne. \n" "** All rights reserved. \n" "** Contact: Taodyne ([email protected]) \n" "** \n" "** This file is part of the Tao3D application, developped by Taodyne.\n" "** It can be only used in the software and these modules. \n" "** \n" "** If you have questions regarding the use of this file, please contact \n" "** Taodyne at [email protected]. \n" "** \n" "********************************************************************************/\n" "#extension GL_EXT_gpu_shader4 : require\n" "uniform vec3 first_color;" "uniform vec3 second_color;" "uniform sampler3D noiseMap;" "uniform int lights;" "uniform int unit;" "varying vec3 viewDir;" "varying vec3 normal;" "/**" "* Compute render color according to materials," "* lights and colors parameters which are" "* set in the current scene." "**/" "vec4 computeRenderColor(vec4 renderColor)" "{" " vec4 lighting_color;" " vec3 N = normalize(normal);" " vec3 V = normalize(viewDir);" " vec4 ambient = vec4(0.0);" " vec4 diffuse = vec4(0.0);" " vec4 specular = vec4(0.0);" " if(lights > 0)" " {" " /* Define a maximum of lights supported*/" " int MAX_LIGHTS = 8;" " /* Get current scene color */" " ambient = gl_FrontLightModelProduct.sceneColor;" " /* Compute render for each enabled lights */" " for(int i = 0; i < MAX_LIGHTS; i++)" " {" " if(bool(lights & (1 << i)))" " {" " vec3 L = normalize(gl_LightSource[i].position.xyz);" " /* Compute ambient part */" " ambient += gl_LightSource[i].ambient;" " /* Diffuse coefficient */" " float nDotL = max(clamp(dot(L, N), 0.0, 1.0), 0.0);" " if (nDotL > 0.0)" " {" " /* Compute diffuse part */" " diffuse += gl_LightSource[i].diffuse * nDotL;" " /* Compute specular coefficient */" " float nDotV = clamp(dot(reflect(-L, N), V), 0.0, 1.0);" " if (nDotV > 0.0)" " {" " /* Compute specular part */" " specular += gl_LightSource[i].specular * pow(nDotV, 76.8);" " }" " }" " }" " }" " /* Define new render color */" " lighting_color = (ambient + diffuse) * renderColor + specular;" " }" " else" " {" " /* Get current scene color */" " ambient = gl_FrontLightModelProduct.sceneColor;" " vec3 L = normalize(vec3(0.0, 0.0, 50.0));" " /* Compute ambient part */" " ambient += vec4(0.0, 0.0, 0.0, 1.0);" " /* Diffuse coefficient */" " float nDotL = max(clamp(dot(L, N), 0.0, 1.0), 0.0);" " if (nDotL > 0.0)" " {" // Compute diffuse part " diffuse += 0.5 * vec4(1.0, 1.0, 1.0, 1.0) * nDotL;" // Compute specular coefficient " float nDotV = clamp(dot(reflect(-L, N), V), 0.0, 1.0);" " if (nDotV > 0.0)" " {" " /* Compute specular part */" " specular += 0.4 * vec4(1.0, 1.0, 1.0, 1.0) * pow(nDotV, 76.8);" " }" " }" " /* Define new render color */" " lighting_color = (ambient + diffuse) * renderColor + specular;" " }" " return lighting_color;" "}" "void main()" "{" " float scaling = 1.0;" " float turbulence = 0.0;" " vec3 texCoord = vec3(0.0);" " /* Use 5 octaves for a better result */" " for (int i = 0; i < 5; i++)" " {" " texCoord = (0.15 / scaling) * gl_TexCoord[0].xyz;" " turbulence += scaling * (texture3D(noiseMap, texCoord).z - 0.5);" " scaling *= 0.4;" " }" " /* Compute ratio according to turbulence */" " float ratio = exp(-5.0 * abs(turbulence));" " /* Compute final color */" " vec3 mainColor = mix(first_color, second_color, ratio);" " gl_FragColor = computeRenderColor(vec4(mainColor, 1.0));" "}"; } else { // If the extension is not available, use this fragment shader // to handle an unique light. fSrc = "/********************************************************************************\n" "** \n" "** Copyright (C) 2011 Taodyne. \n" "** All rights reserved. \n" "** Contact: Taodyne ([email protected]) \n" "** \n" "** This file is part of the Tao3D application, developped by Taodyne.\n" "** It can be only used in the software and these modules. \n" "** \n" "** If you have questions regarding the use of this file, please contact \n" "** Taodyne at [email protected]. \n" "** \n" "********************************************************************************/\n" "uniform vec3 first_color;" "uniform vec3 second_color;" "uniform vec3 third_color;" "uniform sampler3D noiseMap;" "uniform int unit;" "varying vec3 viewDir;" "varying vec3 normal;" "/**" "* Compute render color according to an unique" "* light and material." "**/" "vec4 computeRenderColor(vec4 renderColor)" "{" " vec4 lighting_color;" " vec3 N = normalize(normal);" " vec3 V = normalize(viewDir);" " vec4 ambient = vec4(0.0);" " vec4 diffuse = vec4(0.0);" " vec4 specular = vec4(0.0);" " /* Get current scene color */" " ambient = gl_FrontLightModelProduct.sceneColor;" " vec3 L = normalize(vec3(0.0, 0.0, 50.0));" " /* Compute ambient part */" " ambient += vec4(0.0, 0.0, 0.0, 1.0);" " /* Diffuse coefficient */" " float nDotL = max(clamp(dot(L, N), 0.0, 1.0), 0.0);" " if (nDotL > 0.0)" " {" " /* Compute diffuse part */" " diffuse += 0.5 * vec4(1.0, 1.0, 1.0, 1.0) * nDotL;" " /* Compute specular coefficient */" " float nDotV = clamp(dot(reflect(-L, N), V), 0.0, 1.0);" " if (nDotV > 0.0)" " {" " /* Compute specular part */" " specular += 0.4 * vec4(1.0, 1.0, 1.0, 1.0) * pow(nDotV, 76.8);" " }" " }" " /* Define new render color */" " lighting_color = (ambient + diffuse) * renderColor + specular;" " return lighting_color;" "}" "void main()" "{" " float scaling = 1.0;" " float turbulence = 0.0;" " vec3 texCoord = vec3(0.0);" " /* Use 5 octaves for a better result */" " for (int i = 0; i < 5; i++)" " {" " texCoord = (0.15 / scaling) * gl_TexCoord[0].xyz;" " turbulence += scaling * (texture3D(noiseMap, texCoord).z - 0.5);" " scaling *= 0.4;" " }" " /* Compute ratio according to turbulence */" " float ratio = exp(-5.0 * abs(turbulence));" " /* Compute final color */" " vec3 mainColor = mix(first_color, second_color, ratio);" " gl_FragColor = computeRenderColor(vec4(mainColor, 1.0));" "}"; } if (pgm->addShaderFromSourceCode(QGLShader::Vertex, vSrc.c_str())) { if (pgm->addShaderFromSourceCode(QGLShader::Fragment, fSrc.c_str())) { ok = true; } else { std::cerr << "Error loading fragment shader code: " << "\n"; std::cerr << pgm->log().toStdString(); } } else { std::cerr << "Error loading vertex shader code: " << "\n"; std::cerr << pgm->log().toStdString(); } if (!ok) { delete pgm; pgm = NULL; failed = true; } else { pgm->link(); // Save uniform locations uint id = pgm->programId(); uniforms["scale"] = GL.GetUniformLocation(id, "scale"); uniforms["unit"] = GL.GetUniformLocation(id, "unit"); uniforms["lights"] = GL.GetUniformLocation(id, "lights"); uniforms["noiseMap"] = GL.GetUniformLocation(id, "noiseMap"); uniforms["first_color"] = GL.GetUniformLocation(id, "first_color"); uniforms["second_color"] = GL.GetUniformLocation(id, "second_color"); } } }
bool UpdateApplication::createFile() // ---------------------------------------------------------------------------- // Create the update file // ---------------------------------------------------------------------------- { XL_ASSERT(!file); // Keep the name of the remote file in the URL QString fileName = QFileInfo(url.path()).fileName(); // Choose folder #if QT_VERSION >= 0x050000 // Thank you Qt5 for this insanity, just in case we have several ~/Desktop QString desktop = ""; QStringList desktops = QStandardPaths::standardLocations( QStandardPaths::DesktopLocation); if (desktops.size() >= 1) desktop = desktops[0]; #else QString desktop = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); #endif QString folder = QFileDialog::getExistingDirectory(NULL, tr("Select destination folder"), desktop); if (!folder.isEmpty()) { // Set complete filename QString completeFileName = folder + "/" + fileName; file = new QFile(completeFileName); if (file->exists()) { QString msg = tr("<h3>File exists</h3>"); QString info = tr("<p>The selected folder already contains a file " "called <b>%1</b>.</p>" "<p>Save anyway?</p>").arg(fileName); QMessageBox box(TaoApp->windowWidget()); setBoxMinimumWidth(box, 400); box.setIcon(QMessageBox::Warning); box.setWindowTitle(dialogTitle); box.setText(msg); box.setInformativeText(info); box.setStandardButtons(QMessageBox::Yes | QMessageBox::No); box.setDefaultButton(QMessageBox::No); if (box.exec() == QMessageBox::No) { delete file; file = NULL; return false; } } if (!file->open(QIODevice::WriteOnly | QIODevice::Truncate)) { IFTRACE(update) debug() << "Could not open file for writing: '" << +completeFileName << "' error: " << +file->errorString() << "\n"; QString msg = tr("<h3>Write error</h3>"); QString info = tr("<p>The upgrade cannot be saved to <b>%1</b>.</p>") .arg(fileName); QString details = file->errorString(); QMessageBox box(TaoApp->windowWidget()); setBoxMinimumWidth(box, 400); box.setIcon(QMessageBox::Critical); box.setWindowTitle(dialogTitle); box.setText(msg); box.setInformativeText(info); box.setDetailedText(details); box.setStandardButtons(QMessageBox::Ok); box.exec(); delete file; file = NULL; return false; } IFTRACE(update) debug() << "Save to: '" << +completeFileName << "'\n"; if (state == Downloaded) { // Download completed while user was still choosing file path saveDownloadedData(); } return true; } return false; }
Activity *Selection::Click(uint button, uint count, int x, int y) // ---------------------------------------------------------------------------- // Initial and final click in a selection rectangle // ---------------------------------------------------------------------------- { IFTRACE(widgets) std::cerr << "Selection::Click\n"; bool firstClick = false; bool doneWithSelection = false; bool shiftModifier = qApp->keyboardModifiers() & Qt::ShiftModifier; // The next to be returned even if this is deleted. BUG#1009 Activity * the_next = next; int oy = y; y = widget->height() - y; if (button & Qt::LeftButton) { // count == 0: MB up // count == 1: single click // count == 2: double click if (count) { firstClick = true; rectangle.lower.Set(x-2, y-2); rectangle.upper.Set(x+2, y+2); } else { rectangle.upper.Set(x, y); doneWithSelection = true; } } else { Idle(); delete this; return the_next; } // Get the object at the click point GLuint selected = 0; GLuint handleId = 0; GLuint charSelected = 0; GLuint childSelected = 0; GLuint parentId = 0; selected = ObjectInRectangle(rectangle, &handleId, &charSelected, &childSelected, &parentId); // If we selected an object, need to adjust dialogs to match new selection if (selected) { doneWithSelection = true; widget->updateDialogs(); } // If this is the first click, then update selection Widget::selection_map oldSelection = widget->selection; if (firstClick) { // Check cases where we need to start with a fresh selection if (shiftModifier || handleId) { // User held shift or selected a control handle savedSelection = oldSelection; } else if (oldSelection.count(selected)) { // Clicking on an already selected item savedSelection = oldSelection; } else { // Other cases: start with a fresh selection savedSelection.clear(); widget->requestFocus(NULL, x, y); // Clicking in some other child of a parent: select parent again if (parentId != selected) selected = parentId; } widget->selection = savedSelection; if (selected) { if (shiftModifier && widget->selected(selected) && !handleId) { // De-select previously selected object using shift widget->select(selected, 0); } else if (childSelected && count == 2) { // Double-click on a container: mark it as opened uint bare = selected & ~Widget::SELECTION_MASK; uint normal = bare | Widget::SHAPE_SELECTED; uint opengrp = bare | Widget::CONTAINER_OPENED; widget->select(normal, Widget::CONTAINER_OPENED); widget->select(opengrp, Widget::CONTAINER_OPENED); widget->select(childSelected, 1); } else { // Select given object widget->select(selected, savedSelection[selected] + count); if (!shiftModifier && !handleId) { widget->shapeAction("click", selected, x, oy); } } } widget->handleId = handleId; } if (!widget->selectionChanged && !selectionsMatch(oldSelection, widget->selection)) widget->selectionChanged = true; // In all cases, we want a screen refresh widget->updateGL(); // Delete any text selection we might have if we didn't click in it if (!charSelected) delete widget->textSelection(); // If we double click in a text, create a text selection else if (count == 2) { TextSelect *tsel = widget->textSelection(); if (!tsel) tsel = new TextSelect(widget); delete this; return tsel; } // If we are done with the selection, remove it and shift to a Drag if (doneWithSelection) { Widget *widget = this->widget; // Save before 'delete this' delete this; if (selected) return new Drag(widget); } return NULL; // We dealt with the event }
uint Identify::ObjectInRectangle(const Box &rectangle, uint *handlePtr, uint *characterPtr, uint *childPtr, uint *parentPtr) // ---------------------------------------------------------------------------- // Find the top-most object in the given box, return # of objects // ---------------------------------------------------------------------------- { // Create the select buffer and switch to select mode GLuint capacity = widget->selectionCapacity(); GLuint selected = 0; GLuint handleId = 0; GLuint charSelected = 0; GLuint childSelected = 0; GLuint parentId = 0; int hits = 0; widget->stats.begin(Statistics::SELECT); GLuint *buffer = new GLuint[capacity]; memset(buffer, 0, capacity * sizeof(GLuint)); GL.SelectBuffer(capacity, buffer); GL.RenderMode(GL_SELECT); // Adjust viewport for rendering widget->setup(widget->width(), widget->height(), &rectangle); // Initialize names GL.InitNames(); // Draw the items in "Identity" mode (simplified drawing) widget->identifySelection(); // Get number of hits and extract selection // Each record is as follows: // [0]: Depth of the name stack // [1]: Minimum depth // [2]: Maximum depth // [3..3+[0]-1]: List of names hits = GL.RenderMode(GL_RENDER); if (hits > 0) { GLuint depth = ~0U; GLuint *ptr = buffer; for (int i = 0; i < hits && !handleId; i++) { uint size = ptr[0]; GLuint *selPtr = ptr + 3; GLuint *selNext = selPtr + size; if ((*selPtr & Widget::SELECTION_MASK) && ptr[1] <= depth) { depth = ptr[1]; childSelected = false; IFTRACE(selection) std::cerr << "Selection " << std::hex << *selPtr << " depth " << depth << ": "; // Walk down the hierarchy if item is in a group ptr += 3; parentId = selected = *ptr++; // Check if we have a handleId or character ID while (ptr < selNext) { GLuint child = *ptr++; GLuint selType = child & Widget::SELECTION_MASK; IFTRACE(selection) std::cerr << std::hex << child << " "; if (selType == Widget::HANDLE_SELECTED) handleId = (child & ~Widget::SELECTION_MASK); else if (selType == Widget::CHARACTER_SELECTED) charSelected = child & ~Widget::SELECTION_MASK; else if ((selected & Widget::SELECTION_MASK) == Widget::CONTAINER_OPENED) selected = child; else if (!childSelected) childSelected = child; } IFTRACE(selection) std::cerr << "\n"; } ptr = selNext; } } delete[] buffer; // Update output arguments if (handlePtr) *handlePtr = handleId; if (characterPtr) *characterPtr = charSelected; if (childPtr) *childPtr = childSelected; if (parentPtr) *parentPtr = parentId; widget->stats.end(Statistics::SELECT); return selected; }