add function 'glDrawElements' and example

git-svn-id: svn://kolibrios.org@5380 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2015-01-15 22:15:12 +00:00
parent 448f7a59d1
commit adb3b5e234
2 changed files with 152 additions and 51 deletions

View File

@ -306,68 +306,169 @@ endl
endp endp
align 4 align 4
proc glopDrawElements uses eax ebx edx, context:dword, param:dword proc glopDrawElements, context:dword, param:dword
locals locals
ii dd ?
idx dd ?
states dd ?
type dd ?
size dd ?
indices dd ? ;указатель на 16 или 32 битные индексы
p rd 8 p rd 8
endl endl
pushad
mov edx,[context] mov edx,[context]
mov ebx,[param] mov ebx,[param]
;int i; mov eax,[edx+offs_cont_client_states]
;int idx; mov [states],eax
;int states = c->client_states;
;int count = param[2].i;
;int type = param[3].i;
;unsigned int *indices_u32 = (unsigned int*)param[4].p;
;unsigned short *indices_u16 = (unsigned short*)indices_u32;
mov eax,[ebx+4] mov eax,[ebx+4]
mov [p+4],eax ;p[1].i = param[1].i mov [p+4],eax ;p[1].i = param[1].i
mov ecx,[ebx+8] ;count = param[2].i
mov eax,[ebx+12]
mov [type],eax ;type = param[3].i
mov eax,[ebx+16]
mov [indices],eax ;*indices = param[4].p
mov eax,ebp mov eax,ebp
sub eax,32 ;=sizeof(dd)*8 sub eax,32 ;=sizeof(dd)*8
stdcall glopBegin, edx,eax stdcall glopBegin, edx,eax
; for (int ii=0; ii<count; ii++) { mov dword[ii],0
; idx = (type == GL_UNSIGNED_INT) ? indices_u32[ii] : indices_u16[ii]; align 4
; if (states & COLOR_ARRAY) { .cycle_0: ;for (int ii=0; ii<count; ii++)
; GLParam p[5]; cmp dword[ii],ecx
; int size = c->color_array_size; jge .cycle_0_end
; i = idx * (size + c->color_array_stride); mov esi,[ii]
; p[1].f = c->color_array[i]; cmp dword[type],GL_UNSIGNED_INT
; p[2].f = c->color_array[i+1]; jne @f
; p[3].f = c->color_array[i+2]; shl esi,2
; p[4].f = size > 3 ? c->color_array[i+3] : 1.0f; add esi,[indices]
; glopColor(c, p); mov esi,[esi]
; } jmp .end_0
; if (states & NORMAL_ARRAY) { @@:
; i = idx * (3 + c->normal_array_stride); shl esi,1
; c->current_normal.X = c->normal_array[i]; add esi,[indices]
; c->current_normal.Y = c->normal_array[i+1]; movzx esi,word[esi]
; c->current_normal.Z = c->normal_array[i+2]; .end_0:
; c->current_normal.W = 0.0f; mov [idx],esi
; }
; if (states & TEXCOORD_ARRAY) { bt dword[states],1 ;2^1=COLOR_ARRAY
; int size = c->texcoord_array_size; jnc @f
; i = idx * (size + c->texcoord_array_stride); mov esi,[edx+offs_cont_color_array_size]
; c->current_tex_coord.X = c->texcoord_array[i]; mov [size],esi
; c->current_tex_coord.Y = c->texcoord_array[i+1]; add esi,[edx+offs_cont_color_array_stride]
; c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i+2] : 0.0f; imul esi,[idx] ;esi = i
; c->current_tex_coord.W = size > 3 ? c->texcoord_array[i+3] : 1.0f; shl esi,2
; } add esi,[edx+offs_cont_color_array] ;esi = &context.color_array[i]
; if (states & VERTEX_ARRAY) { mov edi,ebp
; GLParam p[5]; sub edi,28 ;edi = &p[1]
; int size = c->vertex_array_size; mov ebx,[esi+8]
; i = idx * (size + c->vertex_array_stride); mov [edi],ebx ;p[1].f = context.color_array[i+2]
; p[1].f = c->vertex_array[i]; mov ebx,[esi+4]
; p[2].f = c->vertex_array[i+1]; mov [edi+4],ebx ;p[2].f = context.color_array[i+1]
; p[3].f = size > 2 ? c->vertex_array[i+2] : 0.0f; mov ebx,[esi]
; p[4].f = size > 3 ? c->vertex_array[i+3] : 1.0f; mov [edi+8],ebx ;p[3].f = context.color_array[i]
; glopVertex(c, p); add edi,12
; } cmp dword[size],3
; } jle .e1
add esi,12
movsd
jmp .e2
.e1:
mov dword[edi],1.0 ;если задано 3 параметра, то 4-й ставим по умолчанию 1.0
.e2:
mov edi,ebp
sub edi,32 ;edi = &p[0]
mov ebx,ebp
sub ebx,12 ;ebp-12 = &p[5]
push ebx
add ebx,4 ;ebp-8 = &p[6]
push ebx
add ebx,4 ;ebp-4 = &p[7]
push ebx
stdcall RGBFtoRGBI,[edi+12],[edi+8],[edi+4] ;call: r,g,b,&p[7],&p[6],&p[5]
stdcall glopColor, edx,edi ;(context, p(op,rf,gf,bf,af,ri,gi,bi))
@@:
bt dword[states],2 ;2^2=NORMAL_ARRAY
jnc @f
mov esi,[edx+offs_cont_normal_array_stride]
add esi,3
imul esi,[idx] ;esi = idx * (3 + context.normal_array_stride)
shl esi,2
add esi,[edx+offs_cont_normal_array]
mov edi,edx
add edi,offs_cont_current_normal
movsd ;context.current_normal.X = context.normal_array[i]
movsd
movsd
mov dword[edi],0.0 ;context.current_normal.W = 0.0f
@@:
bt dword[states],3 ;2^3=TEXCOORD_ARRAY
jnc @f
mov esi,[edx+offs_cont_texcoord_array_size]
mov [size],esi
add esi,[edx+offs_cont_texcoord_array_stride]
imul esi,[idx] ;esi = i
shl esi,2
add esi,[edx+offs_cont_texcoord_array] ;esi = &context.texcoord_array[i]
mov edi,edx
add edi,offs_cont_current_tex_coord
movsd ;context.current_tex_coord.X = ccontext.texcoord_array[i]
movsd
cmp dword[size],2
jle .e3
movsd
jmp .e4
.e3:
mov dword[edi],0.0 ;если задано 2 параметра, то 3-й ставим по умолчанию 0.0
add edi,4
.e4:
cmp dword[size],3
jle .e5
movsd
jmp @f
.e5:
mov dword[edi],1.0 ;если задано 3 параметра, то 4-й ставим по умолчанию 1.0
@@:
bt dword[states],0 ;2^0=VERTEX_ARRAY
jnc @f
mov esi,[edx+offs_cont_vertex_array_size]
mov [size],esi
add esi,[edx+offs_cont_vertex_array_stride]
imul esi,[idx] ;esi = i
shl esi,2
add esi,[edx+offs_cont_vertex_array] ;esi = &context.vertex_array[i]
mov edi,ebp
sub edi,28 ;edi = &p[1]
movsd ;p[1].f = context.vertex_array[i]
movsd
cmp dword[size],2
jle .e6
movsd
jmp .e7
.e6:
mov dword[edi],0.0 ;если задано 2 параметра, то 3-й ставим по умолчанию 0.0
add edi,4
jmp .e8 ;и 4-й тоже ставим по умолчанию
.e7:
cmp dword[size],3
jle .e8
movsd
sub edi,20 ;edi=&p[0]
jmp .e9
.e8:
mov dword[edi],1.0 ;если задано 3 параметра, то 4-й ставим по умолчанию 1.0
sub edi,16 ;edi=&p[0]
.e9:
stdcall glopVertex, edx,edi
@@:
inc dword[ii]
jmp .cycle_0
.cycle_0_end:
mov eax,ebp mov eax,ebp
sub eax,32 ;=sizeof(dd)*8 sub eax,32 ;=sizeof(dd)*8
stdcall glopEnd, edx,eax stdcall glopEnd, edx,eax
popad
ret ret
endp endp

View File

@ -167,8 +167,8 @@ SetLight:
stdcall [glLightfv], GL_LIGHT0, GL_POSITION, light_position stdcall [glLightfv], GL_LIGHT0, GL_POSITION, light_position
stdcall [glLightfv], GL_LIGHT0, GL_SPOT_DIRECTION, light_dir stdcall [glLightfv], GL_LIGHT0, GL_SPOT_DIRECTION, light_dir
stdcall [glLightfv], GL_LIGHT0, GL_DIFFUSE, white_light ; stdcall [glLightfv], GL_LIGHT0, GL_DIFFUSE, white_light
stdcall [glLightfv], GL_LIGHT0, GL_SPECULAR, white_light ; stdcall [glLightfv], GL_LIGHT0, GL_SPECULAR, white_light
stdcall [glEnable], GL_COLOR_MATERIAL stdcall [glEnable], GL_COLOR_MATERIAL
stdcall [glColorMaterial], GL_FRONT, GL_AMBIENT_AND_DIFFUSE stdcall [glColorMaterial], GL_FRONT, GL_AMBIENT_AND_DIFFUSE
@ -177,7 +177,7 @@ SetLight:
stdcall [glLightModelfv], GL_LIGHT_MODEL_AMBIENT, lmodel_ambient stdcall [glLightModelfv], GL_LIGHT_MODEL_AMBIENT, lmodel_ambient
stdcall [glEnable],GL_LIGHTING stdcall [glEnable],GL_LIGHTING
stdcall [glEnable],GL_LIGHT0 ; stdcall [glEnable],GL_LIGHT0
ret ret
qObj dd 0 qObj dd 0