Subversion Repositories Kolibri OS

Rev

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

  1. ; simple gl like driver for TinyGL and KolibriOS - porting iadn
  2.  
  3.  
  4. struct TinyGLContext
  5.         gl_context dd ?
  6.         xsize dd ? ;+4
  7.         ysize dd ? ;+8
  8.         d_x dd ? ;+12
  9.         d_y dd ? ;+16
  10.         x dd ? ;+20
  11.         y dd ? ;+24
  12. ends
  13.  
  14. ;KOSGLContext kosglCreateContext(KOSGLContext shareList, int flags)
  15. ;{
  16. ;  TinyGLContext *ctx;
  17. ;
  18. ;  if (shareList != NULL) {
  19. ;    gl_fatal_error("No sharing available in TinyGL");    
  20. ;  }
  21. ;
  22. ;    ctx=gl_malloc(sizeof(TinyGLContext));
  23. ;  if (!ctx)
  24. ;      return NULL;
  25. ;  ctx->gl_context=NULL;
  26. ;  return (KOSGLContext) ctx;
  27. ;}
  28.  
  29. ;void kosglDestroyContext( KOSGLContext ctx1 )
  30. ;{
  31. ;  TinyGLContext *ctx = (TinyGLContext *) ctx1;
  32. ;  if (ctx->gl_context != NULL) {
  33. ;    glClose();
  34. ;  }
  35. ;  gl_free(ctx);
  36. ;}
  37.  
  38. ; resize the glx viewport : we try to use the xsize and ysize
  39. ; given. We return the effective size which is guaranted to be smaller
  40.  
  41. align 4
  42. proc gl_resize_viewport uses ebx ecx edx edi esi, context:dword, xsize_ptr:dword, ysize_ptr:dword
  43.         xor eax,eax
  44.  
  45.         mov ecx,[xsize_ptr] ; ecx = &xsize
  46.         mov edi,[ecx]       ; edi =  xsize
  47.         mov esi,[ysize_ptr] ; esi = &ysize
  48.         mov esi,[esi]       ; esi =  ysize
  49.  
  50.         ; we ensure that xsize and ysize are multiples of 2 for the zbuffer.
  51.         ; TODO: find a better solution
  52.         and edi, not 3
  53.         and esi, not 3
  54.  
  55.         cmp edi,0
  56.         jne @f
  57.         cmp esi,0
  58.         jne @f
  59.                 mov eax,-1
  60.                 jmp .end_f
  61.         @@:
  62.  
  63.         mov [ecx],edi
  64.         dec dword[ecx]
  65.         mov ecx,[ysize_ptr]
  66.         mov [ecx],esi
  67.         dec dword[ecx]
  68.  
  69.         mov ebx,[context]
  70.         mov edx,[ebx+offs_cont_opaque] ; edx = (TinyGLContext *)context.opaque
  71.         mov [edx+4],edi
  72.         mov [edx+12],edi ;d_x = xsize
  73.         mov [edx+8],esi
  74.         mov [edx+16],esi ;d_y = ysize
  75.  
  76.         ; resize the Z buffer
  77.         stdcall ZB_resize, dword[ebx+offs_cont_zb],0,edi,esi
  78.         .end_f:
  79.         ret
  80. endp
  81.  
  82. ; we assume here that drawable is a window
  83. align 4
  84. proc kosglMakeCurrent uses ebx ecx, win_x0:dword, win_y0:dword, win_x:dword, win_y:dword, ctx1:dword
  85.         mov ebx,[ctx1]
  86.         cmp dword[ebx],0 ;if (ctx.gl_context == NULL)
  87.         jne .end_f
  88.                 ; create the TinyGL context
  89.                 mov ecx,[win_x0]
  90.                 mov [ebx+20],ecx ;ctx.x = win_x0
  91.                 mov ecx,[win_y0]
  92.                 mov [ebx+24],ecx ;ctx.y = win_y0
  93.                 mov ecx,[win_x]
  94.                 mov [ebx+12],ecx ;ctx.d_x = win_x
  95.                 mov ecx,[win_y]
  96.                 mov [ebx+16],ecx ;ctx.d_y = win_y
  97.  
  98.                 ; currently, we only support 16 bit rendering
  99.                 xor eax,eax
  100.                 stdcall ZB_open, dword[win_x], dword[win_y], dword ZB_MODE_RGB24, eax,eax,eax,eax ;NULL,NULL,NULL
  101.  
  102.                 cmp eax,0
  103.                 jne @f
  104.                         stdcall dbg_print,f_kosgl_1,err_0
  105.                         xor eax,eax
  106.                         jmp .err_f
  107.                 @@:
  108.  
  109.                 ; initialisation of the TinyGL interpreter
  110.                 stdcall glInit, eax
  111.  
  112.                 call gl_get_context
  113.                 mov [ebx],eax ;ctx.gl_context = eax
  114.  
  115.                 mov [eax+offs_cont_opaque],ebx ;ctx.gl_context.opaque = ctx
  116.                 mov dword[eax+offs_cont_gl_resize_viewport],gl_resize_viewport
  117.  
  118.                 ; set the viewport : we force a call to gl_resize_viewport
  119.                 dec dword[eax+offs_cont_viewport+offs_vpor_xsize]
  120.                 dec dword[eax+offs_cont_viewport+offs_vpor_ysize]
  121.  
  122.                 stdcall glViewport, 0, 0, [win_x], [win_y]
  123.         .end_f:
  124.         xor eax,eax
  125.         inc eax
  126.         .err_f:
  127.         ret
  128. endp
  129.  
  130. align 4
  131. proc kosglSwapBuffers uses eax ebx ecx edx esi
  132.         ; retrieve the current TinyGLContext
  133.         call gl_get_context
  134.         mov ebx,[eax+offs_cont_zb]
  135.         mov ebx,[ebx+offs_zbuf_pbuf]
  136.         mov esi,[eax+offs_cont_opaque] ;esi = &context.opaque
  137.         mov eax,7
  138.         mov ecx,[esi+12] ;d_x
  139.         shl ecx,16
  140.         mov cx,[esi+16] ;d_y
  141.         mov edx,[esi+20] ;x
  142.         shl edx,16
  143.         mov dx,[esi+24] ;y
  144.         int 0x40
  145.         ret
  146. endp
  147.