Browse Source

added GIF support via PitMap

Iver 6 days ago
parent
commit
2ab062974e

BIN
builds/libpitmap.so


BIN
builds/librasteriver.so


BIN
builds/main.bin


+ 4 - 2
changelog.txt

@@ -1,2 +1,4 @@
--added RI prefix to header files
--added etymology to readme
+-new PitMap (GIF parsing)
+-new function for loading a GIF
+-flipped X when reading UVs
+-new example scene using RI_load_gif

+ 3 - 0
src/headers/RI_functions.h

@@ -37,4 +37,7 @@ RI_texture* RI_load_image(char* filename);
 // loads an image file as an animated texture
 RI_texture* RI_load_animation(char* filename, uint16_t frame_count);
 
+// loads a gif file as an animated texture
+RI_texture* RI_load_gif(char* filename);
+
 #endif

+ 2 - 0
src/headers/pitmap.h

@@ -6,6 +6,8 @@
 typedef struct {
     uint32_t* frame_buffer;
     int width, height;
+    int frame_count;
+    int frame_height;
 } PM_image;
 
 PM_image* PM_load_image(char* filename, uint16_t debug_mode);

+ 1 - 1
src/kernels/kernels.cl

@@ -841,7 +841,7 @@ __kernel void rasterizer(__global RI_renderable_face *renderable_faces, __global
 
         RI_vector_3 interpolated_normal = {0};
         
-        uint texel_x = current_face->texture.width * ux;
+        uint texel_x = current_face->texture.width - current_face->texture.width * ux;
         uint texel_y = current_face->texture.frame_height * uy + current_face->texture.frame_height * (current_face->texture.current_frame % current_face->texture.frame_count);
 
         uint texel_index = current_face->texture.index + 

+ 2 - 2
src/launch program/main.c

@@ -31,11 +31,11 @@ int main(){
 
     scene->actors = malloc(sizeof(RI_actor) * 5);
 
-    RI_texture* skybox_texture = RI_load_animation("textures/emoji_angry.bmp", 40);
+    RI_texture* skybox_texture = RI_load_gif("textures/test_gif_2.gif");
     RI_texture* gordon_texture = RI_load_image("textures/terrain_texture.bmp");
     RI_texture* gordon_face_texture = RI_load_animation("textures/gordon_face_animated.bmp", 3);
     RI_texture* emoji_texture = RI_load_image("textures/gordon_body.bmp");
-    RI_texture* iver_texture = RI_load_animation("textures/emoji_gif.bmp", 11);
+    RI_texture* iver_texture = RI_load_gif("textures/test.gif.gif");
     RI_texture* sky_texture = RI_load_image("textures/skybox_texture_4_cube_1024x1024.bmp");
 
     scene->actors[0] = RI_new_actor();

BIN
src/libraries/libpitmap.so


+ 55 - 0
src/main/main.c

@@ -108,6 +108,61 @@ RI_texture* RI_load_animation(char* filename, uint16_t frame_count){
     return texture;
 }
 
+RI_texture* RI_load_gif(char* filename){
+    PM_image* image = PM_load_image(filename, (context.debug_flags & RI_DEBUG_PITMAP) == 0 ? 0 : 1);
+
+    RI_texture* texture = RI_malloc(sizeof(RI_texture));
+
+    int previous_length_of_textures_array = context.opencl.length_of_textures_array;
+
+    texture->width = image->width;
+    texture->height = image->height;
+    texture->index = previous_length_of_textures_array;
+
+    texture->frame_count = image->frame_count;
+    texture->frame_height = image->frame_height;
+    texture->current_frame = 0;
+
+    context.opencl.length_of_textures_array += image->width * image->height;
+
+    context.opencl.textures = RI_realloc(context.opencl.textures, context.opencl.length_of_textures_array * sizeof(uint32_t));
+
+    memcpy(context.opencl.textures + previous_length_of_textures_array, image->frame_buffer, sizeof(uint32_t) * image->width * image->height);
+
+    if (context.opencl.textures_mem_buffer) clReleaseMemObject(context.opencl.textures_mem_buffer);
+
+    context.opencl.textures_mem_buffer = clCreateBuffer(
+        context.opencl.context, 
+        CL_MEM_READ_WRITE, 
+        sizeof(uint32_t) * context.opencl.length_of_textures_array, 
+        NULL, NULL
+    );
+    
+    clEnqueueWriteBuffer(
+        context.opencl.queue, 
+        context.opencl.textures_mem_buffer, 
+        CL_TRUE, 
+        0, 
+        sizeof(uint32_t) * context.opencl.length_of_textures_array, 
+        context.opencl.textures, 
+        0, NULL, NULL
+    );
+    
+    clFinish(context.opencl.queue);
+
+    clSetKernelArg(
+        context.opencl.rasterization_kernel, 
+        1, 
+        sizeof(cl_mem), 
+        &context.opencl.textures_mem_buffer
+    );
+
+    free(image->frame_buffer);
+    free(image);
+
+    return texture;
+}
+
 RI_material *RI_new_material(){
     RI_material *new_material = RI_malloc(sizeof(RI_material));
 

BIN
textures/christmas.gif


BIN
textures/test.gif.gif


BIN
textures/test_gif_2.gif