Panda3D
 All Classes Functions Variables Enumerations
specbuf.cxx
1 #include "zgl.h"
2 #include <math.h>
3 #include <stdlib.h>
4 
5 static void calc_buf(GLSpecBuf *buf, const PN_stdfloat shininess)
6 {
7  int i;
8  PN_stdfloat val, inc;
9  val = 0.0f;
10  inc = 1.0f/SPECULAR_BUFFER_SIZE;
11  for (i = 0; i <= SPECULAR_BUFFER_SIZE; i++) {
12  buf->buf[i] = pow(val, shininess);
13  val += inc;
14  }
15 }
16 
17 GLSpecBuf *
18 specbuf_get_buffer(GLContext *c, const int shininess_i,
19  const PN_stdfloat shininess)
20 {
21  GLSpecBuf *found, *oldest;
22  found = oldest = c->specbuf_first;
23  while (found && found->shininess_i != shininess_i) {
24  if (found->last_used < oldest->last_used) {
25  oldest = found;
26  }
27  found = found->next;
28  }
29  if (found) { /* hey, found one! */
30  found->last_used = c->specbuf_used_counter++;
31  return found;
32  }
33  if (oldest == NULL || c->specbuf_num_buffers < MAX_SPECULAR_BUFFERS) {
34  /* create new buffer */
35  GLSpecBuf *buf = (GLSpecBuf *)gl_malloc(sizeof(GLSpecBuf));
36  if (!buf) gl_fatal_error("could not allocate specular buffer");
37  c->specbuf_num_buffers++;
38  buf->next = c->specbuf_first;
39  c->specbuf_first = buf;
40  buf->last_used = c->specbuf_used_counter++;
41  buf->shininess_i = shininess_i;
42  calc_buf(buf, shininess);
43  return buf;
44  }
45  /* overwrite the lru buffer */
46  oldest->shininess_i = shininess_i;
47  oldest->last_used = c->specbuf_used_counter++;
48  calc_buf(oldest, shininess);
49  return oldest;
50 }
Definition: zgl.h:141
Definition: zgl.h:41