2017-10-05 22:04:51 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
# include "shadergen/CustomShaderFeature.h"
# include "shaderGen/HLSL/customFeatureHLSL.h"
2019-05-13 05:28:23 +00:00
# include "shaderGen/GLSL/customFeatureGLSL.h"
2017-10-05 22:04:51 +00:00
# include "math/mathIO.h"
# include "scene/sceneRenderState.h"
# include "core/stream/bitStream.h"
# include "materials/sceneData.h"
# include "gfx/gfxDebugEvent.h"
# include "gfx/gfxTransformSaver.h"
# include "renderInstance/renderPassManager.h"
IMPLEMENT_CONOBJECT ( CustomShaderFeatureData ) ;
ConsoleDocClass ( CustomShaderFeatureData ,
2019-05-13 05:28:23 +00:00
" @brief An example scene object which renders using a callback. \n \n "
" This class implements a basic SceneObject that can exist in the world at a "
" 3D position and render itself. Note that CustomShaderFeatureData handles its own "
" rendering by submitting itself as an ObjectRenderInst (see "
" renderInstance \r enderPassmanager.h) along with a delegate for its render() "
" function. However, the preffered rendering method in the engine is to submit "
" a MeshRenderInst along with a Material, vertex buffer, primitive buffer, and "
" transform and allow the RenderMeshMgr handle the actual rendering. You can "
" see this implemented in RenderMeshExample. \n \n "
" See the C++ code for implementation details. \n \n "
" @ingroup Examples \n " ) ;
2017-10-05 22:04:51 +00:00
//-----------------------------------------------------------------------------
// Object setup and teardown
//-----------------------------------------------------------------------------
CustomShaderFeatureData : : CustomShaderFeatureData ( )
{
}
CustomShaderFeatureData : : ~ CustomShaderFeatureData ( )
{
}
//-----------------------------------------------------------------------------
// Object Editing
//-----------------------------------------------------------------------------
void CustomShaderFeatureData : : initPersistFields ( )
{
2019-05-13 05:28:23 +00:00
// SceneObject already handles exposing the transform
Parent : : initPersistFields ( ) ;
2017-10-05 22:04:51 +00:00
}
bool CustomShaderFeatureData : : onAdd ( )
{
2019-05-13 05:28:23 +00:00
if ( ! Parent : : onAdd ( ) )
return false ;
2017-10-05 22:04:51 +00:00
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
{
mFeatureHLSL = new CustomFeatureHLSL ( ) ;
mFeatureHLSL - > mOwner = this ;
}
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
{
mFeatureGLSL = new CustomFeatureGLSL ( ) ;
mFeatureGLSL - > mOwner = this ;
}
2017-10-05 22:04:51 +00:00
2019-05-13 05:28:23 +00:00
return true ;
2017-10-05 22:04:51 +00:00
}
void CustomShaderFeatureData : : onRemove ( )
{
2019-05-13 05:28:23 +00:00
Parent : : onRemove ( ) ;
2017-10-05 22:04:51 +00:00
}
//Shadergen setup functions
2017-10-06 21:49:50 +00:00
void CustomShaderFeatureData : : addVariable ( String name , String type , String defaultValue )
{
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
mFeatureHLSL - > addVariable ( name , type , defaultValue ) ;
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
mFeatureGLSL - > addVariable ( name , type , defaultValue ) ;
2017-10-06 21:49:50 +00:00
}
2017-10-09 22:15:57 +00:00
void CustomShaderFeatureData : : addUniform ( String name , String type , String defaultValue , U32 arraySize )
{
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
mFeatureHLSL - > addUniform ( name , type , defaultValue , arraySize ) ;
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
mFeatureGLSL - > addUniform ( name , type , defaultValue , arraySize ) ;
2017-10-09 22:15:57 +00:00
}
void CustomShaderFeatureData : : addSampler ( String name , String type , U32 arraySize )
{
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
mFeatureHLSL - > addSampler ( name , type , arraySize ) ;
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
mFeatureGLSL - > addSampler ( name , type , arraySize ) ;
2017-10-09 22:15:57 +00:00
}
void CustomShaderFeatureData : : addTexture ( String name , String type , String samplerState , U32 arraySize )
{
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
mFeatureHLSL - > addTexture ( name , type , samplerState , arraySize ) ;
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
mFeatureGLSL - > addTexture ( name , type , samplerState , arraySize ) ;
2017-10-09 22:15:57 +00:00
}
2019-05-13 05:28:23 +00:00
void CustomShaderFeatureData : : addConnector ( String name , String type , String elementName )
2018-01-16 20:24:21 +00:00
{
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
mFeatureHLSL - > addConnector ( name , type , elementName ) ;
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
mFeatureGLSL - > addConnector ( name , type , elementName ) ;
2018-01-16 20:24:21 +00:00
}
2019-05-13 05:28:23 +00:00
void CustomShaderFeatureData : : addVertTexCoord ( String name )
2017-10-17 13:48:31 +00:00
{
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
mFeatureHLSL - > addVertTexCoord ( name ) ;
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
mFeatureGLSL - > addVertTexCoord ( name ) ;
2017-10-17 13:48:31 +00:00
}
2019-05-13 05:28:23 +00:00
bool CustomShaderFeatureData : : hasFeature ( String name )
2017-10-05 22:04:51 +00:00
{
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
return mFeatureHLSL - > hasFeature ( name ) ;
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
return mFeatureGLSL - > hasFeature ( name ) ;
2017-10-05 22:04:51 +00:00
}
2019-05-13 05:28:23 +00:00
void CustomShaderFeatureData : : writeLine ( String format , S32 argc , ConsoleValueRef * argv )
2017-10-05 22:04:51 +00:00
{
2019-05-13 05:28:23 +00:00
if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : Direct3D11 )
mFeatureHLSL - > writeLine ( format , argc , argv ) ;
else if ( GFX - > getAdapterType ( ) = = GFXAdapterType : : OpenGL )
mFeatureGLSL - > writeLine ( format , argc , argv ) ;
2017-10-05 22:04:51 +00:00
}
2019-05-13 05:28:23 +00:00
DefineEngineMethod ( CustomShaderFeatureData , addVariable , void , ( String name , String type , String defaultValue ) , ( " " , " " , " " ) , " " )
2017-10-05 22:04:51 +00:00
{
2019-05-13 05:28:23 +00:00
object - > addVariable ( name , type , defaultValue ) ;
2017-10-05 22:04:51 +00:00
}
2019-05-13 05:28:23 +00:00
DefineEngineMethod ( CustomShaderFeatureData , addUniform , void , ( String name , String type , String defaultValue , U32 arraySize ) , ( " " , " " , " " , 0 ) , " " )
2017-10-05 22:04:51 +00:00
{
2019-05-13 05:28:23 +00:00
object - > addUniform ( name , type , defaultValue , arraySize ) ;
}
2017-10-05 22:04:51 +00:00
2019-05-13 05:28:23 +00:00
DefineEngineMethod ( CustomShaderFeatureData , addSampler , void , ( String name , U32 arraySize ) , ( " " , 0 ) , " " )
2017-10-05 22:04:51 +00:00
{
2019-05-13 05:28:23 +00:00
object - > addSampler ( name , " " , arraySize ) ;
2017-10-06 21:49:50 +00:00
}
2017-10-05 22:04:51 +00:00
2019-05-13 05:28:23 +00:00
DefineEngineMethod ( CustomShaderFeatureData , addTexture , void , ( String name , String type , String samplerState , U32 arraySize ) , ( " " , " " , 0 ) , " " )
2017-10-09 22:15:57 +00:00
{
2019-05-13 05:28:23 +00:00
object - > addTexture ( name , type , samplerState , arraySize ) ;
2017-10-09 22:15:57 +00:00
}
2019-05-13 05:28:23 +00:00
DefineEngineMethod ( CustomShaderFeatureData , addConnector , void , ( String name , String type , String elementName ) , ( " " , " " , " " ) , " " )
2017-10-09 22:15:57 +00:00
{
2019-05-13 05:28:23 +00:00
object - > addConnector ( name , type , elementName ) ;
2017-10-09 22:15:57 +00:00
}
2019-05-13 05:28:23 +00:00
DefineEngineMethod ( CustomShaderFeatureData , addVertTexCoord , void , ( String name ) , ( " " ) , " " )
2017-10-09 22:15:57 +00:00
{
2019-05-13 05:28:23 +00:00
object - > addVertTexCoord ( name ) ;
2017-10-09 22:15:57 +00:00
}
2019-05-13 05:28:23 +00:00
DefineEngineStringlyVariadicMethod ( CustomShaderFeatureData , writeLine , void , 3 , 0 , " ( string format, string args... ) Dynamically call a method on an object. \n "
" @param method Name of method to call. \n "
" @param args Zero or more arguments for the method. \n "
" @return The result of the method call. " )
2017-10-05 22:04:51 +00:00
{
2019-05-13 05:28:23 +00:00
object - > writeLine ( argv [ 2 ] , argc - 3 , argv + 3 ) ;
2017-10-17 13:48:31 +00:00
}
DefineEngineMethod ( CustomShaderFeatureData , hasFeature , bool , ( String name ) , ( " " ) , " " )
{
2019-05-13 05:28:23 +00:00
return object - > hasFeature ( name ) ;
}