nuclear@44: #include nuclear@15: #include "opengl.h" nuclear@15: #include "renderer.h" nuclear@23: #include "level.h" nuclear@15: #include "sdr.h" nuclear@15: #include "datapath.h" nuclear@15: nuclear@41: static unsigned int load_sdr(const char *vfname, const char *pfname); nuclear@35: nuclear@41: Renderer *rend; nuclear@18: nuclear@15: nuclear@41: Renderer::Renderer() nuclear@41: { nuclear@41: width = height = 0; nuclear@41: } nuclear@17: nuclear@41: Renderer::~Renderer() nuclear@41: { nuclear@41: } nuclear@17: nuclear@41: bool Renderer::init(int xsz, int ysz) nuclear@41: { nuclear@41: width = xsz; nuclear@41: height = ysz; nuclear@17: nuclear@41: rend = this; nuclear@41: return true; nuclear@41: } nuclear@15: nuclear@41: int Renderer::get_tangent_location() const nuclear@41: { nuclear@41: return -1; nuclear@41: } nuclear@15: nuclear@41: unsigned int Renderer::get_current_program() const nuclear@41: { nuclear@41: return 0; nuclear@41: } nuclear@21: nuclear@41: void Renderer::resize(int xsz, int ysz) nuclear@41: { nuclear@41: width = xsz; nuclear@41: height = ysz; nuclear@41: } nuclear@21: nuclear@41: nuclear@41: // ---- fallback forward renderer ---- nuclear@41: FwdRenderer::FwdRenderer() nuclear@17: { nuclear@41: sdrprog = 0; nuclear@41: tang_attr = -1; nuclear@41: } nuclear@41: nuclear@41: FwdRenderer::~FwdRenderer() nuclear@41: { nuclear@41: if(sdrprog) { nuclear@41: free_program(sdrprog); nuclear@32: } nuclear@41: } nuclear@21: nuclear@41: bool FwdRenderer::init(int xsz, int ysz) nuclear@41: { nuclear@41: width = xsz; nuclear@41: height = ysz; nuclear@19: nuclear@41: if(glUseProgram && (sdrprog = load_sdr("fallback.v.glsl", "fallback.p.glsl"))) { nuclear@41: tang_attr = get_attrib_loc(sdrprog, "attr_tangent"); nuclear@41: set_uniform_int(sdrprog, "tex_dif", 0); nuclear@41: set_uniform_int(sdrprog, "tex_norm", 1); nuclear@23: } nuclear@17: return true; nuclear@17: } nuclear@17: nuclear@41: int FwdRenderer::get_tangent_location() const nuclear@17: { nuclear@41: return tang_attr; nuclear@17: } nuclear@17: nuclear@41: unsigned int FwdRenderer::get_current_program() const nuclear@33: { nuclear@41: return sdrprog; nuclear@33: } nuclear@33: nuclear@41: void FwdRenderer::render(const Level *level) const nuclear@35: { nuclear@41: glPushAttrib(GL_ENABLE_BIT); nuclear@51: glEnable(GL_LIGHTING); nuclear@51: glEnable(GL_FOG); nuclear@51: glFogi(GL_FOG_MODE, GL_LINEAR); nuclear@51: glFogf(GL_FOG_START, 3.0f); nuclear@51: glFogf(GL_FOG_END, 6.0f); nuclear@51: nuclear@41: glUseProgram(sdrprog); nuclear@35: nuclear@23: level->draw(); nuclear@20: nuclear@46: glUseProgram(0); nuclear@46: level->draw_post(); nuclear@46: nuclear@41: glPopAttrib(); nuclear@17: } nuclear@17: nuclear@18: static unsigned int load_sdr(const char *vfname, const char *pfname) nuclear@15: { nuclear@15: char vsfile[PATH_MAX], psfile[PATH_MAX]; nuclear@15: const char *fname; nuclear@18: unsigned int prog; nuclear@15: nuclear@18: if((fname = datafile_path(vfname))) { nuclear@17: strcpy(vsfile, fname); nuclear@17: } else { nuclear@17: vsfile[0] = 0; nuclear@17: } nuclear@18: if((fname = datafile_path(pfname))) { nuclear@17: strcpy(psfile, fname); nuclear@17: } else { nuclear@17: psfile[0] = 0; nuclear@17: } nuclear@18: if(!(prog = create_program_load(vsfile, psfile))) { nuclear@18: fprintf(stderr, "failed to load shader program (%s, %s)\n", vsfile, psfile); nuclear@18: return 0; nuclear@15: } nuclear@18: return prog; nuclear@15: }