7 static GLTexture
*find_texture(GLContext
*c
,int h
)
11 t
=c
->shared_state
.texture_hash_table
[h
% TEXTURE_HASH_TABLE_SIZE
];
13 if (t
->handle
== h
) return t
;
19 static void free_texture(GLContext
*c
,int h
)
27 ht
=&c
->shared_state
.texture_hash_table
28 [t
->handle
% TEXTURE_HASH_TABLE_SIZE
];
31 t
->prev
->next
=t
->next
;
33 if (t
->next
!=NULL
) t
->next
->prev
=t
->prev
;
35 for(i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
37 if (im
->pixmap
!= NULL
) gl_free(im
->pixmap
);
43 GLTexture
*alloc_texture(GLContext
*c
,int h
)
47 t
=gl_zalloc(sizeof(GLTexture
));
49 ht
=&c
->shared_state
.texture_hash_table
[h
% TEXTURE_HASH_TABLE_SIZE
];
53 if (t
->next
!= NULL
) t
->next
->prev
=t
;
62 void glInitTextures(GLContext
*c
)
66 c
->texture_2d_enabled
=0;
67 c
->current_texture
=find_texture(c
,0);
70 void glGenTextures(int n
, unsigned int *textures
)
72 GLContext
*c
=gl_get_context();
77 for(i
=0;i
<TEXTURE_HASH_TABLE_SIZE
;i
++) {
78 t
=c
->shared_state
.texture_hash_table
[i
];
80 if (t
->handle
>max
) max
=t
->handle
;
91 void glDeleteTextures(int n
, const unsigned int *textures
)
93 GLContext
*c
=gl_get_context();
98 t
=find_texture(c
,textures
[i
]);
99 if (t
!=NULL
&& t
!=0) {
100 if (t
==c
->current_texture
) {
101 glBindTexture(GL_TEXTURE_2D
,0);
103 free_texture(c
,textures
[i
]);
109 void glopBindTexture(GLContext
*c
,GLParam
*p
)
115 assert(target
== GL_TEXTURE_2D
&& texture
>= 0);
117 t
=find_texture(c
,texture
);
119 t
=alloc_texture(c
,texture
);
121 c
->current_texture
=t
;
124 void glopTexImage2D(GLContext
*c
,GLParam
*p
)
128 int components
=p
[3].i
;
136 unsigned char *pixels1
;
139 if (!(target
== GL_TEXTURE_2D
&& level
== 0 && components
== 3 &&
140 border
== 0 && format
== GL_RGB
&&
141 type
== GL_UNSIGNED_BYTE
)) {
142 gl_fatal_error("glTexImage2D: combinaison of parameters not handled");
146 if (width
!= 256 || height
!= 256) {
147 pixels1
= gl_malloc(256 * 256 * 3);
148 /* no interpolation is done here to respect the original image aliasing ! */
149 gl_resizeImageNoInterpolate(pixels1
,256,256,pixels
,width
,height
);
157 im
=&c
->current_texture
->images
[level
];
160 if (im
->pixmap
!=NULL
) gl_free(im
->pixmap
);
161 #if TGL_FEATURE_RENDER_BITS == 24
162 im
->pixmap
=gl_malloc(width
*height
*3);
164 memcpy(im
->pixmap
,pixels1
,width
*height
*3);
166 #elif TGL_FEATURE_RENDER_BITS == 32
167 im
->pixmap
=gl_malloc(width
*height
*4);
169 gl_convertRGB_to_8A8R8G8B(im
->pixmap
,pixels1
,width
,height
);
171 #elif TGL_FEATURE_RENDER_BITS == 16
172 im
->pixmap
=gl_malloc(width
*height
*2);
174 gl_convertRGB_to_5R6G5B(im
->pixmap
,pixels1
,width
,height
);
179 if (do_free
) gl_free(pixels1
);
183 /* TODO: not all tests are done */
184 void glopTexEnv(GLContext
*c
,GLParam
*p
)
190 if (target
!= GL_TEXTURE_ENV
) {
192 gl_fatal_error("glTexParameter: unsupported option");
195 if (pname
!= GL_TEXTURE_ENV_MODE
) goto error
;
197 if (param
!= GL_DECAL
) goto error
;
200 /* TODO: not all tests are done */
201 void glopTexParameter(GLContext
*c
,GLParam
*p
)
207 if (target
!= GL_TEXTURE_2D
) {
209 gl_fatal_error("glTexParameter: unsupported option");
213 case GL_TEXTURE_WRAP_S
:
214 case GL_TEXTURE_WRAP_T
:
215 if (param
!= GL_REPEAT
) goto error
;
220 void glopPixelStore(GLContext
*c
,GLParam
*p
)
225 if (pname
!= GL_UNPACK_ALIGNMENT
||
227 gl_fatal_error("glPixelStore: unsupported option");