Skip to content

Instantly share code, notes, and snippets.

@FlyingJester
Created June 16, 2014 06:17
Show Gist options
  • Select an option

  • Save FlyingJester/e981a440d6143d350b7a to your computer and use it in GitHub Desktop.

Select an option

Save FlyingJester/e981a440d6143d350b7a to your computer and use it in GitHub Desktop.
#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