예제 #1
0
void
LayerManagerComposite::EndTransaction(const TimeStamp& aTimeStamp,
                                      EndTransactionFlags aFlags)
{
  NS_ASSERTION(mInTransaction, "Didn't call BeginTransaction?");
  NS_ASSERTION(!(aFlags & END_NO_COMPOSITE),
               "Shouldn't get END_NO_COMPOSITE here");
  mInTransaction = false;
  mRenderStartTime = TimeStamp::Now();

  if (!mIsCompositorReady) {
    return;
  }
  mIsCompositorReady = false;

#ifdef MOZ_LAYERS_HAVE_LOG
  MOZ_LAYERS_LOG(("  ----- (beginning paint)"));
  Log();
#endif

  if (mDestroyed) {
    NS_WARNING("Call on destroyed layer manager");
    return;
  }

  // Set composition timestamp here because we need it in
  // ComputeEffectiveTransforms (so the correct video frame size is picked) and
  // also to compute invalid regions properly.
  mCompositor->SetCompositionTime(aTimeStamp);

  if (mRoot && !(aFlags & END_NO_IMMEDIATE_REDRAW)) {
    MOZ_ASSERT(!aTimeStamp.IsNull());
    UpdateAndRender();
    mCompositor->FlushPendingNotifyNotUsed();
  } else {
    // Modified the layer tree.
    mGeometryChanged = true;
  }

  mCompositor->ClearTargetContext();
  mTarget = nullptr;

#ifdef MOZ_LAYERS_HAVE_LOG
  Log();
  MOZ_LAYERS_LOG(("]----- EndTransaction"));
#endif
}
예제 #2
0
파일: g_win32.c 프로젝트: eygbey/Cynfiny
int CALLBACK WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CommandLine, int ShowFlags)
{
	DWORD error;
	UINT DesiredSchedulerMS = 1;

	float MSPerFrame = 0;
	float TargetSecondsPerFrame;

	int width;
	int height;
	
	HWND Window;
	RECT ClientRect;

	HGLRC RC;

	GLenum err = 0;

	GameState state = {0};

	WNDCLASSEX WindowClass;
	WindowClass.cbSize = sizeof(WindowClass);
    WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    WindowClass.lpfnWndProc = MyWindowProc;
    WindowClass.cbClsExtra = 0;
    WindowClass.cbWndExtra = 0;
    WindowClass.hInstance = Instance;
    WindowClass.hIcon = 0;
    WindowClass.hCursor = 0;
    WindowClass.hbrBackground = 0;
    WindowClass.lpszMenuName = NULL;
    WindowClass.lpszClassName = "WindowClass";
    WindowClass.hIconSm = 0;

	if( RegisterClassEx(&WindowClass) )
	{
		width = GetSystemMetrics(SM_CXMAXIMIZED);
		height = GetSystemMetrics(SM_CYMAXIMIZED);

		Window = CreateWindowExA(0, WindowClass.lpszClassName, "My Test Window",
									  WS_OVERLAPPEDWINDOW|WS_VISIBLE|WS_MAXIMIZE,
									  0, 0, width, height,
									  0, 0, Instance, 0);

		TargetSecondsPerFrame = 1.0f / 60.0f;

		if(Window)
		{
			HDC DC = GetDC(Window);
			SetupPixelFormat(DC);
            RC = wglCreateContext(DC);
            wglMakeCurrent(DC, RC);

			err = glewInit();
			if (GLEW_OK != err)
				fprintf(stderr, "Error: %s\n", glewGetErrorString(err));

			GetClientRect(Window, &ClientRect);

			width = ClientRect.right - ClientRect.left;
			height = ClientRect.bottom - ClientRect.top;

			state.width = (float)width;
			state.height = (float)height;

			glViewport(0,0, width, height);
			glEnable(GL_DEPTH_TEST);

			//V3 p1 = { -8.0f, 6.0f, 4.3f };
			V3 p1 = { 0.0f, 6.0f, 4.0f };
			InitCamera(&state.main, p1);
			
			state.deltaT = TargetSecondsPerFrame;
			
			InitGame(&state);
			
			Running = 1;

			LARGE_INTEGER start, end;

			float timeElasped;
			DWORD sleepMS;

			while(Running)
			{
				start = Win32GetTime();

				ProcessMessages(&state);

				if(state.keys & Z_KEY){
					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		    	}else {
					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
				}
				
				UpdateAndRender(&state);

				end = Win32GetTime();
				timeElasped = Win32GetSecondsElapsed(start, end);

				if(timeElasped < TargetSecondsPerFrame){
					sleepMS = (DWORD)((TargetSecondsPerFrame*1000) - (timeElasped*1000));
					Sleep(sleepMS);
				}else{
					OutputDebugString("Missed Frame");
				}


				SwapBuffers(DC);
			}
		}
		else
		{
			error = GetLastError();
		}
	}
	else
	{
		error = GetLastError();
	}

	return 0;
}
예제 #3
0
int main()
{
    SDL_Init(SDL_INIT_VIDEO);
    
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

    SDL_Window * window = SDL_CreateWindow("gamedev", SDL_WINDOWPOS_UNDEFINED,
            SDL_WINDOWPOS_UNDEFINED, 1024, 768,
            SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);

    if(window) {
        SDL_GLContext gl_context = SDL_GL_CreateContext(window);

        // Initialize GLEW so we can get 3.30 stuff
        // I copied this from my quaternion demo
        // TODO: Can I do this without glew?

        // This experimental flag seems to be necessary for GLEW to load entry points
        // for certain core profile functions, like glGenVertexArrays. Really 
        // looking forward to getting rid of GLEW
        glewExperimental = GL_TRUE;
        GLenum err = glewInit();
        if (err != GLEW_OK)
        {
            fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
            exit(1); // or handle the error in a nicer way
        }

        if (!GLEW_VERSION_3_3)  // 
        {
            printf("Missing OpenGL version 3.3\n");
            exit(1); // or handle the error in a nicer way
        }

        printf("GLSL version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));

        game_memory Memory = {};
        Memory.PermanentStoreSize = Megabytes(256);
        Memory.TransientStoreSize = Gigabytes(1);
        Memory.TotalSize = Memory.PermanentStoreSize + Memory.TransientStoreSize;
        void * AllocatedMemory = mmap(0, Memory.TotalSize, PROT_READ | PROT_WRITE,
                MAP_ANON | MAP_PRIVATE, 0, 0);

        if(AllocatedMemory != MAP_FAILED) {
            //TODO: zero out the memory?

            Memory.PermanentStore = (uint8*)AllocatedMemory;
            Memory.TransientStore = Memory.PermanentStore + Memory.PermanentStoreSize;

            Memory.PermanentArena.Base = Memory.PermanentStore;
            Memory.PermanentArena.Size = Memory.PermanentStoreSize;
            Memory.PermanentArena.Offset = 0;

            Memory.TransientArena.Base = Memory.TransientStore;
            Memory.TransientArena.Size = Memory.TransientStoreSize;
            Memory.TransientArena.Offset = 0;

            game_state * GameState = PushStruct(&Memory.PermanentArena, game_state);

            bool Quit = false;
            while(!Quit) {

                // Handle keyboard events
                SDL_Event Event;
                while(SDL_PollEvent(&Event)) {
                    // TODO: probably don't want to take all the events here
                    switch(Event.type) {
                        case SDL_KEYUP:
                        case SDL_KEYDOWN:
                            SDL_KeyboardEvent KB_Event = Event.key;
                            SDL_Keysym Keysym = KB_Event.keysym;
                            switch(Keysym.sym) {
                                case SDLK_q:
                                    Quit = true;
                                    break;
                            }
                            break;
                    }
                }

                // Update/draw
                UpdateAndRender(&Memory, GameState);
                SDL_GL_SwapWindow(window);
            }
        }

        SDL_GL_DeleteContext(gl_context);
    } else {
        printf("Could not initialize SDL window.");
        return 1;
    }
    return 0;
}