Max 5 API Reference
00001 /* 00002 * Copyright 2001-2005 - Cycling '74 00003 * Joshua Kit Clayton - jkc@cycling74.com 00004 * 00005 * OpenGL drawinfo structure used to store texture binding info per draw call. 00006 */ 00007 00008 /****************************************************************************/ 00009 00010 #include "jit.gl.h" 00011 #include "jit.gl.ob3d.h" 00012 #include "jit.gl.ob3d.internal.h" 00013 #include "jit.gl.drawinfo.h" 00014 00015 /****************************************************************************/ 00016 00017 /** 00018 * Initializes t_jit_gl_drawinfo struct with the current context and ob3d. 00019 * 00020 * @ingroup ob3dmod 00021 * 00022 * @param x Jitter object pointer 00023 * @param drawinfo t_jit_gl_drawinfo pointer 00024 * 00025 * @return t_jit_err error code 00026 * 00027 */ 00028 t_jit_err jit_gl_drawinfo_setup(void *x, t_jit_gl_drawinfo *drawinfo) 00029 { 00030 if (!drawinfo) { 00031 jit_object_error((t_object *)x,"jit_gl_drawinfo_setup: invalid drawinfo pointer"); 00032 return JIT_ERR_INVALID_PTR; 00033 } 00034 00035 if (!(drawinfo->ctx=jit_gl_get_context())) { 00036 jit_object_error((t_object *)x,"jit_gl_drawinfo_setup: no context"); 00037 return JIT_ERR_GENERIC; 00038 } 00039 00040 if (!(drawinfo->ob3d=jit_ob3d_get(x))) { 00041 jit_object_error((t_object *)x,"jit_gl_drawinfo_setup: no ob3d"); 00042 return JIT_ERR_GENERIC; 00043 } 00044 00045 return JIT_ERR_NONE; 00046 } 00047 00048 /** 00049 * Determine the number of active texture units to use. 00050 * 00051 * @ingroup ob3dmod 00052 * 00053 * @param drawinfo t_jit_gl_drawinfo pointer 00054 * 00055 * @return number of active texture units 00056 * 00057 */ 00058 long jit_gl_drawinfo_active_textures(t_jit_gl_drawinfo *drawinfo) 00059 { 00060 return JIT_MATH_MIN(drawinfo->ctx->support->texture_units,((t_jit_ob3d *)drawinfo->ob3d)->texturecount); 00061 } 00062 00063 /** 00064 * Set texture coordinate for all active texture units. 00065 * Equivalent to glMultiTexCoord1fARB for each active texture unit. 00066 * 00067 * @ingroup ob3dmod 00068 * 00069 * @param drawinfo t_jit_gl_drawinfo pointer 00070 * @param s s texture coordinate 00071 * 00072 */ 00073 void jit_gl_texcoord1f(t_jit_gl_drawinfo *drawinfo, float s) 00074 { 00075 long i,units; 00076 00077 units = MIN(drawinfo->ctx->support->texture_units,((t_jit_ob3d *)drawinfo->ob3d)->texturecount); 00078 glTexCoord1f(s); 00079 for(i=0;i<units;i++) 00080 glMultiTexCoord1fARB(GL_TEXTURE0_ARB + i, s); 00081 } 00082 00083 /** 00084 * Set texture coordinate for all active texture units. 00085 * Equivalent to glMultiTexCoord2fARB for each active texture unit. 00086 * 00087 * @ingroup ob3dmod 00088 * 00089 * @param drawinfo t_jit_gl_drawinfo pointer 00090 * @param s s texture coordinate 00091 * @param t t texture coordinate 00092 * 00093 */ 00094 void jit_gl_texcoord2f(t_jit_gl_drawinfo *drawinfo, float s, float t) 00095 { 00096 long i,units; 00097 00098 units = MIN(drawinfo->ctx->support->texture_units,((t_jit_ob3d *)drawinfo->ob3d)->texturecount); 00099 glTexCoord2f(s,t); 00100 if (drawinfo->ctx->support->multitexture) { 00101 for(i=0;i<units;i++) 00102 glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, s, t); 00103 } 00104 } 00105 00106 /** 00107 * Set texture coordinate for all active texture units. 00108 * Equivalent to glMultiTexCoord3fARB for each active texture unit. 00109 * 00110 * @ingroup ob3dmod 00111 * 00112 * @param drawinfo t_jit_gl_drawinfo pointer 00113 * @param s s texture coordinate 00114 * @param t t texture coordinate 00115 * @param r r texture coordinate 00116 * 00117 */ 00118 void jit_gl_texcoord3f(t_jit_gl_drawinfo *drawinfo, float s, float t, float r) 00119 { 00120 long i,units; 00121 00122 units = MIN(drawinfo->ctx->support->texture_units,((t_jit_ob3d *)drawinfo->ob3d)->texturecount); 00123 glTexCoord3f(s,t,r); 00124 if (drawinfo->ctx->support->multitexture) { 00125 for(i=0;i<units;i++) 00126 glMultiTexCoord3fARB(GL_TEXTURE0_ARB + i, s, t, r); 00127 } 00128 } 00129 00130 00131 /** 00132 * Set texture coordinate for all active texture units. 00133 * Equivalent to glMultiTexCoord1fvARB for each active texture unit. 00134 * 00135 * @ingroup ob3dmod 00136 * 00137 * @param drawinfo t_jit_gl_drawinfo pointer 00138 * @param v texture coordinate vector 00139 * 00140 */ 00141 void jit_gl_texcoord1fv(t_jit_gl_drawinfo *drawinfo, float *v) 00142 { 00143 long i,units; 00144 00145 units = MIN(drawinfo->ctx->support->texture_units,((t_jit_ob3d *)drawinfo->ob3d)->texturecount); 00146 glTexCoord1fv(v); 00147 if (drawinfo->ctx->support->multitexture) { 00148 for(i=0;i<units;i++) 00149 glMultiTexCoord1fvARB(GL_TEXTURE0_ARB + i, v); 00150 } 00151 } 00152 00153 /** 00154 * Set texture coordinate for all active texture units. 00155 * Equivalent to glMultiTexCoord2fvARB for each active texture unit. 00156 * 00157 * @ingroup ob3dmod 00158 * 00159 * @param drawinfo t_jit_gl_drawinfo pointer 00160 * @param v texture coordinate vector 00161 * 00162 */ 00163 void jit_gl_texcoord2fv(t_jit_gl_drawinfo *drawinfo, float *v) 00164 { 00165 long i,units; 00166 00167 units = MIN(drawinfo->ctx->support->texture_units,((t_jit_ob3d *)drawinfo->ob3d)->texturecount); 00168 glTexCoord2fv(v); 00169 if (drawinfo->ctx->support->multitexture) { 00170 for(i=0;i<units;i++) 00171 glMultiTexCoord2fvARB(GL_TEXTURE0_ARB + i, v); 00172 } 00173 } 00174 00175 /** 00176 * Set texture coordinate for all active texture units. 00177 * Equivalent to glMultiTexCoord3fvARB for each active texture unit. 00178 * 00179 * @ingroup ob3dmod 00180 * 00181 * @param drawinfo t_jit_gl_drawinfo pointer 00182 * @param v texture coordinate vector 00183 * 00184 */ 00185 void jit_gl_texcoord3fv(t_jit_gl_drawinfo *drawinfo, float *v) 00186 { 00187 long i,units; 00188 00189 units = MIN(drawinfo->ctx->support->texture_units,((t_jit_ob3d *)drawinfo->ob3d)->texturecount); 00190 glTexCoord3fv(v); 00191 if (drawinfo->ctx->support->multitexture) { 00192 for(i=0;i<units;i++) 00193 glMultiTexCoord3fvARB(GL_TEXTURE0_ARB + i, v); 00194 } 00195 } 00196 00197 /** 00198 * Bind texture for specified texture unit. 00199 * 00200 * @ingroup ob3dmod 00201 * 00202 * @param drawinfo t_jit_gl_drawinfo pointer 00203 * @param s texture name 00204 * @param i texture unit 00205 * 00206 */ 00207 void jit_gl_bindtexture(t_jit_gl_drawinfo *drawinfo, t_symbol *s, long i) 00208 { 00209 t_jit_ob3d *ob3d=drawinfo->ob3d; 00210 00211 if (s) { 00212 jit_gl_dobindtexture(ob3d, s, i); 00213 } else { 00214 for(i = 0; i < ob3d->texturecount; i++) 00215 { 00216 jit_gl_dobindtexture(ob3d, ob3d->texture[i], i); 00217 } 00218 } 00219 } 00220 00221 /** 00222 * Unbind texture for specified texture unit. 00223 * 00224 * @ingroup ob3dmod 00225 * 00226 * @param drawinfo t_jit_gl_drawinfo pointer 00227 * @param s texture name 00228 * @param i texture unit 00229 * 00230 */ 00231 void jit_gl_unbindtexture(t_jit_gl_drawinfo *drawinfo, t_symbol *s, long i) 00232 { 00233 t_jit_ob3d *ob3d=drawinfo->ob3d; 00234 00235 if (s) { 00236 jit_gl_dounbindtexture(ob3d, s, i); 00237 } else { 00238 for(i = 0; i < ob3d->texturecount; i++) 00239 { 00240 jit_gl_dounbindtexture(ob3d, ob3d->texture[i], i); 00241 } 00242 } 00243 } 00244 00245 void jit_gl_dobindtexture(t_jit_ob3d *ob3d, t_symbol *s, long i) 00246 { 00247 if (s && s != _jit_sym_nothing && s != ps_none) 00248 { 00249 t_atom a; 00250 t_jit_object *o = NULL; 00251 t_jit_ob3d *tex_ob3d; 00252 long capturing; 00253 t_symbol *shared_context; 00254 00255 // find registered gl.texture object with given name 00256 o = jit_object_findregistered(s); 00257 if (o && (jit_object_classname(o) == ps_jit_gl_texture || jit_object_classname(o) == ps_jit_gl_cubemap) ) 00258 { 00259 // bind texture to texunit of current index 00260 // post("jit.gl: binding texture for unit %d: %s", i, s->s_name); 00261 00262 tex_ob3d = (t_jit_ob3d *)jit_ob3d_get(o); 00263 capturing = jit_attr_getlong(o, ps_capturing); 00264 00265 if(tex_ob3d->renderer) { 00266 shared_context = jit_attr_getsym(tex_ob3d->renderer,ps_shared_context); 00267 } 00268 else { 00269 shared_context = _jit_sym_nothing; 00270 } 00271 00272 //bind if texture is captured, belongs to the object's context, or 00273 // is shared with the object's context 00274 if(capturing || tex_ob3d->dest_name == ob3d->dest_name || ob3d->dest_name == shared_context) { 00275 jit_atom_setlong(&a, i); 00276 jit_object_method(o, ps_bind, ps_bind, 1, &a); 00277 } 00278 } 00279 } 00280 jit_gl_report_error("jit_gl_bind_texture"); 00281 } 00282 00283 void jit_gl_dounbindtexture(t_jit_ob3d *ob3d, t_symbol *s, long i) 00284 { 00285 t_jit_ob3d *tex_ob3d; 00286 long capturing; 00287 t_symbol *shared_context; 00288 00289 if (s && s != _jit_sym_nothing && s != ps_none) 00290 { 00291 t_jit_object *o; 00292 t_atom a; 00293 if (o=jit_object_findregistered(s)) 00294 { 00295 if (jit_object_classname(o) == ps_jit_gl_texture || jit_object_classname(o) == ps_jit_gl_cubemap) 00296 { 00297 // unbind texture from texunit of current index 00298 // post("jit.gl: unbinding texture for unit %d: %s", i, s->s_name); 00299 00300 tex_ob3d = (t_jit_ob3d *)jit_ob3d_get(o); 00301 capturing = jit_attr_getlong(o, gensym("capturing")); 00302 00303 if(tex_ob3d->renderer) { 00304 shared_context = jit_attr_getsym(tex_ob3d->renderer, gensym("shared_context")); 00305 } 00306 else { 00307 shared_context = _jit_sym_nothing; 00308 } 00309 00310 // unbind if texture is captured, belongs to the object's context, or 00311 // is shared with the object's context 00312 if(capturing || tex_ob3d->dest_name == ob3d->dest_name || ob3d->dest_name == shared_context) { 00313 jit_atom_setlong(&a, i); 00314 jit_object_method(o, ps_unbind, ps_unbind, 1, &a); 00315 } 00316 } 00317 } 00318 } 00319 } 00320 00321 /** 00322 * Begin texture capture. 00323 * 00324 * @ingroup ob3dmod 00325 * 00326 * @param drawinfo t_jit_gl_drawinfo pointer 00327 * @param s texture name 00328 * @param i ignored 00329 * 00330 */ 00331 void jit_gl_begincapture(t_jit_gl_drawinfo *drawinfo, t_symbol *s, long i) 00332 { 00333 t_jit_ob3d *ob3d=drawinfo->ob3d; 00334 00335 if (s) { 00336 jit_gl_dobegincapture(ob3d, s, i); 00337 } else { 00338 for(i = 0; i < ob3d->capturecount; i++) 00339 { 00340 jit_gl_dobegincapture(ob3d,ob3d->capture[i],i);; 00341 } 00342 } 00343 } 00344 00345 /** 00346 * End texture capture. 00347 * 00348 * @ingroup ob3dmod 00349 * 00350 * @param drawinfo t_jit_gl_drawinfo pointer 00351 * @param s texture name 00352 * @param i ignored 00353 * 00354 */ 00355 void jit_gl_endcapture(t_jit_gl_drawinfo *drawinfo, t_symbol *s, long i) 00356 { 00357 t_jit_ob3d *ob3d=drawinfo->ob3d; 00358 00359 if (s) { 00360 jit_gl_doendcapture(ob3d, s, i); 00361 } else { 00362 for(i = 0; i < ob3d->capturecount; i++) 00363 { 00364 jit_gl_doendcapture(ob3d,ob3d->capture[i],i); 00365 } 00366 } 00367 } 00368 00369 void jit_gl_dobegincapture(t_jit_ob3d *ob3d, t_symbol *s, long i) 00370 { 00371 if (s && s != _jit_sym_nothing && s != ps_none) 00372 { 00373 t_atom a; 00374 t_jit_object *o = NULL; 00375 00376 // find registered gl.texture object with given name 00377 o = jit_object_findregistered(s); 00378 if (o && jit_object_classname(o) == ps_jit_gl_texture) 00379 { 00380 jit_object_method(o, ps_begin_capture, ps_begin_capture, 0, 0); 00381 } 00382 } 00383 jit_gl_report_error("jit_gl_begin_capture"); 00384 } 00385 00386 void jit_gl_doendcapture(t_jit_ob3d *ob3d, t_symbol *s, long i) 00387 { 00388 if (s && s != _jit_sym_nothing && s != ps_none) 00389 { 00390 t_jit_object *o; 00391 t_atom a; 00392 if (o=jit_object_findregistered(s)) 00393 { 00394 if (jit_object_classname(o) == ps_jit_gl_texture) 00395 { 00396 jit_object_method(o, ps_end_capture, ps_end_capture, 0, 0); 00397 } 00398 } 00399 } 00400 jit_gl_report_error("jit_gl_end_capture"); 00401 } 00402 00403 /****************************************************************************/
Copyright © 2008, Cycling '74