void Origami::makeValid() { // no dirty stuff, it uses only other member functions for (int j = 0; j < 20; ++j) //while (1) { bool found = false; int notValid; for (notValid = 0; notValid < verts.size(); ++notValid) { if (verts[notValid].isValid() == false && !isOnEdge(notValid)) { found = true; break; } } if (!found) break; vertex& v = verts[notValid]; crease c = v.getSuggestionByChoice(0); insertWithRaycast(notValid, c.angle, c.sDihedral); recompile(); printf("%d: %f, %f\n", notValid, c.angle, c.sDihedral); bool f = verts[notValid].isValid(); if (f) printf("vertex %d is GOOD\n", notValid); else printf("vertex %d is BAD\n", notValid); } }
void ClippingShader::deleteAllClipSpheres() { // Check if the clipping code has been inserted into shader if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::deleteAllClipSpheres")) return; // Shader name string std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS; // Use a shader mutator ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc()); // Modify the clip spheres count constant in both shader if (errorRaiseShaderMutatorFailure( (!SM.changeIntConstantValue(ShaderMutator::VERTEX_SHADER, "CLIP_SPHERES_COUNT", 0)) || (!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIP_SPHERES_COUNT", 0)), "ClippingShader::deleteAllClipSpheres")) return; // Reload both shaders reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str()); reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str()); // Rearrange spheres arrays m_clipSpheres.resize(0); m_clipSpheresIds.resize(0); m_clipSpheresCentersAndRadiuses.resize(0); // Recompile shaders (automatically calls updateClippingUniforms) recompile(); }
void Surface::setAlpha(double alpha) { m_alpha = alpha; m_colorPositive[3] = alpha; m_colorNegative[3] = alpha; recompile(); }
void FilterTime::onRm () { QModelIndex const idx = m_ui->view->currentIndex(); int const row = idx.row(); QModelIndex const op_idx = m_model->index(row, 1, QModelIndex()); QModelIndex const s_idx = m_model->index(row, 2, QModelIndex()); QModelIndex const u_idx = m_model->index(row, 3, QModelIndex()); QStandardItem * op_item = m_model->itemFromIndex(op_idx); if (!op_item) return; QStandardItem * s_item = m_model->itemFromIndex(s_idx); if (!s_item) return; QStandardItem * u_item = m_model->itemFromIndex(u_idx); if (!u_item) return; QString const & op_val = m_model->data(op_idx, Qt::DisplayRole).toString(); QString const & s_val = m_model->data(s_idx, Qt::DisplayRole).toString(); QString const & u_val = m_model->data(u_idx, Qt::DisplayRole).toString(); m_model->removeRow(idx.row()); remove(op_val, s_val.toULongLong(), u_val); recompile(); emitFilterChangedSignal(); }
// ------------------------------------------------------------------------- void MorphOpenCL::recompile(Morphology::EOperationType opType, int coordsSize) { static int prevCoordsSize[Morphology::OT_Gradient+1] = {0}; SKernelParameters* kparams; cl::Kernel* kernel; if(opType == Morphology::OT_Erode) { kparams = &erodeParams; kernel = &kernelErode; } else if(opType == Morphology::OT_Dilate) { kparams = &dilateParams; kernel = &kernelDilate; } else if(opType == Morphology::OT_Gradient) { kparams = &gradientParams; kernel = &kernelGradient; } else { if(opType == Morphology::OT_TopHat || opType == Morphology::OT_BlackHat || opType == Morphology::OT_Open || opType == Morphology::OT_Close) { recompile(Morphology::OT_Erode, coordsSize); recompile(Morphology::OT_Dilate, coordsSize); } return; } if(!kparams->needRecompile || coordsSize == prevCoordsSize[opType]) return; QString opts = kparams->options + " -DCOORDS_SIZE=" + QString::number(coordsSize); prevCoordsSize[opType] = coordsSize; cl::Program prog = createProgram(kparams->programName,opts); *kernel = createKernel(prog, kparams->kernelName); }
void FilterScript::onScriptRm () { QModelIndex const idx = m_ui->view->currentIndex(); QStandardItem * item = m_model->itemFromIndex(idx); if (!item) return; QString const & val = m_model->data(idx, Qt::DisplayRole).toString(); m_model->removeRow(idx.row()); removeFromScriptFilters(val); recompile(); emitFilterChangedSignal(); }
void FilterScript::onClickedAtScriptList (QModelIndex idx) { if (!idx.isValid()) return; if (idx.column() == 1) { QString const & filter_item = m_model->data(m_model->index(idx.row(), 0, QModelIndex()), Qt::DisplayRole).toString(); QString const & mod = m_model->data(idx, Qt::DisplayRole).toString(); E_FilterMode const curr = stringToFltMod(mod.toStdString().c_str()[0]); size_t const i = (curr + 1) % e_max_fltmod_enum_value; E_FilterMode const new_mode = static_cast<E_FilterMode>(i); m_model->setData(idx, QString(fltModToString(new_mode))); bool const is_inclusive = new_mode == e_Include; setScriptState(filter_item, is_inclusive); recompile(); emitFilterChangedSignal(); } else { QStandardItem * item = m_model->itemFromIndex(idx); Q_ASSERT(item); bool const orig_checked = (item->checkState() == Qt::Checked); Qt::CheckState const checked = orig_checked ? Qt::Unchecked : Qt::Checked; item->setCheckState(checked); QString const & mod = m_model->data(m_model->index(idx.row(), 1, QModelIndex()), Qt::DisplayRole).toString(); E_FilterMode const curr = stringToFltMod(mod.toStdString().c_str()[0]); bool const is_inclusive = curr == e_Include; QString const & val = m_model->data(idx, Qt::DisplayRole).toString(); // @TODO: if state really changed setScriptState(val, is_inclusive); setScriptChecked(val, checked); recompile(); emitFilterChangedSignal(); } }
unsigned int ClippingShader::addClipPlane() { // Check if the clipping code has been inserted into shader if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::addClipPlane")) return -1; // Shader name string std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS; // Use a shader mutator ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc()); // Previous planes count int previousPlanesCount = getClipPlanesCount(); // Modify the clip planes count constant in both shader if (errorRaiseShaderMutatorFailure( (!SM.changeIntConstantValue(ShaderMutator::VERTEX_SHADER, "CLIP_PLANES_COUNT", previousPlanesCount + 1)) || (!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIP_PLANES_COUNT", previousPlanesCount + 1)), "ClippingShader::addClipPlane")) return -1; // Reload both shaders reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str()); reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str()); // Get new plane id unsigned int newPlaneId = getFreeClipPlaneId(); // Resize planes arrays to the right size m_clipPlanes.resize((size_t)(previousPlanesCount + 1)); if (newPlaneId >= m_clipPlanesIds.size()) m_clipPlanesIds.resize((size_t)(newPlaneId + 1)); m_clipPlanesEquations.resize(4*(size_t)(previousPlanesCount + 1), 0.0f); // Set new plane id m_clipPlanesIds[newPlaneId].used = true; m_clipPlanesIds[newPlaneId].index = previousPlanesCount; // Set default parameters values for the new plane Geom::Vec3f defaultNormal (0.0f, 0.0f, 1.0f); Geom::Vec3f defaultOrigin (0.0f, 0.0f, 0.0f); setClipPlaneParamsAll(newPlaneId, defaultNormal, defaultOrigin); // Recompile shaders (automatically calls updateClippingUniforms) recompile(); return newPlaneId; }
void ClippingShader::deleteClipSphere(unsigned int id) { // Check if the given id is valid if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::deleteClipSphere")) return; if (errorRaiseWrongId(!m_clipSpheresIds[id].used, "ClippingShader::deleteClipSphere")) return; // Check if the clipping code has been inserted into shader if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::deleteClipSphere")) return; // Shader name string std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS; // Use a shader mutator ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc()); // Previous spheres count int previousSpheresCount = getClipSpheresCount(); // Modify the clip spheres count constant in both shader if (errorRaiseShaderMutatorFailure( (!SM.changeIntConstantValue(ShaderMutator::VERTEX_SHADER, "CLIP_SPHERES_COUNT", previousSpheresCount - 1)) || (!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIP_SPHERES_COUNT", previousSpheresCount - 1)), "ClippingShader::deleteClipSphere")) return; // Reload both shaders reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str()); reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str()); // Rearrange spheres arrays m_clipSpheres.erase(m_clipSpheres.begin() + m_clipSpheresIds[id].index); for (size_t i = 0; i < m_clipSpheresIds.size(); i++) { if (m_clipSpheresIds[i].index > m_clipSpheresIds[id].index) m_clipSpheresIds[i].index -= 1; } m_clipSpheresIds[id].used = false; m_clipSpheresCentersAndRadiuses.erase( m_clipSpheresCentersAndRadiuses.begin() + 4*m_clipSpheresIds[id].index, m_clipSpheresCentersAndRadiuses.begin() + 4*m_clipSpheresIds[id].index + 4); // Recompile shaders (automatically calls updateClippingUniforms) recompile(); }
void FilterScript::onScriptAdd () { QString const qItem = m_ui->scriptNameLineEdit->text(); if (!qItem.length()) return; QStandardItem * root = m_model->invisibleRootItem(); QStandardItem * child = findChildByText(root, qItem); if (child == 0) { QList<QStandardItem *> row_items = addTriRow(qItem, Qt::Checked, true); root->appendRow(row_items); appendToScriptFilters(qItem, true, true); row_items[0]->setCheckState(Qt::Checked); recompile(); } }
void ClippingShader::setClipMode(clippingMode clipMode) { // Check if it is worth updating values ! if (clipMode == m_clipMode) return; // Check if the clipping code has been inserted into shader if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipMode")) return; // Shader name string std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS; // Copy the given value m_clipMode = clipMode; // Use a shader mutator ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc()); // Change clipping mode constant int newConstantValue; switch (clipMode) { case CLIPPING_MODE_AND : newConstantValue = 0; break; case CLIPPING_MODE_OR : newConstantValue = 1; break; default : newConstantValue = 0; break; } if (errorRaiseShaderMutatorFailure( (!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIPPING_MODE", newConstantValue)), "ClippingShader::setClipMode")) return; // Reload modified shader reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str()); // Recompile shaders (automatically calls updateClippingUniforms) recompile(); }
void handleFileAction( FW::WatchID watchid, const FW::String& dir, const FW::String& filename, FW::Action action ) { switch( action ) { // case FW::Actions::Add: // printf("add %s\n", filename.c_str()); // break; case FW::Actions::Modified: if( filename.find("update.c")!=std::string::npos ) { recompile(); } break; // case FW::Actions::Delete: // printf("del %s\n", filename.c_str()); // break; default: break; } }
int disassemble(Copcodes *popcode_list, Crom_file *prom, char *output_path) { CindirectJmpRuntimeLabels indjmp; Cdisasm disassembler; switch (indjmp.init(prom, output_path)) { case 1: printf("Error: %s\n", indjmp.m_error_str); return 1; case 2: printf("%s\n", indjmp.m_error_str); return 0; } if (disassembler.init(prom)) return 1; disassembler.disasm(popcode_list, prom, &indjmp, output_path); recompile(disassembler.getlisting(), popcode_list, prom, &indjmp, output_path); return 0; }
// constructor receiving a config struct //************************* PtrFreeScene :: PtrFreeScene(const Config& config) : accel_type(config.accel_type) { //************************ // load input scene in luxrays format // TODO what is this -1? Is it the accelerator structure? //data_set = original_scene->UpdateDataSet(); original_scene = new luxrays::Scene(config.scene_file, config.width, config.height, config.accel_type); data_set = original_scene->UpdateDataSet(); vertexes = NULL; normals = NULL; colors = NULL; uvs = NULL; triangles = NULL; mesh_descs = NULL; mesh_ids = NULL; mesh_first_triangle_offset = NULL; compiled_materials = NULL; materials = NULL; mesh_materials = NULL; area_lights = NULL; tex_maps = NULL; rgb_tex = NULL; alpha_tex = NULL; mesh_texs = NULL; bump_map = NULL; bump_map_scales = NULL; normal_map = NULL; // recompile the entire scene ActionList actions; actions.add_all(); recompile(actions); n_nodes = data_set->GetAccelerator()->GetNodesCount(); n_prims = data_set->GetAccelerator()->GetPrimsCount(); nodes = NULL; prims = NULL; }
void Surface::computePropertyData(Function3D function) { if (m_surfaceDataPositive.isEmpty() && m_surfaceDataNegative.isEmpty()) { qDebug() << "Layer::Surface::computePropertyData() called with no data"; return; } m_propertyDataPositive.clear(); m_propertyDataNegative.clear(); double f; if (m_surfaceDataPositive.isEmpty()) { f = function(m_surfaceDataNegative[3], m_surfaceDataNegative[4], m_surfaceDataNegative[5]); }else { f = function(m_surfaceDataPositive[3], m_surfaceDataPositive[4], m_surfaceDataPositive[5]); } m_min = f; m_max = f; for (int i = 0; i < m_surfaceDataPositive.size(); i += 6) { f = function(m_surfaceDataPositive[i+3], m_surfaceDataPositive[i+4], m_surfaceDataPositive[i+5]); m_propertyDataPositive.append(f); m_min = std::min(m_min, f); m_max = std::max(m_max, f); } for (int i = 0; i < m_surfaceDataNegative.size(); i += 6) { f = function(m_surfaceDataNegative[i+3], m_surfaceDataNegative[i+4], m_surfaceDataNegative[i+5]); m_propertyDataNegative.append(f); m_min = std::min(m_min, f); m_max = std::max(m_max, f); } recompile(); }
void Recompile::run() { /* * @Initialize */ // Directory QDir directory(this->_dir); if (!directory.exists()) { emit output(text("failure_directory").arg(directory.absolutePath())); emit recompile(this->_dir, QString()); return; } // File QFileInfo apksigned(directory.absolutePath().append("/build/signedapk.apk")); QFileInfo rebuilt(directory.absolutePath().append("/build/rebuilt.apk")); QFileInfo recompiled(directory.absolutePath().append("/build/recompiled.apk")); QFileInfo zipaligned(directory.absolutePath().append("/build/zipaligned.apk")); /* * @APKTool */ // Arguments QStringList recompile; recompile << QString("-Xms").append(QString::number(Utility::Configuration::heap())).append("m"); recompile << QString("-jar"); recompile << Utility::Configuration::apktool(); recompile << QString("--force"); if (Utility::Configuration::verbose()) recompile << QString("--verbose"); recompile << QString("--output"); recompile << QString(recompiled.absoluteFilePath()); recompile << QString("b"); recompile << QString(directory.absolutePath()); // Process QProcess apktool; apktool.setEnvironment(QProcess::systemEnvironment()); apktool.setProcessChannelMode(QProcess::MergedChannels); // Start apktool.start(QString("java"), recompile, QIODevice::ReadOnly); // Wait (Start) if (!apktool.waitForStarted()) { emit Recompile::recompile(this->_dir, QString()); return; } // Wait (Read) apktool.waitForReadyRead(5 * 1000); // Wait (Stop) apktool.waitForFinished(-1); // Verify if (!recompiled.exists() || !recompiled.isFile()) { // Read QString output = apktool.readAll(); emit Recompile::output(output); emit Recompile::recompile(this->_dir, QString()); return; } /* * @Sign */ // Arguments QStringList sign; sign << QString("-Xms").append(QString::number(Utility::Configuration::heap())).append("m"); sign << QString("-jar"); sign << Utility::Configuration::signapk(); sign << QString("-w"); sign << Utility::Configuration::certificate(); sign << Utility::Configuration::key(); sign << recompiled.absoluteFilePath(); sign << apksigned.absoluteFilePath(); // Process QProcess signapk; signapk.setEnvironment(QProcess::systemEnvironment()); signapk.setProcessChannelMode(QProcess::MergedChannels); // Start signapk.start(QString("java"), sign, QIODevice::ReadOnly); // Wait (Start) if (!signapk.waitForStarted()) { emit Recompile::recompile(this->_dir, QString()); return; } // Wait (Read) signapk.waitForReadyRead(5 * 1000); // Wait (Stop) signapk.waitForFinished(-1); // Verify if (!apksigned.exists() || !apksigned.isFile()) { // Read QString output = signapk.readAll(); emit Recompile::output(output); emit Recompile::recompile(this->_dir, QString()); return; } /* * @Align */ // Arguments QStringList align; align << QString("-f"); if (Utility::Configuration::verbose()) align << QString("-v"); align << QString("4"); align << apksigned.absoluteFilePath(); align << zipaligned.absoluteFilePath(); // Process QProcess zipalign; zipalign.setEnvironment(QProcess::systemEnvironment()); zipalign.setProcessChannelMode(QProcess::MergedChannels); // Start zipalign.start(Utility::Configuration::zipalign(), align, QIODevice::ReadOnly); // Wait (Start) if (!zipalign.waitForStarted()) { emit Recompile::recompile(this->_dir, QString()); return; } // Wait (Read) zipalign.waitForReadyRead(5 * 1000); // Wait (Stop) zipalign.waitForFinished(-1); // Verify if (!zipaligned.exists() || !zipaligned.isFile()) { // Read QString output = zipalign.readAll(); emit Recompile::output(output); emit Recompile::recompile(this->_dir, QString()); return; } if (rebuilt.exists()) QFile(rebuilt.absoluteFilePath()).remove(); // Verify if (QFile(zipaligned.absoluteFilePath()).rename(rebuilt.absoluteFilePath())) { QFile(recompiled.absoluteFilePath()).remove(); QFile(apksigned.absoluteFilePath()).remove(); QFile(zipaligned.absoluteFilePath()).remove(); emit Recompile::recompile(this->_dir, directory.absolutePath()); } else emit Recompile::recompile(this->_dir, QString()); }
void CountCodePattern::initComparing() { // general count stub; 8 instructions. // 0: lis Temp1, high(count_addr) // 1: lwz Temp2, [low(count_addr) + Temp1] // 2: addi Temp2, Temp2, 1 // 3: stw Temp2, [low(count_addr) + Temp1] // 4: cmpwi Temp2, limit // 5: beq 10 // 6: lis Temp1, high(jump_addr) // 7: ori Temp1, Temp1, low(jump_addr) // 8: mtctr Temp1 // 9: balwctr //10: mflr RecompileTempReg //11: stw RecompileTempReg, SP + saved_pc_offset * 4 //12: bl 13 //13: mflr RecompileLinkReg //14: mtlr RecompileTempReg //15: lis R0, high(recompile_addr) //16: ori R0, R0, low(recompile_addr) //17: mtctr R0 //18: balwctrl instsSize = 19 * 4; countAddr_offset = 0; lwz_offset = 1; stw_offset = 3; limit_offset = 4; nm_lis_offset = 6; nm_ori_offset = 7; recompile_lis_offset = 15; recompile_ori_offset = 16; Assembler* oldAssembler = theAssembler; Assembler* a = theAssembler = new Assembler(instsSize, instsSize, false, true); { // make a new block so that the Label's destructor gets called before we reset theAssembler in Assembler::finalize a->load_from_address(Temp2, 0, VMAddressOperand, Temp1); // 2 instructions a->addi(Temp2, Temp2, 1, NumberOperand); a->stw(Temp2, 0, VMAddressOperand, Temp1); a->cmpwi( Temp2, 0, NumberOperand ); // assuming limit fits in si (assert in countStub_ppc) Label recompile(a->printing); a->beq(recompile, predict_usual); // not likley to recompile, so expect to fall through a->long_branch_to((pc_t)0, CodeAddressOperand, Temp1, false); // 4 instructions recompile.define(); // save link so can use link to get address of this code // also key to profiler -- dmu 2/04 a->mflr(RecompileTempReg); a->stw(RecompileTempReg, saved_pc_offset * oopSize, NumberOperand, SP); Label next; a->bl(next, NumberOperand); // needed to get addr of this code next.define(); a->mflr(RecompileLinkReg); a->mtlr(RecompileTempReg); // call recompiler char* fnaddr = Memory->code->trapdoors->Recompile_stub_td(R0); a->long_branch_to(fnaddr, CodeAddressOperand, R0, false); } pattern = (pc_t)AllocateHeap(instsSize, "countStub pattern"); copy_words((int32*)a->instsStart, (int32*)pattern, instsSize / 4); a->finalize(); theAssembler = oldAssembler; }
int main(int argc, char **argv) { // SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); // SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); /* initialize OpenGL */ initGraphics(800,600,0); initGL( ); initInput(); renderInit(); imguiRenderGLInit("DroidSans.ttf"); curl_global_init(CURL_GLOBAL_ALL); FW::FileWatcher* watcher = new FW::FileWatcher(); /*FW::WatchID watchid = */watcher->addWatch( "./", new RecompileListener() ); recompile(); /* resize the initial window */ // resizeWindow( xres, yres ); /* These are to calculate our fps */ static GLint T0 = 0; static GLint Frames = 0; /* wait for events */ bool done = false; SDL_Event event; while ( !done ) { /* handle the events in the queue */ while ( SDL_PollEvent( &event ) ) { switch( event.type ) { //case SDL_ACTIVEEVENT: /* Something's happend with our focus * If we lost focus or we are iconified, we * shouldn't draw the screen */ //if ( event.active.gain == 0 ) // isActive = FALSE; // else // isActive = TRUE; // break; #if 0 case SDL_VIDEORESIZE: /* handle resize event */ surface = SDL_SetVideoMode( event.resize.w, event.resize.h, 16, videoFlags ); if ( !surface ) { fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) ); Quit( 1 ); } resizeWindow( event.resize.w, event.resize.h ); break; #endif case SDL_KEYDOWN: /* handle key presses */ handleKeyPress( &event.key.keysym ); break; case SDL_KEYUP: if(event.key.keysym.sym<=255){ keystat[event.key.keysym.sym] = 0; } break; case SDL_MOUSEMOTION: mousexr = event.motion.xrel; mouseyr = event.motion.yrel; mousex = event.motion.x; mousey = event.motion.y; break; case SDL_MOUSEBUTTONDOWN: mousestat[event.button.button] = 1; break; case SDL_MOUSEBUTTONUP: mousestat[event.button.button] = 0; break; case SDL_QUIT: /* handle quit requests */ done = TRUE; break; default: break; } } /* draw the scene */ //if ( isActive ) { watcher->update(); //glClearColor(1, 0, 0, 1); //glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if(update) { update(); } /* glMatrixMode(GL_PROJECTION); glLoadIdentity(); float projection[16] = { 2.f/800, 0.f, 0.f, 0.f, 0.f, 2.f/600, 0.f, 0.f, 0.f, 0.f, -2.f, 0.f, -1.f, -1.f, -1.f, 1.f }; glLoadMatrixf(projection); glMatrixMode(GL_MODELVIEW); glLoadIdentity();*/ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); imguiRenderGLDraw(800, 600); /* glBegin(GL_TRIANGLES); glColor3f(1, 1, 0); glVertex2d(1, 1); glVertex2d(1, 0); glVertex2d(0, 1); glEnd(); */ /* Draw it to the screen */ swapBuffers(); /* Gather our frames per second */ Frames++; { GLint t = SDL_GetTicks(); if (t - T0 < 16) { // SDL_Delay(16 - (t-T0)); // GLfloat seconds = (t - T0) / 1000.f; // GLfloat fps = Frames / seconds; // Frames = 0; } T0 = t; } } } imguiRenderGLDestroy(); renderFini(); /* clean ourselves up and exit */ Quit( 0 ); /* Should never get here */ return( 0 ); }
bool ClippingShader::insertClippingCode() { // Check if the code has not already been inserted if (errorRaiseClippingCodeAlreadyInserted(m_hasClippingCodeBeenInserted, "ClippingShader::insertClippingCode")) return false; // Check if the vertex and fragment sources are not empty if (errorRaiseShaderSourceIsEmpty((getVertexShaderSrc() == NULL), "ClippingShader::insertClippingCode", ShaderMutator::VERTEX_SHADER)) return false; if (errorRaiseShaderSourceIsEmpty((getFragmentShaderSrc() == NULL), "ClippingShader::insertClippingCode", ShaderMutator::FRAGMENT_SHADER)) return false; // Check if the shader does not use a geometry shader if (errorRaiseShaderUsesGeometryShader((getGeometryShaderSrc() != NULL), "ClippingShader::insertClippingCode")) return false; // Strings to insert in shader sources std::string VS_headInsertion = "\n" "#define CLIP_PLANES_COUNT 0\n" "#define CLIP_SPHERES_COUNT 0\n" "\n" "#define PLANE_CLIPPING_ENABLED (CLIP_PLANES_COUNT > 0)\n" "#define SPHERE_CLIPPING_ENABLED (CLIP_SPHERES_COUNT > 0)\n" "\n" "#define CLIPPING_ENABLED (PLANE_CLIPPING_ENABLED || SPHERE_CLIPPING_ENABLED)\n" "\n" "#if CLIPPING_ENABLED\n" " VARYING_VERT vec3 clip_nonTransformedPos;\n" "#endif\n" "\n"; std::string VS_mainEndInsertion = "\n" " #if CLIPPING_ENABLED\n" " // Pass the non transformed vertex position to the fragment shader for clipping\n" " clip_nonTransformedPos = VertexPosition;\n" " #endif\n"; std::string FS_headInsertion = "\n" "#define CLIP_PLANES_COUNT 0\n" "#define CLIP_SPHERES_COUNT 0\n" "\n" "#define PLANE_CLIPPING_ENABLED (CLIP_PLANES_COUNT > 0)\n" "#define SPHERE_CLIPPING_ENABLED (CLIP_SPHERES_COUNT > 0)\n" "\n" "#define CLIPPING_ENABLED (PLANE_CLIPPING_ENABLED || SPHERE_CLIPPING_ENABLED)\n" "\n" "// In following clipping modes, pixels may be deleted :\n" "// - OR : only after being matched with every object\n" "// - AND : on the fly as soon as one object does not match\n" "#define CLIPPING_MODE_AND 0\n" "#define CLIPPING_MODE_OR 1\n" "#define CLIPPING_MODE 0\n" "\n" "#define CLIPPING_COLOR_ATTENUATION_MODE_LINEAR 0\n" "#define CLIPPING_COLOR_ATTENUATION_MODE_QUADRATIC 1\n" "#define CLIPPING_COLOR_ATTENUATION_MODE 0\n" "\n" "#if CLIPPING_ENABLED\n" "\n" " #if PLANE_CLIPPING_ENABLED\n" " uniform vec4 clip_clipPlanesEquations[CLIP_PLANES_COUNT];\n" " #endif\n" "\n" " #if SPHERE_CLIPPING_ENABLED\n" " uniform vec4 clip_clipSpheresCentersAndRadiuses[CLIP_SPHERES_COUNT];\n" " #endif\n" "\n" " uniform float clip_clipColorAttenuationFactor;\n" "\n" " VARYING_FRAG vec3 clip_nonTransformedPos;\n" "\n" "#endif\n" "\n" "#if CLIPPING_ENABLED\n" "\n" " float clip_doClippingAndGetClippingDistance()\n" " {\n" " // Distance to the nearest clipping object\n" " float minDistanceToClipping = -1.0;\n" "\n" " // OR clipping mode needs a boolean to know if the pixel must be clipped or not\n" " // By default set to true : one clipping object matched sets it to false\n" " #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n" " bool discardPixel = true;\n" " #endif\n" "\n" " #if PLANE_CLIPPING_ENABLED\n" "\n" " // Do clipping for each plane\n" " for (int i = 0; i < CLIP_PLANES_COUNT; i++)\n" " {\n" " // Get the current plane equation\n" " vec4 currClipPlane = clip_clipPlanesEquations[i];\n" "\n" " // If the plane normal is zero, use a default normal vector (0.0, 0.0, 1.0)\n" " float clipPlaneNormalLength = length(currClipPlane.xyz);\n" " if (clipPlaneNormalLength == 0.0)\n" " {\n" " currClipPlane.z = 1.0;\n" " clipPlaneNormalLength = 1.0;\n" " }\n" "\n" " // Signed distance between the point and the plane\n" " float distanceToPlane = dot(clip_nonTransformedPos, currClipPlane.xyz);\n" " distanceToPlane += currClipPlane.w;\n" " distanceToPlane /= clipPlaneNormalLength;\n" "\n" " // AND clipping mode discards at first unmatched clipping object\n" " #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n" " if (distanceToPlane > 0.0)\n" " discard;\n" " #endif\n" "\n" " // In OR clipping mode, one match = no pixel clipping\n" " #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n" " if (distanceToPlane < 0.0)\n" " discardPixel = false;\n" " #endif\n" "\n" " // Keep the distance to the nearest plane\n" " if (minDistanceToClipping < 0.0)\n" " minDistanceToClipping = abs(distanceToPlane);\n" " else\n" " minDistanceToClipping = min(minDistanceToClipping, abs(distanceToPlane));\n" " }\n" "\n" " #endif\n" "\n" " #if SPHERE_CLIPPING_ENABLED\n" "\n" " // Do clipping for each sphere\n" " for (int i = 0; i < CLIP_SPHERES_COUNT; i++)\n" " {\n" " // Get the current sphere center and radius\n" " vec3 currClipSphereCenter = clip_clipSpheresCentersAndRadiuses[i].xyz;\n" " float currClipSphereRadius = clip_clipSpheresCentersAndRadiuses[i].w;\n" "\n" " // Signed distance between the point and the sphere\n" " float distanceToSphere = length(clip_nonTransformedPos - currClipSphereCenter);\n" " distanceToSphere -= abs(currClipSphereRadius);\n" "\n" " // If the sphere radius is negative, this inverses the clipping effect\n" " distanceToSphere *= sign(currClipSphereRadius);\n" "\n" " // AND clipping mode discards at first unmatched clipping object\n" " #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n" " if (distanceToSphere > 0.0)\n" " discard;\n" " #endif\n" "\n" " // In OR clipping mode, one match = no pixel clipping\n" " #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n" " if (distanceToSphere < 0.0)\n" " discardPixel = false;\n" " #endif\n" "\n" " // Keep the distance to the nearest sphere\n" " if (minDistanceToClipping < 0.0)\n" " minDistanceToClipping = abs(distanceToSphere);\n" " else\n" " minDistanceToClipping = min(minDistanceToClipping, abs(distanceToSphere));\n" " }\n" "\n" " #endif\n" "\n" " // In OR clipping mode, the pixel may be deleted only after being matched with every object\n" " #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n" " if (discardPixel)\n" " discard;\n" " #endif\n" "\n" " return minDistanceToClipping;\n" " }\n" "\n" "#endif\n" "\n"; std::string FS_mainBeginInsertion = "\n" " #if CLIPPING_ENABLED\n" " // Apply clipping and get the clipping distance\n" " float clip_minDistanceToClipping = clip_doClippingAndGetClippingDistance();\n" " #endif\n"; std::string FS_mainEndInsertion = "\n" " #if CLIPPING_ENABLED\n" " // Attenuate the final fragment color depending on its distance to clipping objects\n" " float clip_colorAttenuation = clip_minDistanceToClipping * clip_clipColorAttenuationFactor;\n" " #if (CLIPPING_COLOR_ATTENUATION_MODE == CLIPPING_COLOR_ATTENUATION_MODE_QUADRATIC)\n" " clip_colorAttenuation *= clip_colorAttenuation;\n" " #endif\n" " gl_FragColor.rgb /= (1.0 + clip_colorAttenuation);\n" " #endif;\n"; // Shader name string std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS; // Use a shader mutator ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc()); // First check if the vertex shader contains the VertexPosition attribute if (errorRaiseVariableNotFoundInShader(!SM.containsVariableDeclaration(ShaderMutator::VERTEX_SHADER, "VertexPosition"), "ClippingShader::insertClippingCode", ShaderMutator::VERTEX_SHADER, "VertexPosition")) return false; // Modify vertex shader source code if (errorRaiseShaderMutatorFailure( (!SM.insertCodeBeforeMainFunction(ShaderMutator::VERTEX_SHADER, VS_headInsertion)) || (!SM.insertCodeAtMainFunctionBeginning(ShaderMutator::VERTEX_SHADER, VS_mainEndInsertion)), "ClippingShader::insertClippingCode")) return false; // Modify fragment shader source code if (errorRaiseShaderMutatorFailure( (!SM.setMinShadingLanguageVersion(ShaderMutator::FRAGMENT_SHADER, 120)) // Following code insertions need at least shading language 120 (GLSL arrays) || (!SM.insertCodeBeforeMainFunction(ShaderMutator::FRAGMENT_SHADER, FS_headInsertion)) || (!SM.insertCodeAtMainFunctionBeginning(ShaderMutator::FRAGMENT_SHADER, FS_mainBeginInsertion)) || (!SM.insertCodeAtMainFunctionEnd(ShaderMutator::FRAGMENT_SHADER, FS_mainEndInsertion)), "ClippingShader::insertClippingCode")) return false; // Reload both shaders reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str()); reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str()); // Recompile shaders (automatically calls updateClippingUniforms) recompile(); m_hasClippingCodeBeenInserted = true; return true; }
void Surface::clearPropertyData() { m_propertyDataPositive.clear(); m_propertyDataNegative.clear(); recompile(); }
/* * The strategy for this goes as follows: * * 1) Scan the stack, looking at all return addresses that could go into JIT * code. * 2) If an address corresponds to a call site registered by |callSite| during * the last compilation, remember it. * 3) Purge the old compiled state and return if there were no active frames of * this script on the stack. * 4) Fix up the stack by replacing all saved addresses with the addresses the * new compiler gives us for the call sites. */ bool Recompiler::recompile() { JS_ASSERT(script->hasJITCode()); Vector<PatchableAddress> normalPatches(cx); Vector<PatchableAddress> ctorPatches(cx); JSStackFrame *firstCtorFrame = NULL; JSStackFrame *firstNormalFrame = NULL; // Find all JIT'd stack frames to account for return addresses that will // need to be patched after recompilation. for (VMFrame *f = script->compartment->jaegerCompartment->activeFrame(); f != NULL; f = f->previous) { // Scan all frames owned by this VMFrame. JSStackFrame *end = f->entryfp->prev(); for (JSStackFrame *fp = f->fp(); fp != end; fp = fp->prev()) { // Remember the latest frame for each type of JIT'd code, so the // compiler will have a frame to re-JIT from. if (!firstCtorFrame && fp->script() == script && fp->isConstructing()) firstCtorFrame = fp; else if (!firstNormalFrame && fp->script() == script && !fp->isConstructing()) firstNormalFrame = fp; void **addr = fp->addressOfNativeReturnAddress(); if (script->jitCtor && script->jitCtor->isValidCode(*addr)) { if (!ctorPatches.append(findPatch(script->jitCtor, addr))) return false; } else if (script->jitNormal && script->jitNormal->isValidCode(*addr)) { if (!normalPatches.append(findPatch(script->jitNormal, addr))) return false; } } void **addr = f->returnAddressLocation(); if (script->jitCtor && script->jitCtor->isValidCode(*addr)) { if (!ctorPatches.append(findPatch(script->jitCtor, addr))) return false; } else if (script->jitNormal && script->jitNormal->isValidCode(*addr)) { if (!normalPatches.append(findPatch(script->jitNormal, addr))) return false; } } Vector<CallSite> normalSites(cx); Vector<CallSite> ctorSites(cx); if (script->jitNormal && !saveTraps(script->jitNormal, &normalSites)) return false; if (script->jitCtor && !saveTraps(script->jitCtor, &ctorSites)) return false; ReleaseScriptCode(cx, script); if (normalPatches.length() && !recompile(firstNormalFrame, normalPatches, normalSites)) { return false; } if (ctorPatches.length() && !recompile(firstCtorFrame, ctorPatches, ctorSites)) { return false; } return true; }
/* private */ void mainwindow::_create_actions() { _action_exit = new QAction(tr("Exit"), this); _action_loadfile = new QAction(tr("Open"), this); _action_addfile = new QAction(tr("Add"), this); // menu connect(_action_exit, SIGNAL( triggered()), this, SLOT( close_window() )); connect(_action_loadfile, SIGNAL( triggered()), this, SLOT( openfile() )); connect(_action_addfile, SIGNAL( triggered()), this, SLOT( addfile() )); connect(_button_recompile, SIGNAL( released() ), _glwindow, SLOT( recompile() )); connect(_button_set_spheremap, SIGNAL( released() ), _glwindow, SLOT( load_spheremap() )); connect(_addfile_button, SIGNAL(released()), this, SLOT(addfile())); connect(_deletefile_button, SIGNAL(released()), this, SLOT(deletefiles())); connect(_checkbox_spheremap, SIGNAL( stateChanged(int) ), _glwindow, SLOT( spheremapping(int) )); connect(_checkbox_fxaa, SIGNAL( stateChanged(int) ), _glwindow, SLOT( fxaa(int) )); connect(_checkbox_pretessellation, SIGNAL(stateChanged(int)), _glwindow, SLOT(enable_pretessellation(int))); connect(_checkbox_vsync, SIGNAL( stateChanged(int) ), _glwindow, SLOT( vsync(int) )); connect(_checkbox_culling, SIGNAL(stateChanged(int)), _glwindow, SLOT( backface_culling(int))); connect(_checkbox_counting, SIGNAL(stateChanged(int)), _glwindow, SLOT( enable_counter(int))); connect(_checkbox_tritesselation, SIGNAL(stateChanged(int)), _glwindow, SLOT(enable_triangular_tesselation(int))); connect(_checkbox_holefilling, SIGNAL(stateChanged(int)), _glwindow, SLOT(holefilling(int))); connect(_checkbox_conservative_rasterization, SIGNAL(stateChanged(int)), _glwindow, SLOT(conservative_rasterization(int))); connect(_combobox_antialiasing, SIGNAL(currentIndexChanged(int)), this, SLOT(antialiasing())); connect(_combobox_trimming, SIGNAL(currentIndexChanged(int)), this, SLOT(trimming())); connect(_combobox_rendering, SIGNAL(currentIndexChanged(int)), this, SLOT(rendering())); connect(_combobox_fillmode, SIGNAL(currentIndexChanged(int)), this, SLOT(fillmode())); connect(_combobox_preclassification, SIGNAL(currentIndexChanged(int)), this, SLOT(preclassification())); connect(_slider_trim_max_bisections, SIGNAL(valueChanged(int)), _glwindow, SLOT(trim_max_bisections(int))); connect(_slider_trim_error_tolerance, SIGNAL(valueChanged(float)), _glwindow, SLOT(trim_error_tolerance(float))); connect(_slider_tesselation_max_pixel_error, SIGNAL(valueChanged(float)), _glwindow, SLOT(tesselation_max_pixel_error(float))); connect(_slider_tesselation_max_object_error, SIGNAL(valueChanged(float)), _glwindow, SLOT(tesselation_max_geometric_error(float))); connect(_slider_raycasting_max_iterations, SIGNAL(valueChanged(int)), _glwindow, SLOT(raycasting_max_iterations(int))); connect(_slider_raycasting_error_tolerance, SIGNAL(valueChanged(float)), _glwindow, SLOT(raycasting_error_tolerance(float))); connect(_current_specular, SIGNAL(released()), this, SLOT(set_specular())); connect(_current_diffuse, SIGNAL(released()), this, SLOT(set_diffuse())); connect(_current_ambient, SIGNAL(released()), this, SLOT(set_ambient())); connect(_current_shininess, SIGNAL(valueChanged(float)), this, SLOT(set_shininess(float))); connect(_current_opacity, SIGNAL(valueChanged(float)), this, SLOT(set_opacity(float))); connect(_material_apply, SIGNAL(released()), this, SLOT(apply_material())); _file_menu->addSeparator(); _file_menu->addAction (_action_loadfile); _file_menu->addAction (_action_addfile); _file_menu->addAction (_action_exit); }