Subversion Repositories Kolibri OS

Rev

Rev 7929 | 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+GLLight.ambient, 0.0,0.0,0.0,1.0
  68.                 gl_V4_New eax+GLLight.diffuse, 1.0,1.0,1.0,1.0
  69.                 gl_V4_New eax+GLLight.specular, 1.0,1.0,1.0,1.0
  70.                 gl_V4_New eax+GLLight.position, 0.0,0.0,1.0,0.0
  71.                 gl_V3_New eax+GLLight.norm_position, 0.0,0.0,1.0
  72.                 gl_V3_New eax+GLLight.spot_direction, 0.0,0.0,-1.0
  73.                 gl_V3_New eax+GLLight.norm_spot_direction, 0.0,0.0,-1.0
  74.                 mov dword[eax+GLLight.spot_exponent],0.0
  75.                 mov dword[eax+GLLight.spot_cutoff],180.0
  76.                 gl_V3_New eax+GLLight.attenuation, 1.0,0.0,0.0
  77.                 mov dword[eax+GLLight.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.         lea eax,[edx+GLContext.materials]
  92.         @@:
  93.                 gl_V4_New eax+GLMaterial.emission, 0.0,0.0,0.0,1.0
  94.                 gl_V4_New eax+GLMaterial.ambient, 0.2,0.2,0.2,1.0
  95.                 gl_V4_New eax+GLMaterial.diffuse, 0.8,0.8,0.8,1.0
  96.                 gl_V4_New eax+GLMaterial.specular, 0.0,0.0,0.0,1.0
  97.                 mov dword[eax+GLMaterial.shininess], 0.0
  98.                 add eax,sizeof.GLMaterial
  99.         loop @b
  100.  
  101.         mov dword[edx+GLContext.current_color_material_mode],GL_FRONT_AND_BACK
  102.         mov dword[edx+GLContext.current_color_material_type],GL_AMBIENT_AND_DIFFUSE
  103.         mov dword[edx+GLContext.color_material_enabled],0
  104.  
  105.         ; textures
  106.         stdcall glInitTextures,edx
  107.  
  108.         ; default state
  109.         gl_V4_New edx+GLContext.current_color, 1.0,1.0,1.0,1.0
  110.         gl_V3_New edx+GLContext.longcurrent_color, 65535,65535,65535
  111.  
  112.         gl_V4_New edx+GLContext.current_normal, 1.0,0.0,0.0,0.0
  113.  
  114.         mov dword[edx+GLContext.current_edge_flag],1
  115.  
  116.         gl_V4_New edx+GLContext.current_tex_coord, 0.0,0.0,0.0,1.0
  117.  
  118.         mov dword[edx+GLContext.polygon_mode_front],GL_FILL
  119.         mov dword[edx+GLContext.polygon_mode_back],GL_FILL
  120.  
  121.         mov dword[edx+GLContext.current_front_face],0 ;0 = GL_CCW  1 = GL_CW
  122.         mov dword[edx+GLContext.current_cull_face],GL_BACK
  123.         mov dword[edx+GLContext.current_shade_model],GL_SMOOTH
  124.         mov dword[edx+GLContext.cull_face_enabled],0
  125.  
  126.         ; clear
  127.         gl_V4_New edx+GLContext.clear_color, 0.0,0.0,0.0,0.0
  128.         mov dword[edx+GLContext.clear_depth],0
  129.  
  130.         ; selection
  131.         mov dword[edx+GLContext.render_mode],GL_RENDER
  132.         mov dword[edx+GLContext.select_buffer],0 ;NULL
  133.         mov dword[edx+GLContext.name_stack_size],0
  134.  
  135.         ; matrix
  136.         mov dword[edx+GLContext.matrix_mode],0
  137.  
  138.         gl_V3_New edx+GLContext.matrix_stack_depth_max,\
  139.                 MAX_MODELVIEW_STACK_DEPTH,MAX_PROJECTION_STACK_DEPTH,MAX_TEXTURE_STACK_DEPTH
  140.  
  141.         mov ecx,3 ;for(i=0;i<3;i++)
  142.         mov ebx,edx
  143.         @@:
  144.                 mov edi,[ebx+GLContext.matrix_stack_depth_max]
  145.                 shl edi,6 ;вместо imul edi,sizeof(M4)
  146.                 stdcall gl_zalloc,edi
  147.                 mov [ebx+GLContext.matrix_stack],eax
  148.                 mov [ebx+GLContext.matrix_stack_ptr],eax
  149.                 add ebx,4
  150.         loop @b
  151.  
  152.         stdcall glMatrixMode,GL_PROJECTION
  153.         call glLoadIdentity
  154.         stdcall glMatrixMode,GL_TEXTURE
  155.         call glLoadIdentity
  156.         stdcall glMatrixMode,GL_MODELVIEW
  157.         call glLoadIdentity
  158.  
  159.         mov dword[edx+GLContext.matrix_model_projection_updated],1
  160.  
  161.         ; opengl 1.1 arrays
  162.         mov dword[edx+GLContext.client_states],0
  163.  
  164.         ; opengl 1.1 polygon offset
  165.         mov dword[edx+GLContext.offset_states],0
  166.  
  167.         ; clear the resize callback function pointer
  168.         mov dword[edx+GLContext.gl_resize_viewport],0 ;NULL
  169.  
  170.         ; specular buffer
  171.         mov dword[edx+GLContext.specbuf_first],0 ;NULL
  172.         mov dword[edx+GLContext.specbuf_used_counter],0
  173.         mov dword[edx+GLContext.specbuf_num_buffers],0
  174.  
  175.         ; depth test
  176.         mov dword[edx+GLContext.depth_test],0
  177. popad
  178.         ret
  179. endp
  180.  
  181. align 4
  182. proc glClose uses eax
  183.         call gl_get_context
  184.         stdcall endSharedState,eax
  185.         stdcall gl_free,eax
  186.         ret
  187. endp
  188.