コード例 #1
0
/*!
 Add all the variables of this material object to the shader program "program".
 It expects that the program already exits and that the names in _glsl_names are used
 @param program - the glsl shader program integer id
 */
bool GLSpotLightSource::addVariablesToProgram(GLuint program, int variable_index)
{
    
    if(program == -1)return false; // no program exits
    
    
    GLint params;
    glGetProgramiv( program, GL_LINK_STATUS, &params);
    if(params == GL_FALSE)
    {
        cerr << "[GLMaterial] Program " << program << " has not been linked. Materials cannot be added." << endl;
        return false;
    }
    
    
    // enable the program
    glUseProgram(program);
    
    
    // get the location of a uniform variable. Note, the program must be linked at this position.
    _cone_angleIdx = glGetUniformLocation(program, GetVariableName(_glsl_object, _glsl_names[0], variable_index).c_str());
                    checkUniform(_cone_angleIdx, GetVariableName(_glsl_object, _glsl_names[0], variable_index));
    _cone_directionIdx = glGetUniformLocation(program, GetVariableName(_glsl_object, _glsl_names[1], variable_index).c_str());
                    checkUniform(_cone_directionIdx, GetVariableName(_glsl_object, _glsl_names[1], variable_index));

    
    // call the funciton of the base function.
    GLLightSource::addVariablesToProgram(program,variable_index);
    
    // Send the light information to your shader program
    glUniform1f(_cone_angleIdx, _cone_angle);
    glUniform3fv(_cone_directionIdx, 1, &_cone_direction[0]);
    
    return true;
}
コード例 #2
0
JVariableList::MatchResult
JVariableList::FindUniqueVarName
	(
	const JCharacter*	prefix,
	JIndex*				index,
	JString*			maxPrefix
	)
	const
{
	assert( !JStringEmpty(prefix) );

	const JSize count = GetElementCount();
	JArray<JIndex> matchList;

	for (JIndex i=1; i<=count; i++)
		{
		const JString& name = GetVariableName(i);
		if (name == prefix)
			{
			*index     = i;
			*maxPrefix = name;
			return kSingleMatch;
			}
		else if (JStringBeginsWith(name, name.GetLength(), prefix))
			{
			matchList.AppendElement(i);
			}
		}

	const JSize matchCount = matchList.GetElementCount();
	if (matchCount == 0)
		{
		*index = 0;
		maxPrefix->Clear();
		return kNoMatch;
		}
	else if (matchCount == 1)
		{
		*index     = matchList.GetElement(1);
		*maxPrefix = GetVariableName(*index);
		return kSingleMatch;
		}
	else
		{
		*maxPrefix = GetVariableName( matchList.GetElement(1) );
		for (JIndex i=2; i<=matchCount; i++)
			{
			const JString& varName   = GetVariableName( matchList.GetElement(i) );
			const JSize matchLength  = JCalcMatchLength(*maxPrefix, varName);
			const JSize prefixLength = maxPrefix->GetLength();
			if (matchLength < prefixLength)
				{
				maxPrefix->RemoveSubstring(matchLength+1, prefixLength);
				}
			}
		*index = 0;
		return kMultipleMatch;
		}
}
コード例 #3
0
/*!
 Add all the variables of this material object to the shader program "program".
 It expects that the program already exits and that the names in _glsl_names are used
 @param program - the glsl shader program integer id
 */
bool GLLightSource::addVariablesToProgram(GLuint program, int variable_index)
{

    if(program == -1)return false; // no program exits
    
    
    GLint params;
    glGetProgramiv( program, GL_LINK_STATUS, &params);
    if(params == GL_FALSE)
    {
        cerr << "[GLMaterial] Program " << program << " has not been linked. Materials cannot be added." << endl;
        return false;
    }
    
    
    // enable the program
    glUseProgram(program);
    
    
    // get the location of a uniform variable. Note, the program must be linked at this position.
    _ambientIdx = glGetUniformLocation(program, GetVariableName(_glsl_object, _glsl_names[2], variable_index).c_str());
                    checkUniform(_ambientIdx, GetVariableName(_glsl_object,_glsl_names[2], variable_index));
    
    _diffuseIdx = glGetUniformLocation(program, GetVariableName(_glsl_object,_glsl_names[1], variable_index).c_str()  );
                    checkUniform(_diffuseIdx,  GetVariableName(_glsl_object,_glsl_names[1], variable_index));
    
    
    _specularIdx = glGetUniformLocation(program, GetVariableName(_glsl_object,_glsl_names[0], variable_index).c_str() );
                    checkUniform(_specularIdx, GetVariableName(_glsl_object,_glsl_names[0], variable_index).c_str());
    
    _attenuation_coeffIdx = glGetUniformLocation(program, GetVariableName(_glsl_object,_glsl_names[3], variable_index).c_str());
                    checkUniform(_attenuation_coeffIdx, GetVariableName(_glsl_object,_glsl_names[3], variable_index));
    
    
    _lightPosIdx = glGetUniformLocation(program, GetVariableName(_glsl_object,_glsl_names[4], variable_index).c_str());
                    checkUniform(_lightPosIdx, GetVariableName(_glsl_object,_glsl_names[4], variable_index));

    
    // Send the light information to your shader program
    glUniform1f(_ambientIdx, _ambient_intensity );
    glUniform1f(_diffuseIdx, _diffuse_intensity);
    glUniform1f(_specularIdx, _specular_intensity);
    glUniform1f(_attenuation_coeffIdx, _attenuation_coeff);
    glUniform4fv(_lightPosIdx, 1, &_lightPos[0]);
    
    // disable the program
    // glUseProgram(0);
    
    return true;
}
コード例 #4
0
/*!
 Add all the variables of this material object to the shader program "program".
 It expects that the program already exits and that the names in _glsl_names are used
 @param program - the glsl shader program integer id
 */
bool GLMaterial::addVariablesToProgram(GLuint program, int variable_index)
{

    if(program == -1)return false; // no program exits
    
    
    GLint params;
    glGetProgramiv( program, GL_LINK_STATUS, &params);
    if(params == GL_FALSE)
    {
        cerr << "[GLMaterial] Program " << program << " has not been linked. Materials cannot be added." << endl;
        return false;
    }
    
    
    // enable the program
    glUseProgram(program);
    
    glGetProgramiv( program, GL_ACTIVE_UNIFORMS, &params);
 

    GetVariableName(_glsl_struct, _glsl_names[0], variable_index);
    
    // get the location of a uniform variable. Note, the program must be linked at this position.
    _ambientColorPos = glGetUniformLocation(program, GetVariableName(_glsl_struct, _glsl_names[0], variable_index).c_str());
                        checkUniform(_ambientColorPos, _glsl_names[0]);
    
    _diffuseColorPos = glGetUniformLocation(program, GetVariableName(_glsl_struct, _glsl_names[1], variable_index).c_str());
                        checkUniform(_diffuseColorPos, _glsl_names[1]);
    
    _specularColorPos = glGetUniformLocation(program, GetVariableName(_glsl_struct, _glsl_names[2], variable_index).c_str());
                        checkUniform(_specularColorPos, _glsl_names[2]);
    
    _shininessIdx = glGetUniformLocation(program, GetVariableName(_glsl_struct, _glsl_names[3], variable_index).c_str());
                        checkUniform(_shininessIdx, _glsl_names[3]);
    
    
    // Send the material to your shader program
    glUniform3fv(_ambientColorPos, 1, &_ambient_material[0] );
    glUniform3fv(_diffuseColorPos, 1, &_diffuse_material[0]);
    glUniform3fv(_specularColorPos, 1, &_specular_material[0]);
    glUniform1f(_shininessIdx, _shininess);
    
    // disable the program
    // glUseProgram(0);
    
    return true;
}
コード例 #5
0
ファイル: edge.cpp プロジェクト: mbelaoucha/fadalib
string
Edge::ToGraphViz(long unsigned int rank,vector<string> loops, long unsigned int write,GraphPrinterOptions op){
ostringstream result;
result<< op.sigma<<"( "+GetVariableName() 
      +GetIndex()->Generate_C_Code()+")   =   "<<PrintOperation(write,GetSigma()->GetIndex(),op);
result<<"\\n  IF \\n "<<GetCondition()->Generate_C_Code();
return result.str();
}
コード例 #6
0
JBoolean
JVariableList::ParseVariableName
	(
	const JCharacter*	expr,
	const JSize			exprLength,
	JIndex*				index
	)
	const
{
	const JSize count = GetElementCount();
	for (JIndex i=1; i<=count; i++)
		{
		const JString& name = GetVariableName(i);
		if (JStringsEqual(expr, exprLength, name))
			{
			*index = i;
			return kJTrue;
			}
		}

	return kJFalse;
}
コード例 #7
0
ファイル: SCS_Node.cpp プロジェクト: amyvmiwei/UnrealEngine4
UActorComponent* USCS_Node::ExecuteNodeOnActor(AActor* Actor, USceneComponent* ParentComponent, const FTransform* RootTransform, bool bIsDefaultTransform)
{
	check(Actor != nullptr);
	check((ParentComponent != nullptr && !ParentComponent->IsPendingKill()) || (RootTransform != nullptr)); // must specify either a parent component or a world transform

	auto ActualBPGC = Cast<UBlueprintGeneratedClass>(Actor->GetClass());
	UActorComponent* ActualComponentTemplate = GetActualComponentTemplate(ActualBPGC);

	// Create a new component instance based on the template
	UActorComponent* NewActorComp = Actor->CreateComponentFromTemplate(ActualComponentTemplate, VariableName.ToString());
	if(NewActorComp != nullptr)
	{
		NewActorComp->CreationMethod = EComponentCreationMethod::SimpleConstructionScript;
		// SCS created components are net addressable
		NewActorComp->SetNetAddressable();

		// Special handling for scene components
		USceneComponent* NewSceneComp = Cast<USceneComponent>(NewActorComp);
		if (NewSceneComp != nullptr)
		{
			// If NULL is passed in, we are the root, so set transform and assign as RootComponent on Actor
			if (ParentComponent == nullptr || (ParentComponent && ParentComponent->IsPendingKill()))
			{
				FTransform WorldTransform = *RootTransform;
				if(bIsDefaultTransform)
				{
					// Note: We use the scale vector from the component template when spawning (to match what happens with a native root)
					WorldTransform.SetScale3D(NewSceneComp->RelativeScale3D);
				}
				NewSceneComp->SetWorldTransform(WorldTransform);
				Actor->SetRootComponent(NewSceneComp);
			}
			// Otherwise, attach to parent component passed in
			else
			{
				NewSceneComp->AttachTo(ParentComponent, AttachToName);
			}
		}

		// Call function to notify component it has been created
		NewActorComp->OnComponentCreated();

		if (NewActorComp->GetIsReplicated())
		{
			// Make sure this component is added to owning actor's replicated list.
			NewActorComp->SetIsReplicated(true);
		}

		// If we want to save this to a property, do it here
		FName VarName = GetVariableName();
		if (VarName != NAME_None)
		{
			UClass* ActorClass = Actor->GetClass();
			if (UObjectPropertyBase* Prop = FindField<UObjectPropertyBase>(ActorClass, VarName))
			{
				Prop->SetObjectPropertyValue_InContainer(Actor, NewActorComp);
			}
			else
			{
				UE_LOG(LogBlueprint, Log, TEXT("ExecuteNodeOnActor: Couldn't find property '%s' on '%s"), *VarName.ToString(), *Actor->GetName());
#if WITH_EDITOR
				// If we're constructing editable components in the SCS editor, set the component instance corresponding to this node for editing purposes
				USimpleConstructionScript* SCS = GetSCS();
				if(SCS != nullptr && (SCS->IsConstructingEditorComponents() || SCS->GetComponentEditorActorInstance() == Actor))
				{
					EditorComponentInstance = NewSceneComp;
				}
#endif
			}
		}

		// Determine the parent component for our children (it's still our parent if we're a non-scene component)
		USceneComponent* ParentSceneComponentOfChildren = (NewSceneComp != nullptr) ? NewSceneComp : ParentComponent;

		// If we made a component, go ahead and process our children
		for (int32 NodeIdx = 0; NodeIdx < ChildNodes.Num(); NodeIdx++)
		{
			USCS_Node* Node = ChildNodes[NodeIdx];
			check(Node != nullptr);
			Node->ExecuteNodeOnActor(Actor, ParentSceneComponentOfChildren, nullptr, false);
		}
	}

	return NewActorComp;
}