コード例 #1
0
void *
xmlMallocAtomicLoc(KDsize size, const char * file, int line)
{
    MEMHDR *p;
    void *ret;

    if (!xmlMemInitialized) xmlInitMemory();
#ifdef DEBUG_MEMORY
    xmlGenericError(xmlGenericErrorContext,
	    "Malloc(%d)\n",size);
#endif

    TEST_POINT

    p = (MEMHDR *) kdMalloc(RESERVE_SIZE+size);

    if (!p) {
	xmlGenericError(xmlGenericErrorContext,
		"xmlMallocLoc : Out of kdFree space\n");
	xmlMemoryDump();
	return(KD_NULL);
    }
    p->mh_tag = MEMTAG;
    p->mh_size = size;
    p->mh_type = MALLOC_ATOMIC_TYPE;
    p->mh_file = file;
    p->mh_line = line;
    xmlMutexLock(xmlMemMutex);
    p->mh_number = ++block;
    debugMemSize += size;
    debugMemBlocks++;
    if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
#ifdef MEM_LIST
    debugmem_list_add(p);
#endif
    xmlMutexUnlock(xmlMemMutex);

#ifdef DEBUG_MEMORY
    xmlGenericError(xmlGenericErrorContext,
	    "Malloc(%d) Ok\n",size);
#endif

    if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();

    ret = HDR_2_CLIENT(p);

    if (xmlMemTraceBlockAt == ret) {
	xmlGenericError(xmlGenericErrorContext,
			"%p : Malloc(%ld) Ok\n", xmlMemTraceBlockAt, size);
	xmlMallocBreakpoint();
    }

    TEST_POINT

    return(ret);
}
コード例 #2
0
// kdThreadOnce : Wrap initialization code so it is executed only once.
KD_API KDint KD_APIENTRY kdThreadOnce ( KDThreadOnce *once_control, KDvoid (* init_routine) ( KDvoid ) )
{			
	if ( !once_control->impl )
	{
		pthread_once_t  ponce = PTHREAD_ONCE_INIT; 

		once_control->impl = kdMalloc ( sizeof ( pthread_once_t ) );
		kdMemcpy ( once_control->impl, (const KDvoid *) &ponce, sizeof ( pthread_once_t ) );
	}
	
	return pthread_once ( (pthread_once_t *) once_control->impl, init_routine );	
} 
コード例 #3
0
XMDir* xmBadaOpendir ( const KDchar* dirname )
{
	Directory   dir;
	XMDir*      ret;
	result      r;

	r = dir.Construct ( dirname );

	if ( IsFailed ( r ) )
	{
		ret = 0;
		goto failed;
	}

	ret = (XMDir *) kdMalloc ( sizeof ( XMDir ) );
	if ( ret )
	{
		ret->dir_enum = dir.ReadN ( );
		ret->dir_info.d_name = (const KDchar *) kdMalloc ( 256 );
	}
	else
	{
		goto failed;
	}

	return ret;

failed :

	if ( ret )
	{
		kdFree( ret );
		ret = 0;
	}

	xmBadaSetError ( r );

	return ret;
}
コード例 #4
0
char *
xmlMemStrdupLoc(const char *str, const char *file, int line)
{
    char *s;
    KDsize size = kdStrlen(str) + 1;
    MEMHDR *p;

    if (!xmlMemInitialized) xmlInitMemory();
    TEST_POINT

    p = (MEMHDR *) kdMalloc(RESERVE_SIZE+size);
    if (!p) {
      goto error;
    }
    p->mh_tag = MEMTAG;
    p->mh_size = size;
    p->mh_type = STRDUP_TYPE;
    p->mh_file = file;
    p->mh_line = line;
    xmlMutexLock(xmlMemMutex);
    p->mh_number = ++block;
    debugMemSize += size;
    debugMemBlocks++;
    if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
#ifdef MEM_LIST
    debugmem_list_add(p);
#endif
    xmlMutexUnlock(xmlMemMutex);

    s = (char *) HDR_2_CLIENT(p);

    if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();

    if (s != KD_NULL)
      kdStrcpy(s,str);
    else
      goto error;

    TEST_POINT

    if (xmlMemTraceBlockAt == s) {
	xmlGenericError(xmlGenericErrorContext,
			"%p : Strdup() Ok\n", xmlMemTraceBlockAt);
	xmlMallocBreakpoint();
    }

    return(s);

error:
    return(KD_NULL);
}
コード例 #5
0
void XMGPolygon::SetTexture	( const XMGVector2* src_arr_coord, const XMGTexture* texture, XMGTexUnit unit, GLuint src_idx_shape, GLuint src_idx_facet )
{
	XMGRenderImpl*  impl_parent = (XMGRenderImpl *) XMGRender::m_impl;
	XMGTexture*		tex = (XMGTexture *) texture;

	XMGShape*		shape;
	XMGFacet*		facet;

	GLuint			idx_shape;
	GLuint			idx_facet;
	GLuint			idx_vertex;

	GLuint			num_shape;
	GLuint			num_facet;
	GLuint			num_vertex;

	GLuint			off_src;

	XMGVector2X*	arr_coord;

	XMGVector2F		size;

	tex->GetSize ( size );

	off_src = 0;
	for ( impl_parent->RangeArray ( src_idx_shape, impl_parent->m_vec_shape.size ( ), idx_shape, num_shape ); idx_shape < num_shape; idx_shape++ )
	{
		shape = impl_parent->m_vec_shape[ idx_shape ];
		
		for ( impl_parent->RangeArray ( src_idx_facet, shape->m_vec_facet.size ( ), idx_facet, num_facet ); idx_facet < num_facet; idx_facet++ )
		{
			facet = shape->m_vec_facet[ idx_facet ];

			XMGAssert ( arr_coord = (XMGVector2X *) kdMalloc ( sizeof ( XMGVector2X ) * facet->m_num_vertex ) );

			for ( idx_vertex = 0, num_vertex = facet->m_num_vertex; idx_vertex < num_vertex; idx_vertex++ )
			{
				arr_coord[ idx_vertex ].m_x = XMG_F2X ( src_arr_coord[ off_src + idx_vertex ].m_x / size.m_x );
				arr_coord[ idx_vertex ].m_y = XMG_F2X ( src_arr_coord[ off_src + idx_vertex ].m_y / size.m_y );
			}

			SetCoordArray ( arr_coord, unit, idx_shape, idx_facet );
			kdFree ( arr_coord );

			off_src += facet->m_num_vertex;
		}
	}

	XMGRender::SetTexture ( texture, unit, src_idx_shape, src_idx_facet );
	XMGRender::SetDispMode ( XMG_DISP_TEXTURE, src_idx_shape );
}
コード例 #6
0
/* Initializes the OpenGL ES context into a KDWindow */
void initEGL(KDWindow *wnd)
{
    GLbyte *buf = KD_NULL;
    GLbyte *walk;
    KDint i, k;
    const KDint sizes[9] = { 256, 128, 64, 32, 16, 8, 4, 2, 1 };
    const GLubyte rs[9] = { 255, 0, 255, 0, 255, 0, 255, 0, 255 };
    const GLubyte gs[9] = { 0, 0, 255, 0, 0, 255, 0, 0, 255};
    const GLubyte bs[9] = { 0, 255, 0, 255, 0, 255, 0, 255, 0 };

    /* Set the attributes for the window surface */
    static const EGLint s_surfaceAttribs[] =
    {
        EGL_COLORSPACE,		EGL_COLORSPACE_LINEAR,
        EGL_ALPHA_FORMAT,	EGL_ALPHA_FORMAT_NONPRE,
        EGL_NONE
    };
    EGLNativeWindowType nativeType;
    if(kdRealizeWindow(wnd, &nativeType) != 0)
        kdExit(20);

    /* Create a window surface for OpenGL ES */
    GLOBALS->eglWindowSurface	= eglCreateWindowSurface(GLOBALS->eglDisplay, GLOBALS->eglConfig, nativeType, s_surfaceAttribs);

    /* Create a context for OpenGL ES */
#ifndef TEST_LOCKSURFACE
    eglBindAPI (EGL_OPENGL_ES_API);
    GLOBALS->eglContextOpenGLES	= eglCreateContext(GLOBALS->eglDisplay, GLOBALS->eglConfig, KD_NULL, KD_NULL);
    eglMakeCurrent	(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, GLOBALS->eglWindowSurface, GLOBALS->eglContextOpenGLES);
#endif

    /* Generate a texture */
    glGenTextures(1, &GLOBALS->tex);
    glBindTexture(GL_TEXTURE_2D, GLOBALS->tex);

    buf = kdMalloc(sizes[0] * sizes[0] * 3);

    for(k = 0; k < 9; k++)
    {
        walk = buf;
        for(i = 0; i < sizes[k] * sizes[k]; i++)
        {
            *(walk++) = (i % 3 == 0) ? rs[k] : 0;
            *(walk++) = (i % 3 == 0) ? gs[k] : 0;
            *(walk++) = (i % 3 == 0) ? bs[k] : 0;
        }
        glTexImage2D(GL_TEXTURE_2D, k, GL_RGB, sizes[k], sizes[k], 0, GL_RGB, GL_UNSIGNED_BYTE, buf);
    }
    kdFree(buf);
}
コード例 #7
0
KDvoid xmEx_SetTLS ( KDvoid )
{
	XMData*    data = 0;

	data = (XMData *) kdMalloc ( sizeof ( XMData ) );

	kdStrcpy_s ( data->str, 256, "hello" );
	data->val = 100;

	// 
	// 설명 : 쓰레드 로컬 스토리지 데이타 저장
	//
	kdSetTLS ( data );

	kdLogMessagefKHR ( "kdSetTLS : str = '%s', val = %d", data->str, data->val );
}
コード例 #8
0
static void callback_tess_combine ( GLfloat coords[3], GLfloat* vertex_data[4], GLfloat weight[4], GLfloat** data_out, GLvoid* data )
{
	XMGTess*		tess = (XMGTess *) data;
	
	GLfloat*		vertex;
	GLuint			idx;
	
	vertex = (GLfloat *) kdMalloc ( sizeof ( GLfloat ) * 8 );
	
	for ( idx = 0; idx < 3; idx++ )
	{
		vertex[ idx ] = coords[ idx ];
	}
	
	switch ( tess->m_tess_mode )
	{
		case XMG_TESS_COLOR :
			
			for ( idx = 3; idx < 6; idx++ )
			{
				vertex[ idx ] = weight[ 0 ] * vertex_data[ 0 ][ idx ] +
		 						weight[ 1 ] * vertex_data[ 1 ][ idx ] +
								weight[ 2 ] * vertex_data[ 2 ][ idx ] +
								weight[ 3 ] * vertex_data[ 3 ][ idx	];
			}

			break;

		case XMG_TESS_COORD :

			for ( idx = 6; idx < 8; idx++ )
			{
				vertex[ idx ] = weight[ 0 ] * vertex_data[ 0 ][ idx ] +
		 						weight[ 1 ] * vertex_data[ 1 ][ idx ] +
								weight[ 2 ] * vertex_data[ 2 ][ idx ] +
								weight[ 3 ] * vertex_data[ 3 ][ idx	];
			}

			break;
	}

   *data_out = vertex;
}
コード例 #9
0
// kdThreadSemCreate: Create a semaphore. 
KD_API KDThreadSem *KD_APIENTRY kdThreadSemCreate ( KDuint value )
{
	KDThreadSem*    sem = 0;
	
	if ( ( sem = (KDThreadSem *) kdMalloc ( sizeof ( KDThreadSem ) ) ) )
	{
		if ( ( sem_init ( &sem->psem, 0, value ) ) )
		{
			kdSetError ( xmGetErrno ( ) == EINVAL ? KD_EINVAL : KD_ENOSPC );
			kdFree ( sem );
			sem = 0;
		}
	}
	else
	{
		kdSetError ( KD_ENOMEM );
	}		

	return sem;
}
コード例 #10
0
KDvoid xmEventCreate ( KDvoid )
{	
	KD_SET_TLS ( KDTLS );
	KD_GET_TLS ( KDTLS, tls );
	
	tls->xmg_canvas = new XMGCanvas ( );	
	tls->xmg_font   = new XMGFont ( "/res/font/COOPBL.TTF" );	
	tls->xmg_tex[0] = new XMGTexture ( "/res/image/idle.jpg" );
	tls->xmg_tex[1] = new XMGTexture ( "/res/image/menu.jpg" );
	tls->xmg_text   = new XMGText ( );
	tls->xmg_ani    = new XMGAnimate ( );
	tls->xmg_quad   = new XMGQuad ( 1 );
	tls->xmg_morph  = new XMGRender ( 1, g_page_num_vertex );	
	tls->xmg_vertex = (XMGVector3F *) kdMalloc ( sizeof ( XMGVector3F ) * g_page_num_vertex );

	tls->xmg_canvas->ClearColor ( XMGColorF ( 0, 0, 0, 1.0f ) );

	tls->xmg_text->SetFont ( tls->xmg_font );
	tls->xmg_text->SetText ( "XMGraphics : Morphing 2" );
}
コード例 #11
0
// kdThreadAttrCreate : Create a thread attribute object. 
KD_API KDThreadAttr* KD_APIENTRY kdThreadAttrCreate ( KDvoid )
{	
	KDThreadAttr*   attr = 0;

	if ( ( attr = (KDThreadAttr *) kdMalloc ( sizeof ( KDThreadAttr ) ) ) )
	{
		if ( ( pthread_attr_init ( &attr->pattr ) ) )
		{
			kdSetError ( KD_ENOMEM );	
			kdFree ( attr );
			attr = 0;
		}
	}
	else
	{
		kdSetError ( KD_ENOMEM );
	}

	return attr;	
}
コード例 #12
0
JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_kd_KDWindow_CreateWindow
  (JNIEnv *env, jobject obj, jlong display, jintArray jAttrs)
{
    jint * attrs = NULL;
    jsize attrsLen;
    EGLDisplay dpy  = (EGLDisplay)(intptr_t)display;
    KDWindow *window = 0;

    if(dpy==NULL) {
        fprintf(stderr, "[CreateWindow] invalid display connection..\n");
        return 0;
    }

    attrsLen = (*env)->GetArrayLength(env, jAttrs);
    if(0==attrsLen) {
        fprintf(stderr, "[CreateWindow] attribute array size 0..\n");
        return 0;
    }
    attrs = (*env)->GetIntArrayElements(env, jAttrs, 0);
    if(NULL==attrs) {
        fprintf(stderr, "[CreateWindow] attribute array NULL..\n");
        return 0;
    }

    JOGLKDUserdata * userData = kdMalloc(sizeof(JOGLKDUserdata));
    userData->magic = JOGL_KD_USERDATA_MAGIC;
    window = kdCreateWindow(dpy, attrs, (void *)userData);

    (*env)->ReleaseIntArrayElements(env, jAttrs, attrs, 0);

    if(NULL==window) {
        kdFree(userData);
        fprintf(stderr, "[CreateWindow] failed: 0x%X\n", kdGetError());
    } else {
        userData->javaWindow = (*env)->NewGlobalRef(env, obj);
        userData->kdWindow = window;
        (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) userData);
        DBG_PRINT( "[CreateWindow] ok: %p, userdata %p\n", window, userData);
    }
    return (jlong) (intptr_t) window;
}
コード例 #13
0
// kdThreadMutexCreate : Create a mutex.
KD_API KDThreadMutex* KD_APIENTRY kdThreadMutexCreate ( const KDvoid* mutexattr )
{
	pthread_mutex_t pmutex = PTHREAD_MUTEX_INITIALIZER;
	KDThreadMutex*  mutex  = 0;	
	KDint           ret	   = 0;	
	
	if ( ( mutex = (KDThreadMutex *) kdMalloc ( sizeof ( KDThreadMutex ) ) ) )
	{
		kdMemcpy ( &mutex->pmutex, &pmutex, sizeof ( pthread_mutex_t ) );

		if ( ( ret = pthread_mutex_init ( &mutex->pmutex, (const pthread_mutexattr_t *) mutexattr ) ) )
		{
			kdSetError ( ret == ENOMEM ? KD_ENOMEM : KD_EAGAIN );
			kdFree ( mutex );
			mutex = 0;
		}
	}
	else
	{
		kdSetError ( KD_ENOMEM );
	}	
	
	return mutex;	
}
コード例 #14
0
// kdThreadCondCreate : Create a condition variable.
KD_API KDThreadCond* KD_APIENTRY kdThreadCondCreate ( const KDvoid* attr )
{
	pthread_cond_t  pcond = PTHREAD_COND_INITIALIZER;
	KDThreadCond*   cond  = 0;
	KDint           ret	  = 0;	

	if ( ( cond = (KDThreadCond *) kdMalloc ( sizeof ( KDThreadCond ) ) ) )
	{
		kdMemcpy ( &cond->pcond, &pcond, sizeof ( pthread_cond_t ) );

		if ( ( ret = pthread_cond_init ( &cond->pcond, (const pthread_condattr_t *) attr) ) )
		{
			kdSetError ( ret == ENOMEM ? KD_ENOMEM : KD_EAGAIN );
			kdFree ( cond );
			cond = 0;
		}
	}
	else
	{
		kdSetError ( KD_ENOMEM );
	}

	return cond;
}
コード例 #15
0
KDvoid AWTextureFilter::blurInput ( KDvoid* pInput, KDvoid* pOutput, CCTexture2DPixelFormat eFormat, const CCSize& tContentSize, KDint nRadius, const CCRect tRect )
{
    KDint			i, xl, yl, yi, ym, ri, riw;
	KDint			cx = (KDint) tContentSize.cx;
	KDint			cy = (KDint) tContentSize.cy;
	KDint			w  = (KDint) ( tRect.size.cx );
	KDint			h  = (KDint) ( tRect.size.cy );
//	const KDint		wh = (KDint) ( tContentSize.cx * tContentSize.cy );
	KDint			nRead;

	w = ( w == 0 ) ? cx : w;
	h = ( h == 0 ) ? cy : h;
	
	// Check data
	KDint			px = KD_MAX ( 0, (KDint) tRect.origin.x );
	KDint			py = KD_MAX ( 0, (KDint) tRect.origin.y );
    w = px + w - KD_MAX ( 0, ( px + w ) - cx );
	h = py + h - KD_MAX ( 0, ( py + h ) - cy );
    yi = py * cx;
	
	// Generate Gaussian kernel
    nRadius = KD_MIN ( KD_MAX ( 1, nRadius ), 248 );
    KDint	nKernelSize = 1 + nRadius * 2;
    KDint*	pKernel = new KDint [ nKernelSize ];	
    KDint	g = 0, nSum = 0;
	
	// Gaussian filter	
    for ( i = 0; i < nRadius; i++ )
	{
		g = i * i * i + 1;
		pKernel [ i ] = pKernel [ nKernelSize - i - 1 ] = g;
		nSum += g * 2;
    }
	g = nRadius * nRadius;
    pKernel [ nRadius ] = g;
    nSum += g;

	if ( eFormat == kCCTexture2DPixelFormat_RGBA8888 )
	{
		KDint				cr, cg, cb, ca;

		const ccColor4B*	pOriginalData = (ccColor4B*) pInput;
		ccColor4B*			pData = (ccColor4B*) pOutput;
		ccColor4B*			pTemp = (ccColor4B*) kdMalloc ( cx * cy * 4 );
		ccColor4B*			pPixel;
		
		// Horizontal blur
		for ( yl = py; yl < h; yl++ )
		{
			for ( xl = px; xl < w; xl++ )
			{
				cb = cg = cr = ca = 0; 
				ri = xl - nRadius;

				for ( i = 0; i < nKernelSize; i++ )
				{
					nRead = ri + i;
					if ( nRead >= px && nRead < w )
					{
						nRead += yi;
						pPixel = (ccColor4B*) &pOriginalData [ nRead ];
						cr += pPixel->r * pKernel [ i ];
						cg += pPixel->g * pKernel [ i ];
						cb += pPixel->b * pKernel [ i ];
						ca += pPixel->a * pKernel [ i ];
					}
				}

				ri = yi + xl;
				pPixel = &pTemp [ ri ];
				pPixel->r = cr / nSum;
				pPixel->g = cg / nSum;
				pPixel->b = cb / nSum;
				pPixel->a = ca / nSum;
			}
			yi += cx;
		}
		yi = py * cx;
		
		// Vertical blur
		for ( yl = py; yl < h; yl++ )
		{
			ym = yl - nRadius;
			riw = ym * cx;
			for ( xl = px; xl < w; xl++ )
			{
				cb = cg = cr = ca = 0;
				ri = ym;
				nRead = xl + riw;
				for ( i = 0; i < nKernelSize; i++ )
				{
					if ( ri < h && ri >= py )
					{
						pPixel = &pTemp [ nRead ];
						cr += pPixel->r * pKernel [ i ];
						cg += pPixel->g * pKernel [ i ];
						cb += pPixel->b * pKernel [ i ];
						ca += pPixel->a * pKernel [ i ];
					}
					ri++;
					nRead += cx;
				}
				pPixel = &pData [ xl + yi ];
				pPixel->r = cr / nSum;
				pPixel->g = cg / nSum;
				pPixel->b = cb / nSum;
				pPixel->a = ca / nSum;
			}
			yi += cx;
		}

		// Free temp data
		kdFree ( pTemp );		
	}
	else if ( eFormat == kCCTexture2DPixelFormat_A8 )
	{
		KDint		ca;

		const KDubyte*	pOriginalData = (const KDubyte*) pInput;
		KDubyte*		pData = (KDubyte*) pOutput;
		KDubyte*		pTemp = (KDubyte*) kdMalloc ( cx * cy );
		
		// Horizontal blur
		for ( yl = py; yl < h; yl++ )
		{
			for ( xl = px; xl < w; xl++ )
			{
				ca = 0;
				ri = xl - nRadius;
				for ( i = 0; i < nKernelSize; i++ )
				{
					nRead = ri + i;
					if ( nRead >= px && nRead < w )
					{
						nRead += yi;
						ca += pOriginalData [ nRead ] * pKernel [ i ];
					}
				}
				ri = yi + xl;
				pTemp [ ri ] = ca / nSum;
			}
			yi += cx;
		}
		yi = py * cx;
		
		// Vertical blur
		for ( yl = py; yl < h; yl++ )
		{
			ym = yl - nRadius;
			riw = ym * cx;
			for ( xl = px; xl < w; xl++ )
			{
				ca = 0;
				ri = ym;
				nRead = xl + riw;
				for ( i = 0; i < nKernelSize; i++ )
				{
					if ( ri < h && ri >= py )
					{
						ca += pTemp [ nRead ] * pKernel [ i ];
					}
						
					ri++;
					nRead += cx;
				}
				pData [ xl + yi ] = ca / nSum;
			}
			yi += cx;
		}
		
		// Free temp data
		kdFree ( pTemp );		
	}
	else
	{
		CCAssert ( KD_FALSE, "AWTextureFilter : Pixel format don't supported. It should be RGBA8888 or A8" );
	}

	delete [] pKernel;
}
コード例 #16
0
KDint ZipUtils::ccInflateGZipFile ( const KDchar* szFilePath, KDubyte** ppDst )
{
	KDint   nLen;
	KDuint  uOffset = 0;

	CCAssert ( ppDst  , "" );
	CCAssert ( &*ppDst, "" );

	gzFile  pGzFile = gzopen ( szFilePath, "rb" );
	if ( pGzFile == KD_NULL ) 
	{
		//CCLOG ( "XMCocos2D : ZipUtils - error open gzip file : %s", szFilePath );
		return -1;
	}

	// 512k initial decompress buffer 
	KDuint  uBufferSize = 512 * 1024;
	KDuint  uTotalBufferSize = uBufferSize;

	*ppDst = (KDubyte *) kdMalloc ( uBufferSize );
	if ( !ppDst ) 
	{
		CCLOG ( "XMCocos2D : ZipUtils - out of memory");
		return -1;
	}

	for ( ; ; ) 
	{
		nLen = gzread ( pGzFile, *ppDst + uOffset, uBufferSize );
		if ( nLen < 0 ) 
		{
			// CCLOG ( "XMCocos2D : ZipUtils - error in gzread" );
			kdFree ( *ppDst );
			*ppDst = KD_NULL;
			return -1;
		}
		if ( nLen == 0 )
		{
			break;
		}

		uOffset += nLen;

		// finish reading the file
		if ( (KDuint) nLen < uBufferSize )
		{
			break;
		}

		uBufferSize *= BUFFER_INC_FACTOR;
		uTotalBufferSize += uBufferSize;
		KDubyte*  pTemp = (KDubyte *) kdRealloc ( *ppDst, uTotalBufferSize );

		if ( !pTemp ) 
		{
			CCLOG ( "XMCocos2D : ZipUtils - out of memory" );
			kdFree ( *ppDst );
			*ppDst = KD_NULL;
			return -1;
		}

		*ppDst = pTemp;
	}

	if ( gzclose ( pGzFile ) != Z_OK )
	{
		CCLOG ( "XMCocos2D : ZipUtils - gzclose failed" );
	}

	return uOffset;
}
コード例 #17
0
ファイル: kd_dxtcomp.c プロジェクト: h-s-c/libKD
KD_API KDImageATX KD_APIENTRY kdDXTCompressBufferATX(const void *buffer, KDint32 width, KDint32 height, KDint32 comptype, KDint32 levels)
{
    _KDImageATX *image = (_KDImageATX *)kdMalloc(sizeof(_KDImageATX));
    if(image == KD_NULL)
    {
        kdSetError(KD_ENOMEM);
        return KD_NULL;
    }
    image->levels = levels;
    image->width = width;
    image->height = height;

    switch(comptype)
    {
        case(KD_DXTCOMP_TYPE_DXT1_ATX):
        {
            image->format = KD_IMAGE_FORMAT_DXT1_ATX;
            image->alpha = KD_FALSE;
            break;
        }
        case(KD_DXTCOMP_TYPE_DXT1A_ATX):
        {
            kdFree(image);
            kdSetError(KD_EINVAL);
            return KD_NULL;
        }
        case(KD_DXTCOMP_TYPE_DXT3_ATX):
        {
            kdFree(image);
            kdSetError(KD_EINVAL);
            return KD_NULL;
        }
        case(KD_DXTCOMP_TYPE_DXT5_ATX):
        {
            image->format = KD_IMAGE_FORMAT_DXT5_ATX;
            image->alpha = KD_TRUE;
            break;
        }
        default:
        {
            kdFree(image);
            kdSetError(KD_EINVAL);
            return KD_NULL;
        }
    }
    image->bpp = image->alpha ? 16 : 8;
    image->size = (KDsize)image->width * (KDsize)image->height * (KDsize)(image->bpp / 8);

    KDint _width = image->width;
    KDint _height = image->height;
    for(KDint i = 0; i < image->levels; i++)
    {
        _width >>= 1;
        _height >>= 1;
        image->size += (KDsize)_width * (KDsize)_height * (KDsize)(image->bpp / 8);
    }

    image->buffer = kdMalloc(image->size);
    if(image->buffer == KD_NULL)
    {
        kdFree(image);
        kdSetError(KD_ENOMEM);
        return KD_NULL;
    }

    _width = image->width;
    _height = image->height;
    KDint channels = (image->alpha ? 4 : 3);
    for(KDint i = 0; i <= image->levels; i++)
    {
        KDsize size = (KDsize)_width * (KDsize)_height * (KDsize)channels;
        if(size)
        {
            void *tmp = kdMalloc(size);
            if((_width == image->width) && (_height == image->height))
            {
                kdMemcpy(tmp, buffer, size);
            }
            else
            {
                stbir_resize_uint8(buffer, image->width, image->height, 0, tmp, _width, _height, 0, channels);
            }
            for(KDint y = 0; y < _height; y += 4)
            {
                for(KDint x = 0; x < _width; x += 4)
                {
                    KDuint8 block[64];
                    __kdExtractBlock(tmp, x, y, _width, _height, block);
                    stb_compress_dxt_block(image->buffer, block, image->alpha, STB_DXT_NORMAL);
                    image->buffer += image->bpp;
                }
            }
            kdFree(tmp);
        }
        _width >>= 1;
        _height >>= 1;
    }

    return image;
}
コード例 #18
0
void Grid3D::calculateVertexPoints(void)
{
    float width = (float)m_pTexture->getPixelsWide();
    float height = (float)m_pTexture->getPixelsHigh();
    float imageH = m_pTexture->getContentSizeInPixels().height;

    int x, y, i;
    CC_SAFE_FREE(m_pVertices);
    CC_SAFE_FREE(m_pOriginalVertices);
    CC_SAFE_FREE(m_pTexCoordinates);
    CC_SAFE_FREE(m_pIndices);

    unsigned int numOfPoints = (m_tGridSize.width+1) * (m_tGridSize.height+1);

    m_pVertices = kdMalloc(numOfPoints * sizeof(Vertex3F));
    m_pOriginalVertices = kdMalloc(numOfPoints * sizeof(Vertex3F));
    m_pTexCoordinates = kdMalloc(numOfPoints * sizeof(Vertex2F));
    m_pIndices = (GLushort*) kdMalloc(m_tGridSize.width * m_tGridSize.height * sizeof(GLushort) * 6);

    GLfloat *vertArray = (GLfloat*)m_pVertices;
    GLfloat *texArray = (GLfloat*)m_pTexCoordinates;
    GLushort *idxArray = m_pIndices;

    for (x = 0; x < m_tGridSize.width; ++x)
    {
        for (y = 0; y < m_tGridSize.height; ++y)
        {
            int idx = (y * m_tGridSize.width) + x;

            GLfloat x1 = x * m_tStep.x;
            GLfloat x2 = x1 + m_tStep.x;
            GLfloat y1 = y * m_tStep.y;
            GLfloat y2= y1 + m_tStep.y;

            GLushort a = (GLushort)(x * (m_tGridSize.height + 1) + y);
            GLushort b = (GLushort)((x + 1) * (m_tGridSize.height + 1) + y);
            GLushort c = (GLushort)((x + 1) * (m_tGridSize.height + 1) + (y + 1));
            GLushort d = (GLushort)(x * (m_tGridSize.height + 1) + (y + 1));

            GLushort tempidx[6] = {a, b, d, b, c, d};

            memcpy(&idxArray[6*idx], tempidx, 6*sizeof(GLushort));

            int l1[4] = {a*3, b*3, c*3, d*3};
            Vertex3F e(x1, y1, 0);
            Vertex3F f(x2, y1, 0);
            Vertex3F g(x2, y2, 0);
            Vertex3F h(x1, y2, 0);

            Vertex3F l2[4] = {e, f, g, h};

            int tex1[4] = {a*2, b*2, c*2, d*2};
            Point Tex2F[4] = {Point(x1, y1), Point(x2, y1), Point(x2, y2), Point(x1, y2)};

            for (i = 0; i < 4; ++i)
            {
                vertArray[l1[i]] = l2[i].x;
                vertArray[l1[i] + 1] = l2[i].y;
                vertArray[l1[i] + 2] = l2[i].z;

                texArray[tex1[i]] = Tex2F[i].x / width;
                if (m_bIsTextureFlipped)
                {
                    texArray[tex1[i] + 1] = (imageH - Tex2F[i].y) / height;
                }
                else
                {
                    texArray[tex1[i] + 1] = Tex2F[i].y / height;
                }
            }
        }
    }

    memcpy(m_pOriginalVertices, m_pVertices, (m_tGridSize.width+1) * (m_tGridSize.height+1) * sizeof(Vertex3F));
}
コード例 #19
0
KDint ZipUtils::ccInflateCCZFile ( const KDchar* szFilePath, KDubyte** ppDst )
{
	CCAssert ( ppDst  , "" );
	CCAssert ( &*ppDst, "" );

	// load file into memory
	KDubyte*  pCompressed = KD_NULL;
        
    KDint  nLenFile = 0;
    pCompressed = CCFileUtils::sharedFileUtils ( )->getFileData ( szFilePath, "rb", (KDsize *) ( &nLenFile ) );

	if ( KD_NULL == pCompressed || nLenFile == 0 ) 
	{
		//CCLOG ( "XMCocos2D : Error loading CCZ compressed file" );
        return -1;
	}
 
	struct CCZHeader*  pHeader = (struct CCZHeader*) pCompressed;

	// verify header
	if ( pHeader->sig[0] != 'C' || pHeader->sig[1] != 'C' || pHeader->sig[2] != 'Z' || pHeader->sig[3] != '!' ) 
	{
		// CCLOG ( "XMCocos2D : Invalid CCZ file" );
		CC_SAFE_DELETE_ARRAY ( pCompressed );
		return -1;
	}
 
	// verify header version
	KDuint  uVersion = CC_SWAP_INT16_BIG_TO_HOST ( pHeader->version );
	if ( uVersion > 2 ) 
	{
		CCLOG ( "XMCocos2D : Unsupported CCZ header format" );
		CC_SAFE_DELETE_ARRAY ( pCompressed );
		return -1;
	}
 
	// verify compression format
	if ( CC_SWAP_INT16_BIG_TO_HOST ( pHeader->compression_type ) != CCZ_COMPRESSION_ZLIB ) 
	{
		CCLOG ( "XMCocos2D : CCZ Unsupported compression method" );
		CC_SAFE_DELETE_ARRAY ( pCompressed );
		return -1;
	}

	KDuint  uLen = CC_SWAP_INT32_BIG_TO_HOST ( pHeader->len );
 
	*ppDst = (KDubyte*) kdMalloc ( uLen );
	if ( !*ppDst )
	{
		CCLOG ( "XMCocos2D : CCZ - Failed to allocate memory for texture" );
		CC_SAFE_DELETE_ARRAY ( pCompressed );
		return -1;
	}

	KDsize  uLenDst = uLen;
	KDsize  uSizeSrc = (KDsize) pCompressed + sizeof ( *pHeader );
	KDint   nRet = uncompress ( *ppDst, (uLongf *) &uLenDst, (Bytef *) uSizeSrc, nLenFile - sizeof ( *pHeader ) );

	CC_SAFE_DELETE_ARRAY ( pCompressed );

	if ( nRet != Z_OK )
	{
		CCLOG ( "XMCocos2D : CCZ - Failed to uncompress data" );
		CC_SAFE_FREE ( *ppDst );
		return -1;
	}

	return uLen;
}
コード例 #20
0
void TiledGrid3D::calculateVertexPoints(void)
{
    float width = (float)m_pTexture->getPixelsWide();
    float height = (float)m_pTexture->getPixelsHigh();
    float imageH = m_pTexture->getContentSizeInPixels().height;
    
    int numQuads = m_tGridSize.width * m_tGridSize.height;
    CC_SAFE_FREE(m_pVertices);
    CC_SAFE_FREE(m_pOriginalVertices);
    CC_SAFE_FREE(m_pTexCoordinates);
    CC_SAFE_FREE(m_pIndices);

    m_pVertices = kdMalloc(numQuads*4*sizeof(Vertex3F));
    m_pOriginalVertices = kdMalloc(numQuads*4*sizeof(Vertex3F));
    m_pTexCoordinates = kdMalloc(numQuads*4*sizeof(Vertex2F));
    m_pIndices = (GLushort*) kdMalloc(numQuads*6*sizeof(GLushort));

    GLfloat *vertArray = (GLfloat*)m_pVertices;
    GLfloat *texArray = (GLfloat*)m_pTexCoordinates;
    GLushort *idxArray = m_pIndices;
    
    int x, y;
    
    for( x = 0; x < m_tGridSize.width; x++ )
    {
        for( y = 0; y < m_tGridSize.height; y++ )
        {
            float x1 = x * m_tStep.x;
            float x2 = x1 + m_tStep.x;
            float y1 = y * m_tStep.y;
            float y2 = y1 + m_tStep.y;
            
            *vertArray++ = x1;
            *vertArray++ = y1;
            *vertArray++ = 0;
            *vertArray++ = x2;
            *vertArray++ = y1;
            *vertArray++ = 0;
            *vertArray++ = x1;
            *vertArray++ = y2;
            *vertArray++ = 0;
            *vertArray++ = x2;
            *vertArray++ = y2;
            *vertArray++ = 0;
            
            float newY1 = y1;
            float newY2 = y2;
            
            if (m_bIsTextureFlipped) 
            {
                newY1 = imageH - y1;
                newY2 = imageH - y2;
            }

            *texArray++ = x1 / width;
            *texArray++ = newY1 / height;
            *texArray++ = x2 / width;
            *texArray++ = newY1 / height;
            *texArray++ = x1 / width;
            *texArray++ = newY2 / height;
            *texArray++ = x2 / width;
            *texArray++ = newY2 / height;
        }
    }
    
    for (x = 0; x < numQuads; x++)
    {
        idxArray[x*6+0] = (GLushort)(x * 4 + 0);
        idxArray[x*6+1] = (GLushort)(x * 4 + 1);
        idxArray[x*6+2] = (GLushort)(x * 4 + 2);
        
        idxArray[x*6+3] = (GLushort)(x * 4 + 1);
        idxArray[x*6+4] = (GLushort)(x * 4 + 2);
        idxArray[x*6+5] = (GLushort)(x * 4 + 3);
    }
    
    memcpy(m_pOriginalVertices, m_pVertices, numQuads * 12 * sizeof(GLfloat));
}
コード例 #21
0
void XMGPolygon::SetCoordArray ( const XMGVector2X* src_arr_coord, XMGTexUnit unit, GLuint src_idx_shape, GLuint src_idx_facet )
{
	XMGPolygonImpl*	impl = (XMGPolygonImpl *) m_impl;
	XMGRenderImpl*  impl_parent = (XMGRenderImpl *) XMGRender::m_impl;

	XMGTess*		data;

	XMGShape*		shape;
	XMGFacet*		facet;

	GLuint			idx_tess;
	GLuint			idx_shape;
	GLuint			idx_facet;
	GLuint			idx_vertex;

	GLuint			num_shape;
	GLuint			num_facet;
	GLuint			num_vertex;

	GLuint			off_src;

	XMGVector2F*	farr_coord;
	XMGVector2X*	xarr_coord;

	XMGRender::SetCoordArray ( src_arr_coord, unit, src_idx_shape, src_idx_facet );	

	if ( impl_parent->m_has_face[ 0 ] == XMG_FALSE && impl_parent->m_has_face[ 1 ] )
	{
		return;
	}

	if ( src_idx_facet != XMG_FACET_ALL )
	{
		shape = impl_parent->m_vec_shape[ src_idx_facet ];
		facet = shape->m_vec_facet[ src_idx_facet ];
		if ( facet->m_vec_contour.size ( ) == 0 )
		{
			return;
		}
	}

	off_src = 0;
	for ( impl_parent->RangeArray ( src_idx_shape, impl_parent->m_vec_shape.size ( ), idx_shape, num_shape ); idx_shape < num_shape; idx_shape++ )
	{
		shape = impl_parent->m_vec_shape[ idx_shape ];
		
		for ( impl_parent->RangeArray ( src_idx_facet, shape->m_vec_facet.size ( ), idx_facet, num_facet ); idx_facet < num_facet; idx_facet++ )
		{
			facet = shape->m_vec_facet[ idx_facet ];

			if ( idx_facet < 2 )
			{
				switch ( impl_parent->m_geo_type )
				{
					case XMG_GEO_CONE	:
					case XMG_GEO_CWALL	:	idx_tess = 1;			break;
					default				:	idx_tess = idx_facet;	break;
				}

				if ( impl->m_tess[ idx_tess ] )
				{
					data = impl->m_data[ idx_tess ][ idx_shape ];
					data->Init ( XMG_TESS_COORD );

					gluTessBeginPolygon ( impl->m_tess[ idx_tess ], (GLvoid *) data );
					gluTessBeginContour ( impl->m_tess[ idx_tess ] );	

					for ( idx_vertex = 0, num_vertex = shape->m_num_basic; idx_vertex < num_vertex; idx_vertex++ )
					{
						data->m_arr_vertex[ idx_vertex * 8 + 6 ] = XMG_X2F ( src_arr_coord[ off_src + idx_vertex ].m_x );
						data->m_arr_vertex[ idx_vertex * 8 + 7 ] = XMG_X2F ( src_arr_coord[ off_src + idx_vertex ].m_y );

						if ( shape->m_idx_hole != 0 && shape->m_idx_hole == idx_vertex )
						{
							gluNextContour ( impl->m_tess[ idx_tess ], GLU_INTERIOR );
						}

						gluTessVertex ( impl->m_tess[ idx_tess ], &data->m_arr_vertex[ idx_vertex * 8 ], &data->m_arr_vertex[ idx_vertex * 8 ] );
					}

					gluTessEndContour ( impl->m_tess[ idx_tess ] );
					gluTessEndPolygon ( impl->m_tess[ idx_tess ] );

					if ( impl_parent->m_type_coords[ unit ] == XMG_TYPE_FLOAT )
					{
						XMGAssert ( farr_coord = (XMGVector2F *) kdMalloc ( sizeof ( XMGVector2F ) * facet->m_num_ext ) );

						for ( idx_vertex = 0, num_vertex = facet->m_num_ext; idx_vertex < num_vertex; idx_vertex++ )
						{
							farr_coord[ idx_vertex ] = data->m_vec_coord[ idx_vertex ];
						}

						impl_parent->SetBuffer ( impl_parent->m_id_coords[ unit ], farr_coord, sizeof ( XMGVector2F ) * facet->m_off_ext, sizeof ( XMGVector2F ) * facet->m_num_ext );
						kdFree ( farr_coord );
					}
					else
					{
						XMGAssert ( xarr_coord = (XMGVector2X *) kdMalloc ( sizeof ( XMGVector2X ) * facet->m_num_ext ) );

						for ( idx_vertex = 0, num_vertex = facet->m_num_ext; idx_vertex < num_vertex; idx_vertex++ )
						{
							xarr_coord[ idx_vertex ] = data->m_vec_coord[ idx_vertex ];
						}

						impl_parent->SetBuffer ( impl_parent->m_id_coords[ unit ], xarr_coord, sizeof ( XMGVector2X ) * facet->m_off_ext, sizeof ( XMGVector2X ) * facet->m_num_ext );
						kdFree ( xarr_coord );
					}
				}			
			}

			off_src += facet->m_num_vertex;
		}
	}
}
コード例 #22
0
KDvoid xmExample_05 ( KDvoid )
{	
	const KDsize size[3] = { 1000, 100, 10000 };

	KDvoid*	    buf;
	KDint       i;
	
	kdLogMessage ( "Example 05. Memory allocation\n\n" );

	//
	// Case 1 : kdMalloc 
	//

	// 메모리 블럭을 할당한다.
	buf = kdMalloc ( size[ 0 ] );

	// 메모리 블럭 할당이 정상적인지 확인한다.
	if ( buf != KD_NULL )
	{
		kdLogMessage ( "Case 1 : Memory block is allocated." );
	}
	else
	{
		// 메모리 블럭 할당 문제가 무엇인지 확인한다.
		if ( kdGetError ( ) == KD_ENOMEM )
		{
			kdLogMessage ( "Case 1 : Not enough space." );
		}
		else
		{
			kdHandleAssertion ( "kdMalloc", __FILE__, __LINE__ );
		}
	}

	//
	// Case 2 : kdRealloc 
	//

	// 할당된 메모리 블럭 사이즈를 줄여다가 다시 크게한다.
	for ( i = 1; i < 3; i++ )
	{
		// 메모리 블럭을 리사이즈합니다.
		buf = kdRealloc ( buf, size[i] );

		// 메모리 블럭 리사이즈가 정상인지 확인한다.
		if ( buf != KD_NULL )
		{
			kdLogMessage ( "Case 2 : Memory block is resized." );
		}
		else
		{
			// 메모리 블럭 리사이즈 문제가 무엇인지 확인한다.
			if ( kdGetError ( ) == KD_ENOMEM )
			{
				kdLogMessage ( "Case 2 : Not enough space." );
			}
			else
			{
				kdHandleAssertion ( "kdRealloc", __FILE__, __LINE__);
			}
		}
	}

	//
	// Case 3 : kdFree 
	//

	// 메모리 블럭 해제한다.
	kdFree ( buf );
	kdLogMessage ( "Case 3 : Allocated memory block is freed." );
}
コード例 #23
0
void XMGPolygon::SetVertexArray ( const XMGVector3X* src_arr_vertex, const GLuint* arr_idx_hole )
{
	XMGPolygonImpl*	impl = (XMGPolygonImpl *) m_impl;
	XMGRenderImpl*  impl_parent = (XMGRenderImpl *) XMGRender::m_impl;

	XMGTess*		data[2];
	XMGShape*		shape;
	XMGFacet*		facet;
	XMGContour*		contour;

	GLuint			idx_tess;
	GLuint			idx_shape;
	GLuint			idx_facet;
	GLuint			idx_vertex;
	GLuint			idx_vec;
	
	GLuint			num_shape;
	GLuint			num_vertex;
	GLuint			num_vec;

	GLuint			off_vertex;
	GLuint			off_ext;

	XMGVector3X		src_vertex;
	XMGVector3X*	arr_vertex;

	off_vertex = 0;
	off_ext = impl_parent->m_num_vertex;
	impl_parent->m_ext_vertex = 0;
	for ( idx_shape = 0, num_shape = impl_parent->m_vec_shape.size ( ); idx_shape < num_shape; idx_shape++ )
	{
		shape = impl_parent->m_vec_shape[ idx_shape ];
		shape->m_idx_hole = arr_idx_hole ? arr_idx_hole[ idx_shape ] : XMG_HOLE_NULL;

		// Set tess vertices
		if ( impl->m_tess[ 0 ] || impl->m_tess[ 1 ] )
		{
			for ( idx_tess = 0; idx_tess < 2; idx_tess++ )
			{
				if ( impl->m_tess[ idx_tess ] )
				{
					data[ idx_tess ] = impl->m_data[ idx_tess ][ idx_shape ];
					data[ idx_tess ]->Init ( XMG_TESS_VERTEX );

					gluTessBeginPolygon ( impl->m_tess[ idx_tess ], (GLvoid *) data[ idx_tess ] );
					gluTessBeginContour ( impl->m_tess[ idx_tess ] );	
				}
			}

			for ( idx_vertex = 0, num_vertex = shape->m_num_basic; idx_vertex < num_vertex; idx_vertex++ )
			{
				for ( idx_tess = 0; idx_tess < 2; idx_tess++ )
				{
					if ( idx_tess == 0 )
					{
						if ( impl->m_tess[ idx_tess ] )
						{
							src_vertex = src_arr_vertex[ off_vertex + idx_vertex ];
						}
						else
						{
							continue;
						}
					}
					else if ( idx_tess == 1 )
					{
						if ( impl->m_tess[ idx_tess ] )
						{
							switch ( impl_parent->m_geo_type )
							{
								case XMG_GEO_SOLID :

									src_vertex = src_arr_vertex[ off_vertex + num_vertex + idx_vertex ];

									break;

								case XMG_GEO_BSOLID :

									if ( shape->m_idx_hole )
									{
										src_vertex = src_arr_vertex[ idx_vertex < shape->m_idx_hole ? shape->m_idx_hole - idx_vertex - 1 : num_vertex + shape->m_idx_hole - idx_vertex - 1 ];
									}
									else
									{				
										src_vertex = src_arr_vertex[ num_vertex - idx_vertex - 1 ];
									}

									src_vertex.m_z = 0;

									break;
							}							
						}
						else
						{
							continue;
						}
					}

					data[ idx_tess ]->m_arr_vertex[ idx_vertex * 8 + 0 ] = XMG_X2F ( src_vertex.m_x );
					data[ idx_tess ]->m_arr_vertex[ idx_vertex * 8 + 1 ] = XMG_X2F ( src_vertex.m_y );
					data[ idx_tess ]->m_arr_vertex[ idx_vertex * 8 + 2 ] = XMG_X2F ( src_vertex.m_z );	

					if ( shape->m_idx_hole != 0 && shape->m_idx_hole == idx_vertex )
					{
						gluNextContour ( impl->m_tess[ idx_tess ], GLU_INTERIOR );
					}

					gluTessVertex ( impl->m_tess[ idx_tess ], &data[ idx_tess ]->m_arr_vertex[ idx_vertex * 8 ], &data[ idx_tess ]->m_arr_vertex[ idx_vertex * 8 ] );
				}				
			}

			idx_facet = 0;
			for ( idx_tess = 0; idx_tess < 2; idx_tess++ )
			{
				if ( impl->m_tess[ idx_tess ] )
				{
					gluTessEndContour ( impl->m_tess[ idx_tess ] );	
					gluTessEndPolygon ( impl->m_tess[ idx_tess ] );	

					// Set contours with original
					facet = shape->m_vec_facet[ idx_facet ];
					facet->ClearContour ( );

					if ( shape->m_idx_hole == XMG_HOLE_NULL )
					{
						XMGAssert ( contour = new XMGContour ( ) );

						contour->m_draw_limit = XMG_LIMIT_LINE;
						contour->m_off_vertex = facet->m_off_vertex;
						contour->m_num_vertex = facet->m_num_vertex;

						facet->m_vec_contour.push_back ( contour );
					}
					else
					{
						XMGAssert ( contour = new XMGContour ( ) );

						contour->m_draw_limit = XMG_LIMIT_LINE;
						contour->m_off_vertex = facet->m_off_vertex;
						contour->m_num_vertex = shape->m_idx_hole;						
						
						facet->m_vec_contour.push_back ( contour );

						XMGAssert ( contour = new XMGContour ( ) );

						contour->m_draw_limit = XMG_LIMIT_LINE;
						contour->m_off_vertex = facet->m_off_vertex + shape->m_idx_hole;
						contour->m_num_vertex = facet->m_num_vertex - shape->m_idx_hole;
						
						facet->m_vec_contour.push_back ( contour );
					}
					
					// Set contours with tessed
					facet->m_off_ext = off_ext;
					for ( idx_vec = 0, num_vec = data[ idx_tess ]->m_vec_num_vertex.size ( ); idx_vec < num_vec; idx_vec++ )
					{
						XMGAssert ( contour = new XMGContour ( ) );
						
						contour->m_draw_limit = XMG_LIMIT_TRI;
						contour->m_disp_mode  = data[ idx_tess ]->m_vec_mode[ idx_vec ];
						contour->m_off_vertex = off_ext;
						contour->m_num_vertex = data[ idx_tess ]->m_vec_num_vertex[ idx_vec ];	

						facet->m_vec_contour.push_back ( contour );
						off_ext += contour->m_num_vertex;
					}
					
					idx_facet++;
					facet->m_num_ext = data[ idx_tess ]->m_vec_vertex.size ( );
					impl_parent->m_ext_vertex += facet->m_num_ext;
				}
			}
		}

		off_vertex += shape->m_num_input;
	}

	XMGRender::SetVertexArray ( src_arr_vertex, XMG_SHAPE_ALL );

	if ( impl->m_tess[ 0 ] || impl->m_tess[ 1 ] )
	{
		off_vertex = 0;
		num_vertex = impl_parent->m_ext_vertex;
		XMGAssert ( arr_vertex = (XMGVector3X *) kdMalloc ( sizeof ( XMGVector3X ) * num_vertex ) );

		for ( idx_shape = 0, num_shape = impl_parent->m_vec_shape.size ( ); idx_shape < num_shape; idx_shape++ )
		{
			for ( idx_tess = 0; idx_tess < 2; idx_tess++ )
			{
				if ( impl->m_tess[ idx_tess ] )
				{
					data[ idx_tess ] = impl->m_data[ idx_tess ][ idx_shape ];
					for ( idx_vertex = 0, num_vertex = data[ idx_tess ]->m_vec_vertex.size ( ); idx_vertex < num_vertex; idx_vertex++ )
					{
						arr_vertex[ off_vertex ] = data[ idx_tess ]->m_vec_vertex[ idx_vertex ];
						off_vertex++;
					}
					data[ idx_tess ]->ClearVector ( );
				}
			}
		}

		impl_parent->SetBuffer ( impl_parent->m_id_vertex, arr_vertex, sizeof ( XMGVector3X ) * impl_parent->m_num_vertex, sizeof ( XMGVector3X ) * impl_parent->m_ext_vertex );
		kdFree ( arr_vertex );
	}
}
コード例 #24
0
ファイル: kd_imgdec.c プロジェクト: h-s-c/libKD
KD_API KDImageATX KD_APIENTRY kdGetImageFromStreamATX(KDFile *file, KDint format, KDint flags)
{
    _KDImageATX *image = (_KDImageATX *)kdMalloc(sizeof(_KDImageATX));
    if(image == KD_NULL)
    {
        kdSetError(KD_ENOMEM);
        return KD_NULL;
    }
    image->levels = 0;
    image->bpp = 8;

    KDStat st;
    if(kdFstat(file, &st) == -1)
    {
        kdFree(image);
        kdSetError(KD_EIO);
        return KD_NULL;
    }

    void *filedata = kdMalloc((KDsize)st.st_size);
    if(filedata == KD_NULL)
    {
        kdFree(image);
        kdSetError(KD_ENOMEM);
        return KD_NULL;
    }
    if(kdFread(filedata, 1, (KDsize)st.st_size, file) != (KDsize)st.st_size)
    {
        kdFree(filedata);
        kdFree(image);
        kdSetError(KD_EIO);
        return KD_NULL;
    }
    if(kdFseek(file, 0, KD_SEEK_SET) == -1)
    {
        kdFree(filedata);
        kdFree(image);
        kdSetError(KD_EIO);
        return KD_NULL;
    }

    KDint channels = 0;
    image->format = format;
    switch(image->format)
    {
        case(KD_IMAGE_FORMAT_RGBA8888_ATX):
        {
            channels = 4;
            image->alpha = KD_TRUE;
            break;
        }
        case(KD_IMAGE_FORMAT_RGB888_ATX):
        {
            channels = 3;
            image->alpha = KD_FALSE;
            break;
        }
        case(KD_IMAGE_FORMAT_LUMALPHA88_ATX):
        {
            channels = 2;
            image->alpha = KD_TRUE;
            break;
        }
        case(KD_IMAGE_FORMAT_LUM8_ATX):
        {
            channels = 1;
            image->alpha = KD_FALSE;
            break;
        }
        case(KD_IMAGE_FORMAT_COMPRESSED_ATX):
        {
            /* TODO: Load compressed formats (do not decode) */
        }
        default:
        {
            kdFree(filedata);
            kdFree(image);
            kdSetError(KD_EINVAL);
            return KD_NULL;
        }
    }

    if(kdStrstrVEN(file->pathname, ".pvr"))
    {
        if(channels == 4)
        {
            /* PVR v2 only*/
            struct PVR_Texture_Header {
                KDuint dwHeaderSize;      /* size of the structure */
                KDuint dwHeight;          /* height of surface to be created */
                KDuint dwWidth;           /* width of input surface */
                KDuint dwMipMapCount;     /* number of mip-map levels requested */
                KDuint dwpfFlags;         /* pixel format flags */
                KDuint dwTextureDataSize; /* Total size in bytes */
                KDuint dwBitCount;        /* number of bits per pixel  */
                KDuint dwRBitMask;        /* mask for red bit */
                KDuint dwGBitMask;        /* mask for green bits */
                KDuint dwBBitMask;        /* mask for blue bits */
                KDuint dwAlphaBitMask;    /* mask for alpha channel */
                KDuint dwPVR;             /* magic number identifying pvr file */
                KDuint dwNumSurfs;        /* the number of surfaces present in the pvr */
            };
            struct PVR_Texture_Header header;
            kdMemcpy(&header, filedata, sizeof(KDuint) * 13);

            image->height = (KDint)header.dwHeight;
            image->width = (KDint)header.dwWidth;
            image->size = (KDsize)image->width * (KDsize)image->height * (KDsize)channels * sizeof(KDuint);
            image->buffer = kdMalloc(image->size);
            /* PVRCT2/4 RGB/RGBA compressed formats for now */
            __kdDecompressPVRTC((const KDuint8 *)filedata + header.dwHeaderSize, 0, image->width, image->height, image->buffer);
        }
    }
    else
    {
        if(flags == KD_IMAGE_FLAG_FLIP_X_ATX)
        {
            stbi_set_flip_vertically_on_load(1);
        }
        image->buffer = stbi_load_from_memory(filedata, (KDint)st.st_size, &image->width, &image->height, (KDint[]) {0}, channels);
        image->size = (KDsize)image->width * (KDsize)image->height * (KDsize)channels * sizeof(KDuint);
    }

    kdFree(filedata);
    if(image->buffer == KD_NULL)
    {
        kdLogMessagefKHR("%s.\n", stbi_failure_reason());
        kdFree(image);
        kdSetError(KD_EILSEQ);
        return KD_NULL;
    }
    return image;
}
コード例 #25
0
ファイル: kd_imgdec.c プロジェクト: h-s-c/libKD
/* kdGetImageInfoATX, kdGetImageInfoFromStreamATX: Construct an informational image object based on an image in a file or stream. */
KD_API KDImageATX KD_APIENTRY kdGetImageInfoATX(const KDchar *pathname)
{
    _KDImageATX *image = (_KDImageATX *)kdMalloc(sizeof(_KDImageATX));
    if(image == KD_NULL)
    {
        kdSetError(KD_ENOMEM);
        return KD_NULL;
    }
    image->levels = 0;

    KDStat st;
    if(kdStat(pathname, &st) == -1)
    {
        kdFree(image);
        kdSetError(KD_EIO);
        return KD_NULL;
    }
    image->size = (KDsize)st.st_size;

#if defined(__unix__) || defined(__APPLE__) || defined(__EMSCRIPTEN__)
    KDint fd = __kdOpen(pathname, O_RDONLY | O_CLOEXEC, 0);
    if(fd == -1)
#elif(_WIN32)
    WIN32_FIND_DATA data;
    HANDLE fd = FindFirstFileA(pathname, &data);
    if(fd == INVALID_HANDLE_VALUE)
#endif
    {
        kdFree(image);
        kdSetError(KD_EIO);
        return KD_NULL;
    }

    void *filedata = KD_NULL;
#if defined(__unix__) || defined(__APPLE__) || defined(__EMSCRIPTEN__)
    filedata = mmap(KD_NULL, image->size, PROT_READ, MAP_PRIVATE, fd, 0);
    if(filedata == MAP_FAILED)
#elif defined(_WIN32)
    HANDLE fm = CreateFileMapping(fd, KD_NULL, PAGE_READONLY, 0, 0, KD_NULL);
    if(fm)
    {
        filedata = MapViewOfFile(fm, FILE_MAP_READ, 0, 0, image->size);
    }
    if(filedata == KD_NULL)
#endif
    {
#if defined(__unix__) || defined(__APPLE__) || defined(__EMSCRIPTEN__)
        close(fd);
#elif defined(_WIN32)
        CloseHandle(fd);
#endif
        kdFree(image);
        kdSetError(KD_EIO);
        return KD_NULL;
    }

    KDint channels = 0;
    KDint error = stbi_info_from_memory(filedata, (KDint)image->size, &image->width, &image->height, &channels);
    switch(channels)
    {
        case(4):
        {
            image->format = KD_IMAGE_FORMAT_RGBA8888_ATX;
            image->alpha = KD_TRUE;
            break;
        }
        case(3):
        {
            image->format = KD_IMAGE_FORMAT_RGB888_ATX;
            image->alpha = KD_FALSE;
            break;
        }
        case(2):
        {
            image->format = KD_IMAGE_FORMAT_LUMALPHA88_ATX;
            image->alpha = KD_TRUE;
            break;
        }
        case(1):
        {
            image->format = KD_IMAGE_FORMAT_LUM8_ATX;
            image->alpha = KD_FALSE;
            break;
        }
        default:
        {
            error = 0;
            break;
        }
    }

#if defined(__unix__) || defined(__APPLE__) || defined(__EMSCRIPTEN__)
    munmap(filedata, image->size);
    close(fd);
#elif defined(_WIN32)
    UnmapViewOfFile(filedata);
    CloseHandle(fd);
#endif

    if(error == 0)
    {
        kdFree(image);
        kdSetError(KD_EILSEQ);
        return KD_NULL;
    }

    return image;
}
コード例 #26
0
KDuint8* xmReadTileETC ( KDFile* file, XMImage* image )
{
	ETCDecode*		decode = (ETCDecode*) image->decode;

	KDuint8*		pixels		= 0;
	KDint			block_size	= 0; 
	KDint32			tile_size   = 0;

	if ( decode->pixels )
	{
		kdFree ( decode->pixels );
		decode->pixels = 0;
	}

	block_size = 8;

	tile_size = ( ( image->ptr_tile->width + 3 ) / 4 ) * ( ( image->ptr_tile->height + 3 ) / 4 ) * block_size;

	pixels = (KDuint8*) kdMalloc ( tile_size );
	if ( !pixels )
	{
		goto cleanup;
	}

	if ( kdFread ( pixels, tile_size, 1, file ) == 0 )
	{			
		//goto cleanup;
	}

	if ( decode->uncomp == 1 )
	{
		tile_size = image->ptr_tile->width * image->ptr_tile->height * 3;
		decode->pixels = (KDuint8*) kdMalloc ( tile_size );

		if ( decode->pixels )
		{
			etc1_decode_image ( pixels, decode->pixels, image->ptr_tile->width, image->ptr_tile->height, 3, image->ptr_tile->width * 3 );
		}

		kdFree ( pixels );
	}
	else
	{
		decode->pixels = pixels;
		image->ptr_tile->size = tile_size;
	}

	decode->row_count = 0;
	image->ptr_tile->stride = tile_size / image->ptr_tile->height;

	return decode->pixels;

cleanup :

	if ( pixels )
	{
		kdFree ( pixels );
	}

	return 0;
}
コード例 #27
0
XM_APP_MAIN_END

#define ANI_TIME      1500
#define INTERVAL      3000

KDvoid SetMorph ( KDvoid )
{
	KD_GET_TLS ( KDTLS, tls );

	GLfloat*        arr_morph;
	XMGVector2F*    arr_coord;

	XMGMatrix4F     mat;
	XMGRectF        rc;

	XMGVector2F     img;
	XMGVector2F     tex;
	XMGVector2F     rate;
	XMGVector2F     half;

	GLuint          idx;
	GLuint          off;
	GLuint          frame;

	rc.m_w = XMG_I2F ( tls->wnd_cx );
	rc.m_h = XMG_I2F ( tls->wnd_cy );

	tls->xmg_quad->SetVertexArray ( &rc );
	tls->xmg_quad->SetTexture ( tls->xmg_tex[ 0 ] );

	tls->xmg_tex[ 0 ]->GetSize ( tex );
	tls->xmg_tex[ 0 ]->GetImageSize ( img );

	rate.m_x = img.m_x / tex.m_x;
	rate.m_y = img.m_y / tex.m_y;

	arr_coord = (XMGVector2F *) kdMalloc ( sizeof ( XMGVector2F ) * g_page_num_vertex );	

	for ( idx = 0; idx < g_page_num_vertex; idx++ )
	{
		arr_coord[ idx ].m_x = g_page_arr_coord[ idx * 2 + 0 ] * rate.m_x;
		arr_coord[ idx ].m_y = g_page_arr_coord[ idx * 2 + 1 ] * rate.m_y;
	}

	tls->xmg_morph->SetDispMode ( XMG_DISP_TEXTURE );
	tls->xmg_morph->SetCoordArray ( arr_coord );	

	kdFree ( arr_coord );

	arr_morph = (GLfloat *) kdMalloc ( sizeof ( GLfloat ) * ( g_page_num_frame + g_page_num_frame * g_page_num_vertex * 3 ) );

	off = 0;
	for ( frame = 0; frame < g_page_num_frame; frame++ )
	{
		arr_morph[ off ] = XMG_I2F ( ( ANI_TIME / g_page_num_frame ) * frame );	off++;

		for ( idx = 0; idx < g_page_num_vertex; idx++ )
		{
			arr_morph[ off ] =  g_page_arr_vertex[ frame ][ idx * 3 + 0 ];			off++;
			arr_morph[ off ] = -g_page_arr_vertex[ frame ][ idx * 3 + 2 ];			off++;
			arr_morph[ off ] =  g_page_arr_vertex[ frame ][ idx * 3 + 1 ];			off++;
		}
	}

	tls->xmg_ani->SetKeyFrame ( g_page_num_vertex * 3, g_page_num_frame, arr_morph );

	kdFree ( arr_morph );
	
	tls->xmg_morph->SetIndexArray ( g_page_arr_index, (const GLuint*) &g_page_num_index );

	half.m_x = rc.m_w / 2.0f;
	half.m_y = rc.m_h / 2.0f;

	mat.Translate ( half.m_x, half.m_y, 0.0f );
	mat.Rotate ( -90.0f, 0.0f, 0.0f, 1.0f );
	mat.Translate ( -half.m_x, -half.m_y, 0.0f );

	mat.Translate ( -half.m_x / 2, half.m_y, -0.4f );
	mat.Scale ( rc.m_h / 29.9f - 0.45f, half.m_x / 9.22f - 0.06f, 1.0f );

	tls->xmg_morph->SetMatrix ( mat );
	tls->xmg_morph->SetBlend ( XMG_TRUE );
	tls->xmg_morph->SetColor ( XMGColorF ( 0.25f, 0.25f, 0.25f, 0.955f ) );
}
コード例 #28
0
KDvoid Controller::setFrame ( KDint nLocation, Mat& tImage )
{
	if ( tImage.empty ( ) )
	{
		return;
	}

	KDint  nCols = KD_MIN ( nLocation == 0 ? 1024 : 512, tImage.cols );
	KDint  nRows = KD_MIN ( 512, tImage.rows );
	
	KDint  nStartX = nLocation == 0 ? ( 1024 - nCols ) / 2 : nLocation == 1 ? ( 512 - nCols ) / 2 : ( 512 - nCols ) / 2 + 512;
	KDint  nStartY = ( 512 - nRows ) / 2;

	KDubyte*  pDst = (KDubyte*) kdMalloc ( nRows * nCols * 3 );
	uchar*    pSrc = KD_NULL;
	KDint     nOff = 0;

	if ( tImage.channels ( ) == 1 )
	{
		if ( tImage.depth ( ) == 5 )
		{
			for ( KDint  y = 0; y < nRows; ++y )
			{
				for ( KDint  x = 0; x < nCols; ++x )
				{
					pSrc = tImage.ptr<uchar> ( y, x );
					nOff = ( y * nCols + x ) * 3;

					pDst [ nOff + 2 ] = pDst [ nOff + 1 ] = pDst [ nOff + 0 ] = (KDubyte) ( *((KDfloat*) pSrc) * 255 );
				}
			}	
		}
		else
		{
			for ( KDint  y = 0; y < nRows; ++y )
			{
				for ( KDint  x = 0; x < nCols; ++x )
				{
					pSrc = tImage.ptr<uchar> ( y, x );
					nOff = ( y * nCols + x ) * 3;

					pDst [ nOff + 2 ] = pDst [ nOff + 1 ] = pDst [ nOff + 0 ] = pSrc [ 0 ];
				}
			}	
		}
	}
	else
	{
		for ( KDint  y = 0; y < nRows;  ++y )
		{
			for ( KDint  x = 0; x < nCols; ++x )
			{
				pSrc = tImage.ptr<uchar> ( y, x );
				nOff = ( y * nCols + x ) * 3;

				pDst [ nOff + 2 ] = pSrc [ 0 ];
				pDst [ nOff + 1 ] = pSrc [ 1 ];
				pDst [ nOff + 0 ] = pSrc [ 2 ];
			}
		}	
	}

	ccGLBindTexture2D ( m_uTexture );
	glTexSubImage2D ( GL_TEXTURE_2D, 0, nStartX, nStartY, nCols, nRows, GL_RGB, GL_UNSIGNED_BYTE, pDst );

	kdFree ( pDst );
}