Merge branch 'master' into blender2.8
[blender.git] / source / blender / windowmanager / intern / wm_playanim.c
index b4f2435ee2d982740a34e4461654415c2fcb5e47..ec9db1dd98e8f2478a2a9292178e3ab08c221017 100644 (file)
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
-#include "BKE_depsgraph.h"
 #include "BKE_image.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "GPU_matrix.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_batch.h"
+#include "GPU_init_exit.h"
+
 #include "DNA_scene_types.h"
 #include "ED_datafiles.h" /* for fonts */
 #include "GHOST_C-api.h"
 #include "BLF_api.h"
 
+#include "DEG_depsgraph.h"
+
 #include "WM_api.h"  /* only for WM_main_playanim */
 
 #ifdef WITH_AUDASPACE
-#  include AUD_DEVICE_H
-#  include AUD_HANDLE_H
-#  include AUD_SOUND_H
-#  include AUD_SPECIAL_H
+#  include <AUD_Device.h>
+#  include <AUD_Handle.h>
+#  include <AUD_Sound.h>
+#  include <AUD_Special.h>
 
 static AUD_Sound *source = NULL;
 static AUD_Handle *playback_handle = NULL;
@@ -177,6 +184,7 @@ typedef enum eWS_Qual {
 static struct WindowStateGlobal {
        GHOST_SystemHandle ghost_system;
        void *ghost_window;
+       Gwn_Context *gwn_context;
 
        /* events */
        eWS_Qual qual;
@@ -193,10 +201,8 @@ static void playanim_window_get_size(int *r_width, int *r_height)
 static void playanim_gl_matrix(void)
 {
        /* unified matrix, note it affects offset for drawing */
-       glMatrixMode(GL_PROJECTION);
-       glLoadIdentity();
-       glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
-       glMatrixMode(GL_MODELVIEW);
+       /* note! cannot use gpuOrtho2D here because shader ignores. */
+       gpuOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0, 1.0f);
 }
 
 /* implementation */
@@ -311,7 +317,6 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
 
        CLAMP(offs_x, 0.0f, 1.0f);
        CLAMP(offs_y, 0.0f, 1.0f);
-       glRasterPos2f(offs_x, offs_y);
 
        glClearColor(0.1, 0.1, 0.1, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
@@ -319,18 +324,22 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
        /* checkerboard for case alpha */
        if (ibuf->planes == 32) {
                glEnable(GL_BLEND);
-               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+               glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
-               fdrawcheckerboard(offs_x, offs_y, offs_x + span_x, offs_y + span_y);
+               imm_draw_box_checker_2d(offs_x, offs_y, offs_x + span_x, offs_y + span_y);
        }
 
-       glRasterPos2f(offs_x + (ps->draw_flip[0] ? span_x : 0.0f),
-                     offs_y + (ps->draw_flip[1] ? span_y : 0.0f));
+       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 
-       glPixelZoom(ps->zoom * (ps->draw_flip[0] ? -1.0f : 1.0f),
-                   ps->zoom * (ps->draw_flip[1] ? -1.0f : 1.0f));
-
-       glDrawPixels(ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+       immDrawPixelsTex(
+               &state,
+               offs_x + (ps->draw_flip[0] ? span_x : 0.0f),
+               offs_y + (ps->draw_flip[1] ? span_y : 0.0f),
+               ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
+               ibuf->rect,
+               ((ps->draw_flip[0] ? -1.0f : 1.0f)) * (ps->zoom / (float)ps->win_x),
+               ((ps->draw_flip[1] ? -1.0f : 1.0f)) * (ps->zoom / (float)ps->win_y),
+               NULL);
 
        glDisable(GL_BLEND);
 
@@ -340,13 +349,13 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
                int sizex, sizey;
                float fsizex_inv, fsizey_inv;
                char str[32 + FILE_MAX];
-               cpack(-1);
                BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime);
 
                playanim_window_get_size(&sizex, &sizey);
                fsizex_inv = 1.0f / sizex;
                fsizey_inv = 1.0f / sizey;
 
+               BLF_color4f(fontid, 1.0, 1.0, 1.0, 1.0);
                BLF_enable(fontid, BLF_ASPECT);
                BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f);
                BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f);
@@ -357,24 +366,25 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
                float fac = ps->picture->frame / (double)(((PlayAnimPict *)picsbase.last)->frame - ((PlayAnimPict *)picsbase.first)->frame);
 
                fac = 2.0f * fac - 1.0f;
-               glMatrixMode(GL_PROJECTION);
-               glPushMatrix();
-               glLoadIdentity();
-               glMatrixMode(GL_MODELVIEW);
-               glPushMatrix();
-               glLoadIdentity();
-
-               glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
-
-               glBegin(GL_LINES);
-               glVertex2f(fac, -1.0f);
-               glVertex2f(fac, 1.0f);
-               glEnd();
-
-               glPopMatrix();
-               glMatrixMode(GL_PROJECTION);
-               glPopMatrix();
-               glMatrixMode(GL_MODELVIEW);
+               gpuPushProjectionMatrix();
+               gpuLoadIdentityProjectionMatrix();
+               gpuPushMatrix();
+               gpuLoadIdentity();
+
+               unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+               immUniformColor3ub(0, 255, 0);
+
+               immBegin(GWN_PRIM_LINES, 2);
+               immVertex2f(pos, fac, -1.0f);
+               immVertex2f(pos, fac,  1.0f);
+               immEnd();
+
+               immUnbindProgram();
+
+               gpuPopMatrix();
+               gpuPopProjectionMatrix();
        }
 
        GHOST_SwapWindowBuffers(g_WS.ghost_window);
@@ -1270,6 +1280,10 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
 
        //GHOST_ActivateWindowDrawingContext(g_WS.ghost_window);
 
+       /* initialize OpenGL immediate mode */
+       g_WS.gwn_context =  GWN_context_create();
+       GPU_init();
+
        /* initialize the font */
        BLF_init();
        ps.fontid = BLF_load_mem("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
@@ -1535,6 +1549,16 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
        /* we still miss freeing a lot!,
         * but many areas could skip initialization too for anim play */
 
+       GPU_shader_free_builtin_shaders();
+
+       GPU_exit();
+
+       if (g_WS.gwn_context) {
+               GWN_context_active_set(g_WS.gwn_context);
+               GWN_context_discard(g_WS.gwn_context);
+               g_WS.gwn_context = NULL;
+       }
+
        BLF_exit();
 
        GHOST_DisposeWindow(g_WS.ghost_system, g_WS.ghost_window);
@@ -1547,7 +1571,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
 
        IMB_exit();
        BKE_images_exit();
-       DAG_exit();
+       DEG_free_node_types();
 
        totblock = MEM_get_memory_blocks_in_use();
        if (totblock != 0) {