diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-07-25 19:36:48 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-07-26 18:28:48 +0300 |
commit | 97b597cd0440eb3d1b278ee9f3845a87f1d7b4bf (patch) | |
tree | 549389b388c7c89026d571ff0f7c6ae30a67fdba /source/blender/gpu | |
parent | 8b7802db85cbc339a2555be41bae396cb8608b64 (diff) |
GPU: Move and rename gpu_draw*.c to C++
`gpu_draw.c` was a misleading name, `gpu_texture_image.cc` is better
suited.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture_image.cc (renamed from source/blender/gpu/intern/gpu_draw.c) | 83 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture_smoke.cc (renamed from source/blender/gpu/intern/gpu_draw_smoke.c) | 7 |
3 files changed, 45 insertions, 49 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index a4575b88fc5..8651c299367 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -58,8 +58,6 @@ set(SRC intern/gpu_batch_utils.c intern/gpu_buffers.c intern/gpu_codegen.c - intern/gpu_draw.c - intern/gpu_draw_smoke.c intern/gpu_element.c intern/gpu_extensions.c intern/gpu_framebuffer.c @@ -81,6 +79,8 @@ set(SRC intern/gpu_shader_interface.c intern/gpu_state.c intern/gpu_texture.c + intern/gpu_texture_image.cc + intern/gpu_texture_smoke.cc intern/gpu_uniformbuffer.c intern/gpu_vertex_buffer.c intern/gpu_vertex_format.c diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_texture_image.cc index e5f49555265..480a8fc24d7 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_texture_image.cc @@ -213,7 +213,7 @@ static uint gpu_texture_create_tile_mapping(Image *ima, const int multiview_eye) float array_w = GPU_texture_width(tilearray); float array_h = GPU_texture_height(tilearray); - ImageTile *last_tile = ima->tiles.last; + ImageTile *last_tile = (ImageTile *)ima->tiles.last; /* Tiles are sorted by number. */ int max_tile = last_tile->tile_number - 1001; @@ -223,7 +223,7 @@ static uint gpu_texture_create_tile_mapping(Image *ima, const int multiview_eye) glBindTexture(GL_TEXTURE_1D_ARRAY, bindcode); int width = max_tile + 1; - float *data = MEM_callocN(width * 8 * sizeof(float), __func__); + float *data = (float *)MEM_callocN(width * 8 * sizeof(float), __func__); for (int i = 0; i < width; i++) { data[4 * i] = -1.0f; } @@ -257,8 +257,8 @@ typedef struct PackTile { static int compare_packtile(const void *a, const void *b) { - const PackTile *tile_a = a; - const PackTile *tile_b = b; + const PackTile *tile_a = (const PackTile *)a; + const PackTile *tile_b = (const PackTile *)b; return tile_a->pack_score < tile_b->pack_score; } @@ -276,7 +276,7 @@ static uint gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); if (ibuf) { - PackTile *packtile = MEM_callocN(sizeof(PackTile), __func__); + PackTile *packtile = (PackTile *)MEM_callocN(sizeof(PackTile), __func__); packtile->tile = tile; packtile->boxpack.w = ibuf->x; packtile->boxpack.h = ibuf->y; @@ -380,7 +380,7 @@ static uint gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) const bool store_premultiplied = ima->alpha_mode != IMA_ALPHA_STRAIGHT; if (ibuf->channels != 4 || !store_premultiplied) { - rect_float = MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__); + rect_float = (float *)MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__); IMB_colormanagement_imbuf_to_float_texture( rect_float, 0, 0, ibuf->x, ibuf->y, ibuf, store_premultiplied); } @@ -412,7 +412,7 @@ static uint gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) unsigned int *rect = ibuf->rect; if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) { - rect = MEM_mallocN(sizeof(uchar) * 4 * ibuf->x * ibuf->y, __func__); + rect = (uint *)MEM_mallocN(sizeof(uchar) * 4 * ibuf->x * ibuf->y, __func__); IMB_colormanagement_imbuf_to_byte_texture((uchar *)rect, 0, 0, @@ -495,7 +495,7 @@ static uint gpu_texture_create_from_ibuf(Image *ima, ImBuf *ibuf, int textarget) if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) { compress_as_srgb = !IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace); - rect = MEM_mallocN(sizeof(uchar) * 4 * ibuf->x * ibuf->y, __func__); + rect = (uchar *)MEM_mallocN(sizeof(uchar) * 4 * ibuf->x * ibuf->y, __func__); if (rect == NULL) { return bindcode; } @@ -517,7 +517,7 @@ static uint gpu_texture_create_from_ibuf(Image *ima, ImBuf *ibuf, int textarget) const bool store_premultiplied = ima ? (ima->alpha_mode != IMA_ALPHA_STRAIGHT) : false; if (ibuf->channels != 4 || !store_premultiplied) { - rect_float = MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__); + rect_float = (float *)MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__); if (rect_float == NULL) { return bindcode; } @@ -553,31 +553,28 @@ static GPUTexture **gpu_get_movieclip_gputexture(MovieClip *clip, MovieClipUser *cuser, GLenum textarget) { - MovieClip_RuntimeGPUTexture *tex; - for (tex = clip->runtime.gputextures.first; tex; tex = tex->next) { + LISTBASE_FOREACH (MovieClip_RuntimeGPUTexture *, tex, &clip->runtime.gputextures) { if (memcmp(&tex->user, cuser, sizeof(MovieClipUser)) == 0) { - break; - } - } - - if (tex == NULL) { - tex = MEM_mallocN(sizeof(MovieClip_RuntimeGPUTexture), __func__); + if (tex == NULL) { + tex = (MovieClip_RuntimeGPUTexture *)MEM_mallocN(sizeof(MovieClip_RuntimeGPUTexture), + __func__); - for (int i = 0; i < TEXTARGET_COUNT; i++) { - tex->gputexture[i] = NULL; - } + for (int i = 0; i < TEXTARGET_COUNT; i++) { + tex->gputexture[i] = NULL; + } - memcpy(&tex->user, cuser, sizeof(MovieClipUser)); - BLI_addtail(&clip->runtime.gputextures, tex); - } + memcpy(&tex->user, cuser, sizeof(MovieClipUser)); + BLI_addtail(&clip->runtime.gputextures, tex); + } - if (textarget == GL_TEXTURE_2D) { - return &tex->gputexture[TEXTARGET_TEXTURE_2D]; - } - else if (textarget == GL_TEXTURE_CUBE_MAP) { - return &tex->gputexture[TEXTARGET_TEXTURE_CUBE_MAP]; + if (textarget == GL_TEXTURE_2D) { + return &tex->gputexture[TEXTARGET_TEXTURE_2D]; + } + else if (textarget == GL_TEXTURE_CUBE_MAP) { + return &tex->gputexture[TEXTARGET_TEXTURE_CUBE_MAP]; + } + } } - return NULL; } @@ -765,7 +762,7 @@ static void gpu_texture_update_from_ibuf( const bool compress_as_srgb = !IMB_colormanagement_space_is_scene_linear( ibuf->rect_colorspace); - rect = MEM_mallocN(sizeof(uchar) * 4 * w * h, __func__); + rect = (uchar *)MEM_mallocN(sizeof(uchar) * 4 * w * h, __func__); if (rect == NULL) { return; } @@ -785,7 +782,7 @@ static void gpu_texture_update_from_ibuf( const bool store_premultiplied = (ima->alpha_mode != IMA_ALPHA_STRAIGHT); if (ibuf->channels != 4 || scaled || !store_premultiplied) { - rect_float = MEM_mallocN(sizeof(float) * 4 * w * h, __func__); + rect_float = (float *)MEM_mallocN(sizeof(float) * 4 * w * h, __func__); if (rect_float == NULL) { return; } @@ -965,7 +962,8 @@ void GPU_free_texture_movieclip(struct MovieClip *clip) const int MOVIECLIP_NUM_GPUTEXTURES = 1; while (BLI_listbase_count(&clip->runtime.gputextures) > MOVIECLIP_NUM_GPUTEXTURES) { - MovieClip_RuntimeGPUTexture *tex = BLI_pophead(&clip->runtime.gputextures); + MovieClip_RuntimeGPUTexture *tex = (MovieClip_RuntimeGPUTexture *)BLI_pophead( + &clip->runtime.gputextures); for (int i = 0; i < TEXTARGET_COUNT; i++) { /* free glsl image binding */ if (tex->gputexture[i]) { @@ -989,7 +987,7 @@ static void **gpu_gen_cube_map(uint *rect, float *frect, int rectw, int recth) } /* PosX, NegX, PosY, NegY, PosZ, NegZ */ - sides = MEM_mallocN(sizeof(void *) * 6, ""); + sides = (void **)MEM_mallocN(sizeof(void *) * 6, ""); for (int i = 0; i < 6; i++) { sides[i] = MEM_mallocN(block_size * w * h, ""); } @@ -1270,7 +1268,8 @@ void GPU_paint_set_mipmap(Main *bmain, bool mipmap) GTS.texpaint = !mipmap; if (mipmap) { - for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { + + LISTBASE_FOREACH (Image *, ima, &bmain->images) { if (BKE_image_has_opengl_texture(ima)) { if (ima->gpuflag & IMA_GPU_MIPMAP_COMPLETE) { for (int eye = 0; eye < 2; eye++) { @@ -1297,7 +1296,7 @@ void GPU_paint_set_mipmap(Main *bmain, bool mipmap) } } else { - for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { + LISTBASE_FOREACH (Image *, ima, &bmain->images) { if (BKE_image_has_opengl_texture(ima)) { for (int eye = 0; eye < 2; eye++) { for (int a = 0; a < TEXTARGET_COUNT; a++) { @@ -1363,12 +1362,10 @@ static void gpu_free_unused_buffers() BLI_mutex_lock(&gpu_texture_queue_mutex); if (gpu_texture_free_queue != NULL) { - for (LinkNode *node = gpu_texture_free_queue; node; node = node->next) { - GPUTexture *tex = node->link; + GPUTexture *tex; + while ((tex = (GPUTexture *)BLI_linklist_pop(&gpu_texture_free_queue))) { GPU_texture_free(tex); } - - BLI_linklist_free(gpu_texture_free_queue, NULL); gpu_texture_free_queue = NULL; } @@ -1412,7 +1409,7 @@ void GPU_free_image(Image *ima) void GPU_free_images(Main *bmain) { if (bmain) { - for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { + LISTBASE_FOREACH (Image *, ima, &bmain->images) { GPU_free_image(ima); } } @@ -1422,7 +1419,7 @@ void GPU_free_images(Main *bmain) void GPU_free_images_anim(Main *bmain) { if (bmain) { - for (Image *ima = bmain->images.first; ima; ima = ima->id.next) { + LISTBASE_FOREACH (Image *, ima, &bmain->images) { if (BKE_image_is_animated(ima)) { GPU_free_image(ima); } @@ -1450,8 +1447,7 @@ void GPU_free_images_old(Main *bmain) lasttime = ctime; - Image *ima = bmain->images.first; - while (ima) { + LISTBASE_FOREACH (Image *, ima, &bmain->images) { if ((ima->flag & IMA_NOCOLLECT) == 0 && ctime - ima->lastused > U.textimeout) { /* If it's in GL memory, deallocate and set time tag to current time * This gives textures a "second chance" to be used before dying. */ @@ -1464,6 +1460,5 @@ void GPU_free_images_old(Main *bmain) BKE_image_free_buffers(ima); } } - ima = ima->id.next; } } diff --git a/source/blender/gpu/intern/gpu_draw_smoke.c b/source/blender/gpu/intern/gpu_texture_smoke.cc index e0b94e20574..0f5aa361fa7 100644 --- a/source/blender/gpu/intern/gpu_draw_smoke.c +++ b/source/blender/gpu/intern/gpu_texture_smoke.cc @@ -62,7 +62,8 @@ static void create_flame_spectrum_texture(float *data) # define MAX_FIRE_ALPHA 0.06f # define FULL_ON_FIRE 100 - float *spec_pixels = MEM_mallocN(TFUNC_WIDTH * 4 * 16 * 16 * sizeof(float), "spec_pixels"); + float *spec_pixels = (float *)MEM_mallocN(TFUNC_WIDTH * 4 * 16 * 16 * sizeof(float), + "spec_pixels"); blackbody_temperature_to_rgb_table(data, TFUNC_WIDTH, 1500, 3000); @@ -105,7 +106,7 @@ static void create_color_ramp(const struct ColorBand *coba, float *data) static GPUTexture *create_transfer_function(int type, const struct ColorBand *coba) { - float *data = MEM_mallocN(sizeof(float) * 4 * TFUNC_WIDTH, __func__); + float *data = (float *)MEM_mallocN(sizeof(float) * 4 * TFUNC_WIDTH, __func__); switch (type) { case TFUNC_FLAME_SPECTRUM: @@ -221,7 +222,7 @@ static GPUTexture *create_color_texture(FluidDomainSettings *fds, int highres) int cell_count = (highres) ? manta_noise_get_cells(fds->fluid) : fds->total_cells; int *dim = (highres) ? fds->res_noise : fds->res; - float *data = MEM_callocN(sizeof(float) * cell_count * 4, "smokeColorTexture"); + float *data = (float *)MEM_callocN(sizeof(float) * cell_count * 4, "smokeColorTexture"); if (data == NULL) { return NULL; |