forked from KolibriOS/kolibrios
add arrays example
git-svn-id: svn://kolibrios.org@5337 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
4d1b17a1d0
commit
82bb415d1c
@ -3,6 +3,10 @@ COLOR_ARRAY equ 0x0002
|
||||
NORMAL_ARRAY equ 0x0004
|
||||
TEXCOORD_ARRAY equ 0x0008
|
||||
|
||||
;glArrayElement - использование (рисование) одного элемента из массива
|
||||
;glDrawArrays - рисование всех элементов в массиве
|
||||
;glDrawElements - рисование тех элементов в массиве, которые заданны в массиве индексов
|
||||
|
||||
align 4
|
||||
proc glopArrayElement uses eax ebx ecx edx, context:dword, param:dword
|
||||
locals
|
||||
@ -18,8 +22,7 @@ endl
|
||||
add ecx,[eax+offs_cont_color_array_stride]
|
||||
imul ecx,ebx
|
||||
shl ecx,2
|
||||
add ecx,eax
|
||||
add ecx,offs_cont_color_array ;ecx = &context.color_array[i]
|
||||
add ecx,[eax+offs_cont_color_array] ;ecx = &context.color_array[i]
|
||||
mov ebx,ebp
|
||||
sub ebx,20 ;=sizeof(dd)*5
|
||||
mov edx,[ecx]
|
||||
@ -44,8 +47,7 @@ endl
|
||||
add esi,3
|
||||
imul esi,ebx
|
||||
shl esi,2
|
||||
add esi,eax
|
||||
add esi,offs_cont_normal_array ;esi = &normal_array[ebx * (3 + c->normal_array_stride)]
|
||||
add esi,[eax+offs_cont_normal_array] ;esi = &normal_array[ebx * (3 + c->normal_array_stride)]
|
||||
mov edi,eax
|
||||
add edi,offs_cont_current_normal
|
||||
mov ecx,3
|
||||
@ -58,8 +60,7 @@ endl
|
||||
add ecx,[eax+offs_cont_texcoord_array_stride]
|
||||
imul ecx,ebx
|
||||
shl ecx,2
|
||||
add ecx,eax
|
||||
add ecx,offs_cont_texcoord_array ;ecx = &context.texcoord_array[i]
|
||||
add ecx,[eax+offs_cont_texcoord_array] ;ecx = &context.texcoord_array[i]
|
||||
mov edx,[ecx]
|
||||
mov [eax+offs_cont_current_tex_coord],edx
|
||||
mov edx,[ecx+4]
|
||||
@ -90,8 +91,7 @@ endl
|
||||
add ecx,[eax+offs_cont_vertex_array_stride]
|
||||
imul ecx,ebx
|
||||
shl ecx,2
|
||||
add ecx,eax
|
||||
add ecx,offs_cont_vertex_array ;ecx = &context.vertex_array[i]
|
||||
add ecx,[eax+offs_cont_vertex_array] ;ecx = &context.vertex_array[i]
|
||||
mov ebx,ebp
|
||||
sub ebx,20 ;=sizeof(dd)*5
|
||||
mov edx,[ecx]
|
||||
@ -107,7 +107,6 @@ endl
|
||||
mov edx,[ecx+8]
|
||||
.l7:
|
||||
mov [ebx+12],edx
|
||||
|
||||
cmp dword[eax+offs_cont_vertex_array_size],3
|
||||
jg .l8
|
||||
mov edx,1.0
|
||||
@ -137,6 +136,257 @@ endl
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
proc glopDrawArrays, context:dword, param:dword
|
||||
locals
|
||||
vi dd ?
|
||||
idx dd ?
|
||||
states dd ?
|
||||
size dd ?
|
||||
p rd 8 ;функция glopColor требует 8 параметров, другие функции требуют меньше, берем по максимуму что-бы не портить стек
|
||||
endl
|
||||
pushad
|
||||
mov edx,[context]
|
||||
mov ebx,[param]
|
||||
mov ecx,[ebx+12] ;count = param[3].i
|
||||
mov eax,[edx+offs_cont_client_states]
|
||||
mov [states],eax
|
||||
mov eax,[ebx+8]
|
||||
mov [idx],eax ;param[2].i
|
||||
mov eax,[ebx+4]
|
||||
mov [p+4],eax ;p[1].i = param[1].i
|
||||
mov eax,ebp
|
||||
sub eax,32 ;=sizeof(dd)*8
|
||||
stdcall glopBegin, edx,eax
|
||||
|
||||
mov dword[vi],0
|
||||
align 4
|
||||
.cycle_0: ;for (int vi=0; vi<count; vi++)
|
||||
cmp dword[vi],ecx
|
||||
jge .cycle_0_end
|
||||
bt dword[states],1 ;2^1=COLOR_ARRAY
|
||||
jnc @f
|
||||
mov esi,[edx+offs_cont_color_array_size]
|
||||
mov [size],esi
|
||||
add esi,[edx+offs_cont_color_array_stride]
|
||||
imul esi,[idx] ;esi = i
|
||||
shl esi,2
|
||||
add esi,[edx+offs_cont_color_array] ;esi = &context.color_array[i]
|
||||
mov edi,ebp
|
||||
sub edi,28 ;edi = &p[1]
|
||||
movsd ;p[1].f = context.color_array[i]
|
||||
movsd
|
||||
movsd
|
||||
cmp dword[size],3
|
||||
jle .e1
|
||||
movsd
|
||||
sub edi,20 ;&p[0]
|
||||
jmp .e2
|
||||
.e1:
|
||||
mov dword[edi],1.0 ;если задано 3 параметра, то 4-й ставим по умолчанию 1.0
|
||||
sub edi,16 ;&p[0]
|
||||
.e2:
|
||||
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]
|
||||
shl esi,2
|
||||
add esi,[edx+offs_cont_normal_array] ;esi = &context.normal_array[ idx * (3 + context.normal_array_stride) ]
|
||||
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
|
||||
.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[idx]
|
||||
inc dword[vi]
|
||||
jmp .cycle_0
|
||||
.cycle_0_end:
|
||||
|
||||
;mov eax,ebp
|
||||
;sub eax,32 ;=sizeof(dd)*8
|
||||
stdcall glopEnd, edx,eax
|
||||
popad
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
proc glDrawArrays uses eax, mode:dword, first:dword, count:dword
|
||||
locals
|
||||
p rd 4
|
||||
endl
|
||||
mov dword[p],OP_DrawArrays
|
||||
mov eax,[mode]
|
||||
mov dword[p+4],eax
|
||||
mov eax,[first]
|
||||
mov dword[p+8],eax
|
||||
mov eax,[count]
|
||||
mov dword[p+12],eax
|
||||
|
||||
mov eax,ebp
|
||||
sub eax,16 ;=sizeof(dd)*4
|
||||
stdcall gl_add_op,eax
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
proc glopDrawElements uses eax ebx edx, context:dword, param:dword
|
||||
locals
|
||||
p rd 5
|
||||
endl
|
||||
|
||||
mov edx,[context]
|
||||
mov ebx,[param]
|
||||
;int i;
|
||||
;int idx;
|
||||
;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 [p+4],eax ;p[1].i = param[1].i
|
||||
mov eax,ebp
|
||||
sub eax,20 ;=sizeof(dd)*5
|
||||
stdcall glopBegin, edx,eax
|
||||
|
||||
; for (int ii=0; ii<count; ii++) {
|
||||
; idx = (type == GL_UNSIGNED_INT) ? indices_u32[ii] : indices_u16[ii];
|
||||
; if (states & COLOR_ARRAY) {
|
||||
; GLParam p[5];
|
||||
; int size = c->color_array_size;
|
||||
; i = idx * (size + c->color_array_stride);
|
||||
; p[1].f = c->color_array[i];
|
||||
; p[2].f = c->color_array[i+1];
|
||||
; p[3].f = c->color_array[i+2];
|
||||
; p[4].f = size > 3 ? c->color_array[i+3] : 1.0f;
|
||||
; glopColor(c, p);
|
||||
; }
|
||||
; if (states & NORMAL_ARRAY) {
|
||||
; i = idx * (3 + c->normal_array_stride);
|
||||
; c->current_normal.X = c->normal_array[i];
|
||||
; c->current_normal.Y = c->normal_array[i+1];
|
||||
; c->current_normal.Z = c->normal_array[i+2];
|
||||
; c->current_normal.W = 0.0f;
|
||||
; }
|
||||
; if (states & TEXCOORD_ARRAY) {
|
||||
; int size = c->texcoord_array_size;
|
||||
; i = idx * (size + c->texcoord_array_stride);
|
||||
; c->current_tex_coord.X = c->texcoord_array[i];
|
||||
; c->current_tex_coord.Y = c->texcoord_array[i+1];
|
||||
; c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i+2] : 0.0f;
|
||||
; c->current_tex_coord.W = size > 3 ? c->texcoord_array[i+3] : 1.0f;
|
||||
; }
|
||||
; if (states & VERTEX_ARRAY) {
|
||||
; GLParam p[5];
|
||||
; int size = c->vertex_array_size;
|
||||
; i = idx * (size + c->vertex_array_stride);
|
||||
; p[1].f = c->vertex_array[i];
|
||||
; p[2].f = c->vertex_array[i+1];
|
||||
; p[3].f = size > 2 ? c->vertex_array[i+2] : 0.0f;
|
||||
; p[4].f = size > 3 ? c->vertex_array[i+3] : 1.0f;
|
||||
; glopVertex(c, p);
|
||||
; }
|
||||
; }
|
||||
mov eax,ebp
|
||||
sub eax,20 ;=sizeof(dd)*5
|
||||
stdcall glopEnd, edx,eax
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
proc glDrawElements uses eax, mode:dword, count:dword, type:dword, indices:dword
|
||||
locals
|
||||
p rd 5
|
||||
endl
|
||||
;assert(type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT/* nonstandard */);
|
||||
mov dword[p],OP_DrawElements
|
||||
mov eax,[mode]
|
||||
mov dword[p+4],eax
|
||||
mov eax,[count]
|
||||
mov dword[p+8],eax
|
||||
mov eax,[type]
|
||||
mov dword[p+12],eax
|
||||
mov eax,[indices]
|
||||
mov dword[p+16],eax
|
||||
|
||||
mov eax,ebp
|
||||
sub eax,20 ;=sizeof(dd)*5
|
||||
stdcall gl_add_op,eax
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
proc glopEnableClientState uses eax ebx, context:dword, p:dword
|
||||
mov eax,[context]
|
||||
@ -247,7 +497,7 @@ locals
|
||||
endl
|
||||
; assert(type == GL_FLOAT);
|
||||
|
||||
mov dword[p],OP_TexCoordPointer
|
||||
mov dword[p],OP_VertexPointer
|
||||
mov eax,[size]
|
||||
mov dword[p+4],eax
|
||||
mov eax,[stride]
|
||||
|
@ -0,0 +1,201 @@
|
||||
use32
|
||||
org 0x0
|
||||
db 'MENUET01'
|
||||
dd 0x1
|
||||
dd start
|
||||
dd i_end
|
||||
dd mem,stacktop
|
||||
dd 0,cur_dir_path
|
||||
|
||||
include '../../../../../../programs/proc32.inc'
|
||||
include '../../../../../../programs/macros.inc'
|
||||
include '../../../../../../programs/develop/libraries/box_lib/load_lib.mac'
|
||||
include '../../../../../../programs/dll.inc'
|
||||
include '../opengl_const.inc'
|
||||
|
||||
@use_library
|
||||
|
||||
align 4
|
||||
start:
|
||||
load_library name_tgl, cur_dir_path, library_path, system_path, \
|
||||
err_message_found_lib, head_f_l, import_lib_tinygl, err_message_import, head_f_i
|
||||
cmp eax,-1
|
||||
jz button.exit
|
||||
|
||||
mcall 40,0x27
|
||||
|
||||
stdcall [kosglMakeCurrent], 10,10,400,350,ctx1
|
||||
stdcall [glEnable], GL_DEPTH_TEST
|
||||
stdcall [glClearColor], 0.0,0.0,0.0,0.0
|
||||
stdcall [glShadeModel], GL_SMOOTH
|
||||
|
||||
call draw_3d
|
||||
|
||||
align 4
|
||||
red_win:
|
||||
call draw_window
|
||||
|
||||
align 4
|
||||
still:
|
||||
mcall 10
|
||||
cmp al,1
|
||||
jz red_win
|
||||
cmp al,2
|
||||
jz key
|
||||
cmp al,3
|
||||
jz button
|
||||
jmp still
|
||||
|
||||
align 4
|
||||
draw_window:
|
||||
pushad
|
||||
mcall 12,1
|
||||
|
||||
mov edx,0x33ffffff ;0x73ffffff
|
||||
mcall 0,(50 shl 16)+430,(30 shl 16)+400,,,caption
|
||||
stdcall [kosglSwapBuffers]
|
||||
|
||||
mcall 12,2
|
||||
popad
|
||||
ret
|
||||
|
||||
align 4
|
||||
key:
|
||||
mcall 2
|
||||
|
||||
cmp ah,27 ;Esc
|
||||
je button.exit
|
||||
|
||||
cmp ah,61 ;+
|
||||
jne @f
|
||||
fld dword[scale]
|
||||
fadd dword[delt_sc]
|
||||
fstp dword[scale]
|
||||
call draw_3d
|
||||
stdcall [kosglSwapBuffers]
|
||||
@@:
|
||||
cmp ah,45 ;-
|
||||
jne @f
|
||||
fld dword[scale]
|
||||
fsub dword[delt_sc]
|
||||
fstp dword[scale]
|
||||
call draw_3d
|
||||
stdcall [kosglSwapBuffers]
|
||||
@@:
|
||||
cmp ah,178 ;Up
|
||||
jne @f
|
||||
fld dword[angle_y]
|
||||
fadd dword[delt_size]
|
||||
fstp dword[angle_y]
|
||||
call draw_3d
|
||||
stdcall [kosglSwapBuffers]
|
||||
@@:
|
||||
cmp ah,177 ;Down
|
||||
jne @f
|
||||
fld dword[angle_y]
|
||||
fsub dword[delt_size]
|
||||
fstp dword[angle_y]
|
||||
call draw_3d
|
||||
stdcall [kosglSwapBuffers]
|
||||
@@:
|
||||
cmp ah,176 ;Left
|
||||
jne @f
|
||||
fld dword[angle_z]
|
||||
fadd dword[delt_size]
|
||||
fstp dword[angle_z]
|
||||
call draw_3d
|
||||
stdcall [kosglSwapBuffers]
|
||||
@@:
|
||||
cmp ah,179 ;Right
|
||||
jne @f
|
||||
fld dword[angle_z]
|
||||
fsub dword[delt_size]
|
||||
fstp dword[angle_z]
|
||||
call draw_3d
|
||||
stdcall [kosglSwapBuffers]
|
||||
@@:
|
||||
|
||||
jmp still
|
||||
|
||||
align 4
|
||||
button:
|
||||
mcall 17
|
||||
cmp ah,1
|
||||
jne still
|
||||
.exit:
|
||||
mcall -1
|
||||
|
||||
|
||||
align 4
|
||||
caption db 'Test opengl 1.1 arrays, [Esc] - exit, [<-],[->],[Up],[Down] - rotate',0
|
||||
align 4
|
||||
ctx1 db 28 dup (0) ;TinyGLContext or KOSGLContext
|
||||
;sizeof.TinyGLContext = 28
|
||||
|
||||
align 4
|
||||
draw_3d:
|
||||
stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT ;очистим буфер цвета и глубины
|
||||
stdcall [glPushMatrix]
|
||||
|
||||
;масштаб и повороты
|
||||
stdcall [glTranslatef], 0.0,0.0,0.5
|
||||
stdcall [glScalef], [scale], [scale], [scale]
|
||||
stdcall [glRotatef], [angle_z],0.0,0.0,1.0
|
||||
stdcall [glRotatef], [angle_y],0.0,1.0,0.0
|
||||
|
||||
;рисование через массивы
|
||||
stdcall [glVertexPointer], 2, GL_FLOAT, 0, Vertex ;задаем массив для вершин, 2 - число координат для одной вершины
|
||||
stdcall [glColorPointer], 3, GL_FLOAT, 0, Colors ;задаем массив для цветов, 3 - число параметров для одной точки
|
||||
stdcall [glEnableClientState], GL_VERTEX_ARRAY ;включаем режим рисования вершин
|
||||
stdcall [glEnableClientState], GL_COLOR_ARRAY ;включаем режим рисования цветов
|
||||
stdcall [glDrawArrays], GL_POLYGON, 0, 4 ;рисование полигона из 4-х вершин (равносильно вызову 8-ми функций: 4 - для вершин, 4 - для цетов)
|
||||
stdcall [glDisableClientState], GL_COLOR_ARRAY ;отключаем режим рисования цветов
|
||||
stdcall [glDisableClientState], GL_VERTEX_ARRAY ;отключаем режим рисования вершин
|
||||
|
||||
stdcall [glPopMatrix]
|
||||
ret
|
||||
|
||||
align 4
|
||||
scale dd 0.8
|
||||
delt_sc dd 0.05
|
||||
angle_z dd 0.0
|
||||
angle_y dd 0.0
|
||||
delt_size dd 3.0
|
||||
|
||||
align 4
|
||||
Vertex dd -0.9, -0.9, -0.9, 0.9, 0.9, 0.9, 0.9, -0.9 ;4 вершины (по 2 координаты)
|
||||
Colors dd 0.0, 0.5, 1.0, 1.0, 0.0, 0.5, 1.0, 1.0, 1.0, 0.5, 1.0, 0.0 ;4 цвета (по 3 параметра)
|
||||
|
||||
;--------------------------------------------------
|
||||
align 4
|
||||
import_lib_tinygl:
|
||||
|
||||
macro E_LIB n
|
||||
{
|
||||
n dd sz_#n
|
||||
}
|
||||
include '../export.inc'
|
||||
dd 0,0
|
||||
macro E_LIB n
|
||||
{
|
||||
sz_#n db `n,0
|
||||
}
|
||||
include '../export.inc'
|
||||
|
||||
;--------------------------------------------------
|
||||
system_path db '/sys/lib/'
|
||||
name_tgl db 'tinygl.obj',0
|
||||
err_message_found_lib db 'Sorry I cannot load library tinygl.obj',0
|
||||
head_f_i:
|
||||
head_f_l db 'System error',0
|
||||
err_message_import db 'Error on load import library tinygl.obj',0
|
||||
;--------------------------------------------------
|
||||
|
||||
i_end:
|
||||
rb 1024
|
||||
stacktop:
|
||||
cur_dir_path:
|
||||
rb 4096
|
||||
library_path:
|
||||
rb 4096
|
||||
mem:
|
@ -123,6 +123,8 @@ E_LIB glFrontFace ;(int mode)
|
||||
E_LIB glEnableClientState ;(GLenum array)
|
||||
E_LIB glDisableClientState ;(GLenum array)
|
||||
E_LIB glArrayElement ;(GLint i)
|
||||
E_LIB glDrawArrays ;(mode, first, count)
|
||||
E_LIB glDrawElements ;(mode, count, type, indices)
|
||||
E_LIB glVertexPointer ;(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
|
||||
E_LIB glColorPointer ;(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
|
||||
E_LIB glNormalPointer ;(GLenum type, GLsizei stride, const GLvoid *pointer)
|
||||
|
@ -57,6 +57,8 @@ ADD_OP NextBuffer,1,'%p'
|
||||
|
||||
; opengl 1.1 arrays
|
||||
ADD_OP ArrayElement, 1, '%d'
|
||||
ADD_OP DrawArrays, 3, '%C %d %d'
|
||||
ADD_OP DrawElements, 4, '%C %d %C %p'
|
||||
ADD_OP EnableClientState, 1, '%C'
|
||||
ADD_OP DisableClientState, 1, '%C'
|
||||
ADD_OP VertexPointer, 4, '%d %C %d %p'
|
||||
|
Loading…
Reference in New Issue
Block a user