Add texture (not yet fully implemented) and fix chaning of dispose handlers
This commit is contained in:
parent
93fb12eb24
commit
74fd10883c
@ -9,8 +9,9 @@ pkg_check_modules(EPOXY REQUIRED epoxy)
|
|||||||
|
|
||||||
add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter)
|
add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter)
|
||||||
aux_source_directory("src" SRC_DIR)
|
aux_source_directory("src" SRC_DIR)
|
||||||
|
aux_source_directory("stb" STB_DIR)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} SHARED ${SRC_DIR})
|
add_library(${PROJECT_NAME} SHARED ${SRC_DIR} ${STB_DIR})
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${EPOXY_INCLUDE_DIRS})
|
target_include_directories(${PROJECT_NAME} PRIVATE ${EPOXY_INCLUDE_DIRS})
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${GLIB_LDFLAGS} ${EPOXY_LDFLAGS} cglm)
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${GLIB_LDFLAGS} ${EPOXY_LDFLAGS} cglm)
|
||||||
|
45
include/shimatta-opengl-texture.h
Normal file
45
include/shimatta-opengl-texture.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#ifndef _SHIMATTA_OPENGL_TEXTURE_H_
|
||||||
|
#define _SHIMATTA_OPENGL_TEXTURE_H_
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <glib-object.h>
|
||||||
|
#include <epoxy/gl.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define SHIMATTA_TYPE_OPENGL_TEXTURE (shimatta_opengl_texture_get_type())
|
||||||
|
|
||||||
|
G_DECLARE_DERIVABLE_TYPE(ShimattaOpenglTexture, shimatta_opengl_texture, SHIMATTA, OPENGL_TEXTURE, GObject);
|
||||||
|
|
||||||
|
struct _ShimattaOpenglTextureClass {
|
||||||
|
GObjectClass super;
|
||||||
|
void (*use)(ShimattaOpenglTexture *texture);
|
||||||
|
int (*use_in_slot)(ShimattaOpenglTexture *texture, unsigned int slot);
|
||||||
|
};
|
||||||
|
|
||||||
|
void shimatta_opengl_texture_use(ShimattaOpenglTexture *texture);
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_use_in_slot(ShimattaOpenglTexture *texture, unsigned int slot);
|
||||||
|
|
||||||
|
ShimattaOpenglTexture *shimatta_opengl_texture_new(void);
|
||||||
|
|
||||||
|
void shimatta_opengl_texture_set_filter(ShimattaOpenglTexture *texture, int filter_s, int filter_t);
|
||||||
|
|
||||||
|
void shimatta_opengl_texture_set_wrap(ShimattaOpenglTexture *texture, int wrap_s, int wrap_t);
|
||||||
|
|
||||||
|
void shimatta_opengl_texture_set_gen_mipmap(ShimattaOpenglTexture *texture, gboolean gen_mipmap);
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_get_filter(ShimattaOpenglTexture *texture, int *filter_s, int *filter_t);
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_get_wrap(ShimattaOpenglTexture *texture, int *wrap_s, int *wrap_t);
|
||||||
|
|
||||||
|
gboolean shimatta_opengl_texture_get_gen_mipmap(ShimattaOpenglTexture *texture);
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_set_data(ShimattaOpenglTexture *texture, unsigned int width, unsigned int height,
|
||||||
|
GLenum format, void *buffer);
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_set_from_image(ShimattaOpenglTexture *texture, const char *path);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* _SHIMATTA_OPENGL_TEXTURE_H_ */
|
7656
include/stb/stb_image.h
Normal file
7656
include/stb/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@ G_DEFINE_TYPE_WITH_PRIVATE(ShimattaOpenglGraphics, shimatta_opengl_graphics, G_T
|
|||||||
|
|
||||||
static void shimatta_opengl_graphics_dispose(GObject *self)
|
static void shimatta_opengl_graphics_dispose(GObject *self)
|
||||||
{
|
{
|
||||||
(void)self;
|
G_OBJECT_CLASS(shimatta_opengl_graphics_parent_class)->dispose(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_dummy(ShimattaOpenglGraphics *graphics)
|
static void draw_dummy(ShimattaOpenglGraphics *graphics)
|
||||||
|
@ -64,6 +64,8 @@ static void shimatta_opengl_program_dispose(GObject *self)
|
|||||||
if (priv->geometry_file)
|
if (priv->geometry_file)
|
||||||
g_free(priv->geometry_file);
|
g_free(priv->geometry_file);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS(shimatta_opengl_program_parent_class)->dispose(self);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shimatta_opengl_program_class_init(ShimattaOpenglProgramClass *klass)
|
static void shimatta_opengl_program_class_init(ShimattaOpenglProgramClass *klass)
|
||||||
|
148
src/shimatta-opengl-texture.c
Normal file
148
src/shimatta-opengl-texture.c
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
#include <shimatta-opengl-texture.h>
|
||||||
|
#include <epoxy/gl.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GLint texture_wrap_s;
|
||||||
|
GLint texture_wrap_t;
|
||||||
|
GLint texture_min_filter;
|
||||||
|
GLint texture_max_filter;
|
||||||
|
gboolean generate_mipmap;
|
||||||
|
GLuint texture_id;
|
||||||
|
} ShimattaOpenglTexturePrivate;
|
||||||
|
|
||||||
|
G_DEFINE_TYPE_WITH_PRIVATE(ShimattaOpenglTexture, shimatta_opengl_texture, G_TYPE_OBJECT);
|
||||||
|
|
||||||
|
static int shimatta_opengl_texure_use_default_impl(ShimattaOpenglTexture *texture, unsigned int slot, gboolean use_slot)
|
||||||
|
{
|
||||||
|
ShimattaOpenglTexturePrivate *priv;
|
||||||
|
|
||||||
|
g_return_val_if_fail(SHIMATTA_IS_OPENGL_TEXTURE(texture), -1001);
|
||||||
|
|
||||||
|
priv = shimatta_opengl_texture_get_instance_private(texture);
|
||||||
|
|
||||||
|
if (use_slot) {
|
||||||
|
if (slot > 31)
|
||||||
|
return -1002;
|
||||||
|
else
|
||||||
|
glActiveTexture(GL_TEXTURE0+slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, priv->texture_id);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int use_in_slot_default(ShimattaOpenglTexture *texture, unsigned int slot)
|
||||||
|
{
|
||||||
|
return shimatta_opengl_texure_use_default_impl(texture, slot, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void use_default(ShimattaOpenglTexture *texture)
|
||||||
|
{
|
||||||
|
(void)shimatta_opengl_texure_use_default_impl(texture, 0U, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void shimatta_opengl_texture_class_init(ShimattaOpenglTextureClass *klass)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void shimatta_opengl_texture_init(ShimattaOpenglTexture *self)
|
||||||
|
{
|
||||||
|
ShimattaOpenglTexturePrivate *priv;
|
||||||
|
|
||||||
|
priv = shimatta_opengl_texture_get_instance_private(self);
|
||||||
|
priv->texture_id = 0;
|
||||||
|
priv->texture_wrap_s = GL_REPEAT;
|
||||||
|
priv->texture_wrap_s = GL_REPEAT;
|
||||||
|
priv->texture_min_filter = GL_LINEAR;
|
||||||
|
priv->texture_max_filter = GL_LINEAR;
|
||||||
|
priv->generate_mipmap = TRUE;
|
||||||
|
|
||||||
|
glGenTextures(1, &priv->texture_id);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, priv->texture_id);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void shimatta_opengl_texture_use(ShimattaOpenglTexture *texture)
|
||||||
|
{
|
||||||
|
ShimattaOpenglTextureClass *klass;
|
||||||
|
|
||||||
|
g_return_if_fail(SHIMATTA_IS_OPENGL_TEXTURE(texture));
|
||||||
|
klass = SHIMATTA_OPENGL_TEXTURE_GET_CLASS(texture);
|
||||||
|
|
||||||
|
klass->use(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_use_in_slot(ShimattaOpenglTexture *texture, unsigned int slot)
|
||||||
|
{
|
||||||
|
ShimattaOpenglTextureClass *klass;
|
||||||
|
|
||||||
|
g_return_val_if_fail(SHIMATTA_IS_OPENGL_TEXTURE(texture), -1001);
|
||||||
|
klass = SHIMATTA_OPENGL_TEXTURE_GET_CLASS(texture);
|
||||||
|
|
||||||
|
return klass->use_in_slot(texture, slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShimattaOpenglTexture *shimatta_opengl_texture_new()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void shimatta_opengl_texture_set_filter(ShimattaOpenglTexture *texture, int filter_s, int filter_t)
|
||||||
|
{
|
||||||
|
ShimattaOpenglTexturePrivate *priv;
|
||||||
|
|
||||||
|
g_return_if_fail(SHIMATTA_IS_OPENGL_TEXTURE(texture));
|
||||||
|
priv = shimatta_opengl_texture_get_instance_private(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shimatta_opengl_texture_set_wrap(ShimattaOpenglTexture *texture, int wrap_s, int wrap_t)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void shimatta_opengl_texture_set_gen_mipmap(ShimattaOpenglTexture *texture, gboolean gen_mipmap)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_get_filter(ShimattaOpenglTexture *texture, int *filter_s, int *filter_t)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_get_wrap(ShimattaOpenglTexture *texture, int *filter_s, int *filter_t)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean shimatta_opengl_texture_get_gen_mipmap(ShimattaOpenglTexture *texture)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_set_data(ShimattaOpenglTexture *texture, unsigned int width, unsigned int height,
|
||||||
|
GLenum format, void *buffer)
|
||||||
|
{
|
||||||
|
ShimattaOpenglTexturePrivate *priv;
|
||||||
|
|
||||||
|
g_return_val_if_fail(SHIMATTA_IS_OPENGL_TEXTURE(texture), -1001);
|
||||||
|
priv = shimatta_opengl_texture_get_instance_private(texture);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int shimatta_opengl_texture_set_from_image(ShimattaOpenglTexture *texture, const char *path)
|
||||||
|
{
|
||||||
|
ShimattaOpenglTexturePrivate *priv;
|
||||||
|
|
||||||
|
g_return_val_if_fail(SHIMATTA_IS_OPENGL_TEXTURE(texture), -1001);
|
||||||
|
priv = shimatta_opengl_texture_get_instance_private(texture);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
2
stb/stb-implementation.c
Normal file
2
stb/stb-implementation.c
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include <stb/stb_image.h>
|
Loading…
Reference in New Issue
Block a user