finally compiling and running, text still needs rework
This commit is contained in:
@@ -1,28 +1,68 @@
|
||||
static gpu_texture new_gl_texture(void) {
|
||||
#include "twn_gpu_texture_c.h"
|
||||
#include "twn_util.h"
|
||||
|
||||
|
||||
gpu_texture create_gpu_texture(enum texture_filter filter, bool generate_mipmaps) {
|
||||
GLuint texture;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLboolean)generate_mipmaps);
|
||||
|
||||
if (filter == TEXTURE_FILTER_NEAREAST) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
} else if (filter == TEXTURE_FILTER_LINEAR) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
#if !defined(EMSCRIPTEN)
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
#endif
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
return create_gpu_texture(TEXTURE_FILTER_NEAREST, true);
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
||||
void delete_gpu_texture(gpu_texture texture) {
|
||||
glDeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
|
||||
void upload_gpu_texture(gpu_texture texture, void *pixels, int channels, int width, int height) {
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
int format_internal, format;
|
||||
if (channels == 4) {
|
||||
format_internal = GL_RGBA8;
|
||||
format = GL_RGBA;
|
||||
} else if (channels == 1) {
|
||||
format_internal = GL_ALPHA;
|
||||
format = GL_ALPHA;
|
||||
} else {
|
||||
CRY("upload_gpu_texture", "Unsupported channel count");
|
||||
return;
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
surface->w,
|
||||
surface->h,
|
||||
format_internal,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
surface->pixels);
|
||||
pixels);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
|
||||
void bind_gpu_texture(gpu_texture texture) {
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
Reference in New Issue
Block a user