4 * Gestion des textures sous OpenGL
9 * Les textures sont toujours initialisee avec des parametres par defaut
10 * texture 1D: WRAP_S = CLAMP
11 * MAG_FILTER = NEAREST
12 * generation de texture automatique en OBJECT_LINEAR
15 * texture 2D: WRAP_S/T = REPEAT
16 * MAG/MIN_FILTER = LINEAR
17 * generation de texture automatique en OBJECT_LINEAR
20 * texture 2D MipMap: WRAP_S/T = REPEAT
22 * MIN_FILTER = LINEAR_MIPMAP_NEAREST
23 * generation de texture automatique en OBJECT_LINEAR
26 * Historique des modifications
27 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 * 22-05-97: PCT ; Creation
29 * 18-06-97: FMN ; Ajout entete
30 * 20-06-97: PCT ; Correction bug parametres par defaut texture 1D
31 * 30-06-97: PCT ; Correction bug rechargement de la texture courante
32 * 04-07-97: PCT ; suppression de l'utilisation de libimage.a de SGI
33 * 01-08-97: PCT ; suppression InitializeTextureBox()
34 * 04-08-97: FMN,PCT ; Portage WNT
35 * 05-08-97: FMN ; ajout GetTextureData...
36 * 10-09-97: PCT ; ajout commentaires. GetTexture() ne doit pas
37 * etre utilisee dans Cas.Cade ( le chargement est
38 * fait par Graphic3d )
39 * 06-10-97: FMN ; Portage HP
40 * 14-10-97: FMN ; Ajout OpenGl_Extension
41 * 22-10-97: FMN ; Meilleure gestion de l'extension glXGetCurrentDisplayEXT
42 * 04-11-97: FMN ; Gestion des differentes versions GLX
43 * 19-11-97: FMN ; Ajout GetCurrentDisplay plus simple que glXGetCurrentDisplayEXT
44 * 04-12-97: FMN ; On suppose que l'on travaille en OpenGL1.1 (cf OpenGl_Extension)
45 * 17-12-97: FMN ; Probleme compilation SGI
46 * 17-12-97: FMN ; Probleme sur Optimisation sur MyBindTextureEXT()
47 * Le test sur la texture courante doit tenir compte du contexte.
48 * 22-07-98: FGU ; Ajout fonctions TransferTexture_To_Data() et TransferData_To_Texture()
56 #include <OpenGl_tgl_all.hxx>
57 #include <OpenGl_Display.hxx>
58 #include <OpenGl_TextureBox.hxx>
59 #include <OpenGl_ImageBox.hxx>
60 #include <OpenGl_Memory.hxx>
61 #include <OpenGl_ResourceCleaner.hxx>
62 #include <OpenGl_ResourceTexture.hxx>
64 #define GROW_TEXTURES 8
65 #define GROW_TEXTURES_DATA 8
66 #define GROW_CONTEXT 8
69 #define max(a,b) ((a) > (b)) ? (a) : (b);
72 typedef enum {TEXDATA_NONE, TEXDATA_1D, TEXDATA_2D, TEXDATA_2DMM} texDataStatus;
73 typedef enum {TEX_NONE, TEX_ALLOCATED} texStatus;
75 typedef GLfloat SizeType[4];
77 typedef int TextureDataID;
78 #define TEXTUREDATA_ERROR -1
82 char imageFileName[128];
83 int imageWidth, imageHeight;
88 IMPLEMENT_MEMORY_OPERATORS
98 char *use_bind_texture;
109 GLfloat scalex, scaley;
110 GLfloat transx, transy;
113 IMPLEMENT_MEMORY_OPERATORS
117 /*----------------------------------------------------------------------*/
119 * Variables statiques
122 static texDraw *textab = NULL;
123 static int textures_count = 0;
124 static int textures_size = 0;
126 static texData *texdata = NULL;
127 static int textures_data_count = 0;
128 static int textures_data_size = 0;
130 static TextureDataID current_texture_data = TEXTUREDATA_ERROR;
131 static TextureID current_texture = TEXTUREBOX_ERROR;
133 static GLfloat sgenparams[] = { 1.0 ,0.0 ,0.0 ,0.0};
134 static GLfloat tgenparams[] = { 0.0 ,1.0 ,0.0 ,0.0};
136 static GLenum status2type[] = { GL_NONE, GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_2D };
138 /*----------------------------------------------------------------------*/
143 /*----------------------------------------------------------------------*/
145 * recherche l'existence de datas de texture par son nom
147 static TextureDataID FindTextureData(char *FileName)
151 for (i=0; i<textures_data_size; i++)
152 if ( texdata[i].status!=TEXDATA_NONE && strcmp(FileName, texdata[i].imageFileName)==0 )
155 return TEXTUREDATA_ERROR;
158 /*----------------------------------------------------------------------*/
160 * recherche un emplacement de data texture libre
162 static TextureDataID FindFreeTextureData(void)
166 /* ya encore de la place ? */
167 if (textures_data_count == textures_data_size)
169 textures_data_size += GROW_TEXTURES_DATA;
170 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
171 texdata = (texData*)realloc(texdata, textures_data_size*sizeof(texData));
173 texdata = cmn_resizemem<texData>(texdata, textures_data_size);
175 if (texdata == NULL) return TEXTUREDATA_ERROR;
177 for (i=textures_data_count; i<textures_data_size; i++)
178 texdata[i].status = TEXDATA_NONE;
180 /* on a deja assez perdu de temps comme ca => retourne un ID rapidement... */
181 return textures_data_count++;
184 /* recherche d'un ID libre */
185 for (i=0; i<textures_data_size; i++)
186 if (texdata[i].status == TEXDATA_NONE)
188 textures_data_count = max (textures_data_count, i + 1);
192 return TEXTUREDATA_ERROR;
195 /*----------------------------------------------------------------------*/
197 * recherche un emplacement de texture libre
199 static TextureID FindFreeTexture(void)
203 /* ya encore de la place ? */
204 if (textures_count == textures_size)
206 textures_size += GROW_TEXTURES;
207 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
208 textab = (texDraw*)realloc(textab, textures_size*sizeof(texDraw));
210 textab = cmn_resizemem<texDraw>(textab, textures_size);
212 if (textab == NULL) return TEXTUREBOX_ERROR;
214 for (i=textures_count; i<textures_size; i++)
215 textab[i].status = TEX_NONE;
217 /* on a deja assez perdu de temps comme ca => retourne un ID rapidement... */
218 return textures_count++;
221 for (i=0; i<textures_size; i++)
222 if (textab[i].status == TEX_NONE)
224 textures_count = max (textures_count, i + 1);
228 return TEXTUREBOX_ERROR;
231 /*----------------------------------------------------------------------*/
233 * regarde si la texture a ete definie pour le contexte courant
235 static int FindTextureContext(TextureID ID)
239 GLCONTEXT cur = GET_GL_CONTEXT();
240 for (i=0; i<textab[ID].context_count; i++)
241 if (textab[ID].context[i] == cur)
244 return TEXTUREBOX_ERROR;
247 /*----------------------------------------------------------------------*/
249 * chargement d'une texture suivant son type
251 static void LoadTexture(TextureID ID)
255 data = textab[ID].data;
256 switch (texdata[data].status)
259 glTexImage1D(GL_TEXTURE_1D, 0, 4,
260 texdata[data].imageWidth, 0,
261 GL_RGBA, GL_UNSIGNED_BYTE, texdata[data].image);
265 glTexImage2D(GL_TEXTURE_2D, 0, 4,
266 texdata[data].imageWidth, texdata[data].imageHeight, 0,
267 GL_RGBA, GL_UNSIGNED_BYTE, texdata[data].image);
271 gluBuild2DMipmaps(GL_TEXTURE_2D, 4,
272 texdata[data].imageWidth,
273 texdata[data].imageHeight,
274 GL_RGBA, GL_UNSIGNED_BYTE, texdata[data].image);
281 /*----------------------------------------------------------------------*/
283 * les parametres d'initialisation d'une texture
284 * NE PAS METTRE DANS UNE DISPLAY LIST POUR L'INSTANT ( pb avec les matrices )
286 static void SetTextureParam(TextureID ID)
292 data = textab[ID].data;
293 glGetIntegerv(GL_MATRIX_MODE, &cur_matrix);
296 * MISE EN PLACE DE LA MATRICE DE TEXTURE
298 glMatrixMode(GL_TEXTURE);
300 /* if (textab[ID].Gen != GL_SPHERE_MAP)
302 glScalef(textab[ID].scalex, textab[ID].scaley, 1.0);
303 glTranslatef(-textab[ID].transx, -textab[ID].transy, 0.0);
304 glRotatef(-textab[ID].angle, 0.0, 0.0, 1.0);
309 * GENERATION AUTOMATIQUE DE TEXTURE
311 switch (textab[ID].Gen)
313 case GL_OBJECT_LINEAR:
314 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
315 glTexGenfv(GL_S, GL_OBJECT_PLANE, textab[ID].Plane1);
316 if (texdata[data].status != TEXDATA_1D)
318 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
319 glTexGenfv(GL_T, GL_OBJECT_PLANE, textab[ID].Plane2);
324 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
325 if (texdata[data].status != TEXDATA_1D)
326 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
330 glMatrixMode(GL_MODELVIEW);
334 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
335 glTexGenfv(GL_S, GL_EYE_PLANE, textab[ID].Plane1);
337 if (texdata[data].status != TEXDATA_1D)
339 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
340 glTexGenfv(GL_T, GL_EYE_PLANE, textab[ID].Plane2);
349 * RENDU DE LA TEXTURE AVEC LES LUMIERES
351 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textab[ID].Light);
355 * LISSAGE DE LA TEXTURE
357 switch (texdata[data].status)
361 glTexParameteri(texdata[data].type, GL_TEXTURE_MAG_FILTER, textab[ID].Render);
362 glTexParameteri(texdata[data].type, GL_TEXTURE_MIN_FILTER, textab[ID].Render);
366 if (textab[ID].Render == GL_NEAREST)
368 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
385 switch (texdata[data].status)
388 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, textab[ID].Wrap);
393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, textab[ID].Wrap);
394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, textab[ID].Wrap);
400 glMatrixMode(cur_matrix);
403 /*----------------------------------------------------------------------*/
405 * simulation du glGenTexturesEXT pour un context
407 static void MyGenTextureEXT (TextureID ID)
409 int Context = textab[ID].context_count;
410 TextureDataID data = textab[ID].data;
412 textab[ID].context[Context] = GET_GL_CONTEXT();
413 textab[ID].drawable[Context] = GET_GLDEV_CONTEXT();
414 textab[ID].use_bind_texture[Context] = (char )GL_TRUE;
415 glGenTextures (1, &textab[ID].number[Context]);
416 glBindTexture (texdata[data].type, textab[ID].number[Context]);
418 textab[ID].context_count++;
421 /*----------------------------------------------------------------------*/
423 * simulation du glBindTextureEXT
425 static void MyBindTextureEXT (TextureID ID, int Context)
427 TextureDataID data = textab[ID].data;
428 if (texdata[data].status == TEXDATA_NONE)
431 GLenum aParamName = texdata[data].status == TEXDATA_1D ?
432 GL_TEXTURE_BINDING_1D : GL_TEXTURE_BINDING_2D;
435 glGetIntegerv (aParamName, &aCurrTex);
436 if (textab[ID].number[Context] != aCurrTex)
438 glBindTexture (texdata[data].type, textab[ID].number[Context]);
442 /*----------------------------------------------------------------------*/
444 * installation de la texture pour le dernier contexte
446 static int InstallTextureInContext(TextureID ID)
449 printf("InstallTextureInContext::installation de la texture dans le context\n");
453 /* ya encore de la place dans le tableau de context ? */
454 if (textab[ID].context_count == textab[ID].context_size)
457 printf("InstallTextureInContext::allocation dans le context\n");
459 textab[ID].context_size += GROW_CONTEXT;
460 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
462 (GLuint*)realloc(textab[ID].number, textab[ID].context_size*sizeof(GLuint));
464 (GLCONTEXT*)realloc(textab[ID].context, textab[ID].context_size*sizeof(GLCONTEXT));
465 textab[ID].drawable =
466 (GLDRAWABLE*)realloc(textab[ID].drawable, textab[ID].context_size*sizeof(GLDRAWABLE));
467 textab[ID].use_bind_texture =
468 (char*)realloc(textab[ID].use_bind_texture, textab[ID].context_size);
471 cmn_resizemem<GLuint>(textab[ID].number, textab[ID].context_size);
473 cmn_resizemem<GLCONTEXT>(textab[ID].context, textab[ID].context_size);
474 textab[ID].drawable =
475 cmn_resizemem<GLDRAWABLE>(textab[ID].drawable, textab[ID].context_size);
476 textab[ID].use_bind_texture =
477 cmn_resizemem<char>(textab[ID].use_bind_texture, textab[ID].context_size);
479 if ( (textab[ID].number == NULL) ||
480 (textab[ID].context == NULL) ||
481 (textab[ID].drawable == NULL) ||
482 (textab[ID].use_bind_texture == NULL) )
484 /* erreur => libere tout */
485 free(textab[ID].number);
486 free(textab[ID].context);
487 free(textab[ID].drawable);
488 free(textab[ID].use_bind_texture);
489 textab[ID].context_size = 0;
491 return TEXTUREBOX_ERROR;
498 printf("InstallTextureInContext::context ok\n");
503 /*----------------------------------------------------------------------*/
504 static TextureID GetTexture(char *FileName, texDataStatus status)
510 /* essait de trouver la texture */
511 i = FindTextureData(FileName);
512 if (i == TEXTUREDATA_ERROR)
515 printf("GetTexture::la texture %s n'existe pas => chargement\n", FileName);
517 /* creation d'une texture */
518 i = FindFreeTextureData();
519 if (i == TEXTUREDATA_ERROR) return TEXTUREBOX_ERROR;
521 texdata[i].share_count = 0;
522 strcpy(texdata[i].imageFileName, FileName);
523 texdata[i].image = (GLubyte *)read_texture(FileName,
524 &texdata[i].imageWidth,
525 &texdata[i].imageHeight,
527 if (texdata[i].image == NULL) return TEXTUREBOX_ERROR;
529 texdata[i].status = status;
530 texdata[i].type = status2type[status];
533 j = FindFreeTexture();
534 if (j != TEXTUREBOX_ERROR)
537 printf("GetTexture::installation texture pour obj %d\n", j);
539 textab[j].context_count = 0;
540 textab[j].context_size = 0;
541 textab[j].number = NULL;
542 textab[j].drawable = NULL;
543 textab[j].context = NULL;
544 textab[j].use_bind_texture = NULL;
546 textab[j].status = TEX_ALLOCATED;
547 texdata[i].share_count++;
549 SetTextureDefaultParams(j);
552 printf("GetTexture::texture %s(%d) texture %d count=%d\n", texdata[i].imageFileName, i, j, texdata[i].share_count);
556 if (texdata[i].share_count != 0)
557 free(texdata[i].image);
563 /*----------------------------------------------------------------------*/
564 static TextureID GetTextureData(char *FileName, texDataStatus status, const GLint width, const GLint height, const void *data)
569 /* essait de trouver la texture */
570 i = FindTextureData(FileName);
571 if (i == TEXTUREDATA_ERROR)
574 printf("GetTextureData::la texture %s n'existe pas => chargement\n", FileName);
576 /* creation d'une texture */
577 i = FindFreeTextureData();
578 if (i == TEXTUREDATA_ERROR) return TEXTUREBOX_ERROR;
580 texdata[i].share_count = 0;
581 strcpy(texdata[i].imageFileName, FileName);
582 texdata[i].image = (GLubyte *)malloc(width*height*4*sizeof(GLubyte));
583 memcpy(texdata[i].image, data, (width*height*4));
584 texdata[i].imageWidth = width;
585 texdata[i].imageHeight = height;
587 if (texdata[i].image == NULL) return TEXTUREBOX_ERROR;
589 texdata[i].status = status;
590 texdata[i].type = status2type[status];
593 j = FindFreeTexture();
594 if (j != TEXTUREBOX_ERROR)
597 printf("GetTextureData::installation texture pour obj %d\n", j);
599 textab[j].context_count = 0;
600 textab[j].context_size = 0;
601 textab[j].number = NULL;
602 textab[j].drawable = NULL;
603 textab[j].context = NULL;
604 textab[j].use_bind_texture = NULL;
606 textab[j].status = TEX_ALLOCATED;
607 texdata[i].share_count++;
609 SetTextureDefaultParams(j);
612 printf("GetTextureData::texture %s(%d) texture %d count=%d\n", texdata[i].imageFileName, i, j, texdata[i].share_count);
616 if (texdata[i].share_count != 0)
617 free(texdata[i].image);
622 /*----------------------------------------------------------------------*/
624 * Fonctions publiques
628 /*----------------------------------------------------------------------*/
630 GLboolean IsTextureValid(TextureID ID)
632 if ((ID<0) | (ID>=textures_count))
636 return textab[ID].status == TEX_ALLOCATED;
641 /*----------------------------------------------------------------------*/
643 TextureID GetTexture1D(char *FileName)
646 printf("GetTexture1D::loading 1d %s \n", FileName);
648 return GetTexture(FileName, TEXDATA_1D);
651 /*----------------------------------------------------------------------*/
653 TextureID GetTexture2D(char *FileName)
656 printf("GetTexture2D::loading 2d %s \n", FileName);
658 return GetTexture(FileName, TEXDATA_2D);
661 /*----------------------------------------------------------------------*/
663 TextureID GetTexture2DMipMap(char *FileName)
666 printf("GetTexture2DMipMap::loading 2dmm %s \n", FileName);
668 return GetTexture(FileName, TEXDATA_2DMM);
671 /*----------------------------------------------------------------------*/
673 TextureID GetTextureData1D(char *FileName, const GLint width, const GLint height, const void *data)
676 printf("GetTextureData1D::loading 1d %s \n", FileName);
678 return GetTextureData(FileName, TEXDATA_1D, width, height, data);
681 /*----------------------------------------------------------------------*/
683 TextureID GetTextureData2D(char *FileName, const GLint width, const GLint height, const void *data)
686 printf("GetTextureData2D::loading 2d %s \n", FileName);
688 return GetTextureData(FileName, TEXDATA_2D, width, height, data);
691 /*----------------------------------------------------------------------*/
693 TextureID GetTextureData2DMipMap(char *FileName, const GLint width, const GLint height, const void *data)
696 printf("GetTextureData2DMipMap::loading 2dmm %s \n", FileName);
698 return GetTextureData(FileName, TEXDATA_2DMM, width, height, data);
702 /*----------------------------------------------------------------------*/
704 void SetCurrentTexture(TextureID ID)
708 if (!IsTextureValid(ID)) return;
710 context = FindTextureContext(ID);
712 /* la texture n'existe pas dans ce contexte */
713 if (context == TEXTUREBOX_ERROR)
716 printf("SetCurrentTexture::installation texture %d dans context\n", ID);
718 /* si on a une erreur pendant l'installation dans le context
719 * alors on installe la texture sans bind */
720 if (InstallTextureInContext(ID) == TEXTUREBOX_ERROR)
727 /*oui, alors on bind directement */
731 printf("SetCurrentTexture: utilisation du bind %d\n", ID);
733 MyBindTextureEXT(ID, context);
737 current_texture = ID;
738 current_texture_data = textab[ID].data;
741 /*----------------------------------------------------------------------*/
743 void FreeTexture(TextureID ID)
746 bool notResource = false; // if there old-style texture deletion
748 GLCONTEXT cur_context;
749 GLDRAWABLE cur_drawable;
752 if (!IsTextureValid(ID)) return;
754 data = textab[ID].data;
755 texdata[data].share_count--;
756 if (texdata[data].share_count == 0)
758 // liberation des datas de la textures
759 free(texdata[data].image);
761 // liberation de la texture dans tous les contextes
762 cur_drawable = GET_GLDEV_CONTEXT();
763 for (i = 0; i < textab[ID].context_count; ++i)
766 bool isResource = false;
768 if (textab[ID].use_bind_texture[i])
770 if( !OpenGl_ResourceCleaner::GetInstance()->AddResource(textab[ID].context[i],
771 new OpenGl_ResourceTexture(textab[ID].number[i])) )
773 GL_MAKE_CURRENT((openglDisplay.IsNull() ? (Display* )NULL : (Display* )openglDisplay->GetDisplay()),
774 textab[ID].drawable[i],
775 textab[ID].context[i]);
777 // This check has been added to avoid exception,
778 // which is raised when trying to delete textures when no rendering context is available
779 cur_context = GET_GL_CONTEXT();
781 glDeleteTextures (1, &textab[ID].number[i]);
790 if( !isResource && cur_context )
795 GL_MAKE_CURRENT((openglDisplay.IsNull() ? (Display* )NULL : (Display* )openglDisplay->GetDisplay()),
796 cur_drawable, cur_context);
798 texdata[data].status = TEXDATA_NONE;
799 if (data + 1 == textures_data_count)
801 --textures_data_count;
804 free(textab[ID].context);
805 free(textab[ID].drawable);
806 free(textab[ID].use_bind_texture);
807 free(textab[ID].number);
810 textab[ID].status = TEX_NONE;
811 if (ID + 1 == textures_count)
816 current_texture_data = TEXTUREDATA_ERROR;
819 /*----------------------------------------------------------------------*/
821 void EnableTexture(void)
823 if (!IsTextureValid(current_texture)) return;
825 switch (texdata[current_texture_data].status)
828 if (textab[current_texture].Gen != GL_NONE)
829 glEnable(GL_TEXTURE_GEN_S);
830 glEnable(GL_TEXTURE_1D);
835 if (textab[current_texture].Gen != GL_NONE)
837 glEnable(GL_TEXTURE_GEN_S);
838 glEnable(GL_TEXTURE_GEN_T);
840 glEnable(GL_TEXTURE_2D);
847 /*----------------------------------------------------------------------*/
849 void DisableTexture(void)
851 if ( !IsTextureEnabled() )
853 if ( !IsTextureValid( current_texture ) )
856 switch (texdata[current_texture_data].status)
859 if (textab[current_texture].Gen != GL_NONE)
860 glDisable(GL_TEXTURE_GEN_S);
861 glDisable(GL_TEXTURE_1D);
866 if (textab[current_texture].Gen != GL_NONE)
868 glDisable(GL_TEXTURE_GEN_S);
869 glDisable(GL_TEXTURE_GEN_T);
871 glDisable(GL_TEXTURE_2D);
878 /*----------------------------------------------------------------------*/
880 GLboolean IsTextureEnabled(void)
882 GLboolean isEnabled1D= GL_FALSE, isEnabled2D= GL_FALSE;
883 glGetBooleanv( GL_TEXTURE_1D, &isEnabled1D );
884 glGetBooleanv( GL_TEXTURE_2D, &isEnabled2D );
885 return isEnabled1D || isEnabled2D;
888 /*----------------------------------------------------------------------*/
890 void SetTextureModulate(TextureID ID)
892 if (!IsTextureValid(ID)) return;
894 textab[ID].Light = GL_MODULATE;
897 /*----------------------------------------------------------------------*/
899 void SetTextureDecal(TextureID ID)
901 if (!IsTextureValid(ID)) return;
903 textab[ID].Light = GL_DECAL;
906 /*----------------------------------------------------------------------*/
908 void SetTextureClamp(TextureID ID)
910 if (!IsTextureValid(ID)) return;
912 textab[ID].Wrap = GL_CLAMP;
915 /*----------------------------------------------------------------------*/
917 void SetTextureRepeat(TextureID ID)
919 if (!IsTextureValid(ID)) return;
921 textab[ID].Wrap = GL_REPEAT;
924 /*----------------------------------------------------------------------*/
926 /* gestion de la facon d'appliquer la texture */
927 void SetModeObject(TextureID ID, GLfloat sparams[4], GLfloat tparams[4])
929 if (!IsTextureValid(ID)) return;
931 textab[ID].Gen = GL_OBJECT_LINEAR;
932 if (sparams != NULL) memcpy(textab[ID].Plane1, sparams, sizeof(sgenparams));
933 else memcpy(textab[ID].Plane1, sgenparams, sizeof(sgenparams));
935 if (texdata[textab[ID].data].status != TEXDATA_1D) {
936 if (tparams != NULL) memcpy(textab[ID].Plane2, tparams, sizeof(tgenparams));
937 else memcpy(textab[ID].Plane2, tgenparams, sizeof(tgenparams));
941 /*----------------------------------------------------------------------*/
943 void SetModeSphere(TextureID ID)
945 if (!IsTextureValid(ID)) return;
947 textab[ID].Gen = GL_SPHERE_MAP;
950 /*----------------------------------------------------------------------*/
952 void SetModeEye(TextureID ID, GLfloat sparams[4], GLfloat tparams[4])
954 if (!IsTextureValid(ID)) return;
956 textab[ID].Gen = GL_EYE_LINEAR;
957 if (sparams != NULL) memcpy(textab[ID].Plane1, sparams, sizeof(sgenparams));
958 else memcpy(textab[ID].Plane1, sgenparams, sizeof(sgenparams));
960 if (texdata[textab[ID].data].status != TEXDATA_1D) {
961 if (tparams != NULL) memcpy(textab[ID].Plane2, tparams, sizeof(tgenparams));
962 else memcpy(textab[ID].Plane2, tgenparams, sizeof(tgenparams));
966 /*----------------------------------------------------------------------*/
968 void SetModeManual(TextureID ID)
970 if (!IsTextureValid(ID)) return;
972 textab[ID].Gen = GL_NONE;
975 /*----------------------------------------------------------------------*/
977 void SetRenderNearest(TextureID ID)
979 if (!IsTextureValid(ID)) return;
981 textab[ID].Render = GL_NEAREST;
984 /*----------------------------------------------------------------------*/
986 void SetRenderLinear(TextureID ID)
988 if (!IsTextureValid(ID)) return;
990 textab[ID].Render = GL_LINEAR;
993 /*----------------------------------------------------------------------*/
995 void SetTexturePosition(TextureID ID,
996 GLfloat scalex, GLfloat scaley,
997 GLfloat transx, GLfloat transy,
1000 textab[ID].scalex = scalex;
1001 textab[ID].scaley = scaley;
1002 textab[ID].transx = transx;
1003 textab[ID].transy = transy;
1004 textab[ID].angle = angle;
1007 /*----------------------------------------------------------------------*/
1009 void SetTextureDefaultParams(TextureID ID)
1011 if (!IsTextureValid(ID)) return;
1014 printf("SetTextureDefaultParams::set parm par defaut textures\n");
1018 textab[ID].scalex = 1.0;
1019 textab[ID].scaley = 1.0;
1020 textab[ID].transx = 0.0;
1021 textab[ID].transy = 0.0;
1022 textab[ID].angle = 0.0;
1024 textab[ID].Gen = GL_OBJECT_LINEAR;
1025 textab[ID].Light = texdata[textab[ID].data].status == TEXDATA_1D ? GL_DECAL : GL_MODULATE;
1026 textab[ID].Wrap = texdata[textab[ID].data].status == TEXDATA_1D ? GL_CLAMP : GL_REPEAT;
1027 memcpy(textab[ID].Plane1, sgenparams, sizeof(sgenparams));
1028 memcpy(textab[ID].Plane2, tgenparams, sizeof(tgenparams));
1029 textab[ID].Render = texdata[textab[ID].data].status == TEXDATA_1D ? GL_NEAREST : GL_LINEAR;
1032 /*----------------------------------------------------------------------*/
1033 /* Transfere de donnee des donnees internes a la structure TransferData */
1034 void TransferTexture_To_Data(TextureID ID, TextureData *TransfDt)
1037 strcpy(TransfDt->path, texdata[textab[ID].data].imageFileName);
1038 TransfDt->gen = textab[ID].Gen;
1039 TransfDt->wrap = textab[ID].Wrap;
1040 TransfDt->render = textab[ID].Light;
1041 TransfDt->scalex = textab[ID].scalex;
1042 TransfDt->scaley = textab[ID].scaley;
1043 TransfDt->transx = textab[ID].transx;
1044 TransfDt->transy = textab[ID].transy;
1045 TransfDt->angle = textab[ID].angle;
1046 memcpy(TransfDt->plane1, textab[ID].Plane1, sizeof(SizeType));
1047 memcpy(TransfDt->plane2, textab[ID].Plane2, sizeof(SizeType));
1050 /*----------------------------------------------------------------------*/
1051 /* Transfere de donnee de la structure TransferData aux donnees internes */
1052 void TransferData_To_Texture(TextureData *TransfDt, TextureID *newID)
1057 FreeTexture(*newID);
1058 ID = GetTexture2DMipMap(TransfDt->path);
1060 if(IsTextureValid(ID))
1062 /* Affectation de l id courant */
1065 /* Donnees concernant les caracteristiques de la texture */
1066 strcpy(texdata[textab[ID].data].imageFileName, TransfDt->path);
1067 textab[ID].Gen = TransfDt->gen;
1068 textab[ID].Wrap = TransfDt->wrap;
1069 textab[ID].Light = TransfDt->render;
1070 textab[ID].scalex = TransfDt->scalex;
1071 textab[ID].scaley = TransfDt->scaley;
1072 textab[ID].transx = TransfDt->transx;
1073 textab[ID].transy = TransfDt->transy;
1074 textab[ID].angle = TransfDt->angle;
1075 memcpy(textab[ID].Plane1, TransfDt->plane1, sizeof(SizeType));
1076 memcpy(textab[ID].Plane2, TransfDt->plane2, sizeof(SizeType));