# HG changeset patch # User John Tsiombikas # Date 1411547647 -10800 # Node ID d06e4e24f922fb37561a3ad5704f7e940b902e66 # Parent ccbd444939a113b73b01e2c466861080c5c07141 foo diff -r ccbd444939a1 -r d06e4e24f922 src/game.cc --- a/src/game.cc Mon Sep 22 18:36:24 2014 +0300 +++ b/src/game.cc Wed Sep 24 11:34:07 2014 +0300 @@ -1,8 +1,19 @@ #include +#include +#include #include "opengl.h" #include "game.h" #include "goatvr.h" +static void create_rtarg(int x, int y); +static int next_pow2(int x); + +static int win_width, win_height; +static unsigned int fb_tex; +static unsigned int fbo, fb_depth; +static int fb_xsz, fb_ysz; +static int fb_tex_xsz, fb_tex_ysz; + bool game_init() { init_opengl(); @@ -13,6 +24,12 @@ glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); + + int sdk_fb_xsz = vr_getf(VR_LEYE_XRES) + vr_getf(VR_REYE_XRES); + int sdk_fb_ysz = std::max(vr_getf(VR_LEYE_YRES), vr_getf(VR_REYE_YRES)); + create_rtarg(sdk_fb_xsz, sdk_fb_ysz); + + return true; } void game_cleanup() @@ -20,10 +37,65 @@ vr_shutdown(); } -void game_update(long tm); -void game_display(); -void game_reshape(int x, int y); +void game_update(long tm) +{ +} + +void game_display() +{ +} + +void game_reshape(int x, int y) +{ +} + void game_keyboard(int key, bool pressed); void game_mouse_button(int bn, bool state, int x, int y); void game_mouse_motion(int x, int y); + +static void create_rtarg(int x, int y) +{ + if(x == fb_xsz && y == fb_ysz) { + return; // nothing changed + } + + fb_xsz = x; + fb_ysz = y; + fb_tex_xsz = next_pow2(fb_xsz); + fb_tex_ysz = next_pow2(fb_ysz); + + if(!fbo) { + glGenFramebuffers(1, &fbo); + + glGenTextures(1, &fb_tex); + glBindTexture(GL_TEXTURE_2D, fb_tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glGenRenderbuffers(1, &fb_depth); + } + + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + + glBindTexture(GL_TEXTURE_2D, fb_tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fb_tex_xsz, fb_tex_ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb_tex, 0); + + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, fb_tex_xsz, fb_tex_ysz); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb_depth); + + assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); + glBindFramebuffer(GL_FRAMEBUFFER, 0); +} + +static int next_pow2(int x) +{ + x -= 1; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + return x + 1; +}