miscellaneous/texture_template/ortexture_template_texture.cxx

miscellaneous/texture_template/ortexture_template_texture.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE TEXTURES, AND MAKES SUCH TEXTURES AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE TEXTURES. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
TEXTURES DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declaration
#include "ortexture_template_texture.h"
FBClassImplementation( ORLayeredTextureCustom ); //Register class
FBStorableCustomTextureImplementation( ORLayeredTextureCustom, Texture ); //Register to the store/retrieve system
FBShadingElementClassImplementation( ORLayeredTextureCustom, "browsing/template_layeredtexture.png" ); //Register to the asset browser shading element category folder.
/************************************************
* Constructor.
************************************************/
ORLayeredTextureCustom::ORLayeredTextureCustom( const char* pName, HIObject pObject ) : FBLayeredTexture( pName, pObject )
{
}
static void ORLayeredTextureCustom_CustomCompositionSet(HIObject pMbObject, bool pValue)
{
ORLayeredTextureCustom* pFbObject = FBCast<ORLayeredTextureCustom>( pMbObject );
pFbObject->CustomComposition.SetPropertyValue(pValue);
pFbObject->SetLayerConfigDirty();
}
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORLayeredTextureCustom::FBCreate()
{
FBPropertyInitTextureConnectable(this, AuxLayer, "AuxLayer" );
FBPropertyPublish(this, CustomComposition, "CustomComposition", NULL, ORLayeredTextureCustom_CustomCompositionSet);
AuxLayer = FBColorAndAlpha(1.0, 0.0, 0.0, 1.0);
CustomComposition = true;
return true;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORLayeredTextureCustom::FBDestroy()
{
ParentClass::FBDestroy();
}
bool ORLayeredTextureCustom::FbxStore(FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat)
{
ParentClass::FbxStore(pFbxObject, pStoreWhat);
return true;
}
bool ORLayeredTextureCustom::FbxRetrieve(FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat)
{
ParentClass::FbxRetrieve(pFbxObject, pStoreWhat);
return true;
}
bool ORLayeredTextureCustom::PlugDataNotify(FBConnectionAction pAction,FBPlug* pThis,void* pData,void* pDataOld,int pDataSize)
{
if (pThis == &AuxLayer)
{
switch (pAction)
{
{
SetLayerConfigDirty();
}
break;
default:
break;
}
}
return ParentClass::PlugDataNotify(pAction, pThis, pData, pDataOld, pDataSize);
}
bool ORLayeredTextureCustom::EvaluateAnimationNodes( FBEvaluateInfo* pEvaluateInfo )
{
ParentClass::EvaluateAnimationNodes(pEvaluateInfo);
if (CustomComposition && AuxLayer.IsAnimated())
{
// Compute animatable property value in background evaluation thread.
FBPropertyAnimatableColorAndAlpha::ValueType lTmpValue;
AuxLayer.GetData(lTmpValue.mValue, sizeof(lTmpValue.mValue), pEvaluateInfo);
// Trigger composition per frame.
SetLayerConfigDirty();
}
return true;
}
void ORLayeredTextureCustom::TextureLayerComposition(FBTime pTime,FBTime pTimeInCurrentTimeRef, int pWidth, int pHeight)
{
//
// Here we simply demo the default and customized the texture layers blend operations.
// Actually nothing is preventing user to do a more sophisticated real-time composition (keying and etc.,)
// or even a full scene (or shadow map) RTT for advanced fancy tasks.
//
if (! CustomComposition)
{
ParentClass::TextureLayerComposition(pTime, pTimeInCurrentTimeRef, pWidth, pHeight);
}
else
{
//
//Render-To-Texture already setup.
//
// Push GL states.
glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT);
// Clear Buffers.
// Default implementation use BackgroundColor property. Here AuxLayer is used for demo purpose.
// FBColorAndAlpha lBgColor = BackgroundColor;
FBColorAndAlpha lBgColor = AuxLayer;
glClearColor(lBgColor[0], lBgColor[1], lBgColor[2], lBgColor[3]);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0,0, pWidth, pHeight);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 1, 1, 0, -1, 1);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
for (int lLayerIndex = 0, lLayerCount = Layers.GetCount(); lLayerIndex < lLayerCount; lLayerIndex++)
{
FBTexture* lTexture = Layers[lLayerIndex];
// Determine Blend mode.
switch( lTexture->BlendMode )
{
case kFBTextureBlendTranslucent: glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );break;
case kFBTextureBlendAdditive: glBlendFunc( GL_SRC_ALPHA, GL_ONE ); break;
case kFBTextureBlendModulate: glBlendFunc( GL_ZERO, GL_SRC_COLOR );break;
case kFBTextureBlendModulate2: glBlendFunc( GL_DST_COLOR, GL_SRC_COLOR );break;
}
glColor4f(1.0, 1.0, 1.0, lTexture->Alpha);
// Binding the texture with proper parameters and matrix.
lTexture->OGLInit();
// Draw quad for blending.
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 1.0);
glVertex2f(0.0, 0.0);
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0, 1.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, 1.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(1.0, 0.0);
glEnd();
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
// Pop GL states.
glPopAttrib();
}
}