1 /*
2 
3 Memonix, Viewizard Game Core ver 2.0
4 Copyright (c) 2001-2006 Michael Kurinnoy, Viewizard Games
5 All Rights Reserved.
6 
7 Memonix game source codes available under "dual licensing" model.
8 The licensing options available are:
9 
10 * Commercial Licensing. This is the appropriate option if you are creating proprietary
11 applications and you are not prepared to distribute and share the source code of your application.
12 Contact us for pricing at viewizard@viewizard.com
13 
14 * Open Source Licensing. This is the appropriate option if you want to share the source code of
15 your application with everyone you distribute it to, and you also want to give them the right to share who uses it.
16 You should have received a copy of the GNU General Public License version 3 with this source codes. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 
21 
22 #include "RendererInterface.h"
23 
24 
25 extern	int tmpPrimCountGL;
26 extern	PFNGLCLIENTACTIVETEXTUREARBPROC	glClientActiveTexture_ARB;
27 
28 
29 
30 
31 extern int VertexIndexCount;
32 extern GLuint *VertexIndex;
33 
34 
35 
36 
37 ////////////////////////////////////////////////////////////
38 // процедура передачи последовательности вертексов
39 ////////////////////////////////////////////////////////////
vw_SendVertices(int PrimitiveType,int NumVertices,int DataFormat,void * Data,int Stride)40 void vw_SendVertices(int PrimitiveType, int NumVertices, int DataFormat, void *Data, int Stride)
41 {
42 
43 
44 
45 
46         // обязательно в байты, т.к. делаем смещение в байтах!
47 		BYTE *TMP = (BYTE *)Data;
48 
49 		// чтобы знать сколько отступать, кол-во ед. элементов, в нашем случае float
50 		int AddStride = 0;
51 		// кол-во текстур
52 		int TextQ = DataFormat & 0x000000F;
53 
54 		// делаем установку поинтеров + ставим смещения для прорисовки
55 		if ((DataFormat & 0x105F000) == RI_3f_XYZ)
56 		{
57 			glEnableClientState(GL_VERTEX_ARRAY);
58 			glVertexPointer(3, GL_FLOAT, Stride, TMP + AddStride);
59 			AddStride += 3*sizeof(GLfloat);
60 		}
61 
62 		if ((DataFormat & 0x105F000) == RI_2f_XYZ)
63 		{
64 			glEnableClientState(GL_VERTEX_ARRAY);
65 			glVertexPointer(2, GL_FLOAT, Stride, TMP + AddStride);
66 			AddStride += 2*sizeof(GLfloat);
67 		}
68 
69 		if ((DataFormat & 0x1050F00) == RI_3f_NORMAL)
70 		{
71 			glEnableClientState(GL_NORMAL_ARRAY);
72 			glNormalPointer(GL_FLOAT, Stride, TMP + AddStride);
73 			AddStride += 3*sizeof(GLfloat);
74 		}
75 
76 		if ((DataFormat & 0x10500F0) == RI_4f_COLOR)
77 		{
78 			glEnableClientState(GL_COLOR_ARRAY);
79 			glColorPointer(4, GL_FLOAT, Stride, TMP + AddStride);
80 			AddStride += 4*sizeof(GLfloat);
81 		}
82 
83 		if (TextQ > 0)// текстурные коорд. есть...
84 		{
85 			if (glClientActiveTexture_ARB == NULL)
86             {
87 				glEnableClientState(GL_TEXTURE_COORD_ARRAY);
88                 glTexCoordPointer(2, GL_FLOAT,Stride, TMP + AddStride);
89 				AddStride += 2*sizeof(GLfloat);
90             }
91             else
92             {
93                 for (int i=0; i<TextQ; i++)
94                 {
95                     glClientActiveTexture_ARB(GL_TEXTURE0_ARB+i);
96 					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
97                     glTexCoordPointer(2, GL_FLOAT, Stride, TMP + AddStride);
98                     AddStride += 2*sizeof(GLfloat);
99                 }
100             }
101 
102 
103 
104 
105 		// собираем если нужно массив индексов
106 		if (VertexIndexCount < NumVertices)
107 		{
108 			VertexIndexCount = NumVertices;
109 			VertexIndex = new GLuint[NumVertices];
110 			for (int i=0; i<NumVertices; i++) VertexIndex[i] = i;
111 		}
112 
113 
114 
115 		// рисуем
116 		switch(PrimitiveType)
117 		{
118 			case RI_POINTS:
119                 		glDrawElements(GL_POINTS,NumVertices,GL_UNSIGNED_INT,VertexIndex);
120 				tmpPrimCountGL += NumVertices;
121 				break;
122 
123 			case RI_LINES:
124                			glDrawElements(GL_LINES,NumVertices,GL_UNSIGNED_INT,VertexIndex);
125 				tmpPrimCountGL += NumVertices/2;
126 				break;
127 
128 			case RI_TRIANGLES:
129 				glDrawElements(GL_TRIANGLES,NumVertices,GL_UNSIGNED_INT,VertexIndex);
130 				tmpPrimCountGL += NumVertices/3;
131 				break;
132 
133 			case RI_TRIANGLE_STRIP:
134 				glDrawElements(GL_TRIANGLE_STRIP,NumVertices,GL_UNSIGNED_INT,VertexIndex);
135 				tmpPrimCountGL += NumVertices-2;
136 				break;
137 
138 			case RI_TRIANGLE_FAN:
139 				glDrawElements(GL_TRIANGLE_FAN,NumVertices,GL_UNSIGNED_INT,VertexIndex);
140 				tmpPrimCountGL += NumVertices-2;
141 				break;
142 		}
143 
144 
145 
146 
147 
148 		glDisableClientState(GL_NORMAL_ARRAY);
149 		glDisableClientState(GL_COLOR_ARRAY);
150 		glDisableClientState(GL_VERTEX_ARRAY);
151 
152         if (glClientActiveTexture_ARB != NULL)
153         {
154             for (int i=0; i<TextQ; i++)
155             {
156                 glClientActiveTexture_ARB(GL_TEXTURE0_ARB+i);
157                 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
158             }
159             glClientActiveTexture_ARB(GL_TEXTURE0_ARB);
160         }
161         else
162         	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
163 	}
164 
165 
166 
167 }
168