void CgEffect::GetVector(const char* name, Vector4* v) { float values[4]; cgGetParameterValuefc(this->retrieveParameter(name), 4, values); *v = Vector4(values[0], values[1], values[2], values[4]); }
bool CgDxShader::getFloatVectorVariable(const char* name, float4& vec) { if(mProgram) { CGparameter param = cgGetNamedParameter(mProgram, name); if(_check_error(mContext) && param) { cgGetParameterValuefc(param, 4, (float*)vec.value); return _check_error(mContext); } } return false; }
void CgEffect::GetFloat(const char* name, float* f) { cgGetParameterValuefc(this->retrieveParameter(name), 1, f); }
// Call ProcessInput once per frame to process input keys void ProcessInput( bool keys[] ) { // These keys we don't want to auto-repeat, so we clear them in "keys" after handling them once if (keys['E'] && amplitudeGlobalParameter) { float value; cgGetParameterValuefc(amplitudeGlobalParameter, 1, &value); value += 0.1f; cgSetParameter1f(amplitudeGlobalParameter, value); keys['E'] = false; } if (keys['R'] && amplitudeGlobalParameter) { float value; cgGetParameterValuefc(amplitudeGlobalParameter,1, &value); value -= 0.1f; cgSetParameter1f(amplitudeGlobalParameter, value); keys['R'] = false; } if (keys[VK_TAB] ) { // When 'C' is pressed, change cameras _CrtRender.SetNextCamera(); keys[VK_TAB] = false; } if ( keys['M'] ) { // Speed up UI by 25% AdjustUISpeed(1.25f); keys['M'] = false; } if ( keys['N'] ) { // Slow down UI by 25% AdjustUISpeed(0.75f); // Go 25% slower keys['N'] = false; } if (keys['Q']) { if (togglewireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); togglewireframe = FALSE; } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); togglewireframe = TRUE; } keys['Q'] = false; } if (keys['K']) { if (togglehiearchy) { _CrtRender.SetShowHiearchy(CrtTrue); togglehiearchy = FALSE; } else { _CrtRender.SetShowHiearchy(CrtFalse); togglehiearchy = TRUE; } keys['K'] = false; } if (keys['L']) { if (togglelighting) { glDisable(GL_LIGHTING); togglelighting = FALSE; } else { glEnable(GL_LIGHTING); togglelighting = TRUE; } keys['L'] = false; } if (keys['P'] ) { if (sAnimationEnable) { _CrtRender.SetAnimationPaused( CrtTrue ); sAnimationEnable = false; } else { _CrtRender.SetAnimationPaused( CrtFalse ); sAnimationEnable = true; } keys['P'] = false; } if (keys[VK_F1]) { keys[VK_F1]=FALSE; _CrtRender.Destroy(); DestroyGLWindow(); fullscreen=!fullscreen; // Recreate Our OpenGL Window if (!CreateGLWindow("Collada Viewer for PC", _CrtRender.GetScreenWidth(), _CrtRender.GetScreenHeight(),32,fullscreen)) { exit(1); } if ( !_CrtRender.Load( cleaned_file_name )) { exit(0); } keys[VK_F1] = false; } // These keys that do a function as long as they are held down, so we don't clear "keys". // Remember to scale these functions by time! if (keys['S']) { // UI code to move the camera closer _CrtRender.ActiveInstanceCamera->MoveTransform(_CrtRender.GetAnimDelta() * KeyboardTranslateSpeed *0.5f, 0.0f, 0.0f); } if (keys['W']) { // UI code to move the camera farther away _CrtRender.ActiveInstanceCamera->MoveTransform(- _CrtRender.GetAnimDelta() * KeyboardTranslateSpeed * 0.5f, 0.0f, 0.0f); } if (keys[VK_SPACE]) { // UI code to move the camera farther up _CrtRender.ActiveInstanceCamera->MoveTransform(0.0f, 0.0f, _CrtRender.GetAnimDelta() * KeyboardTranslateSpeed); } if (keys['X']) { // UI code to move the camera farther down _CrtRender.ActiveInstanceCamera->MoveTransform(0.0f, 0.0f, - _CrtRender.GetAnimDelta() * KeyboardTranslateSpeed); } if (keys['D']) { // UI code to move the camera farther right _CrtRender.ActiveInstanceCamera->MoveTransform(0.0f, - _CrtRender.GetAnimDelta() * KeyboardTranslateSpeed, 0.0f); } if (keys['A']) { // UI code to move the camera farther left _CrtRender.ActiveInstanceCamera->MoveTransform(0.0f, _CrtRender.GetAnimDelta() * KeyboardTranslateSpeed, 0.0f); } if (keys['F']) { if(togglecullingface == 0) { // turn it front glEnable( GL_CULL_FACE ); glCullFace(GL_FRONT); togglecullingface = 1; } else if(togglecullingface == 1) { // turn it both glDisable( GL_CULL_FACE ); togglecullingface = 2; } else { // turn it back glEnable( GL_CULL_FACE ); glCullFace(GL_BACK); togglecullingface = 0; } keys['F'] = false; } }
static int PubCGparam_func (PState pstate,PubFunction_t *fn, int n) { CGparameter cgparam = NULL; if ((int)fn->upvalue > PCG_GET && (n<1 || FunctionPublish_getArg(pstate,1,LUXI_CLASS_CGPARAM,(void*)&cgparam)<1)) return FunctionPublish_returnError(pstate,"1 cgparam required"); switch((int)fn->upvalue){ case PCG_NEW: { char *name; char *nametype; CGtype cgtype; CGtype basetype; int cnt = 1; if (n < 2 || FunctionPublish_getArg(pstate,3,LUXI_CLASS_STRING,(void*)&name,LUXI_CLASS_STRING,(void*)&nametype,LUXI_CLASS_INT,(void*)&cnt)<2) return FunctionPublish_returnError(pstate,"2 strings required"); cgtype = cgGetType(nametype); basetype = cgGetTypeBase(cgtype); if (VIDCg_getConnector(name) || cgtype==CG_UNKNOWN_TYPE || (basetype != CG_FLOAT && basetype != CG_INT && basetype != CG_BOOL)) return FunctionPublish_returnError(pstate,"name already in use, or illegal cg base type (float, bool, int)"); if (cgGetTypeClass(cgtype) == CG_PARAMETERCLASS_MATRIX && basetype != CG_FLOAT) return FunctionPublish_returnError(pstate,"only float matrix parameters allowed"); cgparam = cnt > 1 ? cgCreateParameterArray(g_VID.cg.context,cgtype,cnt) : cgCreateParameter(g_VID.cg.context,cgtype); VIDCg_setConnector(name,cgparam); return FunctionPublish_returnType(pstate,LUXI_CLASS_CGPARAM,(void*)cgparam); } break; case PCG_DELETE: { int linked = cgGetNumConnectedToParameters(cgparam); if (linked == 0){ VIDCg_setConnector(cgGetParameterName(cgparam),NULL); cgDestroyParameter(cgparam); } return FunctionPublish_returnInt(pstate,linked); } break; case PCG_GET: { char *name; if (n < 1 || !FunctionPublish_getArg(pstate,1,LUXI_CLASS_STRING,(void*)&name)) return FunctionPublish_returnError(pstate,"1 string required"); cgparam = VIDCg_getConnector(name); if (cgparam) return FunctionPublish_returnType(pstate,LUXI_CLASS_CGPARAM,(void*)cgparam); else return 0; } break; case PCG_VALUE: { CGtype cgtype = cgGetParameterType(cgparam); CGtype basetype = cgGetTypeBase(cgtype); CGtype classtype = cgGetTypeClass(cgtype); lxClassType ctype; Reference ref; float *matrix; StaticArray_t *starray; int read = 0; int offset = 0; int size; int into = (int)fn->upvalue == PCG_VALUEINTO; if (n==1 || into){ int vector[4]; switch(classtype){ case CG_PARAMETERCLASS_SCALAR: case CG_PARAMETERCLASS_VECTOR: switch(basetype){ case CG_FLOAT: ctype = LUXI_CLASS_FLOAT; read = cgGetParameterValuefc(cgparam,4,(float*)vector); break; case CG_BOOL: ctype = LUXI_CLASS_BOOLEAN; read = cgGetParameterValueic(cgparam,4,vector); break; case CG_INT: ctype = LUXI_CLASS_INT; read = cgGetParameterValueic(cgparam,4,vector); break; default: return 0; } return FunctionPublish_setRet(pstate,read,ctype,(void*)vector[0],ctype,(void*)vector[1],ctype,(void*)vector[2],ctype,(void*)vector[3]); break; case CG_PARAMETERCLASS_MATRIX: if (into){ // get matrix first if (!FunctionPublish_getNArg(pstate,1,LUXI_CLASS_MATRIX44,(void*)&ref) || !Reference_get(ref,matrix)) return FunctionPublish_returnError(pstate,"1 matrix4x4 required"); } else{ // create matrix matrix = PubMatrix4x4_alloc(); ref = Reference_new(LUXI_CLASS_MATRIX44,matrix); Reference_makeVolatile(ref); } cgGetMatrixParameterfc(cgparam,matrix); return FunctionPublish_returnType(pstate,LUXI_CLASS_MATRIX44,REF2VOID(ref)); break; case CG_PARAMETERCLASS_ARRAY: ctype = basetype == CG_FLOAT ? LUXI_CLASS_FLOATARRAY : LUXI_CLASS_INTARRAY; size = cgGetParameterColumns(cgparam)*cgGetParameterRows(cgparam)*cgGetArrayTotalSize(cgparam); if (into){ // get array first if (FunctionPublish_getArgOffset(pstate,1,3,ctype,(void*)&ref,LUXI_CLASS_INT,(void*)&offset)<1 || !Reference_get(ref,starray) || offset+size > starray->count) return FunctionPublish_returnError(pstate,"1 staticarray [1 int] required (with enough space)"); } else{ // create array starray = StaticArray_new(size,ctype,NULL,NULL); } offset = LUX_MIN(offset,(starray->count-1)); read = LUX_MIN(read,(starray->count-offset)); if (ctype == LUXI_CLASS_FLOATARRAY) cgGetParameterValuefc(cgparam,read,starray->floats); else cgGetParameterValueic(cgparam,read,starray->ints); return FunctionPublish_returnType(pstate,ctype,REF2VOID(starray->ref)); } } else { // set lxVector4 vector; switch(classtype){ case CG_PARAMETERCLASS_SCALAR: case CG_PARAMETERCLASS_VECTOR: ctype = basetype == CG_FLOAT ? LUXI_CLASS_FLOAT : LUXI_CLASS_INT; read = FunctionPublish_getArgOffset(pstate,1,n-1,ctype,(void*)&vector[0],ctype,(void*)&vector[1],ctype,(void*)&vector[2],ctype,(void*)&vector[3]); if (read > 0){ switch(basetype){ case CG_FLOAT: cgSetParameterValuefc(cgparam,n-1,vector); return 0; case CG_BOOL: case CG_INT: cgSetParameterValueic(cgparam,n-1,(int*)vector); return 0; default: return 0; } } break; case CG_PARAMETERCLASS_MATRIX: if (!FunctionPublish_getNArg(pstate,1,LUXI_CLASS_MATRIX44,(void*)&ref) || !Reference_get(ref,matrix)) return FunctionPublish_returnError(pstate,"1 matrix4x4 required"); cgSetMatrixParameterfc(cgparam,matrix); return 0; case CG_PARAMETERCLASS_ARRAY: ctype = basetype == CG_FLOAT ? LUXI_CLASS_FLOATARRAY : LUXI_CLASS_INTARRAY; size = cgGetParameterColumns(cgparam)*cgGetParameterRows(cgparam)*cgGetArrayTotalSize(cgparam); if (FunctionPublish_getArgOffset(pstate,1,3,ctype,(void*)&ref,LUXI_CLASS_INT,(void*)&offset) || !Reference_get(ref,starray) || offset+size > starray->count) return FunctionPublish_returnError(pstate,"1 staticarray [2 ints] required, with enough space"); offset = LUX_MIN(offset,(starray->count-1)); if (ctype == LUXI_CLASS_FLOATARRAY) cgSetParameterValuefc(cgparam,size,&starray->floats[offset]); else cgSetParameterValueic(cgparam,size,&starray->ints[offset]); return 0; default: return 0; } } } case PCG_SIZES: return FunctionPublish_setRet(pstate,3,LUXI_CLASS_INT,(void*)cgGetParameterColumns(cgparam),LUXI_CLASS_INT,(void*)cgGetParameterRows(cgparam),LUXI_CLASS_INT,(void*)cgGetArrayTotalSize(cgparam)); default: break; } return 0; }