Subversion Repositories Kolibri OS

Rev

Rev 6523 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5153 IgorA 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;
6108 IgorA 17
 
5153 IgorA 18
;  if (shareList != NULL) {
19
;    gl_fatal_error("No sharing available in TinyGL");
20
;  }
6108 IgorA 21
 
5153 IgorA 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
 
8069 IgorA 48
	xor eax,eax
49
	or edi,edi
50
	jnz @f
51
	or esi,esi
52
	jnz @f
5153 IgorA 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]
6523 IgorA 64
	mov edx,[ebx+GLContext.opaque] ; edx = (TinyGLContext *)context.opaque
8069 IgorA 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
5153 IgorA 69
 
70
	; resize the Z buffer
6523 IgorA 71
	stdcall ZB_resize, dword[ebx+GLContext.zb],0,edi,esi
5153 IgorA 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]
8069 IgorA 84
		mov [ebx+TinyGLContext.x],ecx
5153 IgorA 85
		mov ecx,[win_y0]
8069 IgorA 86
		mov [ebx+TinyGLContext.y],ecx
5153 IgorA 87
		mov ecx,[win_x]
8069 IgorA 88
		mov [ebx+TinyGLContext.d_x],ecx
5153 IgorA 89
		mov ecx,[win_y]
8069 IgorA 90
		mov [ebx+TinyGLContext.d_y],ecx
5153 IgorA 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
 
6108 IgorA 96
		or eax,eax
97
		jnz @f
98
			stdcall dbg_print,sz_kosglMakeCurrent,err_0
5153 IgorA 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
 
6523 IgorA 109
		mov [eax+GLContext.opaque],ebx ;ctx.gl_context.opaque = ctx
110
		mov dword[eax+GLContext.gl_resize_viewport],gl_resize_viewport
5153 IgorA 111
 
112
		; set the viewport : we force a call to gl_resize_viewport
8069 IgorA 113
		dec dword[eax+GLContext.viewport+GLViewport.xsize]
114
		dec dword[eax+GLContext.viewport+GLViewport.ysize]
5153 IgorA 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
6523 IgorA 128
	mov ebx,[eax+GLContext.zb]
8069 IgorA 129
	mov ebx,[ebx+ZBuffer.pbuf]
6523 IgorA 130
	mov esi,[eax+GLContext.opaque] ;esi = &context.opaque
8069 IgorA 131
	mov eax,SF_PUT_IMAGE
132
	mov ecx,[esi+TinyGLContext.d_x]
5153 IgorA 133
	shl ecx,16
8069 IgorA 134
	mov cx,word[esi+TinyGLContext.d_y]
135
	mov edx,[esi+TinyGLContext.x]
5153 IgorA 136
	shl edx,16
8069 IgorA 137
	mov dx,word[esi+TinyGLContext.y]
5153 IgorA 138
	int 0x40
139
	ret
140
endp