⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m3gvertexbuffer.c

📁 java 1.1 gemini 08_16
💻 C
字号:
/*****************************************************************************
 *
 * Filename:
 * ---------
 *  VertexArray.c
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/*************************************************************************
 * Include Header Files
 *************************************************************************/
#include "m3g.h"

#ifdef SUPPORT_JSR_184
/*************************************************************************
 * Function Definition
 *************************************************************************/
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_VertexBuffer_create()
{
	st_m3g_vertexbuffer* handle; 
	
	ENTER_M3D_CS;	
	handle = M3G_VertexBuffer_new();
	LEAVE_M3D_CS;
	
	if(handle == NULL) KNI_ThrowNew("java/lang/NullPointerException", "null handle");
	KNI_ReturnInt((jint)handle);
}   

KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_m3g_VertexBuffer_finalize()
{   
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_VertexBuffer_getColorsImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);

	//KNI_ReturnInt((jint)handle->colors);
	KNI_ReturnInt((jint)M3G_VertexBuffer_getColors(handle));
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_VertexBuffer_getDefaultColorImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);	
	jint color; 
	
	color = M3G_VertexBuffer_getDefaultColor(handle);
	
	KNI_ReturnInt(color);
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_VertexBuffer_getNormalsImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);

	//KNI_ReturnInt((jint)handle->normals);
	KNI_ReturnInt((jint)M3G_VertexBuffer_getNormals(handle));
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_VertexBuffer_getPositionsImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
    st_m3g_vertexarray* va = NULL;

	KNI_StartHandles(1);
	KNI_DeclareHandle(object_handle);
	KNI_GetParameterAsObject(2, object_handle);
	
	if(*object_handle) {
#if FAST_KNI && defined(CLDCHI)
		jfloat_array* array = (jfloat_array*)*object_handle;

		if(array->length < 4) {
			KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid scalebias");
		} 
		va = (st_m3g_vertexarray*)M3G_VertexBuffer_getPositions(handle,array->elements);
			//array->elements[0] = handle->position_scale;
			//array->elements[1] = handle->position_bias[0];
			//array->elements[2] = handle->position_bias[1];
			//array->elements[3] = handle->position_bias[2];
		
#else
	ASSERT(0);
#endif /* KNI */
	}
    else
    {
        va = (st_m3g_vertexarray*)M3G_VertexBuffer_getPositions(handle,NULL);
    }

	KNI_EndHandles();

	//KNI_ReturnInt((jint)handle->positions);
	KNI_ReturnInt((jint)va);
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_VertexBuffer_getTexCoordsImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
	jint index = KNI_GetParameterAsInt(2);
	st_m3g_vertexarray* ret_texarray = NULL;    
	

	KNI_StartHandles(1);
	KNI_DeclareHandle(object_handle);
	KNI_GetParameterAsObject(3, object_handle);

	if(*object_handle != NULL) {
#if FAST_KNI && defined(CLDCHI)
		jfloat_array* array = (jfloat_array*)*object_handle;

		if(index < 0 || index >= m3g_graphics3d.max_texunits) {
			KNI_ThrowNew("java/lang/IndexOutOfBoundsException", "invalid index");
		} else if(index < handle->texcoordarray_count) {
			if(handle->texcoords[index]) {
				if(array->length < handle->texcoords[index]->component_count+1) {
					KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid scalbias");			
				} 
				ret_texarray = (st_m3g_vertexarray*)M3G_VertexBuffer_getTexCoords(handle,index,array->elements);
                    //////
				
			}
		}
#else
		ASSERT(0);
#endif /* FAST_KNI */			
	} else if(index < handle->texcoordarray_count) {
		ret_texarray = handle->texcoords[index];                            
	}

	KNI_EndHandles();
	KNI_ReturnInt((jint)ret_texarray);
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_VertexBuffer_getVertexCountImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
	jint count  = M3G_VertexBuffer_getVertexCount(handle, 0);
	KNI_ReturnInt(count);
}

KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_m3g_VertexBuffer_setColorsImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
	st_m3g_vertexarray* colors = (st_m3g_vertexarray*)KNI_GetParameterAsInt(2);
	int count = M3G_VertexBuffer_getVertexCount(handle, 3);
	if(colors) {
		if(colors->component_size != 1 || 
		   (colors->component_count!=3 && colors->component_count!=4) ||
		   (count>0 && count != colors->vertex_count)) {
			KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid colors");          
		} else {
			M3G_VertexBuffer_setColors(handle, colors);
		}
	} else {
		handle->colors = NULL;
	}
	KNI_ReturnVoid();
}

KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_m3g_VertexBuffer_setDefaultColorImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
	jint color = KNI_GetParameterAsInt(2);

	M3G_VertexBuffer_setDefaultColor(handle, color);	
	KNI_ReturnVoid();
}

KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_m3g_VertexBuffer_setNormalsImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
	st_m3g_vertexarray* normals = (st_m3g_vertexarray*)KNI_GetParameterAsInt(2);
	int count; 
	
	count = M3G_VertexBuffer_getVertexCount(handle, 2);
	if(normals) {
		if((normals->component_count!=3) ||
		   (count>0 && count != normals->vertex_count)) {
			KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid normals");         
		} else {
			M3G_VertexBuffer_setNormals(handle, normals);
		}
	} else {
		handle->normals = NULL;
	}
	KNI_ReturnVoid();
}

KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_m3g_VertexBuffer_setPositionsImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
	st_m3g_vertexarray* positions = (st_m3g_vertexarray*)KNI_GetParameterAsInt(2);
	jfloat scale = KNI_GetParameterAsFloat(3);
	jfloat bias[3];
	int count = M3G_VertexBuffer_getVertexCount(handle, 1);
	KNI_StartHandles(1);
	KNI_DeclareHandle(object_handle);
	KNI_GetParameterAsObject(4, object_handle);

	if(positions && ((positions->component_count!=3) ||
	   (count>0 && count != positions->vertex_count))) {
		KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid positions");            
	} else {
		if(*object_handle != NULL) {
	#if FAST_KNI && defined(CLDCHI)
			jfloat_array* array = (jfloat_array*)*object_handle;

			if(positions && array->length < 3)	{
				KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid bias");
			} else {
				bias[0] = array->elements[0];
				bias[1] = array->elements[1];
				bias[2] = array->elements[2];
			}
	#else
			ASSERT(0);
	#endif /* FAST_KNI */			
		} else {
			bias[0] = 0.0f;
			bias[1] = 0.0f;
			bias[2] = 0.0f;
		}

		M3G_VertexBuffer_setPositions(handle, positions, scale, bias);
	}

	KNI_EndHandles();   
	KNI_ReturnVoid();
}

KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_m3g_VertexBuffer_setTexCoordsImpl()
{   
	st_m3g_vertexbuffer* handle = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);   
	jint index = KNI_GetParameterAsInt(2);  
	st_m3g_vertexarray* texarray = (st_m3g_vertexarray*)KNI_GetParameterAsInt(3);
	jfloat scale = KNI_GetParameterAsFloat(4);
	jfloat bias[3];
	int count = M3G_VertexBuffer_getVertexCount(handle, 4);
	KNI_StartHandles(1);
	KNI_DeclareHandle(object_handle);
	KNI_GetParameterAsObject(5, object_handle);

	if(texarray && ((texarray->component_count!=2 && texarray->component_count!=3) ||
					(count>0 && count != texarray->vertex_count))) {
		KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid scalbias");         
	} else {
		if(index >= m3g_graphics3d.max_texunits || index < 0) 
			KNI_ThrowNew("java/lang/IndexOutOfBoundsException", "invalid index");

		if(texarray) {
			if(*object_handle != NULL) {
	#if FAST_KNI && defined(CLDCHI)
				jfloat_array* array = (jfloat_array*)*object_handle;
				int i;

				if(array->length < texarray->component_count)	
					KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid scalbias");

				bias[0] = bias[1] = bias[2] = 0.0f;
				for(i=0; i<texarray->component_count; i++) {
					bias[i] = array->elements[i];
				}
	#else
				ASSERT(0);
	#endif /* FAST_KNI */			
			} else {
				bias[0] = bias[1] = bias[2] = 0.0f;
			}

			ENTER_M3D_CS;
			M3G_VertexBuffer_setTexCoords(handle, index, texarray, scale, bias);
			LEAVE_M3D_CS;

		} else {
			handle->texcoords[index] = NULL;
		}
	}
	KNI_EndHandles();    	
	KNI_ReturnVoid();
}
#endif /* #ifdef SUPPORT_JSR_184*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -