31 #include <system_threads.h>
35 #include <libFreeWRL.h>
40 #include "../vrml_parser/Structs.h"
41 #include "../main/headers.h"
43 #include "../scenegraph/readpng.h"
44 #include "../input/InputFunctions.h"
45 #include "../opengl/Material.h"
46 #include "../opengl/OpenGL_Utils.h"
48 #include "../world_script/fieldSet.h"
49 #include "../scenegraph/Component_Shape.h"
50 #include "../scenegraph/Component_CubeMapTexturing.h"
51 #include "../scenegraph/RenderFuncs.h"
52 #include "LoadTextures.h"
72 int multitex_source[2];
73 int multitex_function;
77 #ifndef GL_EXT_texture_cube_map
80 # define GL_TEXTURE_CUBE_MAP_EXT 0x8513
82 # define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515
97 struct Vector *activeTextureTable;
101 int currentlyWorkingOn;
102 int textureInProcess;
106 void *Textures_constructor(){
107 void *v = MALLOCV(
sizeof(
struct pTextures));
111 void Textures_init(
struct tTextures *t){
115 t->prv = Textures_constructor();
118 p->activeTextureTable = NULL;
121 p->currentlyWorkingOn = -1;
123 p->textureInProcess = -1;
126 void Textures_clear(
struct tTextures *t){
128 glDeleteBuffers (1,&t->defaultBlankTexture);
144 #if defined(_MSC_VER)
148 #if !defined(_ANDROID) && !defined(ANDROIDNDK) && !defined(GLES2)
149 GLXContext textureContext = NULL;
161 int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight);
162 void readpng_cleanup(
int free_image_data);
165 static void myTexImage2D (
int generateMipMaps, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLubyte *pixels);
175 # define uint32 uint32_t
180 static void myScaleImage(
int srcX,
int srcY,
int destX,
int destY,
unsigned char *src,
unsigned char *dest) {
184 uint32 *src32 = (uint32 *)src;
185 uint32 *dest32 = (uint32 *)dest;
187 if ((srcY<=0) || (destY<=0) || (srcX<=0) || (destX<=0))
return;
188 if (src == NULL)
return;
189 if (dest == NULL)
return;
191 if ((srcY==destY) && (srcX==destX)) {
193 memcpy (dest,src,srcY*srcX*4);
197 YscaleFactor = ((float)srcY) / ((float)destY);
198 XscaleFactor = ((float)srcX) / ((float)destX);
200 for (wye=0; wye<destY; wye++) {
201 for (yex=0; yex<destX; yex++) {
206 fx = YscaleFactor * ((float) wye);
207 fy = XscaleFactor * ((float) yex);
210 oldIndex = row * srcX + column;
211 dest32[wye*destX+yex] = src32[oldIndex];
216 static void myScaleImage3D(
int srcX,
int srcY,
int srcZ,
int destX,
int destY,
int destZ,
unsigned char *src,
unsigned char *dest) {
222 uint32 *src32 = (uint32 *)src;
223 uint32 *dest32 = (uint32 *)dest;
225 if ((srcY<=0) || (destY<=0) || (srcX<=0) || (destX<=0) || (srcZ<=0) || (destZ<=0))
return;
226 if (src == NULL)
return;
227 if (dest == NULL)
return;
229 if ((srcY==destY) && (srcX==destX) && (srcZ==destZ)) {
231 memcpy (dest,src,srcY*srcX*srcZ*4);
235 YscaleFactor = ((float)srcY) / ((float)destY);
236 XscaleFactor = ((float)srcX) / ((float)destX);
237 ZscaleFactor = ((float)srcZ) / ((float)destZ);
239 for (iz=0; iz<destZ; iz++) {
241 fz = ZscaleFactor * ((float) iz);
243 for (iy=0; iy<destY; iy++) {
245 fy = YscaleFactor * ((float) iy);
247 for (ix=0; ix<destX; ix++) {
251 fx = XscaleFactor * ((float) ix);
253 oldIndex = (page * srcY + row) * srcX + column;
254 dest32[(iz*destY + iy)*destX+ix] = src32[oldIndex];
259 int iclamp(
int ival,
int istart,
int iend) {
261 iret = ival > iend? iend : ival;
262 iret = iret < istart ? istart : iret;
265 void compute_3D_alpha_gradient_store_rgb(
char *dest,
int x,
int y,
int z){
270 int iz,iy,ix, jz,jy,jx,jzz,jyy,jxx, k;
272 int gradient[3], maxgradient[3], mingradient[3];
273 unsigned char *urgba;
274 uint32 *pixels = (uint32 *)dest;
286 for(k=0;k<3;k++) gradient[k] = 0;
287 rgba0 = (
char *) &pixels[(iz*y +iy)*x + ix];
288 urgba = (
unsigned char *)rgba0;
293 if(iz == z-1) jzz = -1;
294 if(iy == y-1) jyy = -1;
295 if(ix == x-1) jxx = -1;
296 jx = jxx; jy = jyy; jz = jzz;
298 rgba1 = (
char *) &pixels[((iz+jz)*y +(iy+jy))*x + (ix+jx)];
299 gradient[0] = (int)rgba1[3] - (
int)rgba0[3];
302 rgba1 = (
char *) &pixels[((iz+jz)*y +(iy+jy))*x + (ix+jx)];
303 gradient[1] = (int)rgba1[3] - (
int)rgba0[3];
306 rgba1 = (
char *) &pixels[((iz+jz)*y +(iy+jy))*x + (ix+jx)];
307 gradient[2] = (int)rgba1[3] - (
int)rgba0[3];
311 int cube[3][3][3], i,j,ii,jj,kk;
313 ii = iclamp(ix+i,0,x-1);
315 jj= iclamp(iy+j,0,y-1);
317 kk = iclamp(iz+k,0,z-1);
318 cube[i+1][j+1][k+1] = ((
unsigned char *)&pixels[(kk*y +jj)*x + ii])[3];
329 gradient[0] += cube[0][0][1] + 2*cube[0][1][1] + cube[0][2][1];
330 gradient[0] -= cube[2][0][1] + 2*cube[2][1][1] + cube[2][2][1];
331 gradient[0] += cube[0][1][0] + 2*cube[0][1][1] + cube[0][1][2];
332 gradient[0] -= cube[2][1][0] + 2*cube[2][1][1] + cube[2][1][2];
335 gradient[1] += cube[1][0][0] + 2*cube[1][0][1] + cube[1][0][2];
336 gradient[1] -= cube[1][2][0] + 2*cube[1][2][1] + cube[1][2][2];
337 gradient[1] += cube[0][0][1] + 2*cube[1][0][1] + cube[2][0][1];
338 gradient[1] -= cube[9][2][1] + 2*cube[1][2][1] + cube[2][2][1];
341 gradient[2] += cube[0][1][0] + 2*cube[1][1][0] + cube[2][1][0];
342 gradient[2] -= cube[0][1][2] + 2*cube[1][1][2] + cube[2][1][2];
343 gradient[2] += cube[1][0][0] + 2*cube[1][1][0] + cube[1][2][0];
344 gradient[2] -= cube[1][9][2] + 2*cube[1][1][2] + cube[1][2][2];
354 for(k=0;k<3;k++) gradient[k] /= 2;
356 maxgradient[k] = max(maxgradient[k],gradient[k]);
357 mingradient[k] = min(mingradient[k],gradient[k]);
363 for(k=0;k<3;k++) gradient[k] += 127;
366 for(k=0;k<3;k++) urgba[k] = (
unsigned char)gradient[k];
375 printf(
"mingradient %d %d %d\n",mingradient[0],mingradient[1],mingradient[2]);
376 printf(
"maxgradient %d %d %d\n",maxgradient[0],maxgradient[1],maxgradient[2]);
385 tti2->texdata = dest;
387 saveImage_web3dit(tti2,
"gradientRGB.web3dit");
389 saveImage_web3dit(tti2,
"gradientRGBA.web3dit");
394 static void GenMipMap2D( GLubyte *src, GLubyte **dst,
int srcWidth,
int srcHeight,
int *dstWidth,
int *dstHeight )
400 *dstWidth = srcWidth / 2;
401 if ( *dstWidth <= 0 )
404 *dstHeight = srcHeight / 2;
405 if ( *dstHeight <= 0 )
408 *dst = MALLOC(
void *,
sizeof(GLubyte) * texelSize * (*dstWidth) * (*dstHeight) );
412 for ( y = 0; y < *dstHeight; y++ )
414 for( x = 0; x < *dstWidth; x++ )
427 (((y * 2) * srcWidth) + (x * 2)) * texelSize;
429 (((y * 2) * srcWidth) + (x * 2 + 1)) * texelSize;
431 ((((y * 2) + 1) * srcWidth) + (x * 2)) * texelSize;
433 ((((y * 2) + 1) * srcWidth) + (x * 2 + 1)) * texelSize;
436 for ( sample = 0; sample < 4; sample++ )
438 r += src[srcIndex[sample]];
439 g += src[srcIndex[sample] + 1];
440 b += src[srcIndex[sample] + 2];
441 a += src[srcIndex[sample] + 3];
451 (*dst)[ ( y * (*dstWidth) + x ) * texelSize ] = (GLubyte)( r );
452 (*dst)[ ( y * (*dstWidth) + x ) * texelSize + 1] = (GLubyte)( g );
453 (*dst)[ ( y * (*dstWidth) + x ) * texelSize + 2] = (GLubyte)( b );
454 (*dst)[ ( y * (*dstWidth) + x ) * texelSize + 3] = (GLubyte)( a );
459 static void myTexImage2D (
int generateMipMaps, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLubyte *pixels) {
460 GLubyte *prevImage = NULL;
461 GLubyte *newImage = NULL;
464 FW_GL_TEXIMAGE2D(target,level,internalformat,width,height,border,format,type,pixels);
466 if (!generateMipMaps)
return;
467 if ((width <=1) && (height <=1))
return;
472 prevImage = MALLOC(GLubyte *, width * height * 4);
473 memcpy (prevImage, pixels, width * height * 4);
478 while ((width > 1) && (height > 1)) {
479 GLint newWidth, newHeight;
481 GenMipMap2D(prevImage,&newImage, width, height, &newWidth, &newHeight);
483 FW_GL_TEXIMAGE2D(target,level,internalformat,newWidth,newHeight,0,format,GL_UNSIGNED_BYTE,newImage);
485 FREE_IF_NZ(prevImage);
486 prevImage = newImage;
492 FREE_IF_NZ(newImage);
499 const char *texst(
int num)
501 if (num == TEX_NOTLOADED)
return "TEX_NOTLOADED";
502 if (num == TEX_LOADING)
return "TEX_LOADING";
503 if (num == TEX_NEEDSBINDING)
return "TEX_NEEDSBINDING";
504 if (num == TEX_LOADED)
return "TEX_LOADED";
505 if (num == TEX_UNSQUASHED)
return "UNSQUASHED";
511 int isTextureAlpha(
int texno) {
517 ti = getTableIndex(texno);
518 if (ti==NULL)
return FALSE;
520 if (ti->status==TEX_LOADED) {
528 int fwl_isTextureinitialized() {
529 return gglobal()->threads.TextureThreadRunning;
533 int fwl_isTextureLoaded(
int texno) {
539 ti = getTableIndex(texno);
540 return (ti->status==TEX_LOADED);
544 int fwl_isTextureParsing() {
549 if (p->textureInProcess > 0) {
550 printf(
"call to fwl_isTextureParsing %d, returning %d\n",
551 p->textureInProcess,p->textureInProcess > 0);
554 return p->textureInProcess >0;
558 void releaseTexture(
struct X3D_Node *node) {
563 if (node->_nodeType == NODE_ImageTexture) {
565 }
else if (node->_nodeType == NODE_PixelTexture) {
567 }
else if (node->_nodeType == NODE_MovieTexture) {
569 }
else if (node->_nodeType == NODE_PixelTexture3D) {
571 }
else if (node->_nodeType == NODE_ImageTexture3D) {
573 }
else if (node->_nodeType == NODE_ComposedTexture3D) {
579 printf (
"releaseTexture, calling getTableIndex\n");
580 ti = getTableIndex(tableIndex);
581 printf (
"releaseTexture, ti %p, ti->status %d\n",ti,ti->status);
582 ti->status = TEX_NOTLOADED;
584 if (ti->OpenGLTexture != TEXTURE_INVALID) {
585 printf (
"deleting %d textures, starting at %u\n",ti->frames, ti->OpenGLTexture);
586 ti->OpenGLTexture = TEXTURE_INVALID;
591 ti = getTableIndex(tableIndex);
593 ti->status = TEX_NOTLOADED;
594 if (ti->OpenGLTexture != TEXTURE_INVALID) {
595 FW_GL_DELETETEXTURES(1, &ti->OpenGLTexture);
596 ti->OpenGLTexture = TEXTURE_INVALID;
608 sprintf (line,
"getTableIndex, looking for %d",indx);
609 ConsoleMessage (line);}
612 ConsoleMessage (
"getTableIndex, texture <0 requested");
616 if (p->activeTextureTable ==NULL ) {
617 ConsoleMessage (
"NULL sizing errror in getTableIndex");
622 if (indx >= vectorSize(p->activeTextureTable)) {
623 ConsoleMessage (
"sizing errror in getTableIndex");
630 printf (
"getTableIndex - valid request\n");
631 sprintf (line,
"getTableIndex, for %d, size %d",indx, vectorSize(p->activeTextureTable));
632 ConsoleMessage (line);}
637 int getTextureTableIndexFromFromTextureNode(
struct X3D_Node *node){
638 int thisTexture = -1;
639 int thisTextureType = node->_nodeType;
640 if (thisTextureType==NODE_ImageTexture){
642 thisTexture = it->__textureTableIndex;
643 }
else if (thisTextureType==NODE_PixelTexture){
645 thisTexture = pt->__textureTableIndex;
646 }
else if (thisTextureType==NODE_MovieTexture){
648 thisTexture = mt->__textureTableIndex;
649 }
else if (thisTextureType==NODE_ImageCubeMapTexture){
651 thisTexture = ict->__textureTableIndex;
652 }
else if (thisTextureType==NODE_GeneratedCubeMapTexture){
654 thisTexture = ict->__textureTableIndex;
655 }
else if (thisTextureType==NODE_PixelTexture3D){
657 thisTexture = pt->__textureTableIndex;
658 }
else if (thisTextureType==NODE_ImageTexture3D){
660 thisTexture = pt->__textureTableIndex;
661 }
else if (thisTextureType==NODE_ComposedTexture3D){
663 thisTexture = pt->__textureTableIndex;
665 ConsoleMessage (
"Invalid type for texture, %s\n",stringNodeType(thisTextureType));
671 int index = getTextureTableIndexFromFromTextureNode(textureNode);
673 ret = getTableIndex(index);
678 void registerTexture0(
int iaction,
struct X3D_Node *tmp) {
686 if ((it->_nodeType == NODE_ImageTexture) || (it->_nodeType == NODE_PixelTexture) ||
687 (it->_nodeType == NODE_ImageCubeMapTexture) ||
688 (it->_nodeType == NODE_GeneratedCubeMapTexture) ||
689 (it->_nodeType == NODE_PixelTexture3D) ||
690 (it->_nodeType == NODE_ImageTexture3D) ||
691 (it->_nodeType == NODE_ComposedTexture3D) ||
692 (it->_nodeType == NODE_MovieTexture)
705 if (p->activeTextureTable == NULL) {
710 textureNumber = vectorSize(p->activeTextureTable);
714 DEBUG_TEX(
"CREATING TEXTURE NODE: type %d\n", it->_nodeType);
717 switch (it->_nodeType) {
719 case NODE_ImageTexture:
720 it->__textureTableIndex = textureNumber;
722 case NODE_PixelTexture: {
725 pt->__textureTableIndex = textureNumber;
727 case NODE_PixelTexture3D: {
730 pt->__textureTableIndex = textureNumber;
732 case NODE_ImageTexture3D: {
735 pt->__textureTableIndex = textureNumber;
737 case NODE_ComposedTexture3D: {
740 pt->__textureTableIndex = textureNumber;
742 case NODE_MovieTexture: {
745 mt->__textureTableIndex = textureNumber;
748 case NODE_ImageCubeMapTexture: {
751 v1t->__textureTableIndex = textureNumber;
755 case NODE_GeneratedCubeMapTexture: {
758 v1t->__textureTableIndex = textureNumber;
765 newTexture->nodeType = it->_nodeType;
766 newTexture->scenegraphNode = X3D_NODE(tmp);
767 newTexture->textureNumber = textureNumber;
777 int *textureNumber = NULL;
782 switch (it->_nodeType) {
784 case NODE_ImageTexture:
785 textureNumber = &it->__textureTableIndex;
787 case NODE_PixelTexture: {
790 textureNumber = &pt->__textureTableIndex;
792 case NODE_PixelTexture3D: {
795 textureNumber = &pt->__textureTableIndex;
797 case NODE_ImageTexture3D: {
800 textureNumber = &pt->__textureTableIndex;
802 case NODE_ComposedTexture3D: {
805 textureNumber = &pt->__textureTableIndex;
807 case NODE_MovieTexture: {
810 textureNumber = &mt->__textureTableIndex;
813 case NODE_ImageCubeMapTexture: {
816 textureNumber = &v1t->__textureTableIndex;
819 case NODE_GeneratedCubeMapTexture: {
822 textureNumber = &v1t->__textureTableIndex;
826 tti = getTableIndex(*textureNumber);
841 FREE_IF_NZ(tti->texdata);
851 void registerTexture(
struct X3D_Node *tmp) {
852 registerTexture0(1,tmp);
854 void unRegisterTexture(
struct X3D_Node *tmp) {
855 registerTexture0(0,tmp);
860 void unRegisterPolyRep(
struct X3D_Node *tmp)
864 free_polyrep(tmp->_intern);
869 void add_node_to_broto_context(
struct X3D_Proto *currentContext,
struct X3D_Node *node);
880 thisurl.n = 0; thisurl.p = NULL;
883 for (count=0; count<6; count++) {
886 case 0: {thistex = X3D_IMAGETEXTURE(node->__frontTexture); thisurl = node->frontUrl;
break;}
887 case 1: {thistex = X3D_IMAGETEXTURE(node->__backTexture); thisurl = node->backUrl;
break;}
888 case 2: {thistex = X3D_IMAGETEXTURE(node->__topTexture); thisurl = node->topUrl;
break;}
889 case 3: {thistex = X3D_IMAGETEXTURE(node->__bottomTexture); thisurl = node->bottomUrl;
break;}
890 case 4: {thistex = X3D_IMAGETEXTURE(node->__rightTexture); thisurl = node->rightUrl;
break;}
891 case 5: {thistex = X3D_IMAGETEXTURE(node->__leftTexture); thisurl = node->leftUrl;
break;}
893 if (thisurl.n != 0 ) {
895 if (thistex == NULL) {
897 thistex = createNewX3DNode(NODE_ImageTexture);
898 thistp = createNewX3DNode (NODE_TextureProperties);
899 if(node->_executionContext){
900 add_node_to_broto_context(X3D_PROTO(node->_executionContext),X3D_NODE(thistex));
901 add_node_to_broto_context(X3D_PROTO(node->_executionContext),X3D_NODE(thistp));
907 thistp->generateMipMaps = GL_FALSE;
910 thistex->textureProperties = X3D_NODE(thistp);
911 ADD_PARENT(X3D_NODE(thistp), X3D_NODE(thistex));
914 printf (
"bg, creating shadow texture node url.n = %d\n",thisurl.n);
919 for (i=0; i<thisurl.n; i++) {
920 thistex->url.p[i] = newASCIIString (thisurl.p[i]->strptr);
922 thistex->url.n = thisurl.n;
925 case 0: {node->__frontTexture = X3D_NODE(thistex);
break;}
926 case 1: {node->__backTexture = X3D_NODE(thistex);
break;}
927 case 2: {node->__topTexture = X3D_NODE(thistex);
break;}
928 case 3: {node->__bottomTexture = X3D_NODE(thistex);
break;}
929 case 4: {node->__rightTexture = X3D_NODE(thistex);
break;}
930 case 5: {node->__leftTexture = X3D_NODE(thistex);
break;}
935 gglobal()->RenderFuncs.textureStackTop = 0;
937 render_node(X3D_NODE(thistex));
939 textureTransform_start();
942 textureCoord_send(&mtf);
943 FW_GL_VERTEX_POINTER(3,GL_FLOAT,0,BackgroundVert);
944 FW_GL_NORMAL_POINTER(GL_FLOAT,0,Backnorms);
946 sendArraysToGPU (GL_TRIANGLES, count*6, 6);
948 textureTransform_end();
960 for (count=0; count<6; count++) {
963 case 0: {POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, node->frontTexture,thistex);
break;}
964 case 1: {POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, node->backTexture,thistex);
break;}
965 case 2: {POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, node->topTexture,thistex);
break;}
966 case 3: {POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, node->bottomTexture,thistex);
break;}
967 case 4: {POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, node->rightTexture,thistex);
break;}
968 case 5: {POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, node->leftTexture,thistex);
break;}
973 if ((thistex->_nodeType == NODE_ImageTexture) ||
974 (thistex->_nodeType == NODE_PixelTexture) ||
975 (thistex->_nodeType == NODE_MovieTexture) ||
976 (thistex->_nodeType == NODE_MultiTexture)) {
979 switch (thistex->_nodeType) {
980 case NODE_ImageTexture: {
981 if (X3D_IMAGETEXTURE(thistex)->textureProperties == NULL) {
982 thistp = createNewX3DNode (NODE_TextureProperties);
983 if(node->_executionContext){
984 add_node_to_broto_context(X3D_PROTO(node->_executionContext),X3D_NODE(thistp));
986 X3D_IMAGETEXTURE(thistex)->textureProperties = X3D_NODE(thistp);
987 ADD_PARENT(X3D_NODE(thistp),thistex);
992 case NODE_PixelTexture: {
993 if (X3D_PIXELTEXTURE(thistex)->textureProperties == NULL) {
994 thistp = createNewX3DNode (NODE_TextureProperties);
995 if(node->_executionContext){
996 add_node_to_broto_context(X3D_PROTO(node->_executionContext),X3D_NODE(thistp));
999 X3D_PIXELTEXTURE(thistex)->textureProperties = X3D_NODE(thistp);
1000 ADD_PARENT(X3D_NODE(thistp),thistex);
1005 case NODE_MovieTexture:
1006 case NODE_MultiTexture:
1010 gglobal()->RenderFuncs.textureStackTop = 0;
1012 render_node((
void *)thistex);
1015 textureCoord_send(&mtf);
1016 FW_GL_VERTEX_POINTER(3,GL_FLOAT,0,BackgroundVert);
1017 FW_GL_NORMAL_POINTER(GL_FLOAT,0,Backnorms);
1019 sendArraysToGPU (GL_TRIANGLES, count*6, 6);
1028 void loadTextureNode (
struct X3D_Node *node,
void *vparam)
1031 if (NODE_NEEDS_COMPILING) {
1033 DEBUG_TEX (
"FORCE NODE RELOAD: %p %s\n", node, stringNodeType(node->_nodeType));
1045 switch (node->_nodeType) {
1047 case NODE_MovieTexture: {
1052 case NODE_PixelTexture:
1053 releaseTexture(node);
1056 case NODE_ImageTexture:
1057 releaseTexture(node);
1060 case NODE_ImageCubeMapTexture:
1061 releaseTexture(node);
1064 case NODE_GeneratedCubeMapTexture:
1068 case NODE_PixelTexture3D:
1069 releaseTexture(node);
1071 case NODE_ImageTexture3D:
1072 releaseTexture(node);
1074 case NODE_ComposedTexture3D:
1075 releaseTexture(node);
1079 printf (
"loadTextureNode, unknown node type %s\n",stringNodeType(node->_nodeType));
1086 new_bind_image (X3D_NODE(node), (
struct multiTexParams *)vparam);
1096 rdr_caps = tg->display.rdr_caps;
1102 if (node->__xparams == 0) {
1104 node->__xparams = MALLOC (
void *,
sizeof (
struct multiTexParams) * rdr_caps->texture_units);
1113 for (count = 0; count < rdr_caps->texture_units; count++) {
1114 paramPtr->multitex_mode[0]= MTMODE_MODULATE;
1115 paramPtr->multitex_mode[1]= 0;
1116 paramPtr->multitex_source[0]=INT_ID_UNDEFINED;
1117 paramPtr->multitex_source[1]=0;
1118 paramPtr->multitex_function=INT_ID_UNDEFINED;
1125 max = node->texture.n;
1126 if (max > rdr_caps->texture_units) max = rdr_caps->texture_units;
1134 for (count = 0; count < max; count++) {
1135 char *smode, *ssource, *sfunc;
1136 smode = ssource = sfunc = NULL;
1137 if(node->mode.n>count){
1139 smode = node->mode.p[count]->strptr;
1141 mode = findFieldInMULTITEXTUREMODE(smode);
1142 if(mode > -1) mode += 1;
1145 if(strchr(smode,
'/') || strchr(smode,
',')){
1147 char *srgb, *salpha, *b1,*b2, *splittable;
1148 int modergb, modealpha;
1149 splittable = strdup(smode);
1150 b1 = strchr(splittable,
' ');
1151 b2 = strrchr(splittable,
' ');
1153 splittable[b1 - splittable] =
'\0';
1155 modergb = findFieldInMULTITEXTUREMODE(srgb);
1157 modergb = MTMODE_MODULATE;
1160 modealpha = findFieldInMULTITEXTUREMODE(salpha);
1162 modealpha = MTMODE_MODULATE;
1171 paramPtr->multitex_mode[0] = mode;
1172 paramPtr->multitex_mode[1] = modea;
1176 if(node->source.n > count) {
1177 int source, sourcea;
1178 ssource = node->source.p[count]->strptr;
1179 source = findFieldInMULTITEXTURESOURCE(ssource);
1180 if(source > -1) source += 1;
1184 if(strchr(ssource,
'/') || strchr(ssource,
',')){
1186 char *srgb, *salpha, *b1,*b2, *splittable;
1187 int sourcergb, sourcealpha;
1188 splittable = strdup(ssource);
1189 b1 = strchr(splittable,
' ');
1190 b2 = strrchr(splittable,
' ');
1192 splittable[b1 - splittable] =
'\0';
1194 sourcergb = findFieldInMULTITEXTURESOURCE(srgb);
1196 sourcergb = INT_ID_UNDEFINED;
1199 sourcealpha = findFieldInMULTITEXTURESOURCE(salpha);
1202 sourcea = sourcealpha;
1206 paramPtr->multitex_source[0] = source;
1207 paramPtr->multitex_source[1] = sourcea;
1212 if (node->function.n>count) {
1214 sfunc = node->function.p[count]->strptr;
1216 ifunc = findFieldInMULTITEXTUREFUNCTION(sfunc);
1219 paramPtr->multitex_function = ifunc;
1224 printf (
"compile_MultiTexture, %d of %d, mode %d %d source %d %d function %d m %s s %s f %s\n",
1225 count,max,paramPtr->multitex_mode[0],paramPtr->multitex_mode[1],paramPtr->multitex_source[0],paramPtr->multitex_source[1],paramPtr->multitex_function,smode,ssource,sfunc);
1240 rdr_caps = tg->display.rdr_caps;
1243 printf (
"loadMultiTexture, this %s has %d textures %x %x\n",stringNodeType(node->_nodeType),
1245 (
int) node->texture.p[0], (
int) node->texture.p[1]);
1246 printf (
" change %d ichange %d\n",node->_change, node->_ichange);
1250 if (NODE_NEEDS_COMPILING) {
1251 compileMultiTexture(node);
1261 max = node->texture.n;
1264 if (max > rdr_caps->texture_units) max = rdr_caps->texture_units;
1265 if (max > MAX_MULTITEXTURE) max = MAX_MULTITEXTURE;
1272 printf (
"loadMultiTExture, param stack:\n");
1273 for (count=0; count<max; count++) {
1274 printf (
" tex %d source %d mode %d\n",count,paramPtr[count].multitex_source,paramPtr[count].multitex_mode);
1278 for (count=0; count < max; count++) {
1280 printf (
"loadMultiTexture, working on texture %d\n",count);
1284 nt = X3D_IMAGETEXTURE(node->texture.p[count]);
1286 switch (nt->_nodeType) {
1287 case NODE_PixelTexture:
1288 case NODE_ImageTexture :
1290 loadTextureNode (X3D_NODE(nt),paramPtr);
1292 case NODE_MultiTexture:
1293 printf (
"MultiTexture texture %d is a MULTITEXTURE!!\n",count);
1296 printf (
"MultiTexture - unknown sub texture type %d\n",
1304 tg->RenderFuncs.textureStackTop++;
1311 printf (
"loadMultiTexture, textureStackTop %d\n",gglobal()->RenderFuncs.textureStackTop);
1312 printf (
"loadMultiTexture, finished with texture %d\n",count);
1318 #define BOUNDARY_TO_GL(direct) \
1319 switch (findFieldInTEXTUREBOUNDARYKEYWORDS(tpNode->boundaryMode##direct->strptr)) { \
1320 case TB_CLAMP: direct##rc=GL_CLAMP; break; \
1321 case TB_CLAMP_TO_EDGE: direct##rc=GL_CLAMP_TO_EDGE; break; \
1322 case TB_CLAMP_TO_BOUNDARY: direct##rc=GL_CLAMP_TO_BORDER; break; \
1323 case TB_MIRRORED_REPEAT: direct##rc=GL_MIRRORED_REPEAT; break; \
1324 case TB_REPEAT: direct##rc=GL_REPEAT; break; \
1325 default: direct##rc = GL_REPEAT; \
1330 #define DEF_FINDFIELD(arr) \
1331 static int findFieldIn##arr(const char* field) \
1333 return findFieldInARR(field, arr, arr##_COUNT); \
1336 DEF_FINDFIELD(TEXTUREMINIFICATIONKEYWORDS)
1337 DEF_FINDFIELD(TEXTUREMAGNIFICATIONKEYWORDS)
1338 DEF_FINDFIELD(TEXTUREBOUNDARYKEYWORDS)
1339 DEF_FINDFIELD(TEXTURECOMPRESSIONKEYWORDS)
1343 int rx,ry,rz,sx,sy,sz;
1349 float anisotropicDegree=1.0f;
1353 GLint minFilter, magFilter;
1355 int generateMipMaps;
1357 unsigned char *mytexdata;
1367 int haveValidTexturePropertiesNode;
1372 rdr_caps = tg->display.rdr_caps;
1376 Src = FALSE; Trc = FALSE; Rrc = FALSE;
1378 haveValidTexturePropertiesNode = FALSE;
1380 borderColour.c[0]=0.0f;borderColour.c[1]=0.0f;borderColour.c[2]=0.0f;borderColour.c[3]=0.0f;
1381 compression = GL_FALSE;
1386 if (!checkNode(me->scenegraphNode, __FILE__,__LINE__)) {
1387 ConsoleMessage (
"main node disappeared, ignoring texture\n");
1388 me->status = TEXTURE_INVALID;
1395 if (me->texdata == NULL) {
1396 char buff[] = {0x70, 0x70, 0x70, 0xff} ;
1400 me->hasAlpha = FALSE;
1401 me->texdata = MALLOC(
unsigned char *, 4);
1402 memcpy (me->texdata, buff, 4);
1408 if (me->OpenGLTexture == TEXTURE_INVALID) {
1410 if ((getAppearanceProperties()->cubeFace==0) || (getAppearanceProperties()->cubeFace == GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT)) {
1411 FW_GL_GENTEXTURES (1, &me->OpenGLTexture);
1415 printf (
"just glGend texture for block %p is %u, type %s\n",
1416 me, me->OpenGLTexture,stringNodeType(me->nodeType));
1422 if (me->nodeType == NODE_ImageTexture) {
1424 Src = it->repeatS; Trc = it->repeatT;
1425 tpNode = X3D_TEXTUREPROPERTIES(it->textureProperties);
1426 }
else if (me->nodeType == NODE_PixelTexture) {
1428 Src = pt->repeatS; Trc = pt->repeatT;
1429 tpNode = X3D_TEXTUREPROPERTIES(pt->textureProperties);
1430 }
else if (me->nodeType == NODE_MovieTexture) {
1432 Src = mt->repeatS; Trc = mt->repeatT;
1433 tpNode =X3D_TEXTUREPROPERTIES(mt->textureProperties);
1434 }
else if (me->nodeType == NODE_PixelTexture3D) {
1436 Src = pt3d->repeatS; Trc = pt3d->repeatT; Rrc = pt3d->repeatR;
1437 tpNode = X3D_TEXTUREPROPERTIES(pt3d->textureProperties);
1438 }
else if (me->nodeType == NODE_ImageTexture3D) {
1441 Src = it3d->repeatS; Trc = it3d->repeatT; Rrc = it3d->repeatR;
1442 tpNode = X3D_TEXTUREPROPERTIES(it3d->textureProperties);
1443 }
else if (me->nodeType == NODE_ComposedTexture3D) {
1446 Src = ct3d->repeatS; Trc = ct3d->repeatT; Rrc = ct3d->repeatR;
1447 tpNode = X3D_TEXTUREPROPERTIES(ct3d->textureProperties);
1448 }
else if (me->nodeType == NODE_ImageCubeMapTexture) {
1450 tpNode = X3D_TEXTUREPROPERTIES(mi->textureProperties);
1451 }
else if (me->nodeType == NODE_GeneratedCubeMapTexture) {
1453 tpNode = X3D_TEXTUREPROPERTIES(mi->textureProperties);
1458 me->repeatSTR[0] = Src;
1459 me->repeatSTR[1] = Trc;
1460 me->repeatSTR[2] = Rrc;
1465 if (tpNode->_nodeType != NODE_TextureProperties) {
1466 ConsoleMessage (
"have a %s as a textureProperties node",stringNodeType(tpNode->_nodeType));
1468 haveValidTexturePropertiesNode = TRUE;
1469 generateMipMaps = tpNode->generateMipMaps?GL_TRUE:GL_FALSE;
1470 texPri = tpNode->texturePriority;
1471 if ((texPri < 0.0) || (texPri>1.0)) {
1473 ConsoleMessage (
"invalid texturePriority of %f",tpNode->texturePriority);
1475 memcpy(&borderColour,&(tpNode->borderColor),
sizeof(
struct SFColorRGBA));
1477 anisotropicDegree = tpNode->anisotropicDegree;
1478 if ((anisotropicDegree < 1.0) || (anisotropicDegree>rdr_caps->anisotropicDegree)) {
1482 anisotropicDegree = rdr_caps->anisotropicDegree;
1485 borderWidth = tpNode->borderWidth;
1486 if (borderWidth < 0) borderWidth=0;
if (borderWidth>1) borderWidth = 1;
1490 switch (findFieldInTEXTUREMAGNIFICATIONKEYWORDS(tpNode->magnificationFilter->strptr)) {
1491 case TMAG_AVG_PIXEL:
1492 magFilter = GL_LINEAR;
break;
1493 case TMAG_DEFAULT: magFilter = GL_LINEAR;
break;
1494 case TMAG_FASTEST: magFilter = GL_LINEAR;
break;
1495 case TMAG_NEAREST_PIXEL: magFilter = GL_NEAREST;
break;
1496 case TMAG_NICEST: magFilter = GL_NEAREST;
break;
1497 default: magFilter = GL_NEAREST; ConsoleMessage (
"unknown magnification filter %s",
1498 tpNode->magnificationFilter->strptr);
1502 if (generateMipMaps)
switch (findFieldInTEXTUREMINIFICATIONKEYWORDS(tpNode->minificationFilter->strptr)) {
1503 case TMIN_AVG_PIXEL: minFilter = GL_NEAREST;
break;
1504 case TMIN_AVG_PIXEL_AVG_MIPMAP: minFilter = GL_NEAREST_MIPMAP_NEAREST;
break;
1505 case TMIN_AVG_PIXEL_NEAREST_MIPMAP: minFilter = GL_NEAREST_MIPMAP_NEAREST;
break;
1506 case TMIN_DEFAULT: minFilter = GL_NEAREST_MIPMAP_LINEAR;
break;
1507 case TMIN_FASTEST: minFilter = GL_NEAREST_MIPMAP_LINEAR;
break;
1508 case TMIN_NICEST: minFilter = GL_NEAREST_MIPMAP_NEAREST;
break;
1509 case TMIN_NEAREST_PIXEL: minFilter = GL_NEAREST;
break;
1510 case TMIN_NEAREST_PIXEL_NEAREST_MIPMAP: minFilter = GL_NEAREST_MIPMAP_LINEAR;
break;
1511 default: minFilter = GL_NEAREST_MIPMAP_NEAREST;
1512 ConsoleMessage (
"unknown minificationFilter of %s",
1513 tpNode->minificationFilter->strptr);
1515 else switch (findFieldInTEXTUREMINIFICATIONKEYWORDS(tpNode->minificationFilter->strptr)) {
1516 case TMIN_AVG_PIXEL:
1517 case TMIN_AVG_PIXEL_AVG_MIPMAP:
1518 case TMIN_AVG_PIXEL_NEAREST_MIPMAP:
1522 case TMIN_NEAREST_PIXEL: minFilter = GL_NEAREST;
break;
1523 case TMIN_NEAREST_PIXEL_NEAREST_MIPMAP: minFilter = GL_LINEAR;
break;
1524 default: minFilter = GL_NEAREST;
1525 ConsoleMessage (
"unknown minificationFilter of %s",
1526 tpNode->minificationFilter->strptr);
1529 switch (findFieldInTEXTURECOMPRESSIONKEYWORDS(tpNode->textureCompression->strptr)) {
1530 case TC_DEFAULT: compression = GL_FASTEST;
break;
1531 case TC_FASTEST: compression = GL_NONE;
break;
1532 case TC_HIGH: compression = GL_FASTEST;
break;
1533 case TC_LOW: compression = GL_NONE;
break;
1534 case TC_MEDIUM: compression = GL_NICEST;
break;
1535 case TC_NICEST: compression = GL_NICEST;
break;
1537 default: compression = GL_NEAREST_MIPMAP_NEAREST;
1538 ConsoleMessage (
"unknown textureCompression of %s",
1539 tpNode->textureCompression->strptr);
1550 if (!haveValidTexturePropertiesNode) {
1552 Src = Src ? GL_REPEAT : GL_CLAMP_TO_EDGE;
1553 Trc = Trc ? GL_REPEAT : GL_CLAMP_TO_EDGE;
1554 Rrc = Rrc ? GL_REPEAT : GL_CLAMP_TO_EDGE;
1555 generateMipMaps = GL_TRUE;
1557 if(me->x > 0 && me->y > 0)
1571 if(me->x < me->y*me->z) ratio = (float)(me->y*me->z) / (float)me->x;
1572 else ratio = (
float)me->x / (float)(me->y*me->z);
1573 if(ratio > 2.0f) generateMipMaps = GL_FALSE;
1577 if ((me->x<=256) || ((me->y*me->z)<=256)) {
1578 minFilter = GL_NEAREST_MIPMAP_NEAREST;
1579 if(!generateMipMaps) minFilter = GL_NEAREST;
1580 magFilter = GL_NEAREST;
1582 minFilter = GL_LINEAR_MIPMAP_NEAREST;
1583 if(!generateMipMaps) minFilter = GL_LINEAR;
1584 magFilter = GL_LINEAR;
1592 if (getAppearanceProperties()->cubeFace != 0) {
1594 unsigned char *dest = me->texdata;
1603 iformat = GL_RGBA; format = GL_RGBA;
1608 if (getAppearanceProperties()->cubeFace == GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT) {
1609 FW_GL_TEXPARAMETERI(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1610 FW_GL_TEXPARAMETERI(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1611 FW_GL_TEXPARAMETERI(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1612 FW_GL_TEXPARAMETERI(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1613 FW_GL_TEXPARAMETERI(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
1624 int cy, cyy, icsize;
1625 sp = (uint32 *) me->texdata;
1626 for (cy=0; cy<ry/2; cy++) {
1628 for(cx=0;cx<rx;cx+=512){
1629 icsize = min(512,rx-cx-1)*4;
1630 memcpy(tp,&sp[cy*rx + cx],icsize);
1631 memcpy(&sp[cy*rx + cx],&sp[cyy*rx + cx],icsize);
1632 memcpy(&sp[cyy*rx + cx],tp,icsize);
1637 generateMipMaps = 0;
1638 myTexImage2D(generateMipMaps, getAppearanceProperties()->cubeFace, 0, iformat, rx, ry, 0, format, GL_UNSIGNED_BYTE, dest);
1641 if (getAppearanceProperties()->cubeFace == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) {
1642 glEnable(GL_TEXTURE_CUBE_MAP);
1643 glEnable(GL_TEXTURE_GEN_S);
1644 glEnable(GL_TEXTURE_GEN_T);
1645 glEnable(GL_TEXTURE_GEN_R);
1650 if (me->nodeType == NODE_ImageCubeMapTexture) {
1667 unpackImageCubeMap(me);
1668 me->status = TEX_LOADED;
1669 }
else if(me->z == 6){
1672 unpackImageCubeMap6(me);
1673 me->status = TEX_LOADED;
1676 }
else if(me->nodeType == NODE_GeneratedCubeMapTexture){
1678 me->status = TEX_LOADED;
1682 mytexdata = me->texdata;
1683 if (mytexdata == NULL) {
1684 printf (
"mytexdata is null, texture failed, put something here\n");
1687 glBindTexture (GL_TEXTURE_2D, me->OpenGLTexture);
1708 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, Src);
1709 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Trc);
1710 #if !defined(GL_ES_VERSION_2_0)
1711 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, Rrc);
1712 FW_GL_TEXPARAMETERF(GL_TEXTURE_2D,GL_TEXTURE_PRIORITY, texPri);
1713 FW_GL_TEXPARAMETERFV(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR,(GLfloat *)&borderColour);
1716 #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
1717 FW_GL_TEXPARAMETERF(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,anisotropicDegree);
1720 if (compression != GL_NONE) {
1721 FW_GL_TEXPARAMETERI(GL_TEXTURE_2D, GL_TEXTURE_INTERNAL_FORMAT, GL_COMPRESSED_RGBA);
1722 glHint(GL_TEXTURE_COMPRESSION_HINT, compression);
1724 npot = rdr_caps->av_npot_texture;
1729 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
1730 FW_GL_TEXPARAMETERI( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
1731 me->magFilter = magFilter == GL_LINEAR ? 1 : 0;
1737 iformat = GL_RGBA; format = GL_RGBA;
1742 unsigned char *dest = mytexdata;
1746 rx = x; ry = y; rz = z;
1751 while(sx) {sx /= 2; rx *= 2;}
1752 if(rx/2 == x) {rx /= 2;}
1755 while(sy) {sy /= 2; ry *= 2;}
1756 if(ry/2 == y) {ry /= 2;}
1760 while(sz) {sz /= 2; rz *= 2;}
1761 if(rz/2 == z) {rz /= 2;}
1764 if (gglobal()->internalc.global_print_opengl_errors) {
1765 DEBUG_MSG(
"initial texture scale to %d %d\n",rx,ry);
1771 int emulating3D_TILED;
1772 emulating3D_TILED = TRUE;
1773 generateMipMaps = FALSE;
1774 if(emulating3D_TILED){
1795 int rc,sc,c,cube_root, max_size;
1796 unsigned char *texdataTiles = NULL;
1798 int nx, ny, ix, iy, nxx, nyy;
1801 max_size = rdr_caps->runtime_max_texture_size;
1804 if(x * y * z > 256 * 256 * 256)
1805 max_size = min(max_size,4096);
1807 cube_root = (int)pow( max_size * max_size + 3, 1.0/3.0);
1812 while(sc) {sc /= 2; rc *= 2;}
1813 if(rc > c) {rc /= 2;}
1816 if(rx != x || ry != y || rz != z || rx > cube_root || ry > cube_root || rz > cube_root) {
1823 if (rx > cube_root) rx = cube_root;
1824 if (ry > cube_root) ry = cube_root;
1825 if (rz > cube_root) rz = cube_root;
1828 if (gglobal()->internalc.global_print_opengl_errors) {
1829 DEBUG_MSG(
"texture size after maxTextureSize taken into account: %d %d, from %d %d\n",rx,ry,x,y);
1837 if(x > rx || y > ry || z > rz){
1842 dest = MALLOC(
unsigned char *, 4 * rx * ry * rz);
1843 myScaleImage3D(x,y,z,mx,my,mz,mytexdata,dest);
1847 FREE_IF_NZ(me->texdata);
1852 if(me->channels == 1){
1854 compute_3D_alpha_gradient_store_rgb(dest,x,y,z);
1857 ny = (int) sqrt(z+1);
1859 nx = z - nx*ny > 0 ? nx+1 : nx;
1869 texdataTiles = MALLOC(
unsigned char *,nxx * nyy * 4);
1870 p2 = (uint32 *)texdataTiles;
1871 p1 = (uint32 *)dest;
1872 for(iz=0;iz<z;iz++){
1879 ifrom = (iz*y + j)*x + k;
1880 ito = (iy*y + j)*nxx + (ix*x) + k;
1894 tti3->texdata = texdataTiles;
1895 saveImage_web3dit(tti3,
"test_tiled_texture.web3dit");
1898 myTexImage2D(generateMipMaps, GL_TEXTURE_2D, 0, iformat, nxx, nyy, 0, format, GL_UNSIGNED_BYTE, texdataTiles);
1899 ConsoleMessage(
"final texture2D size %d %d\n",nxx,nyy);
1900 FREE_IF_NZ(texdataTiles);
1901 if(dest != me->texdata) FREE_IF_NZ(dest);
1907 if(rx != x || ry != y || rx > rdr_caps->runtime_max_texture_size || ry > rdr_caps->runtime_max_texture_size) {
1914 if (rx > rdr_caps->runtime_max_texture_size) rx = rdr_caps->runtime_max_texture_size;
1915 if (ry > rdr_caps->runtime_max_texture_size) ry = rdr_caps->runtime_max_texture_size;
1918 if (gglobal()->internalc.global_print_opengl_errors) {
1919 DEBUG_MSG(
"texture size after maxTextureSize taken into account: %d %d, from %d %d\n",rx,ry,x,y);
1931 if(generateMipMaps){
1938 if ((x==rx) && (y==ry)) {
1944 dest = MALLOC(
unsigned char *, 4 * rx * ry);
1946 myScaleImage(x,y,rx,ry,mytexdata,dest);
1950 myTexImage2D(generateMipMaps, GL_TEXTURE_2D, 0, iformat, rx, ry, 0, format, GL_UNSIGNED_BYTE, dest);
1952 if(mytexdata != dest) {
1958 FREE_IF_NZ (me->texdata);
1967 me->status = TEX_LOADED;
1990 int thisTextureType;
2007 thisTextureType = node->_nodeType;
2008 if (thisTextureType==NODE_ImageTexture){
2011 thisTexture = it->__textureTableIndex;
2012 }
else if (thisTextureType==NODE_PixelTexture){
2014 thisTexture = pt->__textureTableIndex;
2015 }
else if (thisTextureType==NODE_MovieTexture){
2017 thisTexture = mt->__textureTableIndex;
2019 }
else if (thisTextureType==NODE_ImageCubeMapTexture){
2021 thisTexture = ict->__textureTableIndex;
2023 }
else if (thisTextureType==NODE_GeneratedCubeMapTexture){
2025 thisTexture = gct->__textureTableIndex;
2026 }
else if (thisTextureType==NODE_PixelTexture3D){
2029 thisTexture = pt3d->__textureTableIndex;
2030 }
else if (thisTextureType==NODE_ImageTexture3D){
2033 thisTexture = pt3d->__textureTableIndex;
2035 }
else if (thisTextureType==NODE_ComposedTexture3D){
2038 thisTexture = pt3d->__textureTableIndex;
2040 ConsoleMessage (
"Invalid type for texture, %s\n",stringNodeType(thisTextureType));
2044 myTableIndex = getTableIndex(thisTexture);
2045 if (myTableIndex->status != TEX_LOADED) {
2046 DEBUG_TEX(
"new_bind_image, I am %p, textureStackTop %d, thisTexture is %d myTableIndex %p status %s\n",
2047 node,tg->RenderFuncs.textureStackTop,thisTexture,myTableIndex, texst(myTableIndex->status));
2051 tg->RenderFuncs.boundTextureStack[tg->RenderFuncs.textureStackTop] = tg->Textures.defaultBlankTexture;
2052 switch (myTableIndex->status) {
2054 DEBUG_TEX(
"feeding texture %p to texture thread...\n", myTableIndex);
2055 if(mfurl && mfurl->n == 0) {
2057 myTableIndex->status = TEX_NEEDSBINDING;
2059 myTableIndex->status = TEX_LOADING;
2060 send_texture_to_loader(myTableIndex);
2066 DEBUG_TEX(
"I've to wait for %p...\n", myTableIndex);
2069 case TEX_NEEDSBINDING:
2070 DEBUG_TEX(
"texture loaded into memory... now lets load it into OpenGL...\n");
2071 move_texture_to_opengl(myTableIndex);
2078 if (myTableIndex->hasAlpha) tg->RenderFuncs.last_texture_type = TEXTURE_ALPHA;
2079 else tg->RenderFuncs.last_texture_type = TEXTURE_NO_ALPHA;
2083 if (myTableIndex->OpenGLTexture == TEXTURE_INVALID) {
2085 DEBUG_TEX(
"no openGLtexture here status %s\n", texst(myTableIndex->status));
2089 tg->RenderFuncs.boundTextureStack[tg->RenderFuncs.textureStackTop] = myTableIndex->OpenGLTexture;
2096 if (param != NULL) {
2098 memcpy(&(textureParameterStack[tg->RenderFuncs.textureStackTop]), param,
sizeof (
struct multiTexParams));
2101 p->textureInProcess = -1;
2104 case TEX_UNSQUASHED:
2106 printf (
"unknown texture status %d\n",myTableIndex->status);