Subversion Repositories Kolibri OS

Rev

Rev 5213 | Rev 6243 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5213 Rev 5218
1
;
1
;
2
; Z buffer
2
; Z buffer
3
;
3
;
4
 
4
 
5
include 'zfeatures.inc'
5
include 'zfeatures.inc'
6
 
6
 
7
ZB_Z_BITS equ 16
7
ZB_Z_BITS equ 16
8
 
8
 
9
ZB_POINT_Z_FRAC_BITS equ 14
9
ZB_POINT_Z_FRAC_BITS equ 14
10
 
10
 
11
ZB_POINT_S_MIN equ (1 shl 13)
11
ZB_POINT_S_MIN equ (1 shl 13)
12
ZB_POINT_S_MAX equ ( (1 shl 22)-(1 shl 13) )
12
ZB_POINT_S_MAX equ ( (1 shl 22)-(1 shl 13) )
13
ZB_POINT_T_MIN equ (1 shl 21)
13
ZB_POINT_T_MIN equ (1 shl 21)
14
ZB_POINT_T_MAX equ ( (1 shl 30)-(1 shl 21) )
14
ZB_POINT_T_MAX equ ( (1 shl 30)-(1 shl 21) )
15
 
15
 
16
ZB_POINT_RED_MIN equ (1 shl 8)
16
ZB_POINT_RED_MIN equ (1 shl 8)
17
ZB_POINT_RED_MAX equ ( (1 shl 16)-1 )
17
ZB_POINT_RED_MAX equ ( (1 shl 16)-1 )
18
ZB_POINT_GREEN_MIN equ (1 shl 8)
18
ZB_POINT_GREEN_MIN equ (1 shl 8)
19
ZB_POINT_GREEN_MAX equ ( (1 shl 16)-1 )
19
ZB_POINT_GREEN_MAX equ ( (1 shl 16)-1 )
20
ZB_POINT_BLUE_MIN equ (1 shl 8)
20
ZB_POINT_BLUE_MIN equ (1 shl 8)
21
ZB_POINT_BLUE_MAX equ ( (1 shl 16)-1 )
21
ZB_POINT_BLUE_MAX equ ( (1 shl 16)-1 )
22
 
22
 
23
; display modes
23
; display modes
24
ZB_MODE_5R6G5B equ 1  ; true color 16 bits
24
ZB_MODE_5R6G5B equ 1  ; true color 16 bits
25
ZB_MODE_INDEX  equ 2  ; color index 8 bits
25
ZB_MODE_INDEX  equ 2  ; color index 8 bits
26
ZB_MODE_RGBA   equ 3  ; 32 bit rgba mode
26
ZB_MODE_RGBA   equ 3  ; 32 bit rgba mode
27
ZB_MODE_RGB24  equ 4  ; 24 bit rgb mode
27
ZB_MODE_RGB24  equ 4  ; 24 bit rgb mode
28
ZB_NB_COLORS   equ 225 ; number of colors for 8 bit display
28
ZB_NB_COLORS   equ 225 ; number of colors for 8 bit display
29
 
29
 
30
if TGL_FEATURE_RENDER_BITS eq 15
30
if TGL_FEATURE_RENDER_BITS eq 15
31
 
31
 
32
;#define RGB_TO_PIXEL(r,g,b) \
32
;#define RGB_TO_PIXEL(r,g,b) \
33
;  ((((r) >> 1) & 0x7c00) | (((g) >> 6) & 0x03e0) | ((b) >> 11))
33
;  ((((r) >> 1) & 0x7c00) | (((g) >> 6) & 0x03e0) | ((b) >> 11))
34
;typedef unsigned short PIXEL;
34
;typedef unsigned short PIXEL;
35
;/* bytes per pixel */
35
; bytes per pixel
36
;PSZB equ 2
36
;PSZB equ 2
37
;/* bits per pixel = (1 << PSZH) */
37
; bits per pixel = (1 << PSZH)
38
;PSZSH equ 4
38
;PSZSH equ 4
39
 
39
 
40
else if TGL_FEATURE_RENDER_BITS eq 16
40
else if TGL_FEATURE_RENDER_BITS eq 16
41
 
41
 
42
;/* 16 bit mode */
42
; 16 bit mode
43
;#define RGB_TO_PIXEL(r,g,b) \
43
;#define RGB_TO_PIXEL(r,g,b) \
44
;  (((r) & 0xF800) | (((g) >> 5) & 0x07E0) | ((b) >> 11))
44
;  (((r) & 0xF800) | (((g) >> 5) & 0x07E0) | ((b) >> 11))
45
;typedef unsigned short PIXEL;
45
;typedef unsigned short PIXEL;
46
;PSZB equ 2
46
;PSZB equ 2
47
;PSZSH equ 4
47
;PSZSH equ 4
48
 
48
 
49
else if TGL_FEATURE_RENDER_BITS eq 24
49
else if TGL_FEATURE_RENDER_BITS eq 24
50
 
50
 
51
macro RGB_TO_PIXEL r,g,b
51
macro RGB_TO_PIXEL r,g,b
52
{
52
{
53
	mov eax,b
53
	mov eax,b
54
	shr eax,8
54
	shr eax,8
55
	push eax
55
	push eax
56
		mov eax,g
56
		mov eax,g
57
		and eax,0xff00
57
		and eax,0xff00
58
		or dword[esp],eax
58
		or dword[esp],eax
59
		mov eax,r
59
		mov eax,r
60
		shl eax,8
60
		shl eax,8
61
		or dword[esp],eax
61
		or dword[esp],eax
62
	pop eax
62
	pop eax
63
}
63
}
64
 
64
 
65
;typedef unsigned char PIXEL;
65
;typedef unsigned char PIXEL;
66
PSZB equ 3
66
PSZB equ 3
67
PSZSH equ 5
67
PSZSH equ 5
68
 
68
 
69
else if TGL_FEATURE_RENDER_BITS eq 32
69
else if TGL_FEATURE_RENDER_BITS eq 32
70
 
70
 
71
;#define RGB_TO_PIXEL(r,g,b) \
71
;#define RGB_TO_PIXEL(r,g,b) \
72
;  ((((r) << 8) & 0xff0000) | ((g) & 0xff00) | ((b) >> 8))
72
;  ((((r) << 8) & 0xff0000) | ((g) & 0xff00) | ((b) >> 8))
73
;typedef unsigned int PIXEL;
73
;typedef unsigned int PIXEL;
74
;PSZB equ 4
74
;PSZB equ 4
75
;PSZSH equ 5
75
;PSZSH equ 5
76
 
76
 
77
else
77
else
78
 
78
 
79
;#error Incorrect number of bits per pixel
79
;#error Incorrect number of bits per pixel
80
 
80
 
81
end if
81
end if
82
 
82
 
83
struct ZBuffer
83
struct ZBuffer
84
	xsize dd ? ;int
84
	xsize dd ? ;int
85
	ysize dd ? ;int
85
	ysize dd ? ;int
86
	linesize dd ? ;int ;line size, in bytes
86
	linesize dd ? ;int ;line size, in bytes
87
	mode dd ? ;int
87
	mode dd ? ;int
88
    
88
    
89
	zbuf dd ? ;*unsigned short
89
	zbuf dd ? ;*unsigned short
90
	pbuf dd ? ;*PIXEL
90
	pbuf dd ? ;*PIXEL
91
	frame_buffer_allocated dd ? ;int
91
	frame_buffer_allocated dd ? ;int
92
    
92
    
93
	nb_colors dd ? ;int
93
	nb_colors dd ? ;int
94
	dctable dd ? ;*unsigned char
94
	dctable dd ? ;*unsigned char
95
	ctable dd ? ;*int
95
	ctable dd ? ;*int
96
	current_texture dd ? ;*PIXEL
96
	current_texture dd ? ;*PIXEL
97
ends
97
ends
98
 
98
 
99
offs_zbuf_xsize equ 0
99
offs_zbuf_xsize equ 0
100
offs_zbuf_ysize equ 4
100
offs_zbuf_ysize equ 4
101
offs_zbuf_linesize equ 8
101
offs_zbuf_linesize equ 8
102
offs_zbuf_mode equ 16
102
offs_zbuf_mode equ 16
103
offs_zbuf_zbuf equ 20
103
offs_zbuf_zbuf equ 20
104
offs_zbuf_pbuf equ 24
104
offs_zbuf_pbuf equ 24
105
offs_zbuf_frame_buffer_allocated equ 28
105
offs_zbuf_frame_buffer_allocated equ 28
106
offs_zbuf_nb_colors equ 32
106
offs_zbuf_nb_colors equ 32
107
offs_zbuf_dctable equ 36
107
offs_zbuf_dctable equ 36
108
offs_zbuf_ctable equ 40
108
offs_zbuf_ctable equ 40
109
offs_zbuf_current_texture equ 44
109
offs_zbuf_current_texture equ 44
110
 
110
 
111
struct ZBufferPoint
111
struct ZBufferPoint
112
	x dd ? ;int ;integer coordinates in the zbuffer
112
	x dd ? ;int ;integer coordinates in the zbuffer
113
	y dd ? ;int
113
	y dd ? ;int
114
	z dd ? ;int
114
	z dd ? ;int
115
	s dd ? ;int ;coordinates for the mapping
115
	s dd ? ;int ;coordinates for the mapping
116
	t dd ? ;int
116
	t dd ? ;int
117
	r dd ? ;int ;color indexes
117
	r dd ? ;int ;color indexes
118
	g dd ? ;int
118
	g dd ? ;int
119
	b dd ? ;int
119
	b dd ? ;int
120
 
120
 
121
	fsz dd ? ;float ;temporary coordinates for mapping
121
	fsz dd ? ;float ;temporary coordinates for mapping
122
	tz dd ? ;float
122
	tz dd ? ;float
123
ends
123
ends
124
 
124
 
125
offs_zbup_x equ  0
125
offs_zbup_x equ  0
126
offs_zbup_y equ  4
126
offs_zbup_y equ  4
127
offs_zbup_z equ  8
127
offs_zbup_z equ  8
128
offs_zbup_s equ 12
128
offs_zbup_s equ 12
129
offs_zbup_t equ 16
129
offs_zbup_t equ 16
130
offs_zbup_r equ 20
130
offs_zbup_r equ 20
131
offs_zbup_g equ 24
131
offs_zbup_g equ 24
132
offs_zbup_b equ 28
132
offs_zbup_b equ 28
133
offs_zbup_sz equ 32
133
offs_zbup_sz equ 32
134
offs_zbup_tz equ 36
134
offs_zbup_tz equ 36
135
 
135
 
136
; ztriangle.c
136
; ztriangle.c
137
 
137
 
138
;
138
;
139
; Memory allocator for TinyGL
139
; Memory allocator for TinyGL
140
;
140
;
141
 
141
 
142
; modify these functions so that they suit your needs
142
; modify these functions so that they suit your needs
143
 
143
 
144
align 4
144
align 4
145
proc gl_free uses ebx ecx, mptr:dword
145
proc gl_free uses eax ebx ecx, mptr:dword
146
	mov ecx,[mptr]
146
	mov ecx,[mptr]
147
	or ecx,ecx
147
	or ecx,ecx
148
	jz @f
148
	jz @f
149
    @@:
-
 
150
	mcall 68, 13
149
		mcall 68, 13
-
 
150
	@@:
151
	ret
151
	ret
152
endp
152
endp
153
 
153
 
154
;description:
154
;description:
155
; выделение памяти
155
; выделение памяти
156
align 4
156
align 4
157
proc gl_malloc uses ebx ecx, size:dword
157
proc gl_malloc uses ebx ecx, size:dword
158
	mcall 68, 12, [size]
158
	mcall 68, 12, [size]
159
	ret
159
	ret
160
endp
160
endp
161
 
161
 
162
;description:
162
;description:
163
; выделение очищеной памяти
163
; выделение очищеной памяти
164
align 4
164
align 4
165
proc gl_zalloc uses ebx ecx edi, size:dword
165
proc gl_zalloc uses ebx ecx edi, size:dword
166
	mov ecx,[size]
166
	mov ecx,[size]
167
	stdcall gl_malloc,ecx
167
	stdcall gl_malloc,ecx
168
	cmp eax,0
168
	or eax,eax
169
	je @f
169
	jz @f
170
		mov ebx,eax
170
		mov ebx,eax
171
		mov edi,eax
171
		mov edi,eax
172
		xor eax,eax
172
		xor eax,eax
173
		shr ecx,2
173
		shr ecx,2
174
		rep stosd ;очистка памяти (пишем везде 0)
174
		rep stosd ;очистка памяти (пишем везде 0)
175
		mov eax,ebx
175
		mov eax,ebx
176
	@@:
176
	@@:
177
	ret
177
	ret
178
endp
178
endp