1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
21 * Gestion des textures sous OpenGL
26 * Les textures sont toujours initialisee avec des parametres par defaut
27 * texture 1D: WRAP_S = CLAMP
28 * MAG_FILTER = NEAREST
29 * generation de texture automatique en OBJECT_LINEAR
32 * texture 2D: WRAP_S/T = REPEAT
33 * MAG/MIN_FILTER = LINEAR
34 * generation de texture automatique en OBJECT_LINEAR
37 * texture 2D MipMap: WRAP_S/T = REPEAT
39 * MIN_FILTER = LINEAR_MIPMAP_NEAREST
40 * generation de texture automatique en OBJECT_LINEAR
43 * Historique des modifications
44 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 * 22-05-97: PCT ; Creation
46 * 18-06-97: FMN ; Ajout entete
47 * 20-06-97: PCT ; Correction bug parametres par defaut texture 1D
48 * 30-06-97: PCT ; Correction bug rechargement de la texture courante
49 * 04-07-97: PCT ; suppression de l'utilisation de libimage.a de SGI
50 * 01-08-97: PCT ; suppression InitializeTextureBox()
51 * 04-08-97: FMN,PCT ; Portage WNT
52 * 05-08-97: FMN ; ajout GetTextureData...
53 * 10-09-97: PCT ; ajout commentaires. GetTexture() ne doit pas
54 * etre utilisee dans Cas.Cade ( le chargement est
55 * fait par Graphic3d )
56 * 06-10-97: FMN ; Portage HP
57 * 14-10-97: FMN ; Ajout OpenGl_Extension
58 * 22-10-97: FMN ; Meilleure gestion de l'extension glXGetCurrentDisplayEXT
59 * 04-11-97: FMN ; Gestion des differentes versions GLX
60 * 19-11-97: FMN ; Ajout GetCurrentDisplay plus simple que glXGetCurrentDisplayEXT
61 * 04-12-97: FMN ; On suppose que l'on travaille en OpenGL1.1 (cf OpenGl_Extension)
62 * 17-12-97: FMN ; Probleme compilation SGI
63 * 17-12-97: FMN ; Probleme sur Optimisation sur MyBindTextureEXT()
64 * Le test sur la texture courante doit tenir compte du contexte.
65 * 22-07-98: FGU ; Ajout fonctions TransferTexture_To_Data() et TransferData_To_Texture()
73 #include <OpenGl_GlCore11.hxx>
74 #include <OpenGl_Display.hxx>
75 #include <OpenGl_TextureBox.hxx>
76 #include <OpenGl_ImageBox.hxx>
77 #include <OpenGl_ResourceCleaner.hxx>
78 #include <OpenGl_ResourceTexture.hxx>
80 #include <GL/glu.h> // gluBuild2DMipmaps()
82 #include <NCollection_Vector.hxx>
84 typedef enum {TEXDATA_NONE, TEXDATA_1D, TEXDATA_2D, TEXDATA_2DMM} texDataStatus;
85 typedef enum {TEX_NONE, TEX_ALLOCATED} texStatus;
87 typedef GLfloat SizeType[4];
89 typedef int TextureDataID;
90 #define TEXTUREDATA_ERROR -1
94 char imageFileName[128];
95 int imageWidth, imageHeight;
100 DEFINE_STANDARD_ALLOC
108 char use_bind_texture;
114 NCollection_Vector<contextData> contextdata;
123 GLfloat scalex, scaley;
124 GLfloat transx, transy;
127 DEFINE_STANDARD_ALLOC
131 /*----------------------------------------------------------------------*/
133 * Variables statiques
136 static NCollection_Vector<texDraw> textab;
138 static NCollection_Vector<texData> texdata;
140 static TextureDataID current_texture_data = TEXTUREDATA_ERROR;
141 static TextureID current_texture = TEXTUREBOX_ERROR;
143 static GLfloat sgenparams[] = { 1.0 ,0.0 ,0.0 ,0.0};
144 static GLfloat tgenparams[] = { 0.0 ,1.0 ,0.0 ,0.0};
146 static GLenum status2type[] = { GL_NONE, GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_2D };
148 /*----------------------------------------------------------------------*/
153 /*----------------------------------------------------------------------*/
155 * recherche l'existence de datas de texture par son nom
157 static TextureDataID FindTextureData(char *FileName)
159 for (int i = 0; i < texdata.Length(); i++)
161 if ( texdata(i).status != TEXDATA_NONE && strcmp(FileName, texdata(i).imageFileName) == 0 )
167 return TEXTUREDATA_ERROR;
170 /*----------------------------------------------------------------------*/
172 * recherche un emplacement de data texture libre
174 static TextureDataID FindFreeTextureData(void)
176 for (int i = 0; i < texdata.Length(); i++)
178 if (texdata(i).status == TEXDATA_NONE)
185 texdata.Append(aTexData);
186 return texdata.Length() - 1;
189 /*----------------------------------------------------------------------*/
191 * recherche un emplacement de texture libre
193 static TextureID FindFreeTexture(void)
195 for (int i = 0; i < textab.Length(); i++)
197 if (textab(i).status == TEX_NONE)
204 textab.Append(aTexDraw);
205 return textab.Length() - 1;
208 /*----------------------------------------------------------------------*/
210 * regarde si la texture a ete definie pour le contexte courant
212 static int FindTextureContext(TextureID ID)
216 GLCONTEXT cur = GET_GL_CONTEXT();
217 for (i=0; i<textab(ID).contextdata.Length(); i++)
218 if (textab(ID).contextdata(i).context == cur)
221 return TEXTUREBOX_ERROR;
224 /*----------------------------------------------------------------------*/
226 * chargement d'une texture suivant son type
228 static void LoadTexture(TextureID ID)
232 data = textab(ID).data;
233 switch (texdata(data).status)
236 glTexImage1D(GL_TEXTURE_1D, 0, 4,
237 texdata(data).imageWidth, 0,
238 GL_RGBA, GL_UNSIGNED_BYTE, texdata(data).image);
242 glTexImage2D(GL_TEXTURE_2D, 0, 4,
243 texdata(data).imageWidth, texdata(data).imageHeight, 0,
244 GL_RGBA, GL_UNSIGNED_BYTE, texdata(data).image);
248 gluBuild2DMipmaps(GL_TEXTURE_2D, 4,
249 texdata(data).imageWidth,
250 texdata(data).imageHeight,
251 GL_RGBA, GL_UNSIGNED_BYTE, texdata(data).image);
258 /*----------------------------------------------------------------------*/
260 * les parametres d'initialisation d'une texture
261 * NE PAS METTRE DANS UNE DISPLAY LIST POUR L'INSTANT ( pb avec les matrices )
263 static void SetTextureParam(TextureID ID)
269 data = textab(ID).data;
270 glGetIntegerv(GL_MATRIX_MODE, &cur_matrix);
273 * MISE EN PLACE DE LA MATRICE DE TEXTURE
275 glMatrixMode(GL_TEXTURE);
277 /* if (textab(ID).Gen != GL_SPHERE_MAP)
279 glScalef(textab(ID).scalex, textab(ID).scaley, 1.0);
280 glTranslatef(-textab(ID).transx, -textab(ID).transy, 0.0);
281 glRotatef(-textab(ID).angle, 0.0, 0.0, 1.0);
286 * GENERATION AUTOMATIQUE DE TEXTURE
288 switch (textab(ID).Gen)
290 case GL_OBJECT_LINEAR:
291 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
292 glTexGenfv(GL_S, GL_OBJECT_PLANE, textab(ID).Plane1);
293 if (texdata(data).status != TEXDATA_1D)
295 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
296 glTexGenfv(GL_T, GL_OBJECT_PLANE, textab(ID).Plane2);
301 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
302 if (texdata(data).status != TEXDATA_1D)
303 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
307 glMatrixMode(GL_MODELVIEW);
311 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
312 glTexGenfv(GL_S, GL_EYE_PLANE, textab(ID).Plane1);
314 if (texdata(data).status != TEXDATA_1D)
316 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
317 glTexGenfv(GL_T, GL_EYE_PLANE, textab(ID).Plane2);
326 * RENDU DE LA TEXTURE AVEC LES LUMIERES
328 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textab(ID).Light);
332 * LISSAGE DE LA TEXTURE
334 switch (texdata(data).status)
338 glTexParameteri(texdata(data).type, GL_TEXTURE_MAG_FILTER, textab(ID).Render);
339 glTexParameteri(texdata(data).type, GL_TEXTURE_MIN_FILTER, textab(ID).Render);
343 if (textab(ID).Render == GL_NEAREST)
345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
350 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
351 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
362 switch (texdata(data).status)
365 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, textab(ID).Wrap);
370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, textab(ID).Wrap);
371 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, textab(ID).Wrap);
377 glMatrixMode(cur_matrix);
380 /*----------------------------------------------------------------------*/
382 * simulation du glGenTexturesEXT pour un context
384 static void MyGenTextureEXT (TextureID ID)
386 TextureDataID data = textab(ID).data;
387 contextData aContextData;
389 aContextData.context = GET_GL_CONTEXT();
390 aContextData.drawable = GET_GLDEV_CONTEXT();
391 aContextData.use_bind_texture = (char )GL_TRUE;
392 glGenTextures (1, &aContextData.number);
393 textab(ID).contextdata.Append(aContextData);
394 glBindTexture (texdata(data).type, aContextData.number);
398 /*----------------------------------------------------------------------*/
400 * simulation du glBindTextureEXT
402 static void MyBindTextureEXT (TextureID ID, int Context)
404 TextureDataID data = textab(ID).data;
405 if (texdata(data).status == TEXDATA_NONE)
408 GLenum aParamName = texdata(data).status == TEXDATA_1D ?
409 GL_TEXTURE_BINDING_1D : GL_TEXTURE_BINDING_2D;
412 glGetIntegerv (aParamName, &aCurrTex);
413 if (textab(ID).contextdata(Context).number != aCurrTex)
415 glBindTexture (texdata(data).type, textab(ID).contextdata(Context).number);
419 /*----------------------------------------------------------------------*/
421 * installation de la texture pour le dernier contexte
423 static int InstallTextureInContext(TextureID ID)
426 printf("InstallTextureInContext::installation de la texture dans le context\n");
431 printf("InstallTextureInContext::context ok\n");
436 /*----------------------------------------------------------------------*/
437 static TextureID GetTexture(char *FileName, texDataStatus status)
443 /* essait de trouver la texture */
444 i = FindTextureData(FileName);
445 if (i == TEXTUREDATA_ERROR)
448 printf("GetTexture::la texture %s n'existe pas => chargement\n", FileName);
450 /* creation d'une texture */
451 i = FindFreeTextureData();
452 if (i == TEXTUREDATA_ERROR) return TEXTUREBOX_ERROR;
454 texdata(i).share_count = 0;
455 strcpy(texdata(i).imageFileName, FileName);
456 texdata(i).image = (GLubyte *)read_texture(FileName,
457 &texdata(i).imageWidth,
458 &texdata(i).imageHeight,
460 if (texdata(i).image == NULL) return TEXTUREBOX_ERROR;
462 texdata(i).status = status;
463 texdata(i).type = status2type[status];
466 j = FindFreeTexture();
467 if (j != TEXTUREBOX_ERROR)
470 printf("GetTexture::installation texture pour obj %d\n", j);
472 textab(j).contextdata.Clear();
474 textab(j).status = TEX_ALLOCATED;
475 texdata(i).share_count++;
477 SetTextureDefaultParams(j);
480 printf("GetTexture::texture %s(%d) texture %d count=%d\n", texdata(i).imageFileName, i, j, texdata(i).share_count);
484 if (texdata(i).share_count != 0)
485 delete [] texdata(i).image;
491 /*----------------------------------------------------------------------*/
492 static TextureID GetTextureData(char *FileName, texDataStatus status, const GLint width, const GLint height, const void *data)
497 /* essait de trouver la texture */
498 i = FindTextureData(FileName);
499 if (i == TEXTUREDATA_ERROR)
502 printf("GetTextureData::la texture %s n'existe pas => chargement\n", FileName);
504 /* creation d'une texture */
505 i = FindFreeTextureData();
506 if (i == TEXTUREDATA_ERROR) return TEXTUREBOX_ERROR;
508 texdata(i).share_count = 0;
509 strcpy(texdata(i).imageFileName, FileName);
510 texdata(i).image = new GLubyte[width*height*4];
511 memcpy(texdata(i).image, data, (width*height*4));
512 texdata(i).imageWidth = width;
513 texdata(i).imageHeight = height;
515 if (texdata(i).image == NULL) return TEXTUREBOX_ERROR;
517 texdata(i).status = status;
518 texdata(i).type = status2type[status];
521 j = FindFreeTexture();
522 if (j != TEXTUREBOX_ERROR)
525 printf("GetTextureData::installation texture pour obj %d\n", j);
527 textab(j).contextdata.Clear();
529 textab(j).status = TEX_ALLOCATED;
530 texdata(i).share_count++;
532 SetTextureDefaultParams(j);
535 printf("GetTextureData::texture %s(%d) texture %d count=%d\n", texdata(i).imageFileName, i, j, texdata(i).share_count);
539 if (texdata(i).share_count != 0)
540 delete [] texdata(i).image;
545 /*----------------------------------------------------------------------*/
547 * Fonctions publiques
551 /*----------------------------------------------------------------------*/
553 GLboolean IsTextureValid(TextureID ID)
555 if ( (ID < 0) || (ID >= textab.Length()) )
558 if (textab.Length() > 0)
560 return textab(ID).status == TEX_ALLOCATED;
568 /*----------------------------------------------------------------------*/
570 TextureID GetTexture1D(char *FileName)
573 printf("GetTexture1D::loading 1d %s \n", FileName);
575 return GetTexture(FileName, TEXDATA_1D);
578 /*----------------------------------------------------------------------*/
580 TextureID GetTexture2D(char *FileName)
583 printf("GetTexture2D::loading 2d %s \n", FileName);
585 return GetTexture(FileName, TEXDATA_2D);
588 /*----------------------------------------------------------------------*/
590 TextureID GetTexture2DMipMap(char *FileName)
593 printf("GetTexture2DMipMap::loading 2dmm %s \n", FileName);
595 return GetTexture(FileName, TEXDATA_2DMM);
598 /*----------------------------------------------------------------------*/
600 TextureID GetTextureData1D(char *FileName, const GLint width, const GLint height, const void *data)
603 printf("GetTextureData1D::loading 1d %s \n", FileName);
605 return GetTextureData(FileName, TEXDATA_1D, width, height, data);
608 /*----------------------------------------------------------------------*/
610 TextureID GetTextureData2D(char *FileName, const GLint width, const GLint height, const void *data)
613 printf("GetTextureData2D::loading 2d %s \n", FileName);
615 return GetTextureData(FileName, TEXDATA_2D, width, height, data);
618 /*----------------------------------------------------------------------*/
620 TextureID GetTextureData2DMipMap(char *FileName, const GLint width, const GLint height, const void *data)
623 printf("GetTextureData2DMipMap::loading 2dmm %s \n", FileName);
625 return GetTextureData(FileName, TEXDATA_2DMM, width, height, data);
629 /*----------------------------------------------------------------------*/
631 void SetCurrentTexture(TextureID ID)
635 if (!IsTextureValid(ID)) return;
637 context = FindTextureContext(ID);
639 /* la texture n'existe pas dans ce contexte */
640 if (context == TEXTUREBOX_ERROR)
643 printf("SetCurrentTexture::installation texture %d dans context\n", ID);
645 /* si on a une erreur pendant l'installation dans le context
646 * alors on installe la texture sans bind */
647 if (InstallTextureInContext(ID) == TEXTUREBOX_ERROR)
654 /*oui, alors on bind directement */
658 printf("SetCurrentTexture: utilisation du bind %d\n", ID);
660 MyBindTextureEXT(ID, context);
664 current_texture = ID;
665 current_texture_data = textab(ID).data;
668 /*----------------------------------------------------------------------*/
670 void FreeTexture(TextureID ID)
673 bool notResource = false; // if there old-style texture deletion
675 GLCONTEXT cur_context;
676 GLDRAWABLE cur_drawable;
679 if (!IsTextureValid(ID)) return;
681 data = textab(ID).data;
682 texdata(data).share_count--;
683 if (texdata(data).share_count == 0)
685 // liberation des datas de la textures
686 delete [] texdata(data).image;
688 // liberation de la texture dans tous les contextes
689 cur_drawable = GET_GLDEV_CONTEXT();
690 for (i = 0; i < textab(ID).contextdata.Length(); ++i)
693 bool isResource = false;
695 if (textab(ID).contextdata(i).use_bind_texture)
697 if( !OpenGl_ResourceCleaner::GetInstance()->AddResource(textab(ID).contextdata(i).context,
698 new OpenGl_ResourceTexture(textab(ID).contextdata(i).number)) )
700 GL_MAKE_CURRENT((openglDisplay.IsNull() ? (Display* )NULL : (Display* )openglDisplay->GetDisplay()),
701 textab(ID).contextdata(i).drawable,
702 textab(ID).contextdata(i).context);
704 // This check has been added to avoid exception,
705 // which is raised when trying to delete textures when no rendering context is available
706 cur_context = GET_GL_CONTEXT();
708 glDeleteTextures (1, &textab(ID).contextdata(i).number);
717 if( !isResource && cur_context )
722 GL_MAKE_CURRENT((openglDisplay.IsNull() ? (Display* )NULL : (Display* )openglDisplay->GetDisplay()),
723 cur_drawable, cur_context);
725 texdata(data).status = TEXDATA_NONE;
727 textab(ID).contextdata.Clear();
730 textab(ID).status = TEX_NONE;
732 current_texture_data = TEXTUREDATA_ERROR;
735 /*----------------------------------------------------------------------*/
737 void EnableTexture(void)
739 if (!IsTextureValid(current_texture)) return;
741 switch (texdata(current_texture_data).status)
744 if (textab(current_texture).Gen != GL_NONE)
745 glEnable(GL_TEXTURE_GEN_S);
746 glEnable(GL_TEXTURE_1D);
751 if (textab(current_texture).Gen != GL_NONE)
753 glEnable(GL_TEXTURE_GEN_S);
754 glEnable(GL_TEXTURE_GEN_T);
756 glEnable(GL_TEXTURE_2D);
763 /*----------------------------------------------------------------------*/
765 void DisableTexture(void)
767 if ( !IsTextureEnabled() )
769 if ( !IsTextureValid( current_texture ) )
772 switch (texdata(current_texture_data).status)
775 if (textab(current_texture).Gen != GL_NONE)
776 glDisable(GL_TEXTURE_GEN_S);
777 glDisable(GL_TEXTURE_1D);
782 if (textab(current_texture).Gen != GL_NONE)
784 glDisable(GL_TEXTURE_GEN_S);
785 glDisable(GL_TEXTURE_GEN_T);
787 glDisable(GL_TEXTURE_2D);
794 /*----------------------------------------------------------------------*/
796 GLboolean IsTextureEnabled(void)
798 GLboolean isEnabled1D= GL_FALSE, isEnabled2D= GL_FALSE;
799 glGetBooleanv( GL_TEXTURE_1D, &isEnabled1D );
800 glGetBooleanv( GL_TEXTURE_2D, &isEnabled2D );
801 return isEnabled1D || isEnabled2D;
804 /*----------------------------------------------------------------------*/
806 void SetTextureModulate(TextureID ID)
808 if (!IsTextureValid(ID)) return;
810 textab(ID).Light = GL_MODULATE;
813 /*----------------------------------------------------------------------*/
815 void SetTextureDecal(TextureID ID)
817 if (!IsTextureValid(ID)) return;
819 textab(ID).Light = GL_DECAL;
822 /*----------------------------------------------------------------------*/
824 void SetTextureClamp(TextureID ID)
826 if (!IsTextureValid(ID)) return;
828 textab(ID).Wrap = GL_CLAMP;
831 /*----------------------------------------------------------------------*/
833 void SetTextureRepeat(TextureID ID)
835 if (!IsTextureValid(ID)) return;
837 textab(ID).Wrap = GL_REPEAT;
840 /*----------------------------------------------------------------------*/
842 /* gestion de la facon d'appliquer la texture */
843 void SetModeObject(TextureID ID, const GLfloat sparams[4], const GLfloat tparams[4])
845 if (!IsTextureValid(ID)) return;
847 textab(ID).Gen = GL_OBJECT_LINEAR;
848 if (sparams != NULL) memcpy(textab(ID).Plane1, sparams, sizeof(sgenparams));
849 else memcpy(textab(ID).Plane1, sgenparams, sizeof(sgenparams));
851 if (texdata(textab(ID).data).status != TEXDATA_1D) {
852 if (tparams != NULL) memcpy(textab(ID).Plane2, tparams, sizeof(tgenparams));
853 else memcpy(textab(ID).Plane2, tgenparams, sizeof(tgenparams));
857 /*----------------------------------------------------------------------*/
859 void SetModeSphere(TextureID ID)
861 if (!IsTextureValid(ID)) return;
863 textab(ID).Gen = GL_SPHERE_MAP;
866 /*----------------------------------------------------------------------*/
868 void SetModeEye(TextureID ID, const GLfloat sparams[4], const GLfloat tparams[4])
870 if (!IsTextureValid(ID)) return;
872 textab(ID).Gen = GL_EYE_LINEAR;
873 if (sparams != NULL) memcpy(textab(ID).Plane1, sparams, sizeof(sgenparams));
874 else memcpy(textab(ID).Plane1, sgenparams, sizeof(sgenparams));
876 if (texdata(textab(ID).data).status != TEXDATA_1D) {
877 if (tparams != NULL) memcpy(textab(ID).Plane2, tparams, sizeof(tgenparams));
878 else memcpy(textab(ID).Plane2, tgenparams, sizeof(tgenparams));
882 /*----------------------------------------------------------------------*/
884 void SetModeManual(TextureID ID)
886 if (!IsTextureValid(ID)) return;
888 textab(ID).Gen = GL_NONE;
891 /*----------------------------------------------------------------------*/
893 void SetRenderNearest(TextureID ID)
895 if (!IsTextureValid(ID)) return;
897 textab(ID).Render = GL_NEAREST;
900 /*----------------------------------------------------------------------*/
902 void SetRenderLinear(TextureID ID)
904 if (!IsTextureValid(ID)) return;
906 textab(ID).Render = GL_LINEAR;
909 /*----------------------------------------------------------------------*/
911 void SetTexturePosition(TextureID ID,
912 GLfloat scalex, GLfloat scaley,
913 GLfloat transx, GLfloat transy,
916 textab(ID).scalex = scalex;
917 textab(ID).scaley = scaley;
918 textab(ID).transx = transx;
919 textab(ID).transy = transy;
920 textab(ID).angle = angle;
923 /*----------------------------------------------------------------------*/
925 void SetTextureDefaultParams(TextureID ID)
927 if (!IsTextureValid(ID)) return;
930 printf("SetTextureDefaultParams::set parm par defaut textures\n");
934 textab(ID).scalex = 1.0;
935 textab(ID).scaley = 1.0;
936 textab(ID).transx = 0.0;
937 textab(ID).transy = 0.0;
938 textab(ID).angle = 0.0;
940 textab(ID).Gen = GL_OBJECT_LINEAR;
941 textab(ID).Light = texdata(textab(ID).data).status == TEXDATA_1D ? GL_DECAL : GL_MODULATE;
942 textab(ID).Wrap = texdata(textab(ID).data).status == TEXDATA_1D ? GL_CLAMP : GL_REPEAT;
943 memcpy(textab(ID).Plane1, sgenparams, sizeof(sgenparams));
944 memcpy(textab(ID).Plane2, tgenparams, sizeof(tgenparams));
945 textab(ID).Render = texdata(textab(ID).data).status == TEXDATA_1D ? GL_NEAREST : GL_LINEAR;
948 /*----------------------------------------------------------------------*/
949 /* Transfere de donnee des donnees internes a la structure TransferData */
950 void TransferTexture_To_Data(TextureID ID, TextureData *TransfDt)
953 strcpy(TransfDt->path, texdata(textab(ID).data).imageFileName);
954 TransfDt->gen = textab(ID).Gen;
955 TransfDt->wrap = textab(ID).Wrap;
956 TransfDt->render = textab(ID).Light;
957 TransfDt->scalex = textab(ID).scalex;
958 TransfDt->scaley = textab(ID).scaley;
959 TransfDt->transx = textab(ID).transx;
960 TransfDt->transy = textab(ID).transy;
961 TransfDt->angle = textab(ID).angle;
962 memcpy(TransfDt->plane1, textab(ID).Plane1, sizeof(SizeType));
963 memcpy(TransfDt->plane2, textab(ID).Plane2, sizeof(SizeType));
966 /*----------------------------------------------------------------------*/
967 /* Transfere de donnee de la structure TransferData aux donnees internes */
968 void TransferData_To_Texture(TextureData *TransfDt, TextureID *newID)
974 ID = GetTexture2DMipMap(TransfDt->path);
976 if(IsTextureValid(ID))
978 /* Affectation de l id courant */
981 /* Donnees concernant les caracteristiques de la texture */
982 strcpy(texdata(textab(ID).data).imageFileName, TransfDt->path);
983 textab(ID).Gen = TransfDt->gen;
984 textab(ID).Wrap = TransfDt->wrap;
985 textab(ID).Light = TransfDt->render;
986 textab(ID).scalex = TransfDt->scalex;
987 textab(ID).scaley = TransfDt->scaley;
988 textab(ID).transx = TransfDt->transx;
989 textab(ID).transy = TransfDt->transy;
990 textab(ID).angle = TransfDt->angle;
991 memcpy(textab(ID).Plane1, TransfDt->plane1, sizeof(SizeType));
992 memcpy(textab(ID).Plane2, TransfDt->plane2, sizeof(SizeType));