source: trunk/sys/TinyGL/src/select.c @ 288

Last change on this file since 288 was 1, checked in by alain, 8 years ago

First import

File size: 2.2 KB
RevLine 
[1]1#include "zgl.h"
2
3int glRenderMode(int mode)
4{
5  GLContext *c=gl_get_context();
6  int result=0;
7 
8  switch(c->render_mode) {
9  case GL_RENDER:
10    break;
11  case GL_SELECT:
12    if (c->select_overflow) {
13      result=-c->select_hits;
14    } else {
15      result=c->select_hits;
16    }
17    c->select_overflow=0;
18    c->select_ptr=c->select_buffer;
19    c->name_stack_size=0;
20    break;
21  default:
22    assert(0);
23  }
24  switch(mode) {
25  case GL_RENDER:
26    c->render_mode=GL_RENDER;
27    break;
28  case GL_SELECT:
29    c->render_mode=GL_SELECT;
30    assert( c->select_buffer != NULL);
31    c->select_ptr=c->select_buffer;
32    c->select_hits=0;
33    c->select_overflow=0;
34    c->select_hit=NULL;
35    break;
36  default:
37    assert(0);
38  }
39  return result;
40}
41
42void glSelectBuffer(int size,unsigned int *buf)
43{
44  GLContext *c=gl_get_context();
45
46  assert(c->render_mode != GL_SELECT);
47 
48  c->select_buffer=buf;
49  c->select_size=size;
50}
51
52
53void glopInitNames(GLContext *c,GLParam *p)
54{
55  if (c->render_mode == GL_SELECT) {
56    c->name_stack_size=0;
57    c->select_hit=NULL;
58  }
59}
60
61void glopPushName(GLContext *c,GLParam *p)
62{
63  if (c->render_mode == GL_SELECT) {
64    assert(c->name_stack_size<MAX_NAME_STACK_DEPTH);
65    c->name_stack[c->name_stack_size++]=p[1].i;
66    c->select_hit=NULL;
67  }
68}
69
70void glopPopName(GLContext *c,GLParam *p)
71{
72  if (c->render_mode == GL_SELECT) {
73    assert(c->name_stack_size>0);
74    c->name_stack_size--;
75    c->select_hit=NULL;
76  }
77}
78
79void glopLoadName(GLContext *c,GLParam *p)
80{
81  if (c->render_mode == GL_SELECT) {
82   assert(c->name_stack_size>0);
83   c->name_stack[c->name_stack_size-1]=p[1].i;
84   c->select_hit=NULL;
85  }
86}
87
88void gl_add_select(GLContext *c,unsigned int zmin,unsigned int zmax)
89{
90  unsigned int *ptr;
91  int n,i;
92
93  if (!c->select_overflow) {
94    if (c->select_hit==NULL) {
95      n=c->name_stack_size;
96      if ((c->select_ptr-c->select_buffer+3+n) > 
97          c->select_size) {
98        c->select_overflow=1;
99      } else {
100        ptr=c->select_ptr;
101        c->select_hit=ptr;
102        *ptr++=c->name_stack_size;
103        *ptr++=zmin;
104        *ptr++=zmax;
105        for(i=0;i<n;i++) *ptr++=c->name_stack[i];
106        c->select_ptr=ptr;
107        c->select_hits++;
108      }
109    } else {
110      if (zmin<c->select_hit[1]) c->select_hit[1]=zmin;
111      if (zmax>c->select_hit[2]) c->select_hit[2]=zmax;
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.