Subversion Repositories Kolibri OS

Rev

Rev 6523 | 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.         mov ecx,[xsize_ptr] ; ecx = &xsize
  44.         mov edi,[ecx]       ; edi =  xsize
  45.         mov esi,[ysize_ptr] ; esi = &ysize
  46.         mov esi,[esi]       ; esi =  ysize
  47.  
  48.         xor eax,eax
  49.         or edi,edi
  50.         jnz @f
  51.         or esi,esi
  52.         jnz @f
  53.                 mov eax,-1
  54.                 jmp .end_f
  55.         @@:
  56.  
  57.         mov [ecx],edi
  58.         dec dword[ecx]
  59.         mov ecx,[ysize_ptr]
  60.         mov [ecx],esi
  61.         dec dword[ecx]
  62.  
  63.         mov ebx,[context]
  64.         mov edx,[ebx+GLContext.opaque] ; edx = (TinyGLContext *)context.opaque
  65.         mov [edx+TinyGLContext.xsize],edi
  66.         mov [edx+TinyGLContext.d_x],edi
  67.         mov [edx+TinyGLContext.ysize],esi
  68.         mov [edx+TinyGLContext.d_y],esi
  69.  
  70.         ; resize the Z buffer
  71.         stdcall ZB_resize, dword[ebx+GLContext.zb],0,edi,esi
  72.         .end_f:
  73.         ret
  74. endp
  75.  
  76. ; we assume here that drawable is a window
  77. align 4
  78. proc kosglMakeCurrent uses ebx ecx, win_x0:dword, win_y0:dword, win_x:dword, win_y:dword, ctx1:dword
  79.         mov ebx,[ctx1]
  80.         cmp dword[ebx],0 ;if (ctx.gl_context == NULL)
  81.         jne .end_f
  82.                 ; create the TinyGL context
  83.                 mov ecx,[win_x0]
  84.                 mov [ebx+TinyGLContext.x],ecx
  85.                 mov ecx,[win_y0]
  86.                 mov [ebx+TinyGLContext.y],ecx
  87.                 mov ecx,[win_x]
  88.                 mov [ebx+TinyGLContext.d_x],ecx
  89.                 mov ecx,[win_y]
  90.                 mov [ebx+TinyGLContext.d_y],ecx
  91.  
  92.                 ; currently, we only support 16 bit rendering
  93.                 xor eax,eax
  94.                 stdcall ZB_open, dword[win_x], dword[win_y], dword ZB_MODE_RGB24, eax,eax,eax,eax ;NULL,NULL,NULL
  95.  
  96.                 or eax,eax
  97.                 jnz @f
  98.                         stdcall dbg_print,sz_kosglMakeCurrent,err_0
  99.                         xor eax,eax
  100.                         jmp .err_f
  101.                 @@:
  102.  
  103.                 ; initialisation of the TinyGL interpreter
  104.                 stdcall glInit, eax
  105.  
  106.                 call gl_get_context
  107.                 mov [ebx],eax ;ctx.gl_context = eax
  108.  
  109.                 mov [eax+GLContext.opaque],ebx ;ctx.gl_context.opaque = ctx
  110.                 mov dword[eax+GLContext.gl_resize_viewport],gl_resize_viewport
  111.  
  112.                 ; set the viewport : we force a call to gl_resize_viewport
  113.                 dec dword[eax+GLContext.viewport+GLViewport.xsize]
  114.                 dec dword[eax+GLContext.viewport+GLViewport.ysize]
  115.  
  116.                 stdcall glViewport, 0, 0, [win_x], [win_y]
  117.         .end_f:
  118.         xor eax,eax
  119.         inc eax
  120.         .err_f:
  121.         ret
  122. endp
  123.  
  124. align 4
  125. proc kosglSwapBuffers uses eax ebx ecx edx esi
  126.         ; retrieve the current TinyGLContext
  127.         call gl_get_context
  128.         mov ebx,[eax+GLContext.zb]
  129.         mov ebx,[ebx+ZBuffer.pbuf]
  130.         mov esi,[eax+GLContext.opaque] ;esi = &context.opaque
  131.         mov eax,SF_PUT_IMAGE
  132.         mov ecx,[esi+TinyGLContext.d_x]
  133.         shl ecx,16
  134.         mov cx,word[esi+TinyGLContext.d_y]
  135.         mov edx,[esi+TinyGLContext.x]
  136.         shl edx,16
  137.         mov dx,word[esi+TinyGLContext.y]
  138.         int 0x40
  139.         ret
  140. endp
  141.