Subversion Repositories Kolibri OS

Rev

Rev 8063 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. include 'opengl_const.inc'
  2. include 'zbuffer.inc'
  3. include 'zmath.inc'
  4.  
  5. offs_X equ 0
  6. offs_Y equ 4
  7. offs_Z equ 8
  8. offs_W equ 12
  9.  
  10. ;enum { OP_ ## a , ... }
  11. sum1 equ 0
  12. macro ADD_OP a,b,c
  13. {
  14.         OP_#a equ sum1
  15.         sum1 equ (sum1+1)
  16. }
  17. include 'opinfo.inc'
  18.  
  19.  
  20. ;initially # of allocated GLVertexes (will grow when necessary)
  21. POLYGON_MAX_VERTEX equ 16
  22.  
  23. ;Max # of specular light pow buffers
  24. MAX_SPECULAR_BUFFERS equ 8
  25. ;# of entries in specular buffer
  26. SPECULAR_BUFFER_SIZE equ 1024
  27. ;specular buffer granularity
  28. SPECULAR_BUFFER_RESOLUTION equ 1024
  29.  
  30.  
  31. MAX_MODELVIEW_STACK_DEPTH  equ 32
  32. MAX_PROJECTION_STACK_DEPTH equ 8
  33. MAX_TEXTURE_STACK_DEPTH    equ 8
  34. MAX_NAME_STACK_DEPTH equ 64
  35. MAX_TEXTURE_LEVELS   equ 11
  36. MAX_LIGHTS equ 16
  37.  
  38. VERTEX_HASH_SIZE equ 1031
  39.  
  40. MAX_DISPLAY_LISTS equ 1024
  41. OP_BUFFER_MAX_SIZE equ 512
  42.  
  43. TGL_OFFSET_FILL    equ 0x1
  44. TGL_OFFSET_LINE    equ 0x2
  45. TGL_OFFSET_POINT   equ 0x4
  46.  
  47. struct GLSpecBuf
  48.         shininess_i dd ? ;int
  49.         last_used dd ? ;int
  50.         buf rd SPECULAR_BUFFER_SIZE+1 ;float[SPECULAR_BUFFER_SIZE+1]
  51.         next dd ? ;struct GLSpecBuf*
  52. ends
  53.  
  54. offs_spec_shininess_i equ 0
  55. offs_spec_last_used equ 4
  56. offs_spec_buf equ 8
  57. offs_spec_next equ 8+4*(SPECULAR_BUFFER_SIZE+1)
  58.  
  59. struct GLLight
  60.         ambient V4
  61.         diffuse V4
  62.         specular V4
  63.         position V4    
  64.         spot_direction V3
  65.         spot_exponent dd ? ;float
  66.         spot_cutoff dd ? ;float
  67.         attenuation rd 3 ;float[3]
  68.         ; precomputed values
  69.         cos_spot_cutoff dd ? ;float
  70.         norm_spot_direction V3
  71.         norm_position V3
  72.         ; we use a linked list to know which are the enabled lights
  73.         enabled dd ? ;int
  74.         next dd ? ;struct GLLight*
  75.         prev dd ? ;struct GLLight*
  76. ends
  77.  
  78. struct GLMaterial
  79.         emission V4
  80.         ambient  V4
  81.         diffuse  V4
  82.         specular V4
  83.         shininess dd ? ;float
  84.  
  85.         ; computed values
  86.         shininess_i dd ? ;int
  87.         do_specular dd ? ;int
  88. ends
  89.  
  90. struct GLViewport
  91.         xmin dd ? ;int
  92.         ymin dd ? ;int
  93.         xsize dd ? ;int
  94.         ysize dd ? ;int
  95.         scale V3
  96.         trans V3
  97.         updated dd ? ;int
  98. ends
  99.  
  100. struct GLParamBuffer
  101.         ops rd OP_BUFFER_MAX_SIZE ;GLParam[OP_BUFFER_MAX_SIZE]
  102.         next dd ? ;struct GLParamBuffer*
  103. ends
  104.  
  105. offs_gpbu_ops equ 0
  106. offs_gpbu_next equ 4*OP_BUFFER_MAX_SIZE
  107.  
  108. struct GLList
  109.         first_op_buffer dd ? ;GLParamBuffer*
  110.         ; TODO: extensions for an hash table or a better allocating scheme
  111. ends
  112.  
  113. struct GLVertex
  114.         edge_flag dd ? ;int
  115.         normal V3
  116.         coord V4
  117.         tex_coord V4
  118.         color V4
  119.  
  120.         ; computed values
  121.         ec V4 ; eye coordinates
  122.         pc V4 ; coordinates in the normalized volume
  123.         clip_code dd ? ;int ; clip code
  124.         zp ZBufferPoint ; integer coordinates for the rasterization
  125. ends
  126.  
  127. struct GLImage
  128.         pixmap dd ? ;void*
  129.         xsize dd ? ;int
  130.         ysize dd ? ;int
  131.         xsize_log2 dd ? ;unsigned int
  132.         s_bound dd ? ;unsigned int
  133.         t_bound dd ? ;unsigned int
  134. ends
  135.  
  136. offs_imag_pixmap equ 0
  137. offs_imag_xsize equ 4
  138. offs_imag_ysize equ 8
  139. offs_imag_xsize_log2 equ 12
  140. offs_imag_s_bound equ 16
  141. offs_imag_t_bound equ 20
  142.  
  143. ; textures
  144.  
  145. TEXTURE_HASH_TABLE_SIZE equ 256 ;должно быть кратное 2, в коде берется остаток от деления (через and быстрее чем div)
  146.  
  147. struct GLTexture
  148.         images rb sizeof.GLImage * MAX_TEXTURE_LEVELS ;GLImage[MAX_TEXTURE_LEVELS]
  149.         handle dd ? ;int
  150.         next dd ? ;struct GLTexture*
  151.         prev dd ? ;struct GLTexture*
  152. ends
  153.  
  154. offs_text_images equ 0
  155. offs_text_handle equ sizeof.GLImage*MAX_TEXTURE_LEVELS
  156. offs_text_next equ 4+offs_text_handle
  157. offs_text_prev equ 8+offs_text_handle
  158.  
  159. ; shared state
  160.  
  161. struct GLSharedState
  162.         lists dd ? ;GLList**
  163.         texture_hash_table dd ? ;GLTexture**
  164. ends
  165.  
  166.  
  167. ; display context
  168.  
  169. struct GLContext
  170.         ; Z buffer
  171.         zb dd ? ;ZBuffer*
  172.  
  173.         ; lights
  174.         lights rb sizeof.GLLight * MAX_LIGHTS ;GLLight[MAX_LIGHTS]
  175.         first_light dd ? ;GLLight*
  176.         ambient_light_model V4
  177.         local_light_model dd ? ;int
  178.         lighting_enabled dd ? ;int
  179.         light_model_two_side dd ? ;int
  180.  
  181.         ; materials
  182.         materials rb sizeof.GLMaterial * 2 ;GLMaterial[2]
  183.         color_material_enabled dd ? ;int
  184.         current_color_material_mode dd ? ;int
  185.         current_color_material_type dd ? ;int
  186.  
  187.         ; textures
  188.         current_texture dd ? ;GLTexture*
  189.         texture_2d_enabled dd ? ;int
  190.  
  191.         ; shared state
  192.         shared_state GLSharedState
  193.  
  194.         ; current list
  195.         current_op_buffer dd ? ;GLParamBuffer*
  196.         current_op_buffer_index dd ? ;int
  197.         exec_flag dd ? ;int
  198.         compile_flag dd ? ;int
  199.         print_flag dd ? ;int
  200.  
  201.         ; matrix
  202.  
  203.         matrix_mode dd ? ;int режим активного вида матрицы (один из 3-х: GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE)
  204.         matrix_stack rd 3 ;*M4[3] указатель на начало массива матриц
  205.         matrix_stack_ptr rd 3 ;*M4[3] указатель на активную матрицу из массива
  206.         matrix_stack_depth_max rd 3 ;int[3] максимальное число матриц в массивах matrix_stack
  207.  
  208.         matrix_model_view_inv M4
  209.         matrix_model_projection M4
  210.         matrix_model_projection_updated dd ? ;int
  211.         matrix_model_projection_no_w_transform dd ? ;int
  212.         apply_texture_matrix dd ? ;int
  213.  
  214.         ; viewport
  215.         viewport GLViewport
  216.  
  217.         ; current state
  218.         polygon_mode_back dd ? ;int
  219.         polygon_mode_front dd ? ;int
  220.  
  221.         current_front_face dd ? ;int
  222.         current_shade_model dd ? ;int
  223.         current_cull_face dd ? ;int
  224.         cull_face_enabled dd ? ;int
  225.         normalize_enabled dd ? ;int
  226.         draw_triangle_front dd ? ;gl_draw_triangle_func
  227.         draw_triangle_back  dd ? ;gl_draw_triangle_func
  228.  
  229.         ; selection
  230.         render_mode dd ? ;int
  231.         select_buffer dd ? ;unsigned int*
  232.         select_size dd ? ;int
  233.         select_ptr dd ? ;unsigned int*
  234.         select_hit dd ? ;unsigned int*
  235.         select_overflow dd ? ;int
  236.         select_hits dd ? ;int
  237.  
  238.         ; names
  239.         name_stack rd MAX_NAME_STACK_DEPTH ;unsigned int[MAX_NAME_STACK_DEPTH]
  240.         name_stack_size dd ? ;int
  241.  
  242.         ; clear
  243.         clear_depth dd ? ;float
  244.         clear_color V4
  245.  
  246.         ; current vertex state
  247.         current_color V4
  248.         longcurrent_color rd 3 ;unsigned int[3] ;precomputed integer color
  249.         current_normal V4
  250.         current_tex_coord V4
  251.         current_edge_flag dd ? ;int
  252.  
  253.         ; glBegin / glEnd
  254.         in_begin dd ? ;int
  255.         begin_type dd ? ;int
  256.         vertex_n dd ? ;int
  257.         vertex_cnt dd ? ;int
  258.         vertex_max dd ? ;int
  259.         vertex dd ? ;GLVertex*
  260.  
  261.         ; opengl 1.1 arrays
  262.         vertex_array dd ? ;float*
  263.         vertex_array_size dd ? ;int
  264.         vertex_array_stride dd ? ;int
  265.         normal_array dd ? ;float*
  266.         normal_array_stride dd ? ;int
  267.         color_array dd ? ;float*
  268.         color_array_size dd ? ;int
  269.         color_array_stride dd ? ;int
  270.         texcoord_array dd ? ;float*
  271.         texcoord_array_size dd ? ;int
  272.         texcoord_array_stride dd ? ;int
  273.         client_states dd ? ;int
  274.  
  275.         ; opengl 1.1 polygon offset
  276.         offset_factor dd ? ;float
  277.         offset_units dd ? ;float
  278.         offset_states dd ? ;int
  279.  
  280.         ; specular buffer. could probably be shared between contexts,
  281.         ; but that wouldn't be 100% thread safe
  282.         specbuf_first dd ? ;GLSpecBuf*
  283.         specbuf_used_counter dd ? ;int
  284.         specbuf_num_buffers dd ? ;int
  285.  
  286.         ; opaque structure for user's use
  287.         opaque dd ? ;void*
  288.         ; resize viewport function
  289.         gl_resize_viewport dd ? ;(struct GLContext *c,int *xsize,int *ysize)
  290.  
  291.         ; depth test
  292.         depth_test dd ? ;int
  293. ends
  294.  
  295. align 16
  296. gl_ctx dd ? ;extern GLContext*
  297.  
  298. align 16
  299. proc gl_get_context
  300.         mov eax,[gl_ctx]
  301.         ret
  302. endp
  303.  
  304. ; this clip epsilon is needed to avoid some rounding errors after
  305. ; several clipping stages
  306.  
  307. CLIP_EPSILON dd 1.0e-5
  308.  
  309. align 4
  310. proc gl_clipcode uses ebx, x:dword, y:dword, z:dword, w1:dword
  311.         xor ebx,ebx
  312.  
  313.         fld1
  314.         fadd dword[CLIP_EPSILON]
  315.         fmul dword[w1]
  316.  
  317.         fcom dword[x]
  318.         fstsw ax
  319.         sahf
  320.         ja @f
  321.                 or ebx,2
  322.         @@:
  323.         fcom dword[y]
  324.         fstsw ax
  325.         sahf
  326.         ja @f
  327.                 or ebx,8
  328.         @@:
  329.         fcom dword[z]
  330.         fstsw ax
  331.         sahf
  332.         ja @f
  333.                 or ebx,32
  334.         @@:
  335.  
  336.         fchs
  337.         fcom dword[x]
  338.         fstsw ax
  339.         sahf
  340.         jbe @f
  341.                 or ebx,1
  342.         @@:
  343.         fcom dword[y]
  344.         fstsw ax
  345.         sahf
  346.         jbe @f
  347.                 or ebx,4
  348.         @@:
  349.         fcom dword[z]
  350.         fstsw ax
  351.         sahf
  352.         jbe @f
  353.                 or ebx,16
  354.         @@:
  355.  
  356.         ffree st0
  357.         fincstp
  358.  
  359.         mov eax,ebx
  360.         ret
  361. endp
  362.  
  363. ;input:
  364. ; rf,gf,bf - значения float
  365. ; ri,gi,bi - адреса куда будут записаны rf,gf,bf преобразованые в int
  366. align 4
  367. proc RGBFtoRGBI uses eax, rf:dword,gf:dword,bf:dword, ri:dword,gi:dword,bi:dword
  368. locals
  369.         s dd ?
  370. endl
  371.         mov dword[s],(ZB_POINT_RED_MAX - ZB_POINT_RED_MIN)
  372.         fild dword[s]
  373.         fmul dword[rf]
  374.         mov eax,[ri]
  375.         fistp dword[eax]
  376.         add dword[eax],ZB_POINT_RED_MIN
  377.  
  378.         mov dword[s],(ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN)
  379.         fild dword[s]
  380.         fmul dword[gf]
  381.         mov eax,[gi]
  382.         fistp dword[eax]
  383.         add dword[eax],ZB_POINT_GREEN_MIN
  384.  
  385.         ;bi = (unsigned int) (bf * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + ZB_POINT_BLUE_MIN);
  386.         mov dword[s],(ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN)
  387.         fild dword[s]
  388.         fmul dword[bf]
  389.         mov eax,[bi]
  390.         fistp dword[eax]
  391.         add dword[eax],ZB_POINT_BLUE_MIN
  392.         ret
  393. endp
  394.