- OBJ file reading

- VBO memory management
- Lighting
This commit is contained in:
2014-11-17 18:19:46 +01:00
parent ba8e07aa4e
commit 5f388a1723
16 changed files with 578 additions and 135 deletions

View File

@@ -9,11 +9,12 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <glbinding/gl/gl.h>
#include "common.hh"
using namespace gl;
static unsigned ilog2(unsigned in)
{
unsigned ret = 0u;
@@ -40,7 +41,6 @@ public:
SDL_LockSurface(surf);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surf->w, surf->h, GL_RGB, GL_UNSIGNED_BYTE, surf->pixels);
glGenerateMipmap(GL_TEXTURE_2D);
checkGlError();
} catch(...) {
glDeleteTextures(1, &_texID);
throw;
@@ -59,14 +59,12 @@ public:
void bind() {
glBindTexture(GL_TEXTURE_2D, _texID);
checkGlError();
}
private:
void _glCreate(unsigned width, unsigned height) {
glGenTextures(1, &_texID);
checkGlError();
try {
glBindTexture(GL_TEXTURE_2D, _texID);
unsigned logWidth = ilog2(width), logHeight = ilog2(height);
@@ -77,12 +75,11 @@ private:
std::printf("Warning: extension GL_ARB_texture_storage not supported!\n");
for (unsigned i = 0u; i < levels; ++i)
{
glTexImage2D(GL_TEXTURE_2D, i, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, i, static_cast<const int>(GL_RGB8), width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
width = std::max(1u, (width / 2u));
height = std::max(1u, (height / 2u));
}
}
checkGlError();
} catch(...) {
glDeleteTextures(1, &_texID);
}