Created
June 16, 2014 06:17
-
-
Save FlyingJester/e981a440d6143d350b7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "drawingOperation.hpp" | |
| #include "initGL.h" | |
| #include <atomic> | |
| #include <OpenGL/gl3.h> | |
| #include "concurrent_queue.hpp" | |
| #include <stdio.h> | |
| #define F(x) ((float)x) | |
| typedef std::atomic<size_t> atomic_size; | |
| typedef tower::concurrent::concurrent_queue<tower::gfx::DrawingOperation *> drawQueue_t; | |
| volatile atomic_size num_flipscreens; | |
| drawQueue_t drawQueue; | |
| tower::gfx::DrawingOperation::~DrawingOperation(){ | |
| } | |
| void tower::gfx::ColorScreen::call(const struct DrawingState *){ | |
| glClearColor(F(mColor[0])/255.0f, F(mColor[1])/255.0f, F(mColor[2])/255.0f, F(mColor[3])/255.0f); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| glClearColor(0, 0, 0, 255); | |
| } | |
| void tower::gfx::FlipScreen::call(const DrawingState *aState){ | |
| CGL_FlipScreen(aState); | |
| TowerDecNumberOfFinishedFrames(); | |
| } | |
| tower::gfx::FlipScreen::FlipScreen(){ | |
| TowerIncNumberOfFinishedFrames(); | |
| } | |
| size_t TowerGetNumberOfFinishedFrames(void){ | |
| printf("Number of operations is %lu. num_flipscreens is at %p.\n", num_flipscreens.load(), &num_flipscreens); | |
| return num_flipscreens.load(); | |
| } | |
| void TowerIncNumberOfFinishedFrames(void){ | |
| num_flipscreens.fetch_add(1);} | |
| void TowerDecNumberOfFinishedFrames(void){ | |
| num_flipscreens.fetch_sub(1);} | |
| void TowerPushDrawQueue(tower::gfx::DrawingOperation *aOperation){ | |
| drawQueue.push(aOperation); | |
| } | |
| void TowerPopDrawQueue(const struct DrawingState * aState){ | |
| tower::gfx::DrawingOperation *op = drawQueue.pop(); | |
| printf("Popped an operation.\n"); | |
| op->call(aState); | |
| delete op; | |
| } | |
| void TowerInitDrawQueue(void){ | |
| num_flipscreens.store(0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment