Skip to content

Commit

Permalink
Merge pull request #968 from Vavius/fix-moaiimagetexture
Browse files Browse the repository at this point in the history
Attempt to fix MOAIImageTexture reallocated on each new glyph rendered
  • Loading branch information
halfnelson committed Sep 6, 2014
2 parents 1419f68 + 62f8d6a commit 3dcf831
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 2 deletions.
Binary file not shown.
38 changes: 38 additions & 0 deletions samples/test/textbox-dynamic-cache-allocs/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
----------------------------------------------------------------
-- Copyright (c) 2010-2011 Zipline Games, Inc.
-- All Rights Reserved.
-- http://getmoai.com
----------------------------------------------------------------

MOAISim.openWindow ( "test", 320, 480 )

viewport = MOAIViewport.new ()
viewport:setSize ( 320, 480 )
viewport:setScale ( 320, 480 )

layer = MOAILayer2D.new ()
layer:setViewport ( viewport )
MOAISim.pushRenderPass ( layer )

font = MOAIFont.new ()
font:load ( 'arial-rounded.TTF' )

function glyphAlloc ()
text = "Hello 123456789 qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM"
local textbox = MOAITextBox.new ()
textbox:setFont ( font )
textbox:setString ( "as" )
textbox:setTextSize ( 64 )
textbox:setWordBreak ( MOAITextBox.WORD_BREAK_CHAR )
textbox:setRect ( -160, -240, 160, 240 )
textbox:setYFlip ( true )
layer:insertProp ( textbox )

for i = 1, #text do
textbox:setString ( text:sub ( 1, i ))
coroutine.yield ()
end
end

thread = MOAICoroutine.new ()
thread:run ( glyphAlloc )
33 changes: 33 additions & 0 deletions samples/test/textbox-dynamic-cache-allocs/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
::----------------------------------------------------------------::
:: Copyright (c) 2010-2011 Zipline Games, Inc.
:: All Rights Reserved.
:: http://getmoai.com
::----------------------------------------------------------------::

@echo off

:: verify paths
if not exist "%MOAI_BIN%\moai.exe" (
echo.
echo --------------------------------------------------------------------------------
echo ERROR: The MOAI_BIN environment variable either doesn't exist or it's pointing
echo to an invalid path. Please point it at a folder containing moai.exe.
echo --------------------------------------------------------------------------------
echo.
goto end
)

if not exist "%MOAI_CONFIG%" (
echo.
echo -------------------------------------------------------------------------------
echo WARNING: The MOAI_CONFIG environment variable either doesn't exist or it's
echo pointing to an invalid path. Please point it at a folder containing config.lua.
echo -------------------------------------------------------------------------------
echo.
)

:: run moai
"%MOAI_BIN%\moai" "%MOAI_CONFIG%\config.lua" "main.lua"

:end
pause
28 changes: 28 additions & 0 deletions samples/test/textbox-dynamic-cache-allocs/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
#--------------------------------------------------------------------------------------
# Copyright (c) 2010-2013 Zipline Games, Inc.
# All Rights Reserved.
# http://getmoai.com
#--------------------------------------------------------------------------------------

cd `dirname $0`

# Verify paths
if [ ! -f "$MOAI_BIN/moai" ]; then
echo "---------------------------------------------------------------------------"
echo "Error: The MOAI_BIN environment variable doesn't exist or its pointing to an"
echo "invalid path. Please point it at a folder containing moai executable"
echo "---------------------------------------------------------------------------"
exit 1
fi

if [ ! -f "$MOAI_CONFIG/config.lua" ]; then
echo "---------------------------------------------------------------------------"
echo "WARNING: The MOAI_CONFIG environment variable either doesn't exist or it's"
echo "pointing to an invalid path. Please point it at a folder containing config.lua"
echo "---------------------------------------------------------------------------"
exit 1
fi

# Run moai
$MOAI_BIN/moai $MOAI_CONFIG/config.lua main.lua
9 changes: 9 additions & 0 deletions src/moai-sim/MOAIGfxResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ void MOAIGfxResource::Invalidate () {
}
}

//----------------------------------------------------------------//
void MOAIGfxResource::InvalidateContents () {

if ( this->mState != STATE_ERROR ) {

this->mState = STATE_PRECREATE;
}
}

//----------------------------------------------------------------//
void MOAIGfxResource::Load () {

Expand Down
1 change: 1 addition & 0 deletions src/moai-sim/MOAIGfxResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class MOAIGfxResource :
void Clear ();
void Destroy ();
void Invalidate ();
void InvalidateContents ();
virtual bool IsValid () = 0; // return 'true' if the handle to the GPU-side resource is valid (or initialized) - GRAPHICS THREAD
void Load ();
MOAIGfxResource ();
Expand Down
4 changes: 2 additions & 2 deletions src/moai-sim/MOAIImageTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int MOAIImageTexture::_invalidate ( lua_State* L ) {
void MOAIImageTexture::InvalidateAll () {

this->mStatus = INVALID;
this->MOAIGfxResource::Load ();
this->MOAIGfxResource::InvalidateContents ();
}

//----------------------------------------------------------------//
Expand All @@ -63,7 +63,7 @@ void MOAIImageTexture::Invalidate ( ZLIntRect rect ) {
}
this->mStatus = INVALID_REGION;

this->MOAIGfxResource::Load ();
this->MOAIGfxResource::InvalidateContents ();
}

//----------------------------------------------------------------//
Expand Down

0 comments on commit 3dcf831

Please sign in to comment.