GL4Dummies  0.1.7
Référence du fichier gl4dhAnimeManager.c

Bibliothèque de gestion des écrans d'animation et de mises à jour en fonction du son. Plus de détails...

#include "gl4dhAnimeManager.h"
#include <assert.h>
#include <stdlib.h>
Graphe des dépendances par inclusion de gl4dhAnimeManager.c:

Aller au code source de ce fichier.

Fonctions

static int in (void *func, void **funcList, int n)
 regarde si le pointeur func est un élément du tableau funcList Plus de détails...
 
static void add (void *func, void ***funcListp, int *n, int *s)
 ajoute le pointeur func dans le tableau d'éléments *funcListp Plus de détails...
 
static void callAllWithState (GL4DHanime *animations, int state)
 Parcourt un tableau d'animations (possiblement dupliquées) et les appelle une et une seule fois avec l'état state. Plus de détails...
 
static void drawOrUpdateWithAudio (GL4DHanime *animations, int state)
 joue ou met à jour parmi les animations passées en argument l'animation en cours (devant être jouée/mise à jour au temps t). Plus de détails...
 
void gl4dhInit (GL4DHanime *animations, int w, int h, void(*callBeforeAllAnimationsInit)(void))
 Demande l'état initialisation à tous les éléments du tableau d'animations. Plus de détails...
 
void gl4dhClean (void)
 demande l'état libération à tous les éléments du tableau d'animations. Plus de détails...
 
void gl4dhStartingSignal (void)
 donne le top-départ de la démo. Cette fonction doit être appelée juste avant le début de la boucle infinie d'affichage (soit juste avant le premier GL4DH_DRAW obtenu en appelant gl4dhDraw). Plus de détails...
 
Uint32 gl4dhGetTicks (void)
 renvoie le nombre de milisecondes passée depuis le top-départ donné par gl4dhStartingSignal. Plus de détails...
 
void gl4dhDraw (void)
 joue parmi les animations passées en argument l'animation en cours (devant être jouée au temps t). Plus de détails...
 
void gl4dhUpdateWithAudio (void)
 met à jour parmi les animations passées en argument l'animation en cours. Plus de détails...
 

Variables

static Uint32 _startingTime = 0
 
static GL4DHanime_animations = NULL
 pointeur vers le tableau d'animations passé à l'init avec gl4dhInit Plus de détails...
 
static GLuint _fbo = 0
 identifiant du framebuffer utilisé pour dessiner les animations Plus de détails...
 
static GLuint _wTexId = 0
 identifiant de la texture liée en écriture au framebuffer _fbo (la texture dans laquelle les animations sont dessinées) Plus de détails...
 
static GLuint _wdTexId = 0
 
static int _w = 1
 largeur et hauteur de la texture _wTexId liée en écriture au framebuffer _fbo Plus de détails...
 
static int _h = 1
 

Description détaillée

Bibliothèque de gestion des écrans d'animation et de mises à jour en fonction du son.

Auteur
Farès BELHADJ, amsi@.nosp@m.ai.u.nosp@m.niv-p.nosp@m.aris.nosp@m.8.fr
Date
April 29 2014

Définition dans le fichier gl4dhAnimeManager.c.

Documentation des fonctions

◆ add()

static void add ( void *  func,
void ***  funcListp,
int *  n,
int *  s 
)
static

ajoute le pointeur func dans le tableau d'éléments *funcListp

Paramètres
funcun élément dont il faut tester la présence.
funcListple pointeur vers le tableau d'éléments.
nle pointeur vers le nombre d'éléments dans *funcListp.
sle pointeur vers la taille, en nombre d'éléments, de *funcListp.
158  {
159  if(*s == 0) {
160  *n = 0;
161  *funcListp = calloc((*s = 16), sizeof **funcListp);
162  assert(*funcListp);
163  } else if(*n == *s) {
164  *funcListp = realloc(*funcListp, (*s *= 2) * sizeof **funcListp);
165  assert(*funcListp);
166  }
167  (*funcListp)[(*n)++] = func;
168 }

Référencé par callAllWithState().

◆ callAllWithState()

static void callAllWithState ( GL4DHanime animations,
int  state 
)
static

Parcourt un tableau d'animations (possiblement dupliquées) et les appelle une et une seule fois avec l'état state.

Paramètres
animationstableau d'animations se terminant par un élément dont le champ first est à NULL.
stateétat à utiliser pour chaque appel.
175  {
176  int n = 0, s = 0;
177  void **called = NULL;
178  assert(animations);
179  while(animations->first) {
180  if(!in(animations->first, called, n)) {
181  animations->first(state);
182  add(animations->first, &called, &n, &s);
183  }
184  if(animations->last && !in(animations->last, called, n)) {
185  animations->last(state);
186  add(animations->last, &called, &n, &s);
187  }
188  if(animations->transition && !in(animations->transition, called, n)) {
189  animations->transition(NULL, NULL, 0, 0, state);
190  add(animations->transition, &called, &n, &s);
191  }
192  animations++;
193  }
194  if(called)
195  free(called);
196 }

Références add(), GL4DHanime::first, in(), GL4DHanime::last, et GL4DHanime::transition.

Référencé par gl4dhClean(), et gl4dhInit().

◆ drawOrUpdateWithAudio()

static void drawOrUpdateWithAudio ( GL4DHanime animations,
int  state 
)
static

joue ou met à jour parmi les animations passées en argument l'animation en cours (devant être jouée/mise à jour au temps t).

Paramètres
animationstableau d'animations se terminant par un élément dont le champ first est à NULL.
stateétat devant être appliqué : jouer (GL4DH_DRAW) ou mettre à jour (GL4DH_UPDATE_WITH_AUDIO)
206  {
207  int i;
208  static int cur = 0;
209  Uint32 t = 0, at = 0;
210  if(!animations[cur].first)
211  goto noMoreAnimationsFlag;
212  for(i = 0; i < cur; i++) at += animations[i].time;
213  t = gl4dhGetTicks() - at;
214  if(t >= animations[cur].time) {
215  t -= animations[cur].time;
216  cur = (cur + 1);
217  if(!animations[cur].first)
218  goto noMoreAnimationsFlag;
219  }
220  if(animations[cur].transition)
221  animations[cur].transition(animations[cur].first, animations[cur].last, animations[cur].time, t, state);
222  else
223  animations[cur].first(state);
224  return;
225  noMoreAnimationsFlag:
226  if(state == GL4DH_DRAW)
227  exit(0); // mettre cur = 0; pour tourner en boucle
228 }

Références GL4DHanime::first, GL4DH_DRAW, gl4dhGetTicks(), GL4DHanime::time, et GL4DHanime::transition.

Référencé par gl4dhDraw(), et gl4dhUpdateWithAudio().

◆ gl4dhClean()

void gl4dhClean ( void  )

demande l'état libération à tous les éléments du tableau d'animations.

76  {
77  if(_animations) {
79  _animations = NULL;
80  }
81  if(_wTexId) {
82  glDeleteTextures(1, &_wTexId);
83  _wTexId = 0;
84  }
85  if(_wdTexId) {
86  glDeleteTextures(1, &_wdTexId);
87  _wdTexId = 0;
88  }
89  if(_fbo) {
90  glDeleteFramebuffers(1, &_fbo);
91  _fbo = 0;
92  }
93 }

Références _animations, _fbo, _wdTexId, _wTexId, callAllWithState(), et GL4DH_FREE.

Référencé par gl4duClean().

◆ gl4dhDraw()

void gl4dhDraw ( void  )

joue parmi les animations passées en argument l'animation en cours (devant être jouée au temps t).

113  {
114  int vp[4];
115  glGetIntegerv(GL_VIEWPORT, vp);
116  glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
117  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _wTexId, 0);
119 
120  glUseProgram(0);
121 
122  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
123  glBlitFramebuffer(0, 0, _w, _h, vp[0], vp[1], vp[0] + vp[2], vp[1] + vp[3], GL_COLOR_BUFFER_BIT, GL_LINEAR);
124  glBlitFramebuffer(0, 0, _w, _h, vp[0], vp[1], vp[0] + vp[2], vp[1] + vp[3], GL_DEPTH_BUFFER_BIT, GL_NEAREST);
125  glBindFramebuffer(GL_FRAMEBUFFER, 0);
126 
127 }

Références _animations, _fbo, _h, _w, _wTexId, drawOrUpdateWithAudio(), et GL4DH_DRAW.

◆ gl4dhGetTicks()

Uint32 gl4dhGetTicks ( void  )

renvoie le nombre de milisecondes passée depuis le top-départ donné par gl4dhStartingSignal.

106  {
107  return SDL_GetTicks() - _startingTime;
108 }

Références _startingTime.

Référencé par drawOrUpdateWithAudio().

◆ gl4dhInit()

void gl4dhInit ( GL4DHanime animations,
int  w,
int  h,
void(*)(void)  callBeforeAllAnimationsInit 
)

Demande l'état initialisation à tous les éléments du tableau d'animations.

Paramètres
animationstableau d'animations se terminant par un élément dont le champ first est à NULL.
wlargeur de la texture dans laquelle sont réalisées les animations.
hhauteur de la texture dans laquelle sont réalisées les animations.
callBeforeAllAnimationsInitfonction à appeler avant le lancement des inits d'animations. Ce paramètre peut-etre NULL si rien n'est fait avant.
42  {
43  _animations = animations;
44  _w = w; _h = h;
45  if(!_fbo)
46  glGenFramebuffers(1, &_fbo);
47  if(!_wTexId)
48  glGenTextures(1, &_wTexId);
49  glBindTexture(GL_TEXTURE_2D, _wTexId);
50  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
51  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
52  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
53  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
54  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
55  if(!_wdTexId)
56  glGenTextures(1, &_wdTexId);
57  glBindTexture(GL_TEXTURE_2D, _wdTexId);
58  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
59  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
60  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
61  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
62  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
63  glBindTexture(GL_TEXTURE_2D, 0);
64 
65  glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
66  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _wTexId, 0);
67  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _wdTexId, 0);
68  if(callBeforeAllAnimationsInit)
69  callBeforeAllAnimationsInit();
71  glBindFramebuffer(GL_FRAMEBUFFER, 0);
72 }

Références _animations, _fbo, _h, _w, _wdTexId, _wTexId, callAllWithState(), et GL4DH_INIT.

◆ gl4dhStartingSignal()

void gl4dhStartingSignal ( void  )

donne le top-départ de la démo. Cette fonction doit être appelée juste avant le début de la boucle infinie d'affichage (soit juste avant le premier GL4DH_DRAW obtenu en appelant gl4dhDraw).

99  {
100  _startingTime = SDL_GetTicks();
101 }

Références _startingTime.

◆ gl4dhUpdateWithAudio()

void gl4dhUpdateWithAudio ( void  )

met à jour parmi les animations passées en argument l'animation en cours.

Références _animations, drawOrUpdateWithAudio(), et GL4DH_UPDATE_WITH_AUDIO.

◆ in()

static int in ( void *  func,
void **  funcList,
int  n 
)
static

regarde si le pointeur func est un élément du tableau funcList

Paramètres
funcun élément dont il faut tester la présence.
funcListun tableau d'éléments.
nle nombre d'éléments dans funcList.
Renvoie
vrai si l'élément est présent, faux sinon.
143  {
144  int i;
145  for(i = 0; i < n; i++)
146  if(func == funcList[i])
147  return 1;
148  return 0;
149 }

Référencé par blurffunc(), blurfinit(), callAllWithState(), cannyffunc(), cannyfinit(), fractalPaintingffunc(), fractalPaintingfinit(), gl4dfBlur(), gl4dfCanny(), gl4dfConvTex2Frame(), gl4dfConvTex2Tex(), gl4dfMCMD(), gl4dfMedian(), gl4dfScattering(), gl4dfSobel(), gl4dqCreatePurFromPoint(), gl4dqRotatePoint(), medianffunc(), medianfinit(), mv(), scatteringffunc(), scatteringfinit(), sobelffunc(), et sobelfinit().

Documentation des variables

◆ _animations

GL4DHanime* _animations = NULL
static

pointeur vers le tableau d'animations passé à l'init avec gl4dhInit

Référencé par gl4dhClean(), gl4dhDraw(), gl4dhInit(), et gl4dhUpdateWithAudio().

◆ _fbo

GLuint _fbo = 0
static

identifiant du framebuffer utilisé pour dessiner les animations

Référencé par gl4dhClean(), gl4dhDraw(), et gl4dhInit().

◆ _h

int _h = 1
static

Référencé par gl4dhDraw(), et gl4dhInit().

◆ _startingTime

Uint32 _startingTime = 0
static

Référencé par gl4dhGetTicks(), et gl4dhStartingSignal().

◆ _w

int _w = 1
static

largeur et hauteur de la texture _wTexId liée en écriture au framebuffer _fbo

Référencé par gl4dhDraw(), et gl4dhInit().

◆ _wdTexId

GLuint _wdTexId = 0
static

Référencé par gl4dhClean(), et gl4dhInit().

◆ _wTexId

GLuint _wTexId = 0
static

identifiant de la texture liée en écriture au framebuffer _fbo (la texture dans laquelle les animations sont dessinées)

Référencé par gl4dhClean(), gl4dhDraw(), et gl4dhInit().

GL4DHanime::transition
void(* transition)(void(*anim0)(int), void(*anim1)(int), Uint32 fullTime, Uint32 elapsedTime, int state)
Definition: gl4dhAnimeManager.h:31
gl4dhGetTicks
Uint32 gl4dhGetTicks(void)
renvoie le nombre de milisecondes passée depuis le top-départ donné par gl4dhStartingSignal.
Definition: gl4dhAnimeManager.c:106
GL4DHanime::time
Uint32 time
Definition: gl4dhAnimeManager.h:28
in
static int in(void *func, void **funcList, int n)
regarde si le pointeur func est un élément du tableau funcList
Definition: gl4dhAnimeManager.c:143
_wdTexId
static GLuint _wdTexId
Definition: gl4dhAnimeManager.c:29
GL4DH_FREE
@ GL4DH_FREE
Definition: gl4dhAnimeManager.h:24
drawOrUpdateWithAudio
static void drawOrUpdateWithAudio(GL4DHanime *animations, int state)
joue ou met à jour parmi les animations passées en argument l'animation en cours (devant être jouée/m...
Definition: gl4dhAnimeManager.c:206
GL4DH_DRAW
@ GL4DH_DRAW
Definition: gl4dhAnimeManager.h:23
add
static void add(void *func, void ***funcListp, int *n, int *s)
ajoute le pointeur func dans le tableau d'éléments *funcListp
Definition: gl4dhAnimeManager.c:158
_h
static int _h
Definition: gl4dhAnimeManager.c:32
_fbo
static GLuint _fbo
identifiant du framebuffer utilisé pour dessiner les animations
Definition: gl4dhAnimeManager.c:25
_startingTime
static Uint32 _startingTime
Definition: gl4dhAnimeManager.c:17
GL4DHanime::first
void(* first)(int state)
Definition: gl4dhAnimeManager.h:29
GL4DHanime::last
void(* last)(int state)
Definition: gl4dhAnimeManager.h:30
_wTexId
static GLuint _wTexId
identifiant de la texture liée en écriture au framebuffer _fbo (la texture dans laquelle les animatio...
Definition: gl4dhAnimeManager.c:29
callAllWithState
static void callAllWithState(GL4DHanime *animations, int state)
Parcourt un tableau d'animations (possiblement dupliquées) et les appelle une et une seule fois avec ...
Definition: gl4dhAnimeManager.c:175
_animations
static GL4DHanime * _animations
pointeur vers le tableau d'animations passé à l'init avec gl4dhInit
Definition: gl4dhAnimeManager.c:21
GL4DH_INIT
@ GL4DH_INIT
Definition: gl4dhAnimeManager.h:21
_w
static int _w
largeur et hauteur de la texture _wTexId liée en écriture au framebuffer _fbo
Definition: gl4dhAnimeManager.c:32
GL4DH_UPDATE_WITH_AUDIO
@ GL4DH_UPDATE_WITH_AUDIO
Definition: gl4dhAnimeManager.h:22