Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f576c59
Fumbling toward a transformation on CoronaTotalTime, so far the comma…
ggcrunchy Feb 7, 2019
6626191
Moved some of the time transform stuff into ShaderResource with link …
ggcrunchy Feb 8, 2019
e59f04a
Better argument checking for time transforms
ggcrunchy Feb 9, 2019
e05f972
Whoops, wasn't always linking Program back to ShaderResource
ggcrunchy Feb 10, 2019
c7af750
Removed notes to self about changes
ggcrunchy Feb 11, 2019
9058c1f
timeTransform ignored if no time dependency
ggcrunchy Feb 11, 2019
c01d916
Minor changes
ggcrunchy May 29, 2020
08dc3b6
Maintenance Revert Test
scottrules44 Sep 20, 2021
05b91fb
Simulator: Adding Samsung Galaxy 21 as a skin
scottrules44 Sep 22, 2021
f44be24
Maintenance
scottrules44 Sep 22, 2021
581d844
Android: adding rest of media intents for Android 11
scottrules44 Sep 22, 2021
265be3c
Merge
ggcrunchy Sep 23, 2021
e217c80
Merge
ggcrunchy Oct 4, 2021
ca300c1
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Oct 19, 2021
0b5e1e9
First go at graphics.undefineEffect()
ggcrunchy Nov 9, 2021
b41e624
Revert "First go at graphics.undefineEffect()"
ggcrunchy Nov 10, 2021
5be6193
Merging upstream
ggcrunchy Aug 18, 2022
f38ecec
Merge branch 'master' of https://github.com/ggcrunchy/corona
ggcrunchy Aug 18, 2022
bb395b8
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Dec 16, 2022
0bf47a5
Merge remote-tracking branch 'upstream/master'
ggcrunchy Jun 12, 2025
40bb2fa
Basic mechanics of UV unit region more or less working
ggcrunchy Jun 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions librtt/Display/Rtt_ClosedPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "Display/Rtt_Shader.h"
#include "Renderer/Rtt_Program.h"

#include "Display/Rtt_CompositePaint.h"

// ----------------------------------------------------------------------------

namespace Rtt
Expand Down Expand Up @@ -79,12 +81,37 @@ ClosedPath::SetSelfBounds( Real width, Real height )
return false;
}

static bool
ComesFromImageSheet( const Paint* paint )
{
if ( paint->IsType( Paint::kImageSheet ) )
{
return true;
}

if ( !paint->IsType( Paint::kMultitexture ) )
{
return false;
}

const CompositePaint* composite = static_cast< const CompositePaint* >( paint );

if ( composite->GetPaint0() && composite->GetPaint0()->IsType( Paint::kImageSheet ) )
{
return true;
}

return false;
}

void
ClosedPath::UpdatePaint( RenderData& data )
{
if ( HasFill() )
{
fFill->UpdatePaint( data );

data.fFromImageSheet = ComesFromImageSheet( fFill );
}

if ( HasStroke() && fStrokeData )
Expand Down
2 changes: 2 additions & 0 deletions librtt/Display/Rtt_CompositePaint.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class CompositePaint : public Paint
public:
virtual const Paint* AsPaint( Type t ) const;
virtual void ApplyPaintUVTransformations( ArrayVertex2& vertices ) const override;

const Paint* GetPaint0() const { return fPaint0; }

// virtual const MLuaUserdataAdapter& GetAdapter() const;

Expand Down
1 change: 1 addition & 0 deletions librtt/Display/Rtt_DisplayDefaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ DisplayDefaults::DisplayDefaults()
fIsImageSheetSampledInsideFrame( false ),
fIsImageSheetFrameTrimCorrected( false ),
fIsExternalTextureRetina( true ),
fIsUnitRegionWantedForBuiltinEffects( false ),
fSkipsCull( false ),
fSkipsHitTest( false ),
fEnableDepthInScene( false ),
Expand Down
10 changes: 7 additions & 3 deletions librtt/Display/Rtt_DisplayDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ class DisplayDefaults
U8 GetEmitterMapping() const { return fEmitterMapping; }
void SetEmitterMapping( U8 newValue ) { fEmitterMapping = newValue; }

bool IsImageSheetSampledInsideFrame() const { return fIsImageSheetSampledInsideFrame;}
bool IsImageSheetSampledInsideFrame() const { return fIsImageSheetSampledInsideFrame; }
void SetImageSheetSampledInsideFrame( bool newValue ) { fIsImageSheetSampledInsideFrame = newValue; }

bool IsImageSheetFrameTrimCorrected() const { return fIsImageSheetFrameTrimCorrected;}
bool IsImageSheetFrameTrimCorrected() const { return fIsImageSheetFrameTrimCorrected; }
void SetImageSheetFrameTrimCorrected( bool newValue ) { fIsImageSheetFrameTrimCorrected = newValue; }

bool IsExternalTextureRetina() const { return fIsExternalTextureRetina;}
bool IsExternalTextureRetina() const { return fIsExternalTextureRetina; }
void SetExternalTextureRetina( bool newValue ) { fIsExternalTextureRetina = newValue; }

bool IsUnitRegionWantedForBuiltinEffects() const { return fIsUnitRegionWantedForBuiltinEffects; }
void SetIsUnitRegionWantedForBuiltinEffects( bool newValue ) { fIsUnitRegionWantedForBuiltinEffects = newValue; }

public:
bool IsV1Compatibility() const { return fV1Compatibility; }
void SetV1Compatibility( bool newValue ) { fV1Compatibility = newValue; }
Expand Down Expand Up @@ -144,6 +147,7 @@ class DisplayDefaults
bool fIsImageSheetSampledInsideFrame;
bool fIsImageSheetFrameTrimCorrected;
bool fIsExternalTextureRetina;
bool fIsUnitRegionWantedForBuiltinEffects;
bool fSkipsCull;
bool fSkipsHitTest;
bool fEnableDepthInScene;
Expand Down
3 changes: 3 additions & 0 deletions librtt/Display/Rtt_DisplayObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ DisplayObject::DidChangePaint( RenderData& data )
data.fUserUniform1 = NULL;
data.fUserUniform2 = NULL;
data.fUserUniform3 = NULL;

data.fFromImageSheet = false;
data.fWantsUnitRegion = false;
}

// ----------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions librtt/Display/Rtt_LuaLibDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,11 @@ DisplayLibrary::getDefault( lua_State *L )
bool value = defaults.IsExternalTextureRetina();
lua_pushboolean( L, value ? 1 : 0 );
}
else if ( ( Rtt_StringCompare( key, "isUnitRegionWantedForBuiltinEffects" ) == 0 ) )
{
bool value = defaults.IsUnitRegionWantedForBuiltinEffects();
lua_pushboolean( L, value ? 1 : 0 );
}
else if ( ( Rtt_StringCompare( key, "timeTransform" ) == 0 ) )
{
const TimeTransform* transform = defaults.GetTimeTransform();
Expand Down Expand Up @@ -2169,6 +2174,11 @@ DisplayLibrary::setDefault( lua_State *L )
bool value = lua_toboolean( L, index ) ? true : false;
defaults.SetExternalTextureRetina( value );
}
else if ( ( Rtt_StringCompare( key, "isUnitRegionWantedForBuiltinEffects" ) == 0 ) )
{
bool value = lua_toboolean( L, index ) ? true : false;
defaults.SetIsUnitRegionWantedForBuiltinEffects( value );
}
else if ( ( Rtt_StringCompare( key, "timeTransform" ) == 0 ) )
{
if ( lua_isstring( L, index ) )
Expand Down
4 changes: 4 additions & 0 deletions librtt/Display/Rtt_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ Scene::Render( Renderer& renderer, PlatformSurface& rTarget, ProfilingEntryRAII*

if ( ! IsValid() )
{
renderer.SetOptInToUnitRegionEncoding( GetDisplay().GetDefaults().IsUnitRegionWantedForBuiltinEffects() );

const Rtt::Real kMillisecondsPerSecond = 1000.0f;
Rtt_AbsoluteTime elapsedTime = fOwner.GetElapsedTime();
Rtt::Real totalTime = Rtt_AbsoluteToMilliseconds( elapsedTime ) / kMillisecondsPerSecond;
Expand Down Expand Up @@ -318,6 +320,8 @@ Scene::Render( Renderer& renderer, PlatformSurface& rTarget, DisplayObject& obje
const StageObject* stage = object.GetStage();
if ( Rtt_VERIFY( stage == fCurrentStage ) )
{
renderer.SetOptInToUnitRegionEncoding( GetDisplay().GetDefaults().IsUnitRegionWantedForBuiltinEffects() );

Clear( renderer );

// This function is used to render a specific object in a scene.
Expand Down
12 changes: 11 additions & 1 deletion librtt/Display/Rtt_Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ Shader::Prepare( RenderData& objectData, int w, int h, ShaderResource::ProgramMo

objectData.fProgram = program;

ShaderResource::UnitRegionPolicy policy = fResource->GetUnitRegionPolicy();
if ( objectData.fFromImageSheet && ShaderResource::kNone != policy )
{
objectData.fWantsUnitRegion = true;
objectData.fAlwaysUseUnitRegion = ShaderResource::kAlways == policy;
objectData.fHasDistortion = ShaderResource::k25D == mod;
}

const CoronaEffectCallbacks * callbacks = fResource->GetEffectCallbacks();

if (callbacks && callbacks->prepare)
Expand All @@ -275,7 +283,9 @@ Shader::Draw( Renderer& renderer, const RenderData& objectData, const GeometryWr
{
if ( !renderer.CanAddGeometryWriters() ) // ignore during raw draws
{
renderer.SetGeometryWriters( writers, n );
bool encodeUnitRegion = objectData.fWantsUnitRegion &&
( objectData.fAlwaysUseUnitRegion || renderer.GetOptInToUnitRegionEncoding() );
renderer.SetGeometryWriters( writers, n, encodeUnitRegion, objectData.fHasDistortion );
}

DrawState state( fResource->GetEffectCallbacks(), fIsDrawing );
Expand Down
4 changes: 3 additions & 1 deletion librtt/Display/Rtt_ShaderComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ ShaderComposite::Draw( Renderer& renderer, const RenderData& objectData, const G
{
if ( !renderer.CanAddGeometryWriters() ) // ignore during raw draws
{
renderer.SetGeometryWriters( writers, n );
bool encodeUnitRegion = objectData.fWantsUnitRegion &&
( objectData.fAlwaysUseUnitRegion || renderer.GetOptInToUnitRegionEncoding() );
renderer.SetGeometryWriters( writers, n, encodeUnitRegion, objectData.fHasDistortion );
}

DrawState state( fResource->GetEffectCallbacks(), fIsDrawing );
Expand Down
16 changes: 16 additions & 0 deletions librtt/Display/Rtt_ShaderFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,22 @@ ShaderFactory::InitializeBindings( lua_State *L, int shaderIndex, const SharedPt
BindTimeTransform( L, shaderIndex, resource );
}

lua_getfield( L, shaderIndex, "wantUnitRegion" );

bool forBuiltins = LUA_TSTRING == lua_type( L, -1 ) && Rtt_StringCompare( lua_tostring( L, -1 ), "builtin" ) == 0;

if (forBuiltins)
{
resource->SetUnitRegionPolicy( ShaderResource::kOptIn );
}

else if ( LUA_TBOOLEAN == lua_type( L, -1 ) && lua_toboolean( L, -1 ) )
{
resource->SetUnitRegionPolicy( ShaderResource::kAlways );
}

lua_pop( L, 1 );

bool has_vertex_data = BindVertexDataMap( L, shaderIndex, resource );
if( has_vertex_data )
{
Expand Down
2 changes: 2 additions & 0 deletions librtt/Display/Rtt_ShaderResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ ShaderResource::ShaderResource( Program *program, ShaderTypes::Category category
fDetailsCount( 0U ),
fShellTransform( NULL ),
fTimeTransform( NULL ),
fUnitRegionPolicy( kNone ),
fUsesUniforms( false ),
fUsesTime( false )
{
Expand All @@ -286,6 +287,7 @@ ShaderResource::ShaderResource( Program *program, ShaderTypes::Category category
fDetailsCount( 0U ),
fShellTransform( NULL ),
fTimeTransform( NULL ),
fUnitRegionPolicy( kNone ),
fUsesUniforms( false ),
fUsesTime( false )
{
Expand Down
13 changes: 13 additions & 0 deletions librtt/Display/Rtt_ShaderResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ class ShaderResource
}
ProgramMod;

typedef enum UnitRegionPolicy
{
kNone = 0,
kAlways = 1,
kOptIn = 2,
kNumUnitRegionPolicies
}
UnitRegionPolicy;

typedef std::map< std::string, int > VertexDataMap;

struct UniformData
Expand Down Expand Up @@ -98,6 +107,9 @@ class ShaderResource
bool UsesTime() const { return fUsesTime; }
void SetUsesTime( bool newValue ) { fUsesTime = newValue; }

UnitRegionPolicy GetUnitRegionPolicy() const { return fUnitRegionPolicy; }
void SetUnitRegionPolicy( UnitRegionPolicy policy ) { fUnitRegionPolicy = policy; }

const CoronaEffectCallbacks * GetEffectCallbacks() const { return fEffectCallbacks; }
void SetEffectCallbacks( CoronaEffectCallbacks * callbacks );
const CoronaShellTransform * GetShellTransform() const { return fShellTransform; }
Expand Down Expand Up @@ -157,6 +169,7 @@ class ShaderResource
std::vector< std::string > fDetailValues;
U32 fDetailsCount;
TimeTransform *fTimeTransform;
UnitRegionPolicy fUnitRegionPolicy;
bool fUsesUniforms;
bool fUsesTime;

Expand Down
58 changes: 56 additions & 2 deletions librtt/Display/Shader/shell_default_gl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ uniform P_POSITION vec2 u_ContentScale;
uniform P_POSITION mat4 u_ViewProjectionMatrix;

#define CoronaVertexUserData a_UserData
#define CoronaTexCoord a_TexCoord.xy

#if WANT_UNIT_REGION
// want decoded attributes, but varyings aren't readable in general,
// as elaborated below in main()
P_UV vec4 g_DecodedCoords; // (x, y) = texcoord, (z, w) = unit coords

#define CoronaTexCoord g_DecodedCoords.xy
#define CoronaLocalTexCoord g_DecodedCoords.zw
#else
#define CoronaTexCoord a_TexCoord.xy
#define CoronaLocalTexCoord CoronaTexCoord
#endif

#define CoronaTotalTime u_TotalTime
#define CoronaDeltaTime u_DeltaTime
Expand Down Expand Up @@ -67,6 +78,42 @@ varying P_DEFAULT vec4 v_UserData;
P_POSITION vec2 VertexKernel( P_POSITION vec2 position );
#endif

#if WANT_UNIT_REGION
varying P_UV vec2 v_UnitCoords;

P_UV vec2 CoronaAuxDecodeTexCoord( P_UV vec2 texCoord )
{
P_UV vec2 isEncoded = step( vec2( .5 ), abs( texCoord - .5 ) ); // outside [0, 1]?
P_UV vec2 whichSide = sign( texCoord ); // if so, -1 (< 0) or +1 (> 1)

g_DecodedCoords.zw = mix( texCoord, max( whichSide, 0. ), isEncoded ); // if decoded, 0 or 1

v_UnitCoords = g_DecodedCoords.zw;

// "encoded" points interpret the texcoords like a
// (limited) mirrored repeat, so:
// < 0: -x
// from 0 to 1: just x (normal, not encoded)
// > 1: = 2 - x

g_DecodedCoords.xy = mix( texCoord, ( whichSide + 1. ) - texCoord, isEncoded );

return g_DecodedCoords.xy;
}

#ifdef TEX_COORD_Z
P_UV vec2 CoronaDecodeTexCoord( P_UV vec3 texCoord )
{
return CoronaAuxDecodeTexCoord( texCoord.xy / texCoord.z ) * texCoord.z;
}
#else
#define CoronaDecodeTexCoord( texCoord ) CoronaAuxDecodeTexCoord( texCoord.xy )
#endif

#else
#define CoronaDecodeTexCoord( texCoord ) texCoord.xy
#endif

void main()
{
// "varying" are only meant as OUTPUT variables. ie: Write-only variables
Expand All @@ -76,7 +123,7 @@ void main()
// Certain devices, like the "Samsung Galaxy Tab 2", DON'T allow you to
// use "varying" variable like any other local variables.

v_TexCoord = a_TexCoord.xy;
v_TexCoord = CoronaDecodeTexCoord( a_TexCoord );
#ifdef TEX_COORD_Z
v_TexCoordZ = a_TexCoord.z;
#endif
Expand Down Expand Up @@ -122,6 +169,13 @@ varying P_DEFAULT vec4 v_UserData;
#define CoronaColorScale( color ) (v_ColorScale*(color))
#define CoronaVertexUserData v_UserData

#if WANT_UNIT_REGION
varying P_UV vec2 v_UnitCoords;
#define CoronaLocalTexCoord( _ ) v_UnitCoords
#else
#define CoronaLocalTexCoord( texCoord ) texCoord
#endif

#define CoronaTotalTime u_TotalTime
#define CoronaDeltaTime u_DeltaTime
#define CoronaTexelSize u_TexelSize
Expand Down
11 changes: 6 additions & 5 deletions librtt/Renderer/Rtt_GLProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ GLProgram::UpdateShaderSource( Program* program, Program::Version version, Versi
char highp_support[] = "#define FRAGMENT_SHADER_SUPPORTS_HIGHP 0\n";
highp_support[ sizeof( highp_support ) - 3 ] = ( CommandBuffer::GetGpuSupportsHighPrecisionFragmentShaders() ? '1' : '0' );

//! \TODO Make the definition of "TEX_COORD_Z" conditional.
char texCoordZBuffer[] = "";//#define TEX_COORD_Z 1\n";
ShaderResource * shaderResource = program->GetShaderResource();

char wantUnitRegionBuffer[] = "#define WANT_UNIT_REGION 0\n";
wantUnitRegionBuffer[ sizeof( wantUnitRegionBuffer ) - 3] = ( shaderResource->GetUnitRegionPolicy() != ShaderResource::kNone ? '1' : '0' );

const char *program_header_source = program->GetHeaderSource();
const char *header = ( program_header_source ? program_header_source : "" );
Expand All @@ -374,7 +376,7 @@ GLProgram::UpdateShaderSource( Program* program, Program::Version version, Versi
shader_source[0] = header;
shader_source[1] = highp_support;
shader_source[2] = maskBuffer;
shader_source[3] = texCoordZBuffer;
shader_source[3] = wantUnitRegionBuffer;

if ( program->IsCompilerVerbose() )
{
Expand All @@ -383,10 +385,9 @@ GLProgram::UpdateShaderSource( Program* program, Program::Version version, Versi
data.fHeaderNumLines = CountLines( shader_source, numSegments );
}

ShaderResource * shaderResource = program->GetShaderResource();
const CoronaShellTransform * shellTransform = shaderResource->GetShellTransform();
CoronaShellTransformParams params = {};
const char * hints[] = { "header", "highpSupport", "mask", "texCoordZ", NULL };
const char * hints[] = { "header", "highpSupport", "mask", "wantUnitRegion", NULL };
void * shellTransformKey = &fCleanupShellTransform; // n.b. done to make cleanup robust

std::vector< CoronaEffectDetail > details;
Expand Down
Loading