Subversion Repositories Kolibri OS

Rev

Rev 5171 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;строки с именами функций
  2. op_table_str:
  3. macro ADD_OP a,b,c
  4. {
  5.         db 'gl',`a,' ',c,0
  6. }
  7. include 'opinfo.inc'
  8.  
  9. ;указатели на функции ;static void (*op_table_func[])(GLContext *,GLParam *)=
  10. op_table_func:
  11. macro ADD_OP a,b,c
  12. {
  13.         dd glop#a
  14. }
  15. include 'opinfo.inc'
  16.  
  17. ;число параметров в функциях
  18. op_table_size:
  19. macro ADD_OP a,b,c
  20. {
  21.         dd b+1
  22. }
  23. include 'opinfo.inc'
  24.  
  25.  
  26. ;output:
  27. ; eax = context.shared_state.lists[list]
  28. align 4
  29. proc find_list uses ebx, context:dword, list:dword
  30.         mov eax,[context]
  31.         mov eax,[eax+offs_cont_shared_state]
  32.         mov ebx,[list]
  33.         shl ebx,2
  34.         add eax,ebx
  35.         mov eax,[eax]
  36.         ret
  37. endp
  38.  
  39. ;static void delete_list(GLContext *c,int list)
  40. ;{
  41. ;  GLParamBuffer *pb,*pb1;
  42. ;  GLList *l;
  43.  
  44. ;  l=find_list(c,list);
  45. ;  assert(l != NULL);
  46.  
  47. ;  /* free param buffer */
  48. ;  pb=l->first_op_buffer;
  49. ;  while (pb!=NULL) {
  50. ;    pb1=pb->next;
  51. ;    gl_free(pb);
  52. ;    pb=pb1;
  53. ;  }
  54.  
  55. ;  gl_free(l);
  56. ;  c->shared_state.lists[list]=NULL;
  57. ;}
  58.  
  59. ;static GLList *alloc_list(GLContext *c,int list)
  60. ;{
  61. ;  GLList *l;
  62. ;  GLParamBuffer *ob;
  63.  
  64. ;  l=gl_zalloc(sizeof(GLList));
  65. ;  ob=gl_zalloc(sizeof(GLParamBuffer));
  66.  
  67. ;  ob->next=NULL;
  68. ;  l->first_op_buffer=ob;
  69.  
  70. ;  ob->ops[0].op=OP_EndList;
  71.  
  72. ;  c->shared_state.lists[list]=l;
  73. ;  return l;
  74. ;}
  75.  
  76. ;void gl_print_op(FILE *f,GLParam *p)
  77. ;{
  78. ;  int op;
  79. ;  char *s;
  80.  
  81. ;  op=p[0].op;
  82. ;  p++;
  83. ;  s=op_table_str[op];
  84. ;  while (*s != 0) {
  85. ;    if (*s == '%') {
  86. ;      s++;
  87. ;      switch (*s++) {
  88. ;      case 'f':
  89. ;       fprintf(f,"%g",p[0].f);
  90. ;       break;
  91. ;      default:
  92. ;       fprintf(f,"%d",p[0].i);
  93. ;       break;
  94. ;      }
  95. ;      p++;
  96. ;    } else {
  97. ;      fputc(*s,f);
  98. ;      s++;
  99. ;    }
  100. ;  }
  101. ;  fprintf(f,"\n");
  102. ;}
  103.  
  104. align 4
  105. proc gl_compile_op uses eax ebx, context:dword, p:dword
  106.         mov eax,[context]
  107. ;  int op,op_size;
  108. ;  GLParamBuffer *ob,*ob1;
  109. ;  int index,i;
  110.  
  111. ;  op=p[0].op;
  112. ;  op_size=op_table_size[op];
  113. ;  index=c->current_op_buffer_index;
  114. ;  ob=c->current_op_buffer;
  115.  
  116. ;  /* we should be able to add a NextBuffer opcode */
  117. ;  if ((index + op_size) > (OP_BUFFER_MAX_SIZE-2)) {
  118.  
  119. ;    ob1=gl_zalloc(sizeof(GLParamBuffer));
  120. ;    ob1->next=NULL;
  121.  
  122. ;    ob->next=ob1;
  123. ;    ob->ops[index].op=OP_NextBuffer;
  124. ;    ob->ops[index+1].p=(void *)ob1;
  125.  
  126. ;    c->current_op_buffer=ob1;
  127. ;    ob=ob1;
  128. ;    index=0;
  129. ;  }
  130.  
  131. ;  for(i=0;i<op_size;i++) {
  132. ;    ob->ops[index]=p[i];
  133. ;    index++;
  134. ;  }
  135. ;  c->current_op_buffer_index=index;
  136.         ret
  137. endp
  138.  
  139. align 4
  140. proc gl_add_op uses eax ebx ecx, p:dword ;GLParam*
  141. if DEBUG
  142. push edi esi
  143.         mov ebx,[p]
  144.         mov ebx,[ebx]
  145.         lea eax,[op_table_str]
  146.         @@:
  147.                 cmp ebx,0
  148.                 je @f
  149.                 cmp byte[eax],0
  150.                 jne .no_dec
  151.                         dec ebx
  152.                 .no_dec:
  153.                 inc eax
  154.                 jmp @b
  155.         @@:
  156.         stdcall dbg_print,eax,txt_nl
  157.  
  158.         mov esi,eax
  159.         mov word[NumberSymbolsAD],3
  160.         mov ebx,[p]
  161.         lea edi,[buf_param]
  162.         mov byte[edi],0
  163.         mov ecx,80
  164.         .cycle_0:
  165.                 cmp byte[esi],'%'
  166.                 jne .no_param
  167.                         cmp ebx,[p]
  168.                         je @f
  169.                                 stdcall str_n_cat,edi,txt_zp_sp,2
  170.                                 stdcall str_len,edi
  171.                                 add edi,eax
  172.                         @@:
  173.                         add ebx,4
  174.                         inc esi
  175.  
  176.                         cmp byte[esi],'f'
  177.                         jne @f
  178.                                 fld dword[ebx]
  179.                                 fstp qword[Data_Double]
  180.                                 call DoubleFloat_to_String
  181.                                 stdcall str_cat, edi,Data_String
  182.                         @@:
  183.                         cmp byte[esi],'d'
  184.                         jne @f
  185.                                 stdcall str_len,edi
  186.                                 add edi,eax
  187.                                 sub ecx,eax
  188.                                 mov eax,dword[ebx]
  189.                                 stdcall convert_int_to_str,ecx
  190.                         @@:
  191.                 .no_param:
  192.                 inc esi
  193.                 cmp byte[esi],0
  194.                 jne .cycle_0
  195.         stdcall str_cat, edi,txt_nl
  196.         stdcall dbg_print,txt_sp,buf_param
  197. pop esi edi
  198. end if
  199.         call gl_get_context
  200.         mov ebx,[p]
  201.  
  202.         cmp dword[eax+offs_cont_exec_flag],0
  203.         je @f
  204.                 push ebx
  205.                 push eax
  206.                 mov ecx,dword[ebx] ;ecx = OP_...
  207.                 shl ecx,2
  208.                 lea ebx,[op_table_func]
  209.                 add ecx,ebx
  210.                 call dword[ecx] ;op_table_func[op](c,p)
  211.         @@:
  212.         cmp dword[eax+offs_cont_compile_flag],0
  213.         je @f
  214.                 stdcall gl_compile_op,eax,[p]
  215.         @@:
  216.         cmp dword[eax+offs_cont_print_flag],0
  217.         je @f
  218.                 ;gl_print_op(stderr,p);
  219.         @@:
  220.         ret
  221. endp
  222.  
  223. ; this opcode is never called directly
  224. align 4
  225. proc glopEndList, context:dword, p:dword
  226. ;  assert(0);
  227.         ret
  228. endp
  229.  
  230. ; this opcode is never called directly
  231. align 4
  232. proc glopNextBuffer, context:dword, p:dword
  233. ;  assert(0);
  234.         ret
  235. endp
  236.  
  237. ;void glopCallList(GLContext *c,GLParam *p)
  238. ;{
  239. ;  GLList *l;
  240. ;  int list,op;
  241.  
  242. ;  list=p[1].ui;
  243. ;  l=find_list(c,list);
  244. ;  if (l == NULL) gl_fatal_error("list %d not defined",list);
  245. ;  p=l->first_op_buffer->ops;
  246.  
  247. ;  while (1) {
  248. ;    op=p[0].op;
  249. ;    if (op == OP_EndList) break;
  250. ;    if (op == OP_NextBuffer) {
  251. ;      p=(GLParam *)p[1].p;
  252. ;    } else {
  253. ;      op_table_func[op](c,p);
  254. ;      p+=op_table_size[op];
  255. ;    }
  256. ;  }
  257. ;}
  258.  
  259. ;void glNewList(unsigned int list,int mode)
  260. ;{
  261. ;  GLList *l;
  262. ;  GLContext *c=gl_get_context();
  263. ;
  264. ;  assert(mode == GL_COMPILE || mode == GL_COMPILE_AND_EXECUTE);
  265. ;  assert(c->compile_flag == 0);
  266. ;
  267. ;  l=find_list(c,list);
  268. ;  if (l!=NULL) delete_list(c,list);
  269. ;  l=alloc_list(c,list);
  270. ;
  271. ;  c->current_op_buffer=l->first_op_buffer;
  272. ;  c->current_op_buffer_index=0;
  273. ;  
  274. ;  c->compile_flag=1;
  275. ;  c->exec_flag=(mode == GL_COMPILE_AND_EXECUTE);
  276. ;}
  277.  
  278. ;void glEndList(void)
  279. ;{
  280. ;  GLContext *c=gl_get_context();
  281. ;  GLParam p[1];
  282.  
  283. ;  assert(c->compile_flag == 1);
  284.  
  285. ;  /* end of list */
  286. ;  p[0].op=OP_EndList;
  287. ;  gl_compile_op(c,p);
  288.  
  289. ;  c->compile_flag=0;
  290. ;  c->exec_flag=1;
  291. ;}
  292.  
  293. ;output:
  294. ; eax = (find_list(gl_get_context,list) != NULL)
  295. align 4
  296. proc glIsList, list:dword
  297.         call gl_get_context
  298.         stdcall find_list, eax,[list]
  299.         cmp eax,0 ;NULL
  300.         je @f
  301.                 mov eax,1
  302.         @@:
  303.         ret
  304. endp
  305.  
  306. ;unsigned int glGenLists(int range)
  307. ;{
  308. ;  GLContext *c=gl_get_context();
  309. ;  int count,i,list;
  310. ;  GLList **lists;
  311.  
  312. ;  lists=c->shared_state.lists;
  313. ;  count=0;
  314. ;  for(i=0;i<MAX_DISPLAY_LISTS;i++) {
  315. ;    if (lists[i]==NULL) {
  316. ;      count++;
  317. ;      if (count == range) {
  318. ;       list=i-range+1;
  319. ;       for(i=0;i<range;i++) {
  320. ;         alloc_list(c,list+i);
  321. ;       }
  322. ;       return list;
  323. ;      }
  324. ;    } else {
  325. ;      count=0;
  326. ;    }
  327. ;  }
  328. ;  return 0;
  329. ;}
  330.