2014-10-31 22:28:24 +01:00
|
|
|
; simple gl like driver for TinyGL and KolibriOS - porting iadn
|
|
|
|
|
|
|
|
|
|
|
|
struct TinyGLContext
|
|
|
|
gl_context dd ?
|
|
|
|
xsize dd ? ;+4
|
|
|
|
ysize dd ? ;+8
|
|
|
|
d_x dd ? ;+12
|
|
|
|
d_y dd ? ;+16
|
|
|
|
x dd ? ;+20
|
|
|
|
y dd ? ;+24
|
|
|
|
ends
|
|
|
|
|
|
|
|
;KOSGLContext kosglCreateContext(KOSGLContext shareList, int flags)
|
|
|
|
;{
|
|
|
|
; TinyGLContext *ctx;
|
2016-01-28 20:22:54 +01:00
|
|
|
|
2014-10-31 22:28:24 +01:00
|
|
|
; if (shareList != NULL) {
|
|
|
|
; gl_fatal_error("No sharing available in TinyGL");
|
|
|
|
; }
|
2016-01-28 20:22:54 +01:00
|
|
|
|
2014-10-31 22:28:24 +01:00
|
|
|
; ctx=gl_malloc(sizeof(TinyGLContext));
|
|
|
|
; if (!ctx)
|
|
|
|
; return NULL;
|
|
|
|
; ctx->gl_context=NULL;
|
|
|
|
; return (KOSGLContext) ctx;
|
|
|
|
;}
|
|
|
|
|
|
|
|
;void kosglDestroyContext( KOSGLContext ctx1 )
|
|
|
|
;{
|
|
|
|
; TinyGLContext *ctx = (TinyGLContext *) ctx1;
|
|
|
|
; if (ctx->gl_context != NULL) {
|
|
|
|
; glClose();
|
|
|
|
; }
|
|
|
|
; gl_free(ctx);
|
|
|
|
;}
|
|
|
|
|
|
|
|
; resize the glx viewport : we try to use the xsize and ysize
|
|
|
|
; given. We return the effective size which is guaranted to be smaller
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc gl_resize_viewport uses ebx ecx edx edi esi, context:dword, xsize_ptr:dword, ysize_ptr:dword
|
|
|
|
mov ecx,[xsize_ptr] ; ecx = &xsize
|
|
|
|
mov edi,[ecx] ; edi = xsize
|
|
|
|
mov esi,[ysize_ptr] ; esi = &ysize
|
|
|
|
mov esi,[esi] ; esi = ysize
|
|
|
|
|
2020-09-19 21:57:00 +02:00
|
|
|
xor eax,eax
|
|
|
|
or edi,edi
|
|
|
|
jnz @f
|
|
|
|
or esi,esi
|
|
|
|
jnz @f
|
2014-10-31 22:28:24 +01:00
|
|
|
mov eax,-1
|
|
|
|
jmp .end_f
|
|
|
|
@@:
|
|
|
|
|
|
|
|
mov [ecx],edi
|
|
|
|
dec dword[ecx]
|
|
|
|
mov ecx,[ysize_ptr]
|
|
|
|
mov [ecx],esi
|
|
|
|
dec dword[ecx]
|
|
|
|
|
|
|
|
mov ebx,[context]
|
2016-09-16 10:39:28 +02:00
|
|
|
mov edx,[ebx+GLContext.opaque] ; edx = (TinyGLContext *)context.opaque
|
2020-09-19 21:57:00 +02:00
|
|
|
mov [edx+TinyGLContext.xsize],edi
|
|
|
|
mov [edx+TinyGLContext.d_x],edi
|
|
|
|
mov [edx+TinyGLContext.ysize],esi
|
|
|
|
mov [edx+TinyGLContext.d_y],esi
|
2014-10-31 22:28:24 +01:00
|
|
|
|
|
|
|
; resize the Z buffer
|
2016-09-16 10:39:28 +02:00
|
|
|
stdcall ZB_resize, dword[ebx+GLContext.zb],0,edi,esi
|
2014-10-31 22:28:24 +01:00
|
|
|
.end_f:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
; we assume here that drawable is a window
|
|
|
|
align 4
|
|
|
|
proc kosglMakeCurrent uses ebx ecx, win_x0:dword, win_y0:dword, win_x:dword, win_y:dword, ctx1:dword
|
|
|
|
mov ebx,[ctx1]
|
|
|
|
cmp dword[ebx],0 ;if (ctx.gl_context == NULL)
|
|
|
|
jne .end_f
|
|
|
|
; create the TinyGL context
|
|
|
|
mov ecx,[win_x0]
|
2020-09-19 21:57:00 +02:00
|
|
|
mov [ebx+TinyGLContext.x],ecx
|
2014-10-31 22:28:24 +01:00
|
|
|
mov ecx,[win_y0]
|
2020-09-19 21:57:00 +02:00
|
|
|
mov [ebx+TinyGLContext.y],ecx
|
2014-10-31 22:28:24 +01:00
|
|
|
mov ecx,[win_x]
|
2020-09-19 21:57:00 +02:00
|
|
|
mov [ebx+TinyGLContext.d_x],ecx
|
2014-10-31 22:28:24 +01:00
|
|
|
mov ecx,[win_y]
|
2020-09-19 21:57:00 +02:00
|
|
|
mov [ebx+TinyGLContext.d_y],ecx
|
2014-10-31 22:28:24 +01:00
|
|
|
|
|
|
|
; currently, we only support 16 bit rendering
|
|
|
|
xor eax,eax
|
|
|
|
stdcall ZB_open, dword[win_x], dword[win_y], dword ZB_MODE_RGB24, eax,eax,eax,eax ;NULL,NULL,NULL
|
|
|
|
|
2016-01-28 20:22:54 +01:00
|
|
|
or eax,eax
|
|
|
|
jnz @f
|
|
|
|
stdcall dbg_print,sz_kosglMakeCurrent,err_0
|
2014-10-31 22:28:24 +01:00
|
|
|
xor eax,eax
|
|
|
|
jmp .err_f
|
|
|
|
@@:
|
|
|
|
|
|
|
|
; initialisation of the TinyGL interpreter
|
|
|
|
stdcall glInit, eax
|
|
|
|
|
|
|
|
call gl_get_context
|
|
|
|
mov [ebx],eax ;ctx.gl_context = eax
|
|
|
|
|
2016-09-16 10:39:28 +02:00
|
|
|
mov [eax+GLContext.opaque],ebx ;ctx.gl_context.opaque = ctx
|
|
|
|
mov dword[eax+GLContext.gl_resize_viewport],gl_resize_viewport
|
2014-10-31 22:28:24 +01:00
|
|
|
|
|
|
|
; set the viewport : we force a call to gl_resize_viewport
|
2020-09-19 21:57:00 +02:00
|
|
|
dec dword[eax+GLContext.viewport+GLViewport.xsize]
|
|
|
|
dec dword[eax+GLContext.viewport+GLViewport.ysize]
|
2014-10-31 22:28:24 +01:00
|
|
|
|
|
|
|
stdcall glViewport, 0, 0, [win_x], [win_y]
|
|
|
|
.end_f:
|
|
|
|
xor eax,eax
|
|
|
|
inc eax
|
|
|
|
.err_f:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc kosglSwapBuffers uses eax ebx ecx edx esi
|
|
|
|
; retrieve the current TinyGLContext
|
|
|
|
call gl_get_context
|
2016-09-16 10:39:28 +02:00
|
|
|
mov ebx,[eax+GLContext.zb]
|
2020-09-19 21:57:00 +02:00
|
|
|
mov ebx,[ebx+ZBuffer.pbuf]
|
2016-09-16 10:39:28 +02:00
|
|
|
mov esi,[eax+GLContext.opaque] ;esi = &context.opaque
|
2020-09-19 21:57:00 +02:00
|
|
|
mov eax,SF_PUT_IMAGE
|
|
|
|
mov ecx,[esi+TinyGLContext.d_x]
|
2014-10-31 22:28:24 +01:00
|
|
|
shl ecx,16
|
2020-09-19 21:57:00 +02:00
|
|
|
mov cx,word[esi+TinyGLContext.d_y]
|
|
|
|
mov edx,[esi+TinyGLContext.x]
|
2014-10-31 22:28:24 +01:00
|
|
|
shl edx,16
|
2020-09-19 21:57:00 +02:00
|
|
|
mov dx,word[esi+TinyGLContext.y]
|
2014-10-31 22:28:24 +01:00
|
|
|
int 0x40
|
|
|
|
ret
|
|
|
|
endp
|