void *max_ta_jit_kinect2_new(t_symbol *s, long argc, t_atom *argv)
{
    t_max_ta_jit_kinect2	*x;
    void			*o;
    
    x = (t_max_ta_jit_kinect2 *)max_jit_object_alloc(max_ta_jit_kinect2_class, gensym("ta_jit_kinect2"));
    if (x) {
        o = jit_object_new(gensym("ta_jit_kinect2"));
        if (o) {
            max_jit_mop_setup_simple(x, o, argc, argv);
            max_jit_attr_args(x, argc, argv);
            t_atom_long depthdim[2] = {DEPTH_WIDTH, DEPTH_HEIGHT};
            t_atom_long rgbdim[2] = {RGB_WIDTH, RGB_HEIGHT};
            
            //TA: set depth matrix initial attributes
            void *output = max_jit_mop_getoutput(x, 1);
            jit_attr_setsym(output, _jit_sym_type, _jit_sym_float32);
            jit_attr_setlong_array(output, _jit_sym_dim, 2, depthdim);
            jit_attr_setlong(output, _jit_sym_planecount, 1);
            
            //TA: set rgb matrix initial attributes
            output = max_jit_mop_getoutput(x, 2);
            jit_attr_setsym(output, _jit_sym_type, _jit_sym_char);
            jit_attr_setlong_array(output, _jit_sym_dim, 2, rgbdim);
            jit_attr_setlong(output, _jit_sym_planecount, 4);

        }
        else {
            jit_object_error((t_object *)x, "ta.jit.kinect2: could not allocate object");
            object_free((t_object *)x);
            x = NULL;
        }
    }
    return (x);
}
Exemple #2
0
t_jit_err jit_gl_hap_draw(t_jit_gl_hap *x)
{
	t_jit_err result = JIT_ERR_NONE;
	t_jit_gl_drawinfo drawinfo;

	if(x->newfile) {
		if(x->texture && x->deletetex) {
			glDeleteTextures(1, &x->texture);
			x->deletetex = 0;
		}
		
		x->texture = 0;
		jit_gl_hap_load_file(x);
	}
	
	if(!x->movieloaded)
		return JIT_ERR_NONE;
		
	if(jit_gl_drawinfo_setup(x,&drawinfo))
		return JIT_ERR_GENERIC;
		
	jit_gl_hap_getcurrentframe(x);
	
	if(x->validframe) {

		GLint previousFBO;	// make sure we pop out to the right FBO
#ifdef MAC_VERSION
		GLint previousReadFBO;
		GLint previousDrawFBO;
#endif		
		// We are going to bind our FBO to our internal jit.gl.texture as COLOR_0 attachment
		// We need the ID, width/height.
		GLuint texid = jit_attr_getlong(x->texoutput,ps_glid);
		GLuint width = jit_attr_getlong(x->texoutput,ps_width);
		GLuint height = jit_attr_getlong(x->texoutput,ps_height);

		glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &previousFBO);
#ifdef MAC_VERSION
		glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &previousReadFBO);
		glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &previousDrawFBO);
#endif
		
		if(width!=x->dim[0] || height!=x->dim[1]) {
			width = x->dim[0];
			height = x->dim[1];
			jit_attr_setlong_array(x->texoutput, gensym("dim"), 2, x->dim);
			jit_attr_user_touch(x, gensym("dim"));
		}
		
		if(x->hap_format == JIT_GL_HAP_PF_HAP) {
			jit_gl_hap_submit_texture(x);
			jit_gl_report_error("jit.gl.hap submit texture");
		}
		else if(x->hap_format != JIT_GL_HAP_PF_GL) {
			jit_gl_hap_submit_nonhap_texture(x);
			jit_gl_report_error("jit.gl.hap submit non-hap texture");
		}
		
		if(jit_gl_hap_draw_begin(x, texid, width, height)) {
			jit_gl_report_error("jit.gl.hap draw begin");
			jit_gl_hap_dodraw(x, width, height);
			jit_gl_report_error("jit.gl.hap draw texture to FBO");
			jit_gl_hap_draw_end(x);
			jit_gl_report_error("jit.gl.hap draw end");
		}
		else {
			jit_object_error((t_object*)x, "could not bind to FBO");
		}

		glPopClientAttrib();
		glPopAttrib();
		
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previousFBO);
#ifdef MAC_VERSION
		glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, previousReadFBO);
		glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, previousDrawFBO);
#endif

		x->validframe = 0;
		
		jit_object_notify(x, ps_draw, NULL);
		jit_gl_hap_do_report(x);
	}
	
	jit_gl_hap_releaseframe(x);

	return result;
}