void ofxFXObject::allocate(int _width, int _height){ width = _width; height = _height; pingPong.allocate(width, height, internalFormat); compileCode(); };
Script *Script::compileFile(const std::string &filename) { return compileCode( chi::System::fileToString(filename), filename ); }
//-------------------------------------------------------------- void ofApp::setup(){ // Global Settings ofSetLogLevel(OF_LOG_VERBOSE); resolHoriz = 1024; resolVert = 1024; show_fps = true; bHideCursor = false; // FBO Kaleidoscope resolPantalla = 1; pantallaFBOKaleidoscopeA.allocate( resolHoriz, resolVert, GL_RGB); pantallaFBOKaleidoscopeB.allocate( resolHoriz/2, resolVert/2, GL_RGB); pantallaFBOKaleidoscopeC.allocate( resolHoriz/4, resolVert/4, GL_RGB); pingPong.allocate( resolHoriz, resolVert, GL_RGB); pingPong.swap(); ofDirectory dir; dir.listDir("frags/"); int fragDirSize = dir.size(); cout << fragDirSize << endl; for (int val = 0; val < fragDirSize; val++){ stringstream nombre; if (val+1 < 10){ nombre << "frags/frag_000" << val+1 << ".frag"; } else if (val+1 < 100){ nombre << "frags/frag_00" << val+1 << ".frag"; } else if (val+1 < 1000){ nombre << "frags/frag_0" << val+1 << ".frag"; } else { nombre << "frags/frag_" << val+1 << ".frag"; } ofBuffer buffer = ofBufferFromFile(nombre.str()); string stringTemporal = string(buffer); frags.push_back(stringTemporal); fragNames.push_back(nombre.str()); } nFrag = 0; passes = 1; // now compile the first shader bFine = true; compileCode(); bKaleidoscope = false; KaleidoscopeSlices = 12; }
bool ofxFXObject::setCode(string frag, string vert){ if (fragmentShader == frag && vertexShader == vert) return false; bool loaded = false; ofShader test; if (frag.empty() == false) test.setupShaderFromSource(GL_FRAGMENT_SHADER, frag); if (vert.empty() == false) test.setupShaderFromSource(GL_VERTEX_SHADER, vert); bFine = test.linkProgram(); if( bFine ){ if (frag.empty() == false) fragmentShader = frag; if (vert.empty() == false) vertexShader = vert; loaded = compileCode(); } return loaded; }
bool ofApp::setCode(string _fragShader){ bool loaded = false; // string shaderTemporalA = "#version 120\n\ //#extension GL_ARB_texture_rectangle : enable\n"; // stringstream shaderTemporalB; // shaderTemporalB << shaderTemporalA << _fragShader << endl; // _fragShader = shaderTemporalB.str(); // cout << _fragShader << endl; if ( fragmentShader != _fragShader ){ ofShader test; test.setupShaderFromSource(GL_FRAGMENT_SHADER, _fragShader); bFine = test.linkProgram(); if( bFine ){ fragmentShader = _fragShader; loaded = compileCode(); } } return loaded; }
int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h) { //pow(sin(d),dpos)*1.7 if (need_recompile) { int err=0; int x; EnterCriticalSection(&rcs); if (!var_b || g_reset_vars_on_recompile) { clearVars(); var_x = registerVar("x"); var_y = registerVar("y"); var_w = registerVar("w"); var_h = registerVar("h"); var_b = registerVar("b"); var_alpha = registerVar("alpha"); inited=0; } need_recompile=0; for (x = 0; x < 3; x ++) { freeCode(codehandle[x]); codehandle[x]=compileCode(effect_exp[x].get()); } LeaveCriticalSection(&rcs); } *var_w=w; *var_h=h; *var_b=isBeat?1.0:0.0; if (isBeat&0x80000000) return 0; if (codehandle[0] && (!inited || m_lasth != h || m_lastw != w)) { m_lastw=w; m_lasth=h; *var_x=0; *var_y=0; *var_alpha=0.5; executeCode(codehandle[0],visdata); inited=1; } executeCode(codehandle[1],visdata); if (isBeat) executeCode(codehandle[2],visdata); int doblend=blend; int ialpha=127; if (doblend) { ialpha=(int)(*var_alpha*255.0); if (ialpha <= 0) return 0; if (ialpha >= 255) doblend=0; } int *inptr=framebuffer; int *blendptr=framebuffer; int *outptr=fbout; int xa=(int)*var_x; int ya=(int)*var_y; // var_x, var_y at this point tell us how to shift, and blend also tell us what to do. if (!subpixel) { int endy=h+ya; int endx=w+xa; int x,y; if (endx > w) endx=w; if (endy > h) endy=h; if (ya < 0) inptr += -ya*w; if (ya > h) ya=h; if (xa > w) xa=w; for (y = 0; y < ya; y ++) { x=w; if (!doblend) while (x--) *outptr++ = 0; else while (x--) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha); } for (; y < endy; y ++) { int *ip=inptr; if (xa < 0) inptr += -xa; if (!doblend) { for (x = 0; x < xa; x ++) *outptr++=0; for (; x < endx; x ++) *outptr++=*inptr++; for (; x < w; x ++) *outptr++=0; } else { for (x = 0; x < xa; x ++) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha); for (; x < endx; x ++) *outptr++ = BLEND_ADJ(*inptr++,*blendptr++,ialpha); for (; x < w; x ++) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha); } inptr=ip+w; } for (; y < h; y ++) { x=w; if (!doblend) while (x--) *outptr++ = 0; else while (x--) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha); } } else // bilinear filtering version { int xpart,ypart; { double vx=*var_x; double vy=*var_y; xpart=(int) ((vx - (int)vx)*255.0); if (xpart < 0) xpart=-xpart; else { xa++; xpart=255-xpart; } if (xpart < 0) xpart=0; if (xpart > 255) xpart=255; ypart=(int) ((vy - (int)vy)*255.0); if (ypart < 0) ypart=-ypart; else { ya++; ypart=255-ypart; } if (ypart < 0) ypart=0; if (ypart > 255) ypart=255; } int x,y; if (ya < 1-h) ya=1-h; if (xa < 1-w) xa=1-w; if (ya > h-1) ya=h-1; if (xa > w-1) xa=w-1; if (ya < 0) inptr += -ya*w; int endy=h-1+ya; int endx=w-1+xa; if (endx > w-1) endx=w-1; if (endy > h-1) endy=h-1; if (endx < 0) endx=0; if (endy < 0) endy=0; for (y = 0; y < ya; y ++) { x=w; if (!doblend) while (x--) *outptr++ = 0; else while (x--) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha); } for (; y < endy; y ++) { int *ip=inptr; if (xa < 0) inptr += -xa; if (!doblend) { for (x = 0; x < xa; x ++) *outptr++=0; for (; x < endx; x ++) *outptr++=BLEND4((unsigned int *)inptr++,w,xpart,ypart); for (; x < w; x ++) *outptr++=0; } else { for (x = 0; x < xa; x ++) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha); for (; x < endx; x ++) *outptr++ = BLEND_ADJ(BLEND4((unsigned int *)inptr++,w,xpart,ypart),*blendptr++,ialpha); for (; x < w; x ++) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha); } inptr=ip+w; } for (; y < h; y ++) { x=w; if (!doblend) while (x--) *outptr++ = 0; else while (x--) *outptr++ = BLEND_ADJ(0,*blendptr++,ialpha); } } #ifndef NO_MMX __asm emms; #endif return 1; }
typename PEAddingMethods<Register>::ErrorCode PEAddingMethods<Register>::generateCode (Wrapper<Register> *w, uint64_t &codePtr, bool isTlsCallback) { ErrorCode ec; PEFile *pe = dynamic_cast<PEFile*>(DAddingMethods<Register>::file); if(!pe) return ErrorCode::BinaryFileNoPe; if(!w) return ErrorCode::NullWrapper; uint64_t action = 0; uint64_t thread = 0; // Generowanie kodu dla akcji. if(w->detect_handler) { ec = generateCode(w->detect_handler, action); if(ec != ErrorCode::Success) return ec; } // Generowanie kodu dla funkcji wątku. ThreadWrapper<Register> *tw = dynamic_cast<ThreadWrapper<Register>*>(w); if(tw && tw->thread_actions.empty()) return ErrorCode::NoThreadAction; if(tw && !tw->thread_actions.empty()) { ec = generateThreadCode(tw->thread_actions, thread, tw->sleep_time); if(ec != ErrorCode::Success) return ec; } // Generowanie kodu BinaryCode<Register> code; // Tworzenie ramki stosu code.append(CodeDefines<Register>::startFunc); std::list<Register> rts = w->used_regs.toStdList(); bool align = false; // Zachowywanie rejestrów for(auto it = rts.begin(); it != rts.end(); ++it) { if(CodeDefines<Register>::externalRegs.contains(*it)) { code.append(CodeDefines<Register>::saveRegister(*it)); align = !align; } } // Wyrównanie do 16 w przypadku x64 if(std::is_same<Register, Registers_x64>::value && align) code.append(CodeDefines<Register>::reserveStackSpace(CodeDefines<Register>::align16Size)); // Ładowanie parametrów if(!w->dynamic_params.empty()) { DJsonParser parser(DSettings::getSettings().getDescriptionsPath<Register>()); Wrapper<Register> *func_wrap = parser.loadInjectDescription<Register>(windowsApiLoadingFunction); if(!func_wrap) return ErrorCode::ErrorLoadingFunctions; uint64_t get_functions = 0; ec = generateCode(func_wrap, get_functions); delete func_wrap; if(ec != ErrorCode::Success) return ec; ec = generateParametersLoadingCode(code, get_functions, w->dynamic_params, thread); if(ec != ErrorCode::Success) return ec; } // Doklejanie właściwego kodu QByteArray binCode; ec = compileCode(w->code, binCode); if(ec != ErrorCode::Success) return ec; code.append(binCode); // Handler if(action) { Register cond = w->ret; int act_idx = CodeDefines<Register>::internalRegs.indexOf(cond); Register act = act_idx == -1 ? CodeDefines<Register>::internalRegs[0] : CodeDefines<Register>::internalRegs[(act_idx + 1) % CodeDefines<Register>::internalRegs.length()]; generateActionConditionCode(code, action, cond, act); } // Wyrównanie do 16 w przypadku x64 if(std::is_same<Register, Registers_x64>::value && align) code.append(CodeDefines<Register>::clearStackSpace(CodeDefines<Register>::align16Size)); // Przywracanie rejestrów for(auto it = rts.rbegin(); it != rts.rend(); ++it) { if(CodeDefines<Register>::externalRegs.contains(*it)) code.append(CodeDefines<Register>::restoreRegister(*it)); } // Niszczenie ramki stosu i ret code.append(CodeDefines<Register>::endFunc); if(isTlsCallback && !std::is_same<Register, Registers_x64>::value) code.append(CodeDefines<Register>::retN(3 * CodeDefines<Register>::stackCellSize)); else code.append(CodeDefines<Register>::ret); codePtr = pe->injectUniqueData(code, codePointers, relocations); return codePtr == 0 ? ErrorCode::PeOperationFailed : ErrorCode::Success; }