bool WinWindow::activate() { inactiveDueToDeactivate = false; // restore window ShowWindow(hwnd, SW_RESTORE); SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); // recreate OpenGL context const bool hadChild = (hDCChild != NULL); makeContext(); if (!hadChild && hDCChild != NULL) { // reload context data OpenGLGState::initContext(); // force a redraw callExposeCallbacks(); return true; } return false; }
void Fiber::init(bool recordStackUsed) { // It is necessary to disable the logic for ASAN because we change // the fiber's stack. #ifndef FOLLY_SANITIZE_ADDRESS recordStackUsed_ = recordStackUsed; if (UNLIKELY(recordStackUsed_ && !stackFilledWithMagic_)) { auto limit = fcontext_.stackLimit(); auto base = fcontext_.stackBase(); std::fill( static_cast<uint64_t*>(limit), static_cast<uint64_t*>(base), kMagic8Bytes); // newer versions of boost allocate context on fiber stack, // need to create a new one auto size = fiberManager_.options_.stackSize; fcontext_ = makeContext(limit, size, &Fiber::fiberFuncHelper); stackFilledWithMagic_ = true; } #else (void)recordStackUsed; #endif }
Fiber::Fiber(FiberManager& fiberManager) : fiberManager_(fiberManager) { auto size = fiberManager_.options_.stackSize; auto limit = fiberManager_.stackAllocator_.allocate(size); fcontext_ = makeContext(limit, size, &Fiber::fiberFuncHelper); fiberManager_.allFibers_.push_back(*this); }
scriptContext* Mission::addContext( missionNode *node ) { scriptContext *context = makeContext( node ); contextStack *stack = runtime.cur_thread->exec_stack.back(); stack->contexts.push_back( context ); debug( 5, node, SCRIPT_RUN, "added context for this node" ); printRuntime(); return context; }
static void test_backToFront(skiatest::Reporter* reporter) { SkLayerDrawLooper::Builder looperBuilder; SkLayerDrawLooper::LayerInfo layerInfo; // Add the back layer, with the defaults. (void)looperBuilder.addLayerOnTop(layerInfo); // Add the front layer, with some layer info set. layerInfo.fOffset.set(10.0f, 20.0f); layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); layerPaint->setBlendMode(SkBlendMode::kSrc); FakeDevice device; SkCanvas canvas(&device); SkPaint paint; auto looper(looperBuilder.detach()); SkArenaAlloc alloc{48}; SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc); // The back layer should come first. REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver); canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); paint.reset(); // Then the front layer. REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc); canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); // Only two layers were added, so that should be the end. REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); }
int main( int argc, char *argv[] ) { // Open the program's source. if ( argc != 2 ) usage(); FILE *fp = fopen( argv[ 1 ], "r" ); if ( !fp ) { fprintf( stderr, "Can't open file: %s\n", argv[ 1 ] ); usage(); } // Parse the whole program source into an expression object. // The parser uses a one-token lookahead to help parsing compound expressions. char tok[ MAX_TOKEN + 1 ]; Expr *expr = parse( expectToken( tok, fp ), fp ); // If this is a legal input, there shouldn't be any extra tokens at the end. if ( nextToken( tok, fp ) ) { fprintf( stderr, "line %d: unexpected token \"%s\"\n", linesRead(), tok ); exit( EXIT_FAILURE ); } fclose( fp ); // Run the program. Context *ctxt = makeContext(); char *result = expr->eval( expr, ctxt ); // Everything evaluates to a dynamically allocated string, but we don't // do anything with the one out of the top-level expression. free( result ); // We're done, free everything. freeContext( ctxt ); expr->destroy( expr ); return EXIT_SUCCESS; }
int main() { // creates a window and GLES context if (makeContext() != 0) exit(-1); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); flareTex = loadPNG("resources/textures/cloud.png"); width = getDisplayWidth(); height = getDisplayHeight(); glViewport(0, 0, getDisplayWidth(), getDisplayHeight()); // initialises glprint's matrix, shader and texture initGlPrint(getDisplayWidth(), getDisplayHeight()); font1=createFont("resources/textures/font.png",0,256,16,16,16); initSprite(getDisplayWidth(), getDisplayHeight()); fileid = 0; loadfile(); for (int i=0; i<max_flares; i++) { flares[i].x=rand_range(0,getDisplayWidth()); flares[i].y=rand_range(0,getDisplayHeight()); flares[i].vx=rand_range(0,10)-5; flares[i].vy=rand_range(0,10)-5; } /*for (int i=0; i<max_targets; i++) { targets[i].x=rand_range(0,getDisplayWidth()); targets[i].y=rand_range(0,getDisplayHeight()); targets[i].flares = 0; }*/ /*for (int i=0; i<max_flares; i++) { flares[i].x=rand_range(0,getDisplayWidth()); flares[i].y=rand_range(0,getDisplayHeight()); flares[i].vx=rand_range(0,10)-5; flares[i].vy=rand_range(0,10)-5; flares[i].target = (int)rand_range(0,max_targets); targets[flares[i].target].flares ++; }*/ // we don't want to draw the back of triangles // the blending is set up for glprint but disabled // while not in use glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glClearColor(0, 0.5, 1, 1); // count each frame int num_frames = 0; // set to true to leave main loop bool quit = false; // get a pointer to the key down array keys = getKeys(); int* mouse = getMouse(); while (!quit) { // the main loop doEvents(); // update mouse and key arrays if (keys[KEY_ESC]) quit = true; // exit if escape key pressed if (keys[KEY_SPACE]) relocate_targets(); // exit if escape key pressed if (keys[KEY_RETURN]) reassign_flares(); // exit if escape key pressed if (keys[KEY_S] && !lastkeys[KEY_S]) save(); // exit if escape key pressed if (keys[KEY_CURSL] && !lastkeys[KEY_CURSL]){ fileid--; if (fileid <0) fileid = 0; loadfile(); // exit if escape key pressed } if (keys[KEY_CURSR] && !lastkeys[KEY_CURSR]){ fileid++; loadfile(); // exit if escape key pressed } if (keys[KEY_C]){ max_targets = 1; // exit if escape key pressed reassign_flares(); } lastkeys[KEY_S] = keys[KEY_S]; lastkeys[KEY_CURSL] = keys[KEY_CURSL]; lastkeys[KEY_CURSR] = keys[KEY_CURSR]; mx = mouse[0]; my = mouse[1]; if(mouse[2] != 0){ spawn_target(mx,my); } for (int i=0; i<RE_MULTIPLY; i++){ random_events(); } think(); render(); // the render loop usleep(1600); // no need to run cpu/gpu full tilt } closeContext(); // tidy up return 0; }
void ContextFixture::SetUp() { makeContext(0); }
int main() { lightDir.x=0.5; lightDir.y=.7; lightDir.z=-0.5; kmVec3Normalize(&lightDir,&lightDir); // creates a window and GLES context if (makeContext() != 0) exit(-1); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); // The obj shapes and their textures are loaded cubeTex = loadPNG("resources/textures/dice.png"); loadObj(&cubeObj, "resources/models/cube.gbo", "resources/shaders/textured.vert", "resources/shaders/textured.frag"); shipTex = loadPNG("resources/textures/shipv2.png"); loadObjCopyShader(&shipObj,"resources/models/ship.gbo",&cubeObj); alienTex = loadPNG("resources/textures/alien.png"); loadObjCopyShader(&alienObj, "resources/models/alien.gbo", &cubeObj); shotTex = loadPNG("resources/textures/shot.png"); loadObjCopyShader(&shotObj, "resources/models/shot.gbo", &cubeObj); expTex = loadPNG("resources/textures/explosion.png"); playerPos.x = 0; playerPos.y = 0; playerPos.z = 0; kmMat4Identity(&view); pEye.x = 0; pEye.y = 2; pEye.z = 4; pCenter.x = 0; pCenter.y = 0; pCenter.z = -5; pUp.x = 0; pUp.y = 1; pUp.z = 0; kmMat4LookAt(&view, &pEye, &pCenter, &pUp); // projection matrix, as distance increases // the way the model is drawn is effected kmMat4Identity(&projection); kmMat4PerspectiveProjection(&projection, 45, (float)getDisplayWidth() / getDisplayHeight(), 0.1, 100); glViewport(0, 0, getDisplayWidth(), getDisplayHeight()); // these two matrices are pre combined for use with each model render kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); // initialises glprint's matrix shader and texture initGlPrint(getDisplayWidth(), getDisplayHeight()); font1=createFont("resources/textures/font.png",0,256,16,16,16); font2=createFont("resources/textures/bigfont.png",32,512,9.5,32,48); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // only used by glprintf glEnable(GL_DEPTH_TEST); struct timeval t, ta, t1, t2; // fps stuff gettimeofday(&t1, NULL); int num_frames = 0; bool quit = false; mouse = getMouse(); keys = getKeys(); resetAliens(); for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { playerShots[n].alive = false; } initPointClouds("resources/shaders/particle.vert", "resources/shaders/particle.frag",(float)getDisplayWidth()/24.0); for (int n = 0; n < MAX_ALIENS; n++) { aliens[n].explosion=createPointCloud(40); resetExposion(aliens[n].explosion); // sets initials positions } while (!quit) { // the main loop doEvents(); // update mouse and key arrays // mask of 4 is right mouse if (keys[KEY_ESC]) quit = true; glClearColor(0, .5, 1, 1); // render between two gettimeofday calls so // we can sleep long enough to roughly sync // to ~60fps but not on the pi! // TODO find something a tad more elegent long i; gettimeofday(&t, NULL); i = t.tv_sec * 1e6 + t.tv_usec; // render(); float rad; // radians rotation based on frame counter glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); frame++; rad = frame * (0.0175f * 2); kmMat4Identity(&model); kmMat4Translation(&model, playerPos.x, playerPos.y, playerPos.z); playerCroll += (PIDcal(playerRoll, playerCroll, &playerPre_error, &playerIntegral) / 2); kmMat4RotationPitchYawRoll(&model, 0, 3.1416, playerCroll * 3); // kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shipTex); drawObj(&shipObj, &mvp, &mv, lightDir, viewDir); glPrintf(50 + sinf(rad) * 16, 240 + cosf(rad) * 16, font2,"frame=%i fps=%3.2f", frame, lfps); kmVec3 tmp; playerFireCount--; if (keys[KEY_LCTRL] && playerFireCount < 0) { struct playerShot_t *freeShot; freeShot = getFreeShot(); if (freeShot != 0) { playerFireCount = 15; freeShot->alive = true; kmVec3Assign(&freeShot->pos, &playerPos); } } for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { if (playerShots[n].alive) { playerShots[n].pos.z -= .08; if (playerShots[n].pos.z < -10) playerShots[n].alive = false; kmMat4Identity(&model); kmMat4Translation(&model, playerShots[n].pos.x, playerShots[n].pos.y, playerShots[n].pos.z); kmMat4RotationPitchYawRoll(&model, rad * 4, 0, -rad * 4); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shotTex); drawObj(&shotObj, &mvp, &mv, lightDir, viewDir); } } playerRoll = 0; if (keys[KEY_CURSL] && playerPos.x > -10) { playerPos.x -= 0.1; playerRoll = .2; } if (keys[KEY_CURSR] && playerPos.x < 10) { playerPos.x += 0.1; playerRoll = -.2; } pEye.x = playerPos.x * 1.25; pCenter.x = playerPos.x; pCenter.y = playerPos.y + 1; pCenter.z = playerPos.z; int deadAliens; deadAliens = 0; for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].alive == true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4RotationPitchYawRoll(&model, -.4, 0, 0); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, alienTex); drawObj(&alienObj, &mvp, &mv, lightDir, viewDir); kmVec3 d; for (int i = 0; i < MAX_PLAYER_SHOTS; i++) { kmVec3Subtract(&d, &aliens[n].pos, &playerShots[i].pos); if (kmVec3Length(&d) < .7 && playerShots[i].alive) { aliens[n].alive = false; playerShots[i].alive = false; aliens[n].exploding = true; resetExposion(aliens[n].explosion); } } } if (aliens[n].alive != true && aliens[n].exploding != true) { deadAliens++; } } if (deadAliens == MAX_ALIENS) { resetAliens(); } // draw explosions after ALL aliens for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].exploding==true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); glBindTexture(GL_TEXTURE_2D, expTex); drawPointCloud(aliens[n].explosion, &mvp); aliens[n].explosion->tick=aliens[n].explosion->tick+0.05; if (aliens[n].explosion->tick>1.25) { aliens[n].exploding=false; } else { // update the explosion for (int i=0; i<aliens[n].explosion->totalPoints; i++) { float t; t=aliens[n].explosion->tick; if (i>aliens[n].explosion->totalPoints/2) t=t/2.0; aliens[n].explosion->pos[i*3]=aliens[n].explosion->vel[i*3] * t; aliens[n].explosion->pos[i*3+1]=aliens[n].explosion->vel[i*3+1] * t; aliens[n].explosion->pos[i*3+2]=aliens[n].explosion->vel[i*3+2] * t; } } } } // move camera kmMat4LookAt(&view, &pEye, &pCenter, &pUp); kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); kmVec3Subtract(&viewDir,&pEye,&pCenter); kmVec3Normalize(&viewDir,&viewDir); // dump values glPrintf(100, 280, font1,"eye %3.2f %3.2f %3.2f ", pEye.x, pEye.y, pEye.z); glPrintf(100, 296, font1,"centre %3.2f %3.2f %3.2f ", pCenter.x, pCenter.y, pCenter.z); glPrintf(100, 320, font1,"mouse %i,%i %i ", mouse[0], mouse[1], mouse[2]); glPrintf(100, 340, font1,"frame %i %i ", frame, frame % 20); swapBuffers(); gettimeofday(&ta, NULL); long j = (ta.tv_sec * 1e6 + ta.tv_usec); i = j - i; if (i < 0) i = 1000000; // pass through - slower that 60fps if (i < 16000) usleep(16000 - i); // every 10 frames average the time taken and store // fps value for later printing with glprintf if (++num_frames % 10 == 0) { gettimeofday(&t2, NULL); float dtf = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec) * 1e-6; lfps = num_frames / dtf; num_frames = 0; t1 = t2; } } closeContext(); return 0; }
extern "C" BoxedGenerator::BoxedGenerator(BoxedFunctionBase* function, Box* arg1, Box* arg2, Box* arg3, Box** args) : function(function), arg1(arg1), arg2(arg2), arg3(arg3), args(nullptr), entryExited(false), running(false), returnValue(nullptr), exception(nullptr, nullptr, nullptr), context(nullptr), returnContext(nullptr) #if STAT_TIMERS , prev_stack(NULL), my_timer(generator_timer_counter, 0, true) #endif { int numArgs = function->f->numReceivedArgs(); if (numArgs > 3) { numArgs -= 3; this->args = new (numArgs) GCdArray(); memcpy(&this->args->elts[0], args, numArgs * sizeof(Box*)); } static StatCounter generator_stack_reused("generator_stack_reused"); static StatCounter generator_stack_created("generator_stack_created"); void* initial_stack_limit; if (available_addrs.size() == 0) { generator_stack_created.log(); uint64_t stack_low = next_stack_addr; uint64_t stack_high = stack_low + MAX_STACK_SIZE; next_stack_addr = stack_high; #if STACK_GROWS_DOWN this->stack_begin = (void*)stack_high; initial_stack_limit = (void*)(stack_high - INITIAL_STACK_SIZE); void* p = mmap(initial_stack_limit, INITIAL_STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS | MAP_GROWSDOWN, -1, 0); ASSERT(p == initial_stack_limit, "%p %s", p, strerror(errno)); // Create an inaccessible redzone so that the generator stack won't grow indefinitely. // Looks like it throws a SIGBUS if we reach the redzone; it's unclear if that's better // or worse than being able to consume all available memory. void* p2 = mmap((void*)stack_low, STACK_REDZONE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0); assert(p2 == (void*)stack_low); // Interestingly, it seems like MAP_GROWSDOWN will leave a page-size gap between the redzone and the growable // region. if (VERBOSITY() >= 1) { printf("Created new generator stack, starts at %p, currently extends to %p\n", (void*)stack_high, initial_stack_limit); printf("Created a redzone from %p-%p\n", (void*)stack_low, (void*)(stack_low + STACK_REDZONE_SIZE)); } #else #error "implement me" #endif // we're registering memory that isn't in the gc heap here, // which may sound wrong. Generators, however, can represent // a larger tax on system resources than just their GC // allocation, so we try to encode that here as additional gc // heap pressure. gc::registerGCManagedBytes(INITIAL_STACK_SIZE); } else { generator_stack_reused.log(); #if STACK_GROWS_DOWN uint64_t stack_high = available_addrs.back(); this->stack_begin = (void*)stack_high; initial_stack_limit = (void*)(stack_high - INITIAL_STACK_SIZE); available_addrs.pop_back(); #else #error "implement me" #endif } assert(((intptr_t)stack_begin & (~(intptr_t)(0xF))) == (intptr_t)stack_begin && "stack must be aligned"); context = makeContext(stack_begin, (void (*)(intptr_t))generatorEntry); }