Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. align 4
  3. proc initSharedState uses eax ebx, context:dword
  4.         mov ebx,[context]
  5.  
  6.         stdcall gl_zalloc, 4*MAX_DISPLAY_LISTS
  7.         mov [ebx+GLContext.shared_state],eax ;...lists=gl_zalloc(...)
  8.         stdcall gl_zalloc, 4*TEXTURE_HASH_TABLE_SIZE
  9.         mov [ebx+GLContext.shared_state+4],eax ;...texture_hash_table=gl_zalloc(...)
  10.  
  11.         stdcall alloc_texture, [context],0
  12.         ret
  13. endp
  14.  
  15. align 4
  16. proc endSharedState uses eax ebx, context:dword
  17.         mov ebx,[context]
  18.  
  19. ;  for(i=0;i<MAX_DISPLAY_LISTS;i++) {
  20. ;    /* TODO */
  21. ;  }
  22.         stdcall gl_free, dword[ebx+GLContext.shared_state] ;lists
  23.         stdcall gl_free, dword[ebx+GLContext.shared_state+4] ;texture_hash_table
  24.         ret
  25. endp
  26.  
  27. align 4
  28. proc glInit, zbuffer1:dword
  29. pushad
  30.         stdcall gl_zalloc,sizeof.GLContext
  31.         mov dword[gl_ctx],eax
  32.         mov edx,eax
  33.  
  34.         mov ecx,[zbuffer1]
  35.         mov dword[edx+GLContext.zb],ecx
  36.  
  37.         ; allocate GLVertex array
  38.         mov dword[edx+GLContext.vertex_max],POLYGON_MAX_VERTEX
  39.         stdcall gl_malloc, POLYGON_MAX_VERTEX*sizeof.GLVertex
  40.         mov dword[edx+GLContext.vertex],eax
  41.  
  42.         ; viewport
  43.         xor eax,eax
  44.         mov dword[edx+GLContext.viewport+offs_vpor_xmin],eax
  45.         mov dword[edx+GLContext.viewport+offs_vpor_ymin],eax
  46.         mov eax,[ecx+offs_zbuf_xsize]
  47.         mov dword[edx+GLContext.viewport+offs_vpor_xsize],eax
  48.         mov eax,[ecx+offs_zbuf_ysize]
  49.         mov dword[edx+GLContext.viewport+offs_vpor_ysize],eax
  50.         mov dword[edx+GLContext.viewport+offs_vpor_updated],1
  51.  
  52.         ; shared state
  53.         stdcall initSharedState,edx
  54.  
  55.         ; lists
  56.         mov dword[edx+GLContext.exec_flag],1
  57.         mov dword[edx+GLContext.compile_flag],0
  58.         mov dword[edx+GLContext.print_flag],0
  59.  
  60.         mov dword[edx+GLContext.in_begin],0
  61.  
  62.         ; lights
  63.         mov ecx,MAX_LIGHTS
  64.         mov eax,edx
  65.         add eax,GLContext.lights
  66.         .cycle_0:
  67.                 gl_V4_New eax+offs_ligh_ambient, 0.0,0.0,0.0,1.0
  68.                 gl_V4_New eax+offs_ligh_diffuse, 1.0,1.0,1.0,1.0
  69.                 gl_V4_New eax+offs_ligh_specular, 1.0,1.0,1.0,1.0
  70.                 gl_V4_New eax+offs_ligh_position, 0.0,0.0,1.0,0.0
  71.                 gl_V3_New eax+offs_ligh_norm_position, 0.0,0.0,1.0
  72.                 gl_V3_New eax+offs_ligh_spot_direction, 0.0,0.0,-1.0
  73.                 gl_V3_New eax+offs_ligh_norm_spot_direction, 0.0,0.0,-1.0
  74.                 mov dword[eax+offs_ligh_spot_exponent],0.0
  75.                 mov dword[eax+offs_ligh_spot_cutoff],180.0
  76.                 gl_V3_New eax+offs_ligh_attenuation, 1.0,0.0,0.0
  77.                 mov dword[eax+offs_ligh_enabled],0
  78.                 add eax,sizeof.GLLight
  79.                 dec ecx
  80.                 cmp ecx,0
  81.         jg .cycle_0
  82.  
  83.         mov dword[edx+GLContext.first_light],0 ;NULL
  84.         gl_V4_New edx+GLContext.ambient_light_model, 0.2,0.2,0.2,1.0
  85.         mov dword[edx+GLContext.local_light_model],0
  86.         mov dword[edx+GLContext.lighting_enabled],0
  87.         mov dword[edx+GLContext.light_model_two_side],0
  88.  
  89.         ; default materials
  90.         mov ecx,2 ;for(i=0;i<2;i++)
  91.         mov eax,edx
  92.         add eax,GLContext.materials
  93.         @@:
  94.                 gl_V4_New eax+offs_mate_emission, 0.0,0.0,0.0,1.0
  95.                 gl_V4_New eax+offs_mate_ambient, 0.2,0.2,0.2,1.0
  96.                 gl_V4_New eax+offs_mate_diffuse, 0.8,0.8,0.8,1.0
  97.                 gl_V4_New eax+offs_mate_specular, 0.0,0.0,0.0,1.0
  98.                 mov dword[eax+offs_mate_shininess], 0.0
  99.                 add eax,sizeof.GLMaterial
  100.         loop @b
  101.  
  102.         mov dword[edx+GLContext.current_color_material_mode],GL_FRONT_AND_BACK
  103.         mov dword[edx+GLContext.current_color_material_type],GL_AMBIENT_AND_DIFFUSE
  104.         mov dword[edx+GLContext.color_material_enabled],0
  105.  
  106.         ; textures
  107.         stdcall glInitTextures,edx
  108.  
  109.         ; default state
  110.         gl_V4_New edx+GLContext.current_color, 1.0,1.0,1.0,1.0
  111.         gl_V3_New edx+GLContext.longcurrent_color, 65535,65535,65535
  112.  
  113.         gl_V4_New edx+GLContext.current_normal, 1.0,0.0,0.0,0.0
  114.  
  115.         mov dword[edx+GLContext.current_edge_flag],1
  116.  
  117.         gl_V4_New edx+GLContext.current_tex_coord, 0.0,0.0,0.0,1.0
  118.  
  119.         mov dword[edx+GLContext.polygon_mode_front],GL_FILL
  120.         mov dword[edx+GLContext.polygon_mode_back],GL_FILL
  121.  
  122.         mov dword[edx+GLContext.current_front_face],0 ;0 = GL_CCW  1 = GL_CW
  123.         mov dword[edx+GLContext.current_cull_face],GL_BACK
  124.         mov dword[edx+GLContext.current_shade_model],GL_SMOOTH
  125.         mov dword[edx+GLContext.cull_face_enabled],0
  126.  
  127.         ; clear
  128.         gl_V4_New edx+GLContext.clear_color, 0.0,0.0,0.0,0.0
  129.         mov dword[edx+GLContext.clear_depth],0
  130.  
  131.         ; selection
  132.         mov dword[edx+GLContext.render_mode],GL_RENDER
  133.         mov dword[edx+GLContext.select_buffer],0 ;NULL
  134.         mov dword[edx+GLContext.name_stack_size],0
  135.  
  136.         ; matrix
  137.         mov dword[edx+GLContext.matrix_mode],0
  138.  
  139.         gl_V3_New edx+GLContext.matrix_stack_depth_max,\
  140.                 MAX_MODELVIEW_STACK_DEPTH,MAX_PROJECTION_STACK_DEPTH,MAX_TEXTURE_STACK_DEPTH
  141.  
  142.         mov ecx,3 ;for(i=0;i<3;i++)
  143.         mov ebx,edx
  144.         @@:
  145.                 mov edi,[ebx+GLContext.matrix_stack_depth_max]
  146.                 shl edi,6 ;вместо imul edi,sizeof(M4)
  147.                 stdcall gl_zalloc,edi
  148.                 mov [ebx+GLContext.matrix_stack],eax
  149.                 mov [ebx+GLContext.matrix_stack_ptr],eax
  150.                 add ebx,4
  151.         loop @b
  152.  
  153.         stdcall glMatrixMode,GL_PROJECTION
  154.         call glLoadIdentity
  155.         stdcall glMatrixMode,GL_TEXTURE
  156.         call glLoadIdentity
  157.         stdcall glMatrixMode,GL_MODELVIEW
  158.         call glLoadIdentity
  159.  
  160.         mov dword[edx+GLContext.matrix_model_projection_updated],1
  161.  
  162.         ; opengl 1.1 arrays
  163.         mov dword[edx+GLContext.client_states],0
  164.  
  165.         ; opengl 1.1 polygon offset
  166.         mov dword[edx+GLContext.offset_states],0
  167.  
  168.         ; clear the resize callback function pointer
  169.         mov dword[edx+GLContext.gl_resize_viewport],0 ;NULL
  170.  
  171.         ; specular buffer
  172.         mov dword[edx+GLContext.specbuf_first],0 ;NULL
  173.         mov dword[edx+GLContext.specbuf_used_counter],0
  174.         mov dword[edx+GLContext.specbuf_num_buffers],0
  175.  
  176.         ; depth test
  177.         mov dword[edx+GLContext.depth_test],0
  178. popad
  179.         ret
  180. endp
  181.  
  182. align 4
  183. proc glClose uses eax
  184.         call gl_get_context
  185.         stdcall endSharedState,eax
  186.         stdcall gl_free,eax
  187.         ret
  188. endp
  189.