Formatting

This commit is contained in:
Maschell 2020-08-13 12:38:07 +02:00
parent 61917ce2a4
commit 2b42bbd60f
81 changed files with 4978 additions and 4570 deletions

2
.gitignore vendored
View File

@ -6,3 +6,5 @@ lib/
libgui.layout libgui.layout
obj/ obj/
CMakeLists.txt CMakeLists.txt
cmake-build-debug/
.idea/

View File

@ -57,7 +57,7 @@ typedef struct ftgxCharData_ {
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */ int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */ int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
GX2Texture * texture; GX2Texture *texture;
} ftgxCharData; } ftgxCharData;
/*! \struct ftgxDataOffset_ /*! \struct ftgxDataOffset_
@ -75,28 +75,28 @@ typedef struct ftgxCharData_ ftgxCharData;
typedef struct ftgxDataOffset_ ftgxDataOffset; typedef struct ftgxDataOffset_ ftgxDataOffset;
#define _TEXT(t) L ## t /**< Unicode helper macro. */ #define _TEXT(t) L ## t /**< Unicode helper macro. */
#define FTGX_NULL 0x0000 #define FTGX_NULL 0x0000
#define FTGX_JUSTIFY_LEFT 0x0001 #define FTGX_JUSTIFY_LEFT 0x0001
#define FTGX_JUSTIFY_CENTER 0x0002 #define FTGX_JUSTIFY_CENTER 0x0002
#define FTGX_JUSTIFY_RIGHT 0x0004 #define FTGX_JUSTIFY_RIGHT 0x0004
#define FTGX_JUSTIFY_MASK 0x000f #define FTGX_JUSTIFY_MASK 0x000f
#define FTGX_ALIGN_TOP 0x0010 #define FTGX_ALIGN_TOP 0x0010
#define FTGX_ALIGN_MIDDLE 0x0020 #define FTGX_ALIGN_MIDDLE 0x0020
#define FTGX_ALIGN_BOTTOM 0x0040 #define FTGX_ALIGN_BOTTOM 0x0040
#define FTGX_ALIGN_BASELINE 0x0080 #define FTGX_ALIGN_BASELINE 0x0080
#define FTGX_ALIGN_GLYPH_TOP 0x0100 #define FTGX_ALIGN_GLYPH_TOP 0x0100
#define FTGX_ALIGN_GLYPH_MIDDLE 0x0200 #define FTGX_ALIGN_GLYPH_MIDDLE 0x0200
#define FTGX_ALIGN_GLYPH_BOTTOM 0x0400 #define FTGX_ALIGN_GLYPH_BOTTOM 0x0400
#define FTGX_ALIGN_MASK 0x0ff0 #define FTGX_ALIGN_MASK 0x0ff0
#define FTGX_STYLE_UNDERLINE 0x1000 #define FTGX_STYLE_UNDERLINE 0x1000
#define FTGX_STYLE_STRIKE 0x2000 #define FTGX_STYLE_STRIKE 0x2000
#define FTGX_STYLE_MASK 0xf000 #define FTGX_STYLE_MASK 0xf000
/**< Constant color value used only to sanitize Doxygen documentation. */ /**< Constant color value used only to sanitize Doxygen documentation. */
static const GX2ColorF32 ftgxWhite = (GX2ColorF32) { static const GX2ColorF32 ftgxWhite = (GX2ColorF32) {
1.0f, 1.0f, 1.0f, 1.0f 1.0f, 1.0f, 1.0f, 1.0f
}; };
@ -129,29 +129,39 @@ private:
std::map<int16_t, ftGX2Data> fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */ std::map<int16_t, ftGX2Data> fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */
int16_t getStyleOffsetWidth(uint16_t width, uint16_t format); int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize); int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize);
void unloadFont(); void unloadFont();
ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize); ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize);
uint16_t cacheGlyphDataComplete(int16_t pixelSize); uint16_t cacheGlyphDataComplete(int16_t pixelSize);
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData); void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
void copyTextureToFramebuffer(CVideo * pVideo, GX2Texture *tex, int16_t screenX, int16_t screenY, int16_t screenZ, const glm::vec4 & color, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor, const float & internalRenderingScale); void copyTextureToFramebuffer(CVideo *pVideo, GX2Texture *tex, int16_t screenX, int16_t screenY, int16_t screenZ, const glm::vec4 &color, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 &blurColor,
const float &internalRenderingScale);
public: public:
FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace = false); FreeTypeGX(const uint8_t *fontBuffer, FT_Long bufferSize, bool lastFace = false);
~FreeTypeGX(); ~FreeTypeGX();
uint16_t drawText(CVideo * pVideo, int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, const glm::vec4 & color, uint16_t drawText(CVideo *pVideo, int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, const glm::vec4 &color,
uint16_t textStyling, uint16_t textWidth, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor, const float & internalRenderingScale); uint16_t textStyling, uint16_t textWidth, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 &blurColor, const float &internalRenderingScale);
uint16_t getWidth(const wchar_t *text, int16_t pixelSize); uint16_t getWidth(const wchar_t *text, int16_t pixelSize);
uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000); uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000);
uint16_t getHeight(const wchar_t *text, int16_t pixelSize); uint16_t getHeight(const wchar_t *text, int16_t pixelSize);
void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0); void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0);
static wchar_t* charToWideChar(const char* p); static wchar_t *charToWideChar(const char *p);
static char* wideCharToUTF8(const wchar_t* strChar);
static char *wideCharToUTF8(const wchar_t *strChar);
}; };
#endif /* FREETYPEGX_H_ */ #endif /* FREETYPEGX_H_ */

View File

@ -6,14 +6,16 @@
class GameBgImage : public GuiImageAsync { class GameBgImage : public GuiImageAsync {
public: public:
GameBgImage(const std::string & filename, GuiImageData *preloadImage); GameBgImage(const std::string &filename, GuiImageData *preloadImage);
virtual ~GameBgImage(); virtual ~GameBgImage();
void setAlphaFadeOut(const glm::vec4 & a) { void setAlphaFadeOut(const glm::vec4 &a) {
alphaFadeOut = a; alphaFadeOut = a;
} }
void draw(CVideo *pVideo); void draw(CVideo *pVideo);
private: private:
glm::mat4 identity; glm::mat4 identity;
glm::vec4 alphaFadeOut; glm::vec4 alphaFadeOut;

View File

@ -6,18 +6,23 @@
class GridBackground : public GuiImage { class GridBackground : public GuiImage {
public: public:
GridBackground(GuiImageData *imgData); GridBackground(GuiImageData *imgData);
virtual ~GridBackground(); virtual ~GridBackground();
void setColorIntensity(const glm::vec4 & color) { void setColorIntensity(const glm::vec4 &color) {
colorIntensity = color; colorIntensity = color;
} }
const glm::vec4 & getColorIntensity() const {
const glm::vec4 &getColorIntensity() const {
return colorIntensity; return colorIntensity;
} }
void setDistanceFadeOut(const float & a) {
void setDistanceFadeOut(const float &a) {
distanceFadeOut = a; distanceFadeOut = a;
} }
void draw(CVideo *pVideo, const glm::mat4 & modelView);
void draw(CVideo *pVideo, const glm::mat4 &modelView);
private: private:
glm::mat4 m_modelView; glm::mat4 m_modelView;
glm::vec4 colorIntensity; glm::vec4 colorIntensity;

View File

@ -32,59 +32,76 @@ public:
//!\param w Width //!\param w Width
//!\param h Height //!\param h Height
GuiButton(float w, float h); GuiButton(float w, float h);
//!Destructor //!Destructor
virtual ~GuiButton(); virtual ~GuiButton();
//!Sets the button's image //!Sets the button's image
//!\param i Pointer to GuiImage object //!\param i Pointer to GuiImage object
void setImage(GuiImage* i); void setImage(GuiImage *i);
//!Sets the button's image on over //!Sets the button's image on over
//!\param i Pointer to GuiImage object //!\param i Pointer to GuiImage object
void setImageOver(GuiImage* i); void setImageOver(GuiImage *i);
void setIcon(GuiImage *i);
void setIconOver(GuiImage *i);
void setIcon(GuiImage* i);
void setIconOver(GuiImage* i);
//!Sets the button's image on hold //!Sets the button's image on hold
//!\param i Pointer to GuiImage object //!\param i Pointer to GuiImage object
void setImageHold(GuiImage* i); void setImageHold(GuiImage *i);
//!Sets the button's image on click //!Sets the button's image on click
//!\param i Pointer to GuiImage object //!\param i Pointer to GuiImage object
void setImageClick(GuiImage* i); void setImageClick(GuiImage *i);
//!Sets the button's label //!Sets the button's label
//!\param t Pointer to GuiText object //!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0) //!\param n Index of label to set (optional, default is 0)
void setLabel(GuiText* t, int32_t n = 0); void setLabel(GuiText *t, int32_t n = 0);
//!Sets the button's label on over (eg: different colored text) //!Sets the button's label on over (eg: different colored text)
//!\param t Pointer to GuiText object //!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0) //!\param n Index of label to set (optional, default is 0)
void setLabelOver(GuiText* t, int32_t n = 0); void setLabelOver(GuiText *t, int32_t n = 0);
//!Sets the button's label on hold //!Sets the button's label on hold
//!\param t Pointer to GuiText object //!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0) //!\param n Index of label to set (optional, default is 0)
void setLabelHold(GuiText* t, int32_t n = 0); void setLabelHold(GuiText *t, int32_t n = 0);
//!Sets the button's label on click //!Sets the button's label on click
//!\param t Pointer to GuiText object //!\param t Pointer to GuiText object
//!\param n Index of label to set (optional, default is 0) //!\param n Index of label to set (optional, default is 0)
void setLabelClick(GuiText* t, int32_t n = 0); void setLabelClick(GuiText *t, int32_t n = 0);
//!Sets the sound to play on over //!Sets the sound to play on over
//!\param s Pointer to GuiSound object //!\param s Pointer to GuiSound object
void setSoundOver(GuiSound * s); void setSoundOver(GuiSound *s);
//!Sets the sound to play on hold //!Sets the sound to play on hold
//!\param s Pointer to GuiSound object //!\param s Pointer to GuiSound object
void setSoundHold(GuiSound * s); void setSoundHold(GuiSound *s);
//!Sets the sound to play on click //!Sets the sound to play on click
//!\param s Pointer to GuiSound object //!\param s Pointer to GuiSound object
void setSoundClick(GuiSound * s); void setSoundClick(GuiSound *s);
//!Set a new GuiTrigger for the element //!Set a new GuiTrigger for the element
//!\param i Index of trigger array to set //!\param i Index of trigger array to set
//!\param t Pointer to GuiTrigger //!\param t Pointer to GuiTrigger
void setTrigger(GuiTrigger * t, int32_t idx = -1); void setTrigger(GuiTrigger *t, int32_t idx = -1);
//! //!
void resetState(void); void resetState(void);
//!Constantly called to draw the GuiButton //!Constantly called to draw the GuiButton
void draw(CVideo *video); void draw(CVideo *video);
//!Constantly called to allow the GuiButton to respond to updated input data //!Constantly called to allow the GuiButton to respond to updated input data
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void update(GuiController * c); void update(GuiController *c);
sigslot::signal2<GuiButton *, const GuiController *> selected; sigslot::signal2<GuiButton *, const GuiController *> selected;
sigslot::signal2<GuiButton *, const GuiController *> deSelected; sigslot::signal2<GuiButton *, const GuiController *> deSelected;
@ -96,22 +113,22 @@ public:
protected: protected:
static const int32_t iMaxGuiTriggers = 10; static const int32_t iMaxGuiTriggers = 10;
GuiImage * image; //!< Button image (default) GuiImage *image; //!< Button image (default)
GuiImage * imageOver; //!< Button image for STATE_SELECTED GuiImage *imageOver; //!< Button image for STATE_SELECTED
GuiImage * imageHold; //!< Button image for STATE_HELD GuiImage *imageHold; //!< Button image for STATE_HELD
GuiImage * imageClick; //!< Button image for STATE_CLICKED GuiImage *imageClick; //!< Button image for STATE_CLICKED
GuiImage * icon; GuiImage *icon;
GuiImage * iconOver; GuiImage *iconOver;
GuiText * label[4]; //!< Label(s) to display (default) GuiText *label[4]; //!< Label(s) to display (default)
GuiText * labelOver[4]; //!< Label(s) to display for STATE_SELECTED GuiText *labelOver[4]; //!< Label(s) to display for STATE_SELECTED
GuiText * labelHold[4]; //!< Label(s) to display for STATE_HELD GuiText *labelHold[4]; //!< Label(s) to display for STATE_HELD
GuiText * labelClick[4]; //!< Label(s) to display for STATE_CLICKED GuiText *labelClick[4]; //!< Label(s) to display for STATE_CLICKED
GuiSound * soundOver; //!< Sound to play for STATE_SELECTED GuiSound *soundOver; //!< Sound to play for STATE_SELECTED
GuiSound * soundHold; //!< Sound to play for STATE_HELD GuiSound *soundHold; //!< Sound to play for STATE_HELD
GuiSound * soundClick; //!< Sound to play for STATE_CLICKED GuiSound *soundClick; //!< Sound to play for STATE_CLICKED
GuiTrigger * trigger[iMaxGuiTriggers]; //!< GuiTriggers (input actions) that this element responds to GuiTrigger *trigger[iMaxGuiTriggers]; //!< GuiTriggers (input actions) that this element responds to
GuiTrigger * clickedTrigger; GuiTrigger *clickedTrigger;
GuiTrigger * heldTrigger; GuiTrigger *heldTrigger;
}; };
#endif #endif

View File

@ -26,23 +26,23 @@ class GuiCheckBox : public GuiToggle {
public: public:
//!Constructor //!Constructor
//!\param checked Checked //!\param checked Checked
GuiCheckBox(GuiImage * background, bool checked, float width = 0.0f,float height= 0.0f); GuiCheckBox(GuiImage *background, bool checked, float width = 0.0f, float height = 0.0f);
//!Destructor //!Destructor
virtual ~GuiCheckBox(); virtual ~GuiCheckBox();
void setImageBackground(GuiImage* img); void setImageBackground(GuiImage *img);
void setImageSelected(GuiImage* img); void setImageSelected(GuiImage *img);
void setImageHighlighted(GuiImage* img); void setImageHighlighted(GuiImage *img);
protected: protected:
GuiImage * backgroundImg = NULL; GuiImage *backgroundImg = NULL;
GuiImage * selectedImg = NULL; GuiImage *selectedImg = NULL;
GuiImage * highlightedImg = NULL; GuiImage *highlightedImg = NULL;
void update(GuiController * c); void update(GuiController *c);
}; };
#endif #endif

View File

@ -24,32 +24,32 @@ class GuiController {
public: public:
//!Constructor //!Constructor
GuiController(int32_t channel) GuiController(int32_t channel)
: chan(channel) { : chan(channel) {
memset(&lastData, 0, sizeof(lastData)); memset(&lastData, 0, sizeof(lastData));
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
switch(chan) { switch (chan) {
default: default:
case GuiTrigger::CHANNEL_1: case GuiTrigger::CHANNEL_1:
chanIdx = 0; chanIdx = 0;
break; break;
case GuiTrigger::CHANNEL_2: case GuiTrigger::CHANNEL_2:
chanIdx = 1; chanIdx = 1;
break; break;
case GuiTrigger::CHANNEL_3: case GuiTrigger::CHANNEL_3:
chanIdx = 2; chanIdx = 2;
break; break;
case GuiTrigger::CHANNEL_4: case GuiTrigger::CHANNEL_4:
chanIdx = 3; chanIdx = 3;
break; break;
case GuiTrigger::CHANNEL_5: case GuiTrigger::CHANNEL_5:
chanIdx = 4; chanIdx = 4;
break; break;
} }
} }
//!Destructor //!Destructor
virtual ~GuiController() {} virtual ~GuiController() {}
virtual bool update(int32_t width, int32_t height) = 0; virtual bool update(int32_t width, int32_t height) = 0;

View File

@ -27,7 +27,8 @@ public:
//!Constructor //!Constructor
//!\param w Width //!\param w Width
//!\param h Height //!\param h Height
GuiDragListener(float w,float h); GuiDragListener(float w, float h);
//!Destructor //!Destructor
virtual ~GuiDragListener(); virtual ~GuiDragListener();
@ -36,17 +37,17 @@ public:
//!Set a new GuiTrigger for the element //!Set a new GuiTrigger for the element
//!\param i Index of trigger array to set //!\param i Index of trigger array to set
//!\param t Pointer to GuiTrigger //!\param t Pointer to GuiTrigger
void setTrigger(GuiTrigger * t, int32_t idx = -1); void setTrigger(GuiTrigger *t, int32_t idx = -1);
//!Constantly called to allow the GuiDragListener to respond to updated input data //!Constantly called to allow the GuiDragListener to respond to updated input data
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void update(GuiController * c); void update(GuiController *c);
sigslot::signal5<GuiDragListener *, const GuiController *, GuiTrigger *,int32_t,int32_t> dragged; sigslot::signal5<GuiDragListener *, const GuiController *, GuiTrigger *, int32_t, int32_t> dragged;
protected: protected:
static const int32_t iMaxGuiTriggers = 10; static const int32_t iMaxGuiTriggers = 10;
GuiTrigger * trigger[iMaxGuiTriggers]; //!< GuiTriggers (input actions) that this element responds to GuiTrigger *trigger[iMaxGuiTriggers]; //!< GuiTriggers (input actions) that this element responds to
}; };
#endif #endif

View File

@ -36,34 +36,35 @@
enum { enum {
EFFECT_NONE = 0x00, EFFECT_NONE = 0x00,
EFFECT_SLIDE_TOP = 0x01, EFFECT_SLIDE_TOP = 0x01,
EFFECT_SLIDE_BOTTOM = 0x02, EFFECT_SLIDE_BOTTOM = 0x02,
EFFECT_SLIDE_RIGHT = 0x04, EFFECT_SLIDE_RIGHT = 0x04,
EFFECT_SLIDE_LEFT = 0x08, EFFECT_SLIDE_LEFT = 0x08,
EFFECT_SLIDE_IN = 0x10, EFFECT_SLIDE_IN = 0x10,
EFFECT_SLIDE_OUT = 0x20, EFFECT_SLIDE_OUT = 0x20,
EFFECT_SLIDE_FROM = 0x40, EFFECT_SLIDE_FROM = 0x40,
EFFECT_FADE = 0x80, EFFECT_FADE = 0x80,
EFFECT_SCALE = 0x100, EFFECT_SCALE = 0x100,
EFFECT_COLOR_TRANSITION = 0x200 EFFECT_COLOR_TRANSITION = 0x200
}; };
enum { enum {
ALIGN_LEFT = 0x01, ALIGN_LEFT = 0x01,
ALIGN_CENTER = 0x02, ALIGN_CENTER = 0x02,
ALIGN_RIGHT = 0x04, ALIGN_RIGHT = 0x04,
ALIGN_TOP = 0x10, ALIGN_TOP = 0x10,
ALIGN_MIDDLE = 0x20, ALIGN_MIDDLE = 0x20,
ALIGN_BOTTOM = 0x40, ALIGN_BOTTOM = 0x40,
ALIGN_TOP_LEFT = ALIGN_LEFT | ALIGN_TOP, ALIGN_TOP_LEFT = ALIGN_LEFT | ALIGN_TOP,
ALIGN_TOP_CENTER = ALIGN_CENTER | ALIGN_TOP, ALIGN_TOP_CENTER = ALIGN_CENTER | ALIGN_TOP,
ALIGN_TOP_RIGHT = ALIGN_RIGHT | ALIGN_TOP, ALIGN_TOP_RIGHT = ALIGN_RIGHT | ALIGN_TOP,
ALIGN_CENTERED = ALIGN_CENTER | ALIGN_MIDDLE, ALIGN_CENTERED = ALIGN_CENTER | ALIGN_MIDDLE,
}; };
//!Forward declaration //!Forward declaration
class GuiController; class GuiController;
class CVideo; class CVideo;
//!Primary GUI class. Most other classes inherit from this class. //!Primary GUI class. Most other classes inherit from this class.
@ -71,60 +72,66 @@ class GuiElement {
public: public:
//!Constructor //!Constructor
GuiElement(); GuiElement();
//!Destructor //!Destructor
virtual ~GuiElement() {} virtual ~GuiElement() {}
//!Set the element's parent //!Set the element's parent
//!\param e Pointer to parent element //!\param e Pointer to parent element
virtual void setParent(GuiElement * e) { virtual void setParent(GuiElement *e) {
parentElement = e; parentElement = e;
} }
//!Gets the element's parent //!Gets the element's parent
//!\return Pointer to parent element //!\return Pointer to parent element
virtual GuiElement * getParent() { virtual GuiElement *getParent() {
return parentElement; return parentElement;
} }
//!Gets the current leftmost coordinate of the element //!Gets the current leftmost coordinate of the element
//!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values //!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values
//!\return left coordinate //!\return left coordinate
virtual float getLeft(); virtual float getLeft();
//!Gets the current topmost coordinate of the element //!Gets the current topmost coordinate of the element
//!Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values //!Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values
//!\return top coordinate //!\return top coordinate
virtual float getTop(); virtual float getTop();
//!Gets the current Z coordinate of the element //!Gets the current Z coordinate of the element
//!\return Z coordinate //!\return Z coordinate
virtual float getDepth() { virtual float getDepth() {
float zParent = 0.0f; float zParent = 0.0f;
if(parentElement) if (parentElement)
zParent = parentElement->getDepth(); zParent = parentElement->getDepth();
return zParent+zoffset; return zParent + zoffset;
} }
virtual float getCenterX(void) { virtual float getCenterX(void) {
float pCenterX = 0.0f; float pCenterX = 0.0f;
if(parentElement) if (parentElement)
pCenterX = parentElement->getCenterX(); pCenterX = parentElement->getCenterX();
pCenterX += xoffset + xoffsetDyn; pCenterX += xoffset + xoffsetDyn;
if(alignment & ALIGN_LEFT) { if (alignment & ALIGN_LEFT) {
float pWidth = 0.0f; float pWidth = 0.0f;
float pScale = 0.0f; float pScale = 0.0f;
if(parentElement) { if (parentElement) {
pWidth = parentElement->getWidth(); pWidth = parentElement->getWidth();
pScale = parentElement->getScaleX(); pScale = parentElement->getScaleX();
} }
pCenterX -= pWidth * 0.5f * pScale - width * 0.5f * getScaleX(); pCenterX -= pWidth * 0.5f * pScale - width * 0.5f * getScaleX();
} else if(alignment & ALIGN_RIGHT) { } else if (alignment & ALIGN_RIGHT) {
float pWidth = 0.0f; float pWidth = 0.0f;
float pScale = 0.0f; float pScale = 0.0f;
if(parentElement) { if (parentElement) {
pWidth = parentElement->getWidth(); pWidth = parentElement->getWidth();
pScale = parentElement->getScaleX(); pScale = parentElement->getScaleX();
} }
@ -137,26 +144,26 @@ public:
virtual float getCenterY(void) { virtual float getCenterY(void) {
float pCenterY = 0.0f; float pCenterY = 0.0f;
if(parentElement) if (parentElement)
pCenterY = parentElement->getCenterY(); pCenterY = parentElement->getCenterY();
pCenterY += yoffset + yoffsetDyn; pCenterY += yoffset + yoffsetDyn;
if(alignment & ALIGN_TOP) { if (alignment & ALIGN_TOP) {
float pHeight = 0.0f; float pHeight = 0.0f;
float pScale = 0.0f; float pScale = 0.0f;
if(parentElement) { if (parentElement) {
pHeight = parentElement->getHeight(); pHeight = parentElement->getHeight();
pScale = parentElement->getScaleY(); pScale = parentElement->getScaleY();
} }
pCenterY += pHeight * 0.5f * pScale - getHeight() * 0.5f * getScaleY(); pCenterY += pHeight * 0.5f * pScale - getHeight() * 0.5f * getScaleY();
} else if(alignment & ALIGN_BOTTOM) { } else if (alignment & ALIGN_BOTTOM) {
float pHeight = 0.0f; float pHeight = 0.0f;
float pScale = 0.0f; float pScale = 0.0f;
if(parentElement) { if (parentElement) {
pHeight = parentElement->getHeight(); pHeight = parentElement->getHeight();
pScale = parentElement->getScaleY(); pScale = parentElement->getScaleY();
} }
@ -165,24 +172,29 @@ public:
} }
return pCenterY; return pCenterY;
} }
//!Gets elements xoffset //!Gets elements xoffset
virtual float getOffsetX() { virtual float getOffsetX() {
return xoffset; return xoffset;
} }
//!Gets elements yoffset //!Gets elements yoffset
virtual float getOffsetY() { virtual float getOffsetY() {
return yoffset; return yoffset;
} }
//!Gets the current width of the element. Does not currently consider the scale //!Gets the current width of the element. Does not currently consider the scale
//!\return width //!\return width
virtual float getWidth() { virtual float getWidth() {
return width; return width;
}; };
//!Gets the height of the element. Does not currently consider the scale //!Gets the height of the element. Does not currently consider the scale
//!\return height //!\return height
virtual float getHeight() { virtual float getHeight() {
return height; return height;
} }
//!Sets the size (width/height) of the element //!Sets the size (width/height) of the element
//!\param w Width of element //!\param w Width of element
//!\param h Height of element //!\param h Height of element
@ -190,124 +202,143 @@ public:
width = w; width = w;
height = h; height = h;
} }
//!Sets the element's visibility //!Sets the element's visibility
//!\param v Visibility (true = visible) //!\param v Visibility (true = visible)
virtual void setVisible(bool v) { virtual void setVisible(bool v) {
visible = v; visible = v;
visibleChanged(this, v); visibleChanged(this, v);
} }
//!Checks whether or not the element is visible //!Checks whether or not the element is visible
//!\return true if visible, false otherwise //!\return true if visible, false otherwise
virtual bool isVisible() const { virtual bool isVisible() const {
return !isStateSet(STATE_HIDDEN) && visible; return !isStateSet(STATE_HIDDEN) && visible;
}; };
//!Checks whether or not the element is selectable //!Checks whether or not the element is selectable
//!\return true if selectable, false otherwise //!\return true if selectable, false otherwise
virtual bool isSelectable() { virtual bool isSelectable() {
return !isStateSet(STATE_DISABLED) && selectable; return !isStateSet(STATE_DISABLED) && selectable;
} }
virtual bool isDrawOverOnlyWhenSelected() { virtual bool isDrawOverOnlyWhenSelected() {
return drawOverOnlyWhenSelected; return drawOverOnlyWhenSelected;
} }
virtual void setdrawOverOnlyWhenSelected(bool s) { virtual void setdrawOverOnlyWhenSelected(bool s) {
drawOverOnlyWhenSelected = s; drawOverOnlyWhenSelected = s;
} }
//!Checks whether or not the element is clickable //!Checks whether or not the element is clickable
//!\return true if clickable, false otherwise //!\return true if clickable, false otherwise
virtual bool isClickable() { virtual bool isClickable() {
return !isStateSet(STATE_DISABLED) && clickable; return !isStateSet(STATE_DISABLED) && clickable;
} }
//!Checks whether or not the element is holdable //!Checks whether or not the element is holdable
//!\return true if holdable, false otherwise //!\return true if holdable, false otherwise
virtual bool isHoldable() { virtual bool isHoldable() {
return !isStateSet(STATE_DISABLED) && holdable; return !isStateSet(STATE_DISABLED) && holdable;
} }
//!Sets whether or not the element is selectable //!Sets whether or not the element is selectable
//!\param s Selectable //!\param s Selectable
virtual void setSelectable(bool s) { virtual void setSelectable(bool s) {
selectable = s; selectable = s;
} }
//!Sets whether or not the element is clickable //!Sets whether or not the element is clickable
//!\param c Clickable //!\param c Clickable
virtual void setClickable(bool c) { virtual void setClickable(bool c) {
clickable = c; clickable = c;
} }
//!Sets whether or not the element is holdable //!Sets whether or not the element is holdable
//!\param c Holdable //!\param c Holdable
virtual void setHoldable(bool d) { virtual void setHoldable(bool d) {
holdable = d; holdable = d;
} }
//!Sets the element's state //!Sets the element's state
//!\param s State (STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_DISABLED) //!\param s State (STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_DISABLED)
//!\param c Controller channel (0-3, -1 = none) //!\param c Controller channel (0-3, -1 = none)
virtual void setState(int32_t s, int32_t c = -1) { virtual void setState(int32_t s, int32_t c = -1) {
if(c >= 0 && c < 5) { if (c >= 0 && c < 5) {
state[c] |= s; state[c] |= s;
} else { } else {
for(int32_t i = 0; i < 5; i++) for (int32_t i = 0; i < 5; i++)
state[i] |= s; state[i] |= s;
} }
stateChan = c; stateChan = c;
stateChanged(this, s, c); stateChanged(this, s, c);
} }
virtual void clearState(int32_t s, int32_t c = -1) { virtual void clearState(int32_t s, int32_t c = -1) {
if(c >= 0 && c < 5) { if (c >= 0 && c < 5) {
state[c] &= ~s; state[c] &= ~s;
} else { } else {
for(int32_t i = 0; i < 5; i++) for (int32_t i = 0; i < 5; i++)
state[i] &= ~s; state[i] &= ~s;
} }
stateChan = c; stateChan = c;
stateChanged(this, s, c); stateChanged(this, s, c);
} }
virtual bool isStateSet(int32_t s, int32_t c = -1) const { virtual bool isStateSet(int32_t s, int32_t c = -1) const {
if(c >= 0 && c < 5) { if (c >= 0 && c < 5) {
return (state[c] & s) != 0; return (state[c] & s) != 0;
} else { } else {
for(int32_t i = 0; i < 5; i++) for (int32_t i = 0; i < 5; i++)
if((state[i] & s) != 0) if ((state[i] & s) != 0)
return true; return true;
return false; return false;
} }
} }
//!Gets the element's current state //!Gets the element's current state
//!\return state //!\return state
virtual int32_t getState(int32_t c = 0) { virtual int32_t getState(int32_t c = 0) {
return state[c]; return state[c];
}; };
//!Gets the controller channel that last changed the element's state //!Gets the controller channel that last changed the element's state
//!\return Channel number (0-3, -1 = no channel) //!\return Channel number (0-3, -1 = no channel)
virtual int32_t getStateChan() { virtual int32_t getStateChan() {
return stateChan; return stateChan;
}; };
//!Resets the element's state to STATE_DEFAULT //!Resets the element's state to STATE_DEFAULT
virtual void resetState() { virtual void resetState() {
for(int32_t i = 0; i < 5; i++) for (int32_t i = 0; i < 5; i++)
state[i] = STATE_DEFAULT; state[i] = STATE_DEFAULT;
stateChan = -1; stateChan = -1;
} }
//!Sets the element's alpha value //!Sets the element's alpha value
//!\param a alpha value //!\param a alpha value
virtual void setAlpha(float a) { virtual void setAlpha(float a) {
alpha = a; alpha = a;
} }
//!Gets the element's alpha value //!Gets the element's alpha value
//!Considers alpha, alphaDyn, and the parent element's getAlpha() value //!Considers alpha, alphaDyn, and the parent element's getAlpha() value
//!\return alpha //!\return alpha
virtual float getAlpha() { virtual float getAlpha() {
float a; float a;
if(alphaDyn >= 0) if (alphaDyn >= 0)
a = alphaDyn; a = alphaDyn;
else else
a = alpha; a = alpha;
if(parentElement) if (parentElement)
a = (a * parentElement->getAlpha()); a = (a * parentElement->getAlpha());
return a; return a;
} }
//!Sets the element's scale //!Sets the element's scale
//!\param s scale (1 is 100%) //!\param s scale (1 is 100%)
virtual void setScale(float s) { virtual void setScale(float s) {
@ -315,106 +346,123 @@ public:
scaleY = s; scaleY = s;
scaleZ = s; scaleZ = s;
} }
//!Sets the element's scale //!Sets the element's scale
//!\param s scale (1 is 100%) //!\param s scale (1 is 100%)
virtual void setScaleX(float s) { virtual void setScaleX(float s) {
scaleX = s; scaleX = s;
} }
//!Sets the element's scale //!Sets the element's scale
//!\param s scale (1 is 100%) //!\param s scale (1 is 100%)
virtual void setScaleY(float s) { virtual void setScaleY(float s) {
scaleY = s; scaleY = s;
} }
//!Sets the element's scale //!Sets the element's scale
//!\param s scale (1 is 100%) //!\param s scale (1 is 100%)
virtual void setScaleZ(float s) { virtual void setScaleZ(float s) {
scaleZ = s; scaleZ = s;
} }
//!Gets the element's current scale //!Gets the element's current scale
//!Considers scale, scaleDyn, and the parent element's getScale() value //!Considers scale, scaleDyn, and the parent element's getScale() value
virtual float getScale() { virtual float getScale() {
float s = 0.5f * (scaleX+scaleY) * scaleDyn; float s = 0.5f * (scaleX + scaleY) * scaleDyn;
if(parentElement) if (parentElement)
s *= parentElement->getScale(); s *= parentElement->getScale();
return s; return s;
} }
//!Gets the element's current scale //!Gets the element's current scale
//!Considers scale, scaleDyn, and the parent element's getScale() value //!Considers scale, scaleDyn, and the parent element's getScale() value
virtual float getScaleX() { virtual float getScaleX() {
float s = scaleX * scaleDyn; float s = scaleX * scaleDyn;
if(parentElement) if (parentElement)
s *= parentElement->getScaleX(); s *= parentElement->getScaleX();
return s; return s;
} }
//!Gets the element's current scale //!Gets the element's current scale
//!Considers scale, scaleDyn, and the parent element's getScale() value //!Considers scale, scaleDyn, and the parent element's getScale() value
virtual float getScaleY() { virtual float getScaleY() {
float s = scaleY * scaleDyn; float s = scaleY * scaleDyn;
if(parentElement) if (parentElement)
s *= parentElement->getScaleY(); s *= parentElement->getScaleY();
return s; return s;
} }
//!Gets the element's current scale //!Gets the element's current scale
//!Considers scale, scaleDyn, and the parent element's getScale() value //!Considers scale, scaleDyn, and the parent element's getScale() value
virtual float getScaleZ() { virtual float getScaleZ() {
float s = scaleZ; float s = scaleZ;
if(parentElement) if (parentElement)
s *= parentElement->getScaleZ(); s *= parentElement->getScaleZ();
return s; return s;
} }
//!Checks whether rumble was requested by the element //!Checks whether rumble was requested by the element
//!\return true is rumble was requested, false otherwise //!\return true is rumble was requested, false otherwise
virtual bool isRumbleActive() { virtual bool isRumbleActive() {
return rumble; return rumble;
} }
//!Sets whether or not the element is requesting a rumble event //!Sets whether or not the element is requesting a rumble event
//!\param r true if requesting rumble, false if not //!\param r true if requesting rumble, false if not
virtual void setRumble(bool r) { virtual void setRumble(bool r) {
rumble = r; rumble = r;
} }
//!Set an effect for the element //!Set an effect for the element
//!\param e Effect to enable //!\param e Effect to enable
//!\param a Amount of the effect (usage varies on effect) //!\param a Amount of the effect (usage varies on effect)
//!\param t Target amount of the effect (usage varies on effect) //!\param t Target amount of the effect (usage varies on effect)
virtual void setEffect(int32_t e, int32_t a, int32_t t=0); virtual void setEffect(int32_t e, int32_t a, int32_t t = 0);
//!Sets an effect to be enabled on wiimote cursor over //!Sets an effect to be enabled on wiimote cursor over
//!\param e Effect to enable //!\param e Effect to enable
//!\param a Amount of the effect (usage varies on effect) //!\param a Amount of the effect (usage varies on effect)
//!\param t Target amount of the effect (usage varies on effect) //!\param t Target amount of the effect (usage varies on effect)
virtual void setEffectOnOver(int32_t e, int32_t a, int32_t t=0); virtual void setEffectOnOver(int32_t e, int32_t a, int32_t t = 0);
//!Shortcut to SetEffectOnOver(EFFECT_SCALE, 4, 110) //!Shortcut to SetEffectOnOver(EFFECT_SCALE, 4, 110)
virtual void setEffectGrow() { virtual void setEffectGrow() {
setEffectOnOver(EFFECT_SCALE, 4, 110); setEffectOnOver(EFFECT_SCALE, 4, 110);
} }
//!Reset all applied effects //!Reset all applied effects
virtual void resetEffects(); virtual void resetEffects();
//!Gets the current element effects //!Gets the current element effects
//!\return element effects //!\return element effects
virtual int32_t getEffect() const { virtual int32_t getEffect() const {
return effects; return effects;
} }
//!\return true if element animation is on going //!\return true if element animation is on going
virtual bool isAnimated() const { virtual bool isAnimated() const {
return (parentElement != 0) && (getEffect() > 0); return (parentElement != 0) && (getEffect() > 0);
} }
//!Checks whether the specified coordinates are within the element's boundaries //!Checks whether the specified coordinates are within the element's boundaries
//!\param x X coordinate //!\param x X coordinate
//!\param y Y coordinate //!\param y Y coordinate
//!\return true if contained within, false otherwise //!\return true if contained within, false otherwise
virtual bool isInside(float x, float y) { virtual bool isInside(float x, float y) {
return ( x > (this->getCenterX() - getScaleX() * getWidth() * 0.5f) return (x > (this->getCenterX() - getScaleX() * getWidth() * 0.5f)
&& x < (this->getCenterX() + getScaleX() * getWidth() * 0.5f) && x < (this->getCenterX() + getScaleX() * getWidth() * 0.5f)
&& y > (this->getCenterY() - getScaleY() * getHeight() * 0.5f) && y > (this->getCenterY() - getScaleY() * getHeight() * 0.5f)
&& y < (this->getCenterY() + getScaleY() * getHeight() * 0.5f)); && y < (this->getCenterY() + getScaleY() * getHeight() * 0.5f));
} }
//!Sets the element's position //!Sets the element's position
//!\param x X coordinate //!\param x X coordinate
//!\param y Y coordinate //!\param y Y coordinate
@ -422,6 +470,7 @@ public:
xoffset = x; xoffset = x;
yoffset = y; yoffset = y;
} }
//!Sets the element's position //!Sets the element's position
//!\param x X coordinate //!\param x X coordinate
//!\param y Y coordinate //!\param y Y coordinate
@ -431,38 +480,46 @@ public:
yoffset = y; yoffset = y;
zoffset = z; zoffset = z;
} }
//!Gets whether or not the element is in STATE_SELECTED //!Gets whether or not the element is in STATE_SELECTED
//!\return true if selected, false otherwise //!\return true if selected, false otherwise
virtual int32_t getSelected() { virtual int32_t getSelected() {
return -1; return -1;
} }
//!Sets the element's alignment respective to its parent element //!Sets the element's alignment respective to its parent element
//!Bitwise ALIGN_LEFT | ALIGN_RIGHT | ALIGN_CENTRE, ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE) //!Bitwise ALIGN_LEFT | ALIGN_RIGHT | ALIGN_CENTRE, ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
//!\param align Alignment //!\param align Alignment
virtual void setAlignment(int32_t a) { virtual void setAlignment(int32_t a) {
alignment = a; alignment = a;
} }
//!Gets the element's alignment //!Gets the element's alignment
virtual int32_t getAlignment() const { virtual int32_t getAlignment() const {
return alignment; return alignment;
} }
//!Angle of the object //!Angle of the object
virtual void setAngle(float a) { virtual void setAngle(float a) {
angle = a; angle = a;
} }
//!Angle of the object //!Angle of the object
virtual float getAngle() const { virtual float getAngle() const {
float r_angle = angle; float r_angle = angle;
if(parentElement) r_angle += parentElement->getAngle(); if (parentElement) r_angle += parentElement->getAngle();
return r_angle; return r_angle;
} }
//!Called constantly to allow the element to respond to the current input data //!Called constantly to allow the element to respond to the current input data
//!\param t Pointer to a GuiController, containing the current input data from PAD/WPAD/VPAD //!\param t Pointer to a GuiController, containing the current input data from PAD/WPAD/VPAD
virtual void update(GuiController * t) { } virtual void update(GuiController *t) {}
//!Called constantly to redraw the element //!Called constantly to redraw the element
virtual void draw(CVideo * v) { } virtual void draw(CVideo *v) {}
//!Called constantly to process stuff in the element //!Called constantly to process stuff in the element
virtual void process() { } virtual void process() {}
//!Updates the element's effects (dynamic values) //!Updates the element's effects (dynamic values)
//!Called by Draw(), used for animation purposes //!Called by Draw(), used for animation purposes
@ -491,12 +548,14 @@ public:
//POINT r = { p.x + getLeft(), p.y + getTop() }; //POINT r = { p.x + getLeft(), p.y + getTop() };
return p; return p;
} }
//! Switch pointer screen to control position //! Switch pointer screen to control position
POINT PtrToControl(POINT p) { POINT PtrToControl(POINT p) {
//! TODO for 3D //! TODO for 3D
//POINT r = { p.x - getLeft(), p.y - getTop() }; //POINT r = { p.x - getLeft(), p.y - getTop() };
return p; return p;
} }
//! Signals //! Signals
sigslot::signal2<GuiElement *, bool> visibleChanged; sigslot::signal2<GuiElement *, bool> visibleChanged;
sigslot::signal3<GuiElement *, int32_t, int32_t> stateChanged; sigslot::signal3<GuiElement *, int32_t, int32_t> stateChanged;
@ -521,7 +580,7 @@ protected:
int32_t alignment; //!< Horizontal element alignment, respective to parent element int32_t alignment; //!< Horizontal element alignment, respective to parent element
int32_t state[5]; //!< Element state (DEFAULT, SELECTED, CLICKED, DISABLED) int32_t state[5]; //!< Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
int32_t stateChan; //!< Which controller channel is responsible for the last change in state int32_t stateChan; //!< Which controller channel is responsible for the last change in state
GuiElement * parentElement; //!< Parent element GuiElement *parentElement; //!< Parent element
//! TODO: Move me to some Animator class //! TODO: Move me to some Animator class
int32_t xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects) int32_t xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects)

View File

@ -26,75 +26,99 @@ class GuiFrame : public GuiElement {
public: public:
//!Constructor //!Constructor
GuiFrame(GuiFrame *parent = 0); GuiFrame(GuiFrame *parent = 0);
//!\overload //!\overload
//!\param w Width of window //!\param w Width of window
//!\param h Height of window //!\param h Height of window
GuiFrame(float w, float h, GuiFrame *parent = 0); GuiFrame(float w, float h, GuiFrame *parent = 0);
//!Destructor //!Destructor
virtual ~GuiFrame(); virtual ~GuiFrame();
//!Appends a GuiElement to the GuiFrame //!Appends a GuiElement to the GuiFrame
//!\param e The GuiElement to append. If it is already in the GuiFrame, it is removed first //!\param e The GuiElement to append. If it is already in the GuiFrame, it is removed first
void append(GuiElement* e); void append(GuiElement *e);
//!Inserts a GuiElement into the GuiFrame at the specified index //!Inserts a GuiElement into the GuiFrame at the specified index
//!\param e The GuiElement to insert. If it is already in the GuiFrame, it is removed first //!\param e The GuiElement to insert. If it is already in the GuiFrame, it is removed first
//!\param i Index in which to insert the element //!\param i Index in which to insert the element
void insert(GuiElement* e, uint32_t i); void insert(GuiElement *e, uint32_t i);
//!Removes the specified GuiElement from the GuiFrame //!Removes the specified GuiElement from the GuiFrame
//!\param e GuiElement to be removed //!\param e GuiElement to be removed
void remove(GuiElement* e); void remove(GuiElement *e);
//!Removes all GuiElements //!Removes all GuiElements
void removeAll(); void removeAll();
//!Bring element to front of the window //!Bring element to front of the window
void bringToFront(GuiElement *e) { void bringToFront(GuiElement *e) {
remove(e); remove(e);
append(e); append(e);
} }
//!Returns the GuiElement at the specified index //!Returns the GuiElement at the specified index
//!\param index The index of the element //!\param index The index of the element
//!\return A pointer to the element at the index, NULL on error (eg: out of bounds) //!\return A pointer to the element at the index, NULL on error (eg: out of bounds)
GuiElement* getGuiElementAt(uint32_t index) const; GuiElement *getGuiElementAt(uint32_t index) const;
//!Returns the size of the list of elements //!Returns the size of the list of elements
//!\return The size of the current element list //!\return The size of the current element list
uint32_t getSize(); uint32_t getSize();
//!Sets the visibility of the window //!Sets the visibility of the window
//!\param v visibility (true = visible) //!\param v visibility (true = visible)
void setVisible(bool v); void setVisible(bool v);
//!Resets the window's state to STATE_DEFAULT //!Resets the window's state to STATE_DEFAULT
void resetState(); void resetState();
//!Sets the window's state //!Sets the window's state
//!\param s State //!\param s State
void setState(int32_t s, int32_t c = -1); void setState(int32_t s, int32_t c = -1);
void clearState(int32_t s, int32_t c = -1); void clearState(int32_t s, int32_t c = -1);
//!Gets the index of the GuiElement inside the window that is currently selected //!Gets the index of the GuiElement inside the window that is currently selected
//!\return index of selected GuiElement //!\return index of selected GuiElement
int32_t getSelected(); int32_t getSelected();
//!Dim the Window's background //!Dim the Window's background
void dimBackground(bool d); void dimBackground(bool d);
//!Draws all the elements in this GuiFrame //!Draws all the elements in this GuiFrame
void draw(CVideo * v); void draw(CVideo *v);
//!Updates the window and all elements contains within //!Updates the window and all elements contains within
//!Allows the GuiFrame and all elements to respond to the input data specified //!Allows the GuiFrame and all elements to respond to the input data specified
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
void update(GuiController * t); void update(GuiController *t);
//!virtual Close Window - this will put the object on the delete queue in MainWindow //!virtual Close Window - this will put the object on the delete queue in MainWindow
virtual void close(); virtual void close();
//!virtual show window function //!virtual show window function
virtual void show() {} virtual void show() {}
//!virtual hide window function //!virtual hide window function
virtual void hide() {} virtual void hide() {}
//!virtual enter main loop function (blocking) //!virtual enter main loop function (blocking)
virtual void exec() {} virtual void exec() {}
//!virtual updateEffects which is called by the main loop //!virtual updateEffects which is called by the main loop
virtual void updateEffects(); virtual void updateEffects();
//!virtual process which is called by the main loop //!virtual process which is called by the main loop
virtual void process(); virtual void process();
//! Signals //! Signals
//! On Closing //! On Closing
sigslot::signal1<GuiFrame *> closing; sigslot::signal1<GuiFrame *> closing;
protected: protected:
bool dim; //! Enable/disable dim of a window only bool dim; //! Enable/disable dim of a window only
GuiFrame *parent; //!< Parent Window GuiFrame *parent; //!< Parent Window
std::vector<GuiElement*> elements; //!< Contains all elements within the GuiFrame std::vector<GuiElement *> elements; //!< Contains all elements within the GuiFrame
}; };
#endif #endif

View File

@ -32,65 +32,79 @@ public:
//!\overload //!\overload
//!\param img Pointer to GuiImageData element //!\param img Pointer to GuiImageData element
GuiImage(GuiImageData * img); GuiImage(GuiImageData *img);
//!\overload //!\overload
//!Creates an image filled with the specified color //!Creates an image filled with the specified color
//!\param w Image width //!\param w Image width
//!\param h Image height //!\param h Image height
//!\param c Array with 4 x image color (BL, BR, TL, TR) //!\param c Array with 4 x image color (BL, BR, TL, TR)
GuiImage(int32_t w, int32_t h, const GX2Color & c, int32_t imgType = IMAGE_COLOR); GuiImage(int32_t w, int32_t h, const GX2Color &c, int32_t imgType = IMAGE_COLOR);
GuiImage(int32_t w, int32_t h, const GX2Color * c, uint32_t colorCount = 1, int32_t imgType = IMAGE_COLOR);
GuiImage(int32_t w, int32_t h, const GX2Color *c, uint32_t colorCount = 1, int32_t imgType = IMAGE_COLOR);
//!Destructor //!Destructor
virtual ~GuiImage(); virtual ~GuiImage();
//!Sets the number of times to draw the image horizontally //!Sets the number of times to draw the image horizontally
//!\param t Number of times to draw the image //!\param t Number of times to draw the image
void setTileHorizontal(int32_t t) { void setTileHorizontal(int32_t t) {
tileHorizontal = t; tileHorizontal = t;
} }
//!Sets the number of times to draw the image vertically //!Sets the number of times to draw the image vertically
//!\param t Number of times to draw the image //!\param t Number of times to draw the image
void setTileVertical(int32_t t) { void setTileVertical(int32_t t) {
tileVertical = t; tileVertical = t;
} }
//!Constantly called to draw the image //!Constantly called to draw the image
void draw(CVideo *pVideo); void draw(CVideo *pVideo);
//!Gets the image data //!Gets the image data
//!\return pointer to image data //!\return pointer to image data
GuiImageData * getImageData() const { GuiImageData *getImageData() const {
return imageData; return imageData;
} }
//!Sets up a new image using the GuiImageData object specified //!Sets up a new image using the GuiImageData object specified
//!\param img Pointer to GuiImageData object //!\param img Pointer to GuiImageData object
void setImageData(GuiImageData * img); void setImageData(GuiImageData *img);
//!Gets the pixel color at the specified coordinates of the image //!Gets the pixel color at the specified coordinates of the image
//!\param x X coordinate //!\param x X coordinate
//!\param y Y coordinate //!\param y Y coordinate
GX2Color getPixel(int32_t x, int32_t y); GX2Color getPixel(int32_t x, int32_t y);
//!Sets the pixel color at the specified coordinates of the image //!Sets the pixel color at the specified coordinates of the image
//!\param x X coordinate //!\param x X coordinate
//!\param y Y coordinate //!\param y Y coordinate
//!\param color Pixel color //!\param color Pixel color
void setPixel(int32_t x, int32_t y, const GX2Color & color); void setPixel(int32_t x, int32_t y, const GX2Color &color);
//!Change ImageColor //!Change ImageColor
void setImageColor(const GX2Color & c, int32_t idx = -1); void setImageColor(const GX2Color &c, int32_t idx = -1);
//!Change ImageColor //!Change ImageColor
void setSize(int32_t w, int32_t h); void setSize(int32_t w, int32_t h);
void setPrimitiveVertex(int32_t prim, const float *pos, const float *tex, uint32_t count); void setPrimitiveVertex(int32_t prim, const float *pos, const float *tex, uint32_t count);
void setBlurDirection(uint8_t dir, float value) { void setBlurDirection(uint8_t dir, float value) {
if(dir < 2) { if (dir < 2) {
blurDirection[dir] = value; blurDirection[dir] = value;
} }
} }
void setColorIntensity(const glm::vec4 & col) {
void setColorIntensity(const glm::vec4 &col) {
colorIntensity = col; colorIntensity = col;
} }
protected: protected:
void internalInit(int32_t w, int32_t h); void internalInit(int32_t w, int32_t h);
int32_t imgType; //!< Type of image data (IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA) int32_t imgType; //!< Type of image data (IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA)
GuiImageData * imageData; //!< Poiner to image data. May be shared with GuiImageData data GuiImageData *imageData; //!< Poiner to image data. May be shared with GuiImageData data
int32_t tileHorizontal; //!< Number of times to draw (tile) the image horizontally int32_t tileHorizontal; //!< Number of times to draw (tile) the image horizontally
int32_t tileVertical; //!< Number of times to draw (tile) the image vertically int32_t tileVertical; //!< Number of times to draw (tile) the image vertically
@ -104,8 +118,8 @@ protected:
float imageAngle; float imageAngle;
glm::vec3 blurDirection; glm::vec3 blurDirection;
const float * posVtxs; const float *posVtxs;
const float * texCoords; const float *texCoords;
uint32_t vtxCount; uint32_t vtxCount;
int32_t primitive; int32_t primitive;
}; };

View File

@ -24,17 +24,21 @@
class GuiImageAsync : public GuiImage { class GuiImageAsync : public GuiImage {
public: public:
GuiImageAsync(const uint8_t *imageBuffer, const uint32_t & imageBufferSize, GuiImageData * preloadImg); GuiImageAsync(const uint8_t *imageBuffer, const uint32_t &imageBufferSize, GuiImageData *preloadImg);
GuiImageAsync(const std::string & filename, GuiImageData * preloadImg);
GuiImageAsync(const std::string &filename, GuiImageData *preloadImg);
virtual ~GuiImageAsync(); virtual ~GuiImageAsync();
static void clearQueue(); static void clearQueue();
static void removeFromQueue(GuiImageAsync * image) {
static void removeFromQueue(GuiImageAsync *image) {
threadRemoveImage(image); threadRemoveImage(image);
} }
//! don't forget to LOCK GUI if using this asynchron call //! don't forget to LOCK GUI if using this asynchron call
sigslot::signal1<GuiImageAsync *> imageLoaded; sigslot::signal1<GuiImageAsync *> imageLoaded;
static void threadExit(); static void threadExit();
private: private:
@ -46,14 +50,16 @@ private:
const uint32_t imgBufferSize; const uint32_t imgBufferSize;
static void guiImageAsyncThread(CThread *thread, void *arg); static void guiImageAsyncThread(CThread *thread, void *arg);
static void threadAddImage(GuiImageAsync* Image);
static void threadRemoveImage(GuiImageAsync* Image); static void threadAddImage(GuiImageAsync *Image);
static void threadRemoveImage(GuiImageAsync *Image);
static std::vector<GuiImageAsync *> imageQueue; static std::vector<GuiImageAsync *> imageQueue;
static CThread *pThread; static CThread *pThread;
static std::recursive_mutex * pMutex; static std::recursive_mutex *pMutex;
static uint32_t threadRefCounter; static uint32_t threadRefCounter;
static GuiImageAsync * pInUse; static GuiImageAsync *pInUse;
static bool bExitRequested; static bool bExitRequested;
}; };

View File

@ -26,38 +26,48 @@ class GuiImageData : public GuiElement {
public: public:
//!Constructor //!Constructor
GuiImageData(); GuiImageData();
//!\param img Image data //!\param img Image data
//!\param imgSize The image size //!\param imgSize The image size
GuiImageData(const uint8_t * img, int32_t imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8); GuiImageData(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8);
//!Destructor //!Destructor
virtual ~GuiImageData(); virtual ~GuiImageData();
//!Load image from buffer //!Load image from buffer
//!\param img Image data //!\param img Image data
//!\param imgSize The image size //!\param imgSize The image size
void loadImage(const uint8_t * img, int32_t imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8); void loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8);
//! getter functions //! getter functions
const GX2Texture * getTexture() const { const GX2Texture *getTexture() const {
return texture; return texture;
}; };
const GX2Sampler * getSampler() const {
const GX2Sampler *getSampler() const {
return sampler; return sampler;
}; };
//!Gets the image width //!Gets the image width
//!\return image width //!\return image width
int32_t getWidth() const { int32_t getWidth() const {
if(texture) return texture->surface.width; if (texture) return texture->surface.width;
else return 0; else return 0;
}; };
//!Gets the image height //!Gets the image height
//!\return image height //!\return image height
int32_t getHeight() const { int32_t getHeight() const {
if(texture) return texture->surface.height; if (texture) return texture->surface.height;
else return 0; else return 0;
}; };
//! release memory of the image data //! release memory of the image data
void releaseData(void); void releaseData(void);
private: private:
void gdImageToUnormR8G8B8A8(gdImagePtr gdImg, uint32_t *imgBuffer, uint32_t width, uint32_t height, uint32_t pitch); void gdImageToUnormR8G8B8A8(gdImagePtr gdImg, uint32_t *imgBuffer, uint32_t width, uint32_t height, uint32_t pitch);
void gdImageToUnormR5G6B5(gdImagePtr gdImg, uint16_t *imgBuffer, uint32_t width, uint32_t height, uint32_t pitch); void gdImageToUnormR5G6B5(gdImagePtr gdImg, uint16_t *imgBuffer, uint32_t width, uint32_t height, uint32_t pitch);
GX2Texture *texture; GX2Texture *texture;

View File

@ -22,9 +22,11 @@
class GuiParticleImage : public GuiImage, public sigslot::has_slots<> { class GuiParticleImage : public GuiImage, public sigslot::has_slots<> {
public: public:
GuiParticleImage(int32_t w, int32_t h, uint32_t particleCount, float minRadius, float maxRadius, float minSpeed, float maxSpeed); GuiParticleImage(int32_t w, int32_t h, uint32_t particleCount, float minRadius, float maxRadius, float minSpeed, float maxSpeed);
virtual ~GuiParticleImage(); virtual ~GuiParticleImage();
void draw(CVideo *pVideo); void draw(CVideo *pVideo);
private: private:
float *posVertexs; float *posVertexs;
uint8_t *colorVertexs; uint8_t *colorVertexs;

View File

@ -30,38 +30,51 @@
class GuiScrollbar : public GuiElement, public sigslot::has_slots<> { class GuiScrollbar : public GuiElement, public sigslot::has_slots<> {
public: public:
GuiScrollbar(int32_t height); GuiScrollbar(int32_t height);
virtual ~GuiScrollbar(); virtual ~GuiScrollbar();
void ScrollOneUp(); void ScrollOneUp();
void ScrollOneDown(); void ScrollOneDown();
int32_t GetSelectedItem() { int32_t GetSelectedItem() {
return SelItem; return SelItem;
} }
int32_t GetSelectedIndex() { int32_t GetSelectedIndex() {
return SelInd; return SelInd;
} }
void draw(CVideo * video);
void update(GuiController * t); void draw(CVideo *video);
void update(GuiController *t);
//! Signals //! Signals
sigslot::signal2<int32_t, int32_t> listChanged; sigslot::signal2<int32_t, int32_t> listChanged;
//! Slots //! Slots
void SetScrollSpeed(int32_t speed) { void SetScrollSpeed(int32_t speed) {
ScrollSpeed = speed; ScrollSpeed = speed;
}; };
void SetPageSize(int32_t size); void SetPageSize(int32_t size);
void SetRowSize(int32_t size); void SetRowSize(int32_t size);
void SetSelectedItem(int32_t pos); void SetSelectedItem(int32_t pos);
void SetSelectedIndex(int32_t pos); void SetSelectedIndex(int32_t pos);
void SetEntrieCount(int32_t cnt); void SetEntrieCount(int32_t cnt);
void setSoundClick(GuiSound * snd) { void setSoundClick(GuiSound *snd) {
clickSound = snd; clickSound = snd;
arrowUpBtn->setSoundClick(snd); arrowUpBtn->setSoundClick(snd);
arrowDownBtn->setSoundClick(snd); arrowDownBtn->setSoundClick(snd);
} }
void setImageScrollbarLine(GuiImage * img) { void setImageScrollbarLine(GuiImage *img) {
if(img) { if (img) {
scrollbarLineImage = img; scrollbarLineImage = img;
scrollbarLineImage->setParent(this); scrollbarLineImage->setParent(this);
scrollbarLineImage->setParent(this); scrollbarLineImage->setParent(this);
@ -70,24 +83,24 @@ public:
} }
} }
void setImageArrowDown(GuiImage * img) { void setImageArrowDown(GuiImage *img) {
if(img) { if (img) {
arrowDownImage = img; arrowDownImage = img;
arrowDownBtn->setSize(img->getWidth(), img->getHeight()); arrowDownBtn->setSize(img->getWidth(), img->getHeight());
arrowDownBtn->setImage(img); arrowDownBtn->setImage(img);
} }
} }
void setImageArrowUp(GuiImage * img) { void setImageArrowUp(GuiImage *img) {
if(img) { if (img) {
arrowUpImage = img; arrowUpImage = img;
arrowUpBtn->setSize(img->getWidth(), img->getHeight()); arrowUpBtn->setSize(img->getWidth(), img->getHeight());
arrowUpBtn->setImage(img); arrowUpBtn->setImage(img);
} }
} }
void setImageScrollbarBox(GuiImage * img) { void setImageScrollbarBox(GuiImage *img) {
if(img) { if (img) {
scrollbarBoxImage = img; scrollbarBoxImage = img;
scrollbarBoxBtn->setSize(img->getWidth(), height); scrollbarBoxBtn->setSize(img->getWidth(), height);
scrollbarBoxBtn->setImage(img); scrollbarBoxBtn->setImage(img);
@ -101,8 +114,11 @@ public:
protected: protected:
void setScrollboxPosition(int32_t SelItem, int32_t SelInd); void setScrollboxPosition(int32_t SelItem, int32_t SelInd);
void OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnDownButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnDownButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnBoxButtonHold(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnBoxButtonHold(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
uint32_t ScrollState; uint32_t ScrollState;
@ -116,16 +132,16 @@ protected:
int32_t EntrieCount; int32_t EntrieCount;
int32_t pressedChan; int32_t pressedChan;
GuiButton * arrowUpBtn; GuiButton *arrowUpBtn;
GuiButton * arrowDownBtn; GuiButton *arrowDownBtn;
GuiButton * scrollbarBoxBtn; GuiButton *scrollbarBoxBtn;
GuiSound * clickSound = NULL; GuiSound *clickSound = NULL;
GuiImage * scrollbarLineImage = NULL; GuiImage *scrollbarLineImage = NULL;
GuiImage * arrowDownImage = NULL; GuiImage *arrowDownImage = NULL;
GuiImage * arrowUpImage = NULL; GuiImage *arrowUpImage = NULL;
GuiImage * scrollbarBoxImage = NULL; GuiImage *scrollbarBoxImage = NULL;
GuiTrigger touchTrigger; GuiTrigger touchTrigger;
GuiTrigger wpadTouchTrigger; GuiTrigger wpadTouchTrigger;

View File

@ -26,62 +26,72 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<> {
public: public:
//!Constructor //!Constructor
//!\param checked Checked //!\param checked Checked
GuiSelectBox(GuiImage * background, std::string caption,float width = 0.0f, float height = 0.0f,GuiFrame *parent = 0); GuiSelectBox(GuiImage *background, std::string caption, float width = 0.0f, float height = 0.0f, GuiFrame *parent = 0);
//!Destructor //!Destructor
virtual ~GuiSelectBox(); virtual ~GuiSelectBox();
sigslot::signal2<GuiSelectBox *, std::string> valueChanged; sigslot::signal2<GuiSelectBox *, std::string> valueChanged;
sigslot::signal2<GuiSelectBox *, bool> showhide; sigslot::signal2<GuiSelectBox *, bool> showhide;
void setImageTopBackground(GuiImage * img) { void setImageTopBackground(GuiImage *img) {
topBackgroundImg = img; topBackgroundImg = img;
topValueButton.setImage(img); topValueButton.setImage(img);
} }
void setImageTopHighlighted(GuiImage * img) { void setImageTopHighlighted(GuiImage *img) {
topHighlightedImg = img; topHighlightedImg = img;
topValueButton.setIconOver(img); topValueButton.setIconOver(img);
} }
void setImageValueBackground(GuiImageData * img) { void setImageValueBackground(GuiImageData *img) {
valueImageData = img; valueImageData = img;
} }
void setImageValueHighlighted(GuiImageData * img) { void setImageValueHighlighted(GuiImageData *img) {
valueHighlightedImageData = img; valueHighlightedImageData = img;
} }
void setImageValueSelected(GuiImageData * img) { void setImageValueSelected(GuiImageData *img) {
valueSelectedImageData = img; valueSelectedImageData = img;
} }
void setSoundClick(GuiSound * snd) { void setSoundClick(GuiSound *snd) {
buttonClickSound = snd; buttonClickSound = snd;
topValueButton.setSoundClick(snd); topValueButton.setSoundClick(snd);
} }
void OnTopValueClicked(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnTopValueClicked(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void Init(std::map<std::string,std::string> values, int32_t valueID);
void Init(std::map<std::string, std::string> values, int32_t valueID);
void setState(int32_t s, int32_t c = -1); void setState(int32_t s, int32_t c = -1);
virtual void setSize(float width, float height); virtual void setSize(float width, float height);
virtual float getTopValueHeight(); virtual float getTopValueHeight();
virtual float getTopValueWidth(); virtual float getTopValueWidth();
virtual float getHeight(); virtual float getHeight();
virtual float getWidth(); virtual float getWidth();
protected: protected:
void DeleteValueData(); void DeleteValueData();
void update(GuiController * c);
void update(GuiController *c);
void OnValueClicked(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnValueClicked(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnDPADClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnDPADClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnValueOpenEffectFinish(GuiElement *element); void OnValueOpenEffectFinish(GuiElement *element);
void OnValueCloseEffectFinish(GuiElement *element); void OnValueCloseEffectFinish(GuiElement *element);
void ShowHideValues(bool showhide); void ShowHideValues(bool showhide);
void SelectValue(uint32_t value); void SelectValue(uint32_t value);
uint32_t selected; uint32_t selected;
@ -91,13 +101,13 @@ protected:
bool opened; bool opened;
std::string captionText; std::string captionText;
GuiFrame valuesFrame; GuiFrame valuesFrame;
GuiImage* topBackgroundImg = NULL; GuiImage *topBackgroundImg = NULL;
GuiImage* topHighlightedImg = NULL; GuiImage *topHighlightedImg = NULL;
GuiButton topValueButton; GuiButton topValueButton;
GuiImageData * valueImageData = NULL; GuiImageData *valueImageData = NULL;
GuiImageData * valueSelectedImageData = NULL; GuiImageData *valueSelectedImageData = NULL;
GuiImageData * valueHighlightedImageData = NULL; GuiImageData *valueHighlightedImageData = NULL;
GuiText topValueText; GuiText topValueText;
GuiTrigger touchTrigger; GuiTrigger touchTrigger;
@ -112,7 +122,7 @@ protected:
GuiButton DPADButtons; GuiButton DPADButtons;
GuiSound* buttonClickSound; GuiSound *buttonClickSound;
typedef struct { typedef struct {
GuiImage *valueButtonImg; GuiImage *valueButtonImg;
@ -122,7 +132,7 @@ protected:
GuiText *valueButtonText; GuiText *valueButtonText;
} SelectBoxValueButton; } SelectBoxValueButton;
std::map<GuiButton * ,std::string> buttonToValue; std::map<GuiButton *, std::string> buttonToValue;
std::vector<SelectBoxValueButton> valueButtons; std::vector<SelectBoxValueButton> valueButtons;
}; };

View File

@ -25,32 +25,45 @@ public:
//!Constructor //!Constructor
//!\param sound Pointer to the sound data //!\param sound Pointer to the sound data
//!\param filesize Length of sound data //!\param filesize Length of sound data
GuiSound(const char * filepath); GuiSound(const char *filepath);
GuiSound(const uint8_t * sound, int32_t length);
GuiSound(const uint8_t *sound, int32_t length);
//!Destructor //!Destructor
virtual ~GuiSound(); virtual ~GuiSound();
//!Load a file and replace the old one //!Load a file and replace the old one
bool Load(const char * filepath); bool Load(const char *filepath);
//!Load a file and replace the old one //!Load a file and replace the old one
bool Load(const uint8_t * snd, int32_t len); bool Load(const uint8_t *snd, int32_t len);
//!Start sound playback //!Start sound playback
void Play(); void Play();
//!Stop sound playback //!Stop sound playback
void Stop(); void Stop();
//!Pause sound playback //!Pause sound playback
void Pause(); void Pause();
//!Resume sound playback //!Resume sound playback
void Resume(); void Resume();
//!Checks if the sound is currently playing //!Checks if the sound is currently playing
//!\return true if sound is playing, false otherwise //!\return true if sound is playing, false otherwise
bool IsPlaying(); bool IsPlaying();
//!Rewind the music //!Rewind the music
void Rewind(); void Rewind();
//!Set sound volume //!Set sound volume
//!\param v Sound volume (0-100) //!\param v Sound volume (0-100)
void SetVolume(uint32_t v); void SetVolume(uint32_t v);
//!\param l Loop (true to loop) //!\param l Loop (true to loop)
void SetLoop(bool l); void SetLoop(bool l);
protected: protected:
int32_t voice; //!< Currently assigned ASND voice channel int32_t voice; //!< Currently assigned ASND voice channel
}; };

View File

@ -26,25 +26,27 @@ class GuiSwitch : public GuiToggle {
public: public:
//!Constructor //!Constructor
//!\param checked Checked //!\param checked Checked
GuiSwitch(GuiImage * background, bool checked, float w = 0.0f, float h = 0.0f); GuiSwitch(GuiImage *background, bool checked, float w = 0.0f, float h = 0.0f);
//!Destructor //!Destructor
virtual ~GuiSwitch(); virtual ~GuiSwitch();
void setImageBackground(GuiImage* img); void setImageBackground(GuiImage *img);
void setImageOn(GuiImage* img); void setImageOn(GuiImage *img);
void setImageOff(GuiImage* img); void setImageOff(GuiImage *img);
void setImageHighlighted(GuiImage *img);
void setImageHighlighted(GuiImage* img);
protected: protected:
GuiImage * backgroundImg = NULL; GuiImage *backgroundImg = NULL;
GuiImage * onImg = NULL; GuiImage *onImg = NULL;
GuiImage * offImg = NULL; GuiImage *offImg = NULL;
GuiImage * highlightedImg = NULL; GuiImage *highlightedImg = NULL;
void draw(CVideo * v); void draw(CVideo *v);
}; };
#endif #endif

View File

@ -18,6 +18,7 @@
#define GUI_TEXT_H_ #define GUI_TEXT_H_
#include <gui/GuiElement.h> #include <gui/GuiElement.h>
//!Forward declaration //!Forward declaration
class FreeTypeGX; class FreeTypeGX;
@ -26,26 +27,34 @@ class GuiText : public GuiElement {
public: public:
//!Constructor //!Constructor
GuiText(); GuiText();
//!\param t Text //!\param t Text
//!\param s Font size //!\param s Font size
//!\param c Font color //!\param c Font color
GuiText(const char * t, int32_t s, const glm::vec4 & c); GuiText(const char *t, int32_t s, const glm::vec4 &c);
//!\overload //!\overload
//!\param t Text //!\param t Text
//!\param s Font size //!\param s Font size
//!\param c Font color //!\param c Font color
GuiText(const wchar_t * t, int32_t s, const glm::vec4 & c); GuiText(const wchar_t *t, int32_t s, const glm::vec4 &c);
//!\overload //!\overload
//!\Assumes SetPresets() has been called to setup preferred text attributes //!\Assumes SetPresets() has been called to setup preferred text attributes
//!\param t Text //!\param t Text
GuiText(const char * t); GuiText(const char *t);
//!Destructor //!Destructor
virtual ~GuiText(); virtual ~GuiText();
//!Sets the text of the GuiText element //!Sets the text of the GuiText element
//!\param t Text //!\param t Text
virtual void setText(const char * t); virtual void setText(const char *t);
virtual void setText(const wchar_t * t);
virtual void setTextf(const char *format, ...) __attribute__((format(printf,2,3))); virtual void setText(const wchar_t *t);
virtual void setTextf(const char *format, ...) __attribute__((format(printf, 2, 3)));
//!Sets up preset values to be used by GuiText(t) //!Sets up preset values to be used by GuiText(t)
//!Useful when printing multiple text elements, all with the same attributes set //!Useful when printing multiple text elements, all with the same attributes set
//!\param sz Font size //!\param sz Font size
@ -53,60 +62,77 @@ public:
//!\param w Maximum width of texture image (for text wrapping) //!\param w Maximum width of texture image (for text wrapping)
//!\param wrap Wrapmode when w>0 //!\param wrap Wrapmode when w>0
//!\param a Text alignment //!\param a Text alignment
static void setPresets(int32_t sz, const glm::vec4 & c, int32_t w, int32_t a); static void setPresets(int32_t sz, const glm::vec4 &c, int32_t w, int32_t a);
static void setPresetFont(FreeTypeGX *font); static void setPresetFont(FreeTypeGX *font);
//!Sets the font size //!Sets the font size
//!\param s Font size //!\param s Font size
void setFontSize(int32_t s); void setFontSize(int32_t s);
//!Sets the maximum width of the drawn texture image //!Sets the maximum width of the drawn texture image
//!If the text exceeds this, it is wrapped to the next line //!If the text exceeds this, it is wrapped to the next line
//!\param w Maximum width //!\param w Maximum width
//!\param m WrapMode //!\param m WrapMode
void setMaxWidth(int32_t w = 0, int32_t m = WRAP); void setMaxWidth(int32_t w = 0, int32_t m = WRAP);
//!Sets the font color //!Sets the font color
//!\param c Font color //!\param c Font color
void setColor(const glm::vec4 & c); void setColor(const glm::vec4 &c);
void setBlurGlowColor(float blurIntensity, const glm::vec4 & c); void setBlurGlowColor(float blurIntensity, const glm::vec4 &c);
void setTextBlur(float blur) { void setTextBlur(float blur) {
defaultBlur = blur; defaultBlur = blur;
} }
//!Get the original text as char //!Get the original text as char
virtual const wchar_t * getText() const { virtual const wchar_t *getText() const {
return text; return text;
} }
virtual std::string toUTF8(void) const; virtual std::string toUTF8(void) const;
//!Get the Horizontal Size of Text //!Get the Horizontal Size of Text
int32_t getTextWidth() { int32_t getTextWidth() {
return textWidth; return textWidth;
} }
int32_t getTextWidth(int32_t ind); int32_t getTextWidth(int32_t ind);
//!Get the max textwidth //!Get the max textwidth
int32_t getTextMaxWidth() { int32_t getTextMaxWidth() {
return maxWidth; return maxWidth;
} }
//!Get fontsize //!Get fontsize
int32_t getFontSize() { int32_t getFontSize() {
return size; return size;
}; };
//!Set max lines to draw //!Set max lines to draw
void setLinesToDraw(int32_t l) { void setLinesToDraw(int32_t l) {
linestodraw = l; linestodraw = l;
} }
//!Get current Textline (for position calculation) //!Get current Textline (for position calculation)
const wchar_t * getDynText(int32_t ind = 0); const wchar_t *getDynText(int32_t ind = 0);
virtual const wchar_t * getTextLine(int32_t ind) {
virtual const wchar_t *getTextLine(int32_t ind) {
return getDynText(ind); return getDynText(ind);
}; };
//!Change the font //!Change the font
bool setFont(FreeTypeGX *font); bool setFont(FreeTypeGX *font);
//! virtual function used in child classes //! virtual function used in child classes
virtual int32_t getStartWidth() { virtual int32_t getStartWidth() {
return 0; return 0;
}; };
//!Constantly called to draw the text //!Constantly called to draw the text
void draw(CVideo *pVideo); void draw(CVideo *pVideo);
//! text enums //! text enums
enum { enum {
WRAP, WRAP,
@ -115,7 +141,7 @@ public:
SCROLL_NONE SCROLL_NONE
}; };
protected: protected:
static FreeTypeGX * presentFont; static FreeTypeGX *presentFont;
static int32_t presetSize; static int32_t presetSize;
static int32_t presetMaxWidth; static int32_t presetMaxWidth;
static float presetInternalRenderingScale; static float presetInternalRenderingScale;
@ -124,14 +150,17 @@ protected:
//!Clear the dynamic text //!Clear the dynamic text
void clearDynamicText(); void clearDynamicText();
//!Create a dynamic dotted text if the text is too long //!Create a dynamic dotted text if the text is too long
void makeDottedText(); void makeDottedText();
//!Scroll the text once //!Scroll the text once
void scrollText(uint32_t frameCount); void scrollText(uint32_t frameCount);
//!Wrap the text to several lines //!Wrap the text to several lines
void wrapText(); void wrapText();
wchar_t * text; wchar_t *text;
std::vector<wchar_t *> textDyn; std::vector<wchar_t *> textDyn;
std::vector<uint16_t> textDynWidth; std::vector<uint16_t> textDynWidth;
int32_t wrapMode; //!< Wrapping toggle int32_t wrapMode; //!< Wrapping toggle

View File

@ -21,39 +21,46 @@
#include <gui/GuiFrame.h> #include <gui/GuiFrame.h>
//!A simple CheckBox //!A simple CheckBox
class GuiToggle : public GuiButton, public sigslot::has_slots<> class GuiToggle : public GuiButton, public sigslot::has_slots<> {
{ public:
public: //!Constructor
//!Constructor //!\param checked Checked
//!\param checked Checked GuiToggle(bool checked, float width, float height);
GuiToggle(bool checked,float width,float height);
//!Destructor
virtual ~GuiToggle();
void setValue(bool checked){
if(selected != checked){
selected = checked;
bChanged=true;
valueChanged(this,selected);
}
}
void setChecked(){
setValue(true);
} //!Destructor
void setUnchecked(){ virtual ~GuiToggle();
setValue(false);
}
bool getValue(){
return selected;
}
sigslot::signal2<GuiToggle *, bool> valueChanged;
void OnToggleClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
protected:
bool selected; void setValue(bool checked) {
bool bChanged; if (selected != checked) {
selected = checked;
bChanged = true;
valueChanged(this, selected);
}
}
void update(GuiController * c); void setChecked() {
setValue(true);
}
void setUnchecked() {
setValue(false);
}
bool getValue() {
return selected;
}
sigslot::signal2<GuiToggle *, bool> valueChanged;
void OnToggleClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
protected:
bool selected;
bool bChanged;
void update(GuiController *c);
}; };
#endif #endif

View File

@ -68,19 +68,24 @@ public:
//!Constructor //!Constructor
GuiTrigger(); GuiTrigger();
//!Constructor //!Constructor
GuiTrigger(uint32_t ch, uint32_t btns, bool clickEverywhere = false, bool holdEverywhere = false, bool selectionClickEverywhere = false); GuiTrigger(uint32_t ch, uint32_t btns, bool clickEverywhere = false, bool holdEverywhere = false, bool selectionClickEverywhere = false);
//!Destructor //!Destructor
virtual ~GuiTrigger(); virtual ~GuiTrigger();
//!Sets a simple trigger. Requires: element is selected, and trigger button is pressed //!Sets a simple trigger. Requires: element is selected, and trigger button is pressed
void setTrigger(uint32_t ch, uint32_t btns); void setTrigger(uint32_t ch, uint32_t btns);
void setClickEverywhere(bool b) { void setClickEverywhere(bool b) {
bClickEverywhere = b; bClickEverywhere = b;
} }
void setHoldOnly(bool b) { void setHoldOnly(bool b) {
bHoldEverywhere = b; bHoldEverywhere = b;
} }
void setSelectionClickEverywhere(bool b) { void setSelectionClickEverywhere(bool b) {
bSelectionClickEverywhere = b; bSelectionClickEverywhere = b;
} }
@ -88,20 +93,29 @@ public:
bool isClickEverywhere() const { bool isClickEverywhere() const {
return bClickEverywhere; return bClickEverywhere;
} }
bool isHoldEverywhere() const { bool isHoldEverywhere() const {
return bHoldEverywhere; return bHoldEverywhere;
} }
bool isSelectionClickEverywhere() const { bool isSelectionClickEverywhere() const {
return bSelectionClickEverywhere; return bSelectionClickEverywhere;
} }
bool left(const GuiController *controller) const; bool left(const GuiController *controller) const;
bool right(const GuiController *controller) const; bool right(const GuiController *controller) const;
bool up(const GuiController *controller) const; bool up(const GuiController *controller) const;
bool down(const GuiController *controller) const; bool down(const GuiController *controller) const;
int32_t clicked(const GuiController *controller) const; int32_t clicked(const GuiController *controller) const;
bool held(const GuiController *controller) const; bool held(const GuiController *controller) const;
bool released(const GuiController *controller) const; bool released(const GuiController *controller) const;
private: private:
uint32_t chan; uint32_t chan;
uint32_t btns; uint32_t btns;

View File

@ -24,12 +24,12 @@ class VPadController : public GuiController {
public: public:
//!Constructor //!Constructor
VPadController(int32_t channel) VPadController(int32_t channel)
: GuiController(channel) { : GuiController(channel) {
memset(&vpad, 0, sizeof(vpad)); memset(&vpad, 0, sizeof(vpad));
} }
//!Destructor //!Destructor
virtual ~VPadController() {} virtual ~VPadController() {}
bool update(int32_t width, int32_t height) { bool update(int32_t width, int32_t height) {
lastData = data; lastData = data;
@ -37,7 +37,7 @@ public:
VPADReadError vpadError = VPAD_READ_NO_SAMPLES; VPADReadError vpadError = VPAD_READ_NO_SAMPLES;
VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError); VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError);
if(vpadError == VPAD_READ_SUCCESS) { if (vpadError == VPAD_READ_SUCCESS) {
data.buttons_r = vpad.release; data.buttons_r = vpad.release;
data.buttons_h = vpad.hold; data.buttons_h = vpad.hold;
data.buttons_d = vpad.trigger; data.buttons_d = vpad.trigger;
@ -47,8 +47,8 @@ public:
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1); VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1);
//! calculate the screen offsets //! calculate the screen offsets
data.x = -(width >> 1) + (int32_t)(((float)tpCalib.x / 1280.0f) * (float)width); data.x = -(width >> 1) + (int32_t) (((float) tpCalib.x / 1280.0f) * (float) width);
data.y = -(height >> 1) + (int32_t)(float)height - (((float)tpCalib.y / 720.0f) * (float)height); data.y = -(height >> 1) + (int32_t) (float) height - (((float) tpCalib.y / 720.0f) * (float) height);
return true; return true;
} }

View File

@ -25,119 +25,120 @@ class WPadController : public GuiController {
public: public:
//!Constructor //!Constructor
WPadController(int32_t channel) WPadController(int32_t channel)
: GuiController(channel) { : GuiController(channel) {
memset(&kpadData, 0, sizeof(kpadData)); memset(&kpadData, 0, sizeof(kpadData));
} }
//!Destructor //!Destructor
virtual ~WPadController() {} virtual ~WPadController() {}
uint32_t remapWiiMoteButtons(uint32_t buttons) { uint32_t remapWiiMoteButtons(uint32_t buttons) {
uint32_t conv_buttons = 0; uint32_t conv_buttons = 0;
if(buttons & WPAD_BUTTON_LEFT) if (buttons & WPAD_BUTTON_LEFT)
conv_buttons |= GuiTrigger::BUTTON_LEFT; conv_buttons |= GuiTrigger::BUTTON_LEFT;
if(buttons & WPAD_BUTTON_RIGHT) if (buttons & WPAD_BUTTON_RIGHT)
conv_buttons |= GuiTrigger::BUTTON_RIGHT; conv_buttons |= GuiTrigger::BUTTON_RIGHT;
if(buttons & WPAD_BUTTON_DOWN) if (buttons & WPAD_BUTTON_DOWN)
conv_buttons |= GuiTrigger::BUTTON_DOWN; conv_buttons |= GuiTrigger::BUTTON_DOWN;
if(buttons & WPAD_BUTTON_UP) if (buttons & WPAD_BUTTON_UP)
conv_buttons |= GuiTrigger::BUTTON_UP; conv_buttons |= GuiTrigger::BUTTON_UP;
if(buttons & WPAD_BUTTON_PLUS) if (buttons & WPAD_BUTTON_PLUS)
conv_buttons |= GuiTrigger::BUTTON_PLUS; conv_buttons |= GuiTrigger::BUTTON_PLUS;
if(buttons & WPAD_BUTTON_2) if (buttons & WPAD_BUTTON_2)
conv_buttons |= GuiTrigger::BUTTON_2; conv_buttons |= GuiTrigger::BUTTON_2;
if(buttons & WPAD_BUTTON_1) if (buttons & WPAD_BUTTON_1)
conv_buttons |= GuiTrigger::BUTTON_1; conv_buttons |= GuiTrigger::BUTTON_1;
if(buttons & WPAD_BUTTON_B) if (buttons & WPAD_BUTTON_B)
conv_buttons |= GuiTrigger::BUTTON_B; conv_buttons |= GuiTrigger::BUTTON_B;
if(buttons & WPAD_BUTTON_A) if (buttons & WPAD_BUTTON_A)
conv_buttons |= GuiTrigger::BUTTON_A; conv_buttons |= GuiTrigger::BUTTON_A;
if(buttons & WPAD_BUTTON_MINUS) if (buttons & WPAD_BUTTON_MINUS)
conv_buttons |= GuiTrigger::BUTTON_MINUS; conv_buttons |= GuiTrigger::BUTTON_MINUS;
if(buttons & WPAD_BUTTON_Z) if (buttons & WPAD_BUTTON_Z)
conv_buttons |= GuiTrigger::BUTTON_Z; conv_buttons |= GuiTrigger::BUTTON_Z;
if(buttons & WPAD_BUTTON_C) if (buttons & WPAD_BUTTON_C)
conv_buttons |= GuiTrigger::BUTTON_C; conv_buttons |= GuiTrigger::BUTTON_C;
if(buttons & WPAD_BUTTON_HOME) if (buttons & WPAD_BUTTON_HOME)
conv_buttons |= GuiTrigger::BUTTON_HOME; conv_buttons |= GuiTrigger::BUTTON_HOME;
return conv_buttons; return conv_buttons;
} }
uint32_t remapClassicButtons(uint32_t buttons) { uint32_t remapClassicButtons(uint32_t buttons) {
uint32_t conv_buttons = 0; uint32_t conv_buttons = 0;
if(buttons & WPAD_CLASSIC_BUTTON_LEFT) if (buttons & WPAD_CLASSIC_BUTTON_LEFT)
conv_buttons |= GuiTrigger::BUTTON_LEFT; conv_buttons |= GuiTrigger::BUTTON_LEFT;
if(buttons & WPAD_CLASSIC_BUTTON_RIGHT) if (buttons & WPAD_CLASSIC_BUTTON_RIGHT)
conv_buttons |= GuiTrigger::BUTTON_RIGHT; conv_buttons |= GuiTrigger::BUTTON_RIGHT;
if(buttons & WPAD_CLASSIC_BUTTON_DOWN) if (buttons & WPAD_CLASSIC_BUTTON_DOWN)
conv_buttons |= GuiTrigger::BUTTON_DOWN; conv_buttons |= GuiTrigger::BUTTON_DOWN;
if(buttons & WPAD_CLASSIC_BUTTON_UP) if (buttons & WPAD_CLASSIC_BUTTON_UP)
conv_buttons |= GuiTrigger::BUTTON_UP; conv_buttons |= GuiTrigger::BUTTON_UP;
if(buttons & WPAD_CLASSIC_BUTTON_PLUS) if (buttons & WPAD_CLASSIC_BUTTON_PLUS)
conv_buttons |= GuiTrigger::BUTTON_PLUS; conv_buttons |= GuiTrigger::BUTTON_PLUS;
if(buttons & WPAD_CLASSIC_BUTTON_X) if (buttons & WPAD_CLASSIC_BUTTON_X)
conv_buttons |= GuiTrigger::BUTTON_X; conv_buttons |= GuiTrigger::BUTTON_X;
if(buttons & WPAD_CLASSIC_BUTTON_Y) if (buttons & WPAD_CLASSIC_BUTTON_Y)
conv_buttons |= GuiTrigger::BUTTON_Y; conv_buttons |= GuiTrigger::BUTTON_Y;
if(buttons & WPAD_CLASSIC_BUTTON_B) if (buttons & WPAD_CLASSIC_BUTTON_B)
conv_buttons |= GuiTrigger::BUTTON_B; conv_buttons |= GuiTrigger::BUTTON_B;
if(buttons & WPAD_CLASSIC_BUTTON_A) if (buttons & WPAD_CLASSIC_BUTTON_A)
conv_buttons |= GuiTrigger::BUTTON_A; conv_buttons |= GuiTrigger::BUTTON_A;
if(buttons & WPAD_CLASSIC_BUTTON_MINUS) if (buttons & WPAD_CLASSIC_BUTTON_MINUS)
conv_buttons |= GuiTrigger::BUTTON_MINUS; conv_buttons |= GuiTrigger::BUTTON_MINUS;
if(buttons & WPAD_CLASSIC_BUTTON_HOME) if (buttons & WPAD_CLASSIC_BUTTON_HOME)
conv_buttons |= GuiTrigger::BUTTON_HOME; conv_buttons |= GuiTrigger::BUTTON_HOME;
if(buttons & WPAD_CLASSIC_BUTTON_ZR) if (buttons & WPAD_CLASSIC_BUTTON_ZR)
conv_buttons |= GuiTrigger::BUTTON_ZR; conv_buttons |= GuiTrigger::BUTTON_ZR;
if(buttons & WPAD_CLASSIC_BUTTON_ZL) if (buttons & WPAD_CLASSIC_BUTTON_ZL)
conv_buttons |= GuiTrigger::BUTTON_ZL; conv_buttons |= GuiTrigger::BUTTON_ZL;
if(buttons & WPAD_CLASSIC_BUTTON_R) if (buttons & WPAD_CLASSIC_BUTTON_R)
conv_buttons |= GuiTrigger::BUTTON_R; conv_buttons |= GuiTrigger::BUTTON_R;
if(buttons & WPAD_CLASSIC_BUTTON_L) if (buttons & WPAD_CLASSIC_BUTTON_L)
conv_buttons |= GuiTrigger::BUTTON_L; conv_buttons |= GuiTrigger::BUTTON_L;
return conv_buttons; return conv_buttons;
} }
WPADChan getChanByInt(int32_t chan) { WPADChan getChanByInt(int32_t chan) {
if(chan == 0) { if (chan == 0) {
return WPAD_CHAN_0; return WPAD_CHAN_0;
} }
if(chan == 1) { if (chan == 1) {
return WPAD_CHAN_1; return WPAD_CHAN_1;
} }
if(chan == 2) { if (chan == 2) {
return WPAD_CHAN_3; return WPAD_CHAN_3;
} }
if(chan == 3) { if (chan == 3) {
return WPAD_CHAN_3; return WPAD_CHAN_3;
} }
return WPAD_CHAN_0; return WPAD_CHAN_0;
@ -148,12 +149,12 @@ public:
WPADExtensionType controller_type; WPADExtensionType controller_type;
//! check if the controller is connected //! check if the controller is connected
if(WPADProbe(getChanByInt(chanIdx-1), &controller_type) != 0) if (WPADProbe(getChanByInt(chanIdx - 1), &controller_type) != 0)
return false; return false;
KPADRead(getChanByInt(chanIdx-1), &kpadData, 1); KPADRead(getChanByInt(chanIdx - 1), &kpadData, 1);
if(kpadData.extensionType <= 1) { if (kpadData.extensionType <= 1) {
data.buttons_r = remapWiiMoteButtons(kpadData.release); data.buttons_r = remapWiiMoteButtons(kpadData.release);
data.buttons_h = remapWiiMoteButtons(kpadData.hold); data.buttons_h = remapWiiMoteButtons(kpadData.hold);
data.buttons_d = remapWiiMoteButtons(kpadData.trigger); data.buttons_d = remapWiiMoteButtons(kpadData.trigger);
@ -165,11 +166,11 @@ public:
data.validPointer = (kpadData.posValid == 1 || kpadData.posValid == 2) && (kpadData.pos.x >= -1.0f && kpadData.pos.x <= 1.0f) && (kpadData.pos.y >= -1.0f && kpadData.pos.y <= 1.0f); data.validPointer = (kpadData.posValid == 1 || kpadData.posValid == 2) && (kpadData.pos.x >= -1.0f && kpadData.pos.x <= 1.0f) && (kpadData.pos.y >= -1.0f && kpadData.pos.y <= 1.0f);
//! calculate the screen offsets if pointer is valid else leave old value //! calculate the screen offsets if pointer is valid else leave old value
if(data.validPointer) { if (data.validPointer) {
data.x = (width >> 1) * kpadData.pos.x; data.x = (width >> 1) * kpadData.pos.x;
data.y = (height >> 1) * (-kpadData.pos.y); data.y = (height >> 1) * (-kpadData.pos.y);
if(kpadData.angle.y > 0.0f) if (kpadData.angle.y > 0.0f)
data.pointerAngle = (-kpadData.angle.x + 1.0f) * 0.5f * 180.0f; data.pointerAngle = (-kpadData.angle.x + 1.0f) * 0.5f * 180.0f;
else else
data.pointerAngle = (kpadData.angle.x + 1.0f) * 0.5f * 180.0f - 180.0f; data.pointerAngle = (kpadData.angle.x + 1.0f) * 0.5f * 180.0f - 180.0f;

View File

@ -1,5 +1,5 @@
#ifndef __GX2_EXTENSION_H #ifndef __GX2_EXTENSION_H
#define __GX2_EXTENSION_H #define __GX2_EXTENSION_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -37,22 +37,22 @@ typedef struct _GX2ColorF32 {
} GX2ColorF32; } GX2ColorF32;
static const uint32_t attribute_dest_comp_selector[20] = { static const uint32_t attribute_dest_comp_selector[20] = {
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001,
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1,
GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW
}; };
static const uint32_t texture_comp_selector[54] = { static const uint32_t texture_comp_selector[54] = {
GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001,
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE,
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE,
GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01,
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001,
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1,
GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01 GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01
}; };
static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, GX2SurfaceDim dim, uint32_t width, uint32_t height, uint32_t depth, GX2SurfaceFormat format, GX2AAMode aa) { static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, GX2SurfaceDim dim, uint32_t width, uint32_t height, uint32_t depth, GX2SurfaceFormat format, GX2AAMode aa) {
@ -63,10 +63,10 @@ static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, GX2SurfaceDim
depthBuffer->surface.mipLevels = 1; depthBuffer->surface.mipLevels = 1;
depthBuffer->surface.format = format; depthBuffer->surface.format = format;
depthBuffer->surface.aa = aa; depthBuffer->surface.aa = aa;
depthBuffer->surface.use = (GX2SurfaceUse)(((format==GX2_SURFACE_FORMAT_UNORM_R24_X8) || (format==GX2_SURFACE_FORMAT_FLOAT_D24_S8)) ? depthBuffer->surface.use = (GX2SurfaceUse) (((format == GX2_SURFACE_FORMAT_UNORM_R24_X8) || (format == GX2_SURFACE_FORMAT_FLOAT_D24_S8)) ?
GX2_SURFACE_USE_DEPTH_BUFFER : (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE)); GX2_SURFACE_USE_DEPTH_BUFFER : (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE));
depthBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT; depthBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT;
depthBuffer->surface.swizzle = 0; depthBuffer->surface.swizzle = 0;
depthBuffer->viewMip = 0; depthBuffer->viewMip = 0;
depthBuffer->viewFirstSlice = 0; depthBuffer->viewFirstSlice = 0;
depthBuffer->viewNumSlices = depth; depthBuffer->viewNumSlices = depth;
@ -96,21 +96,21 @@ static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, GX2SurfaceDim
colorBuffer->surface.alignment = 0; colorBuffer->surface.alignment = 0;
colorBuffer->surface.pitch = 0; colorBuffer->surface.pitch = 0;
uint32_t i; uint32_t i;
for(i = 0; i < 13; i++) for (i = 0; i < 13; i++)
colorBuffer->surface.mipLevelOffset[i] = 0; colorBuffer->surface.mipLevelOffset[i] = 0;
colorBuffer->viewMip = 0; colorBuffer->viewMip = 0;
colorBuffer->viewFirstSlice = 0; colorBuffer->viewFirstSlice = 0;
colorBuffer->viewNumSlices = depth; colorBuffer->viewNumSlices = depth;
colorBuffer->aaBuffer = NULL; colorBuffer->aaBuffer = NULL;
colorBuffer->aaSize = 0; colorBuffer->aaSize = 0;
for(i = 0; i < 5; i++) for (i = 0; i < 5; i++)
colorBuffer->regs[i] = 0; colorBuffer->regs[i] = 0;
GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface); GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface);
GX2InitColorBufferRegs(colorBuffer); GX2InitColorBufferRegs(colorBuffer);
} }
static inline void GX2InitAttribStream(GX2AttribStream* attr, uint32_t location, uint32_t buffer, uint32_t offset, GX2AttribFormat format) { static inline void GX2InitAttribStream(GX2AttribStream *attr, uint32_t location, uint32_t buffer, uint32_t offset, GX2AttribFormat format) {
attr->location = location; attr->location = location;
attr->buffer = buffer; attr->buffer = buffer;
attr->offset = offset; attr->offset = offset;
@ -118,7 +118,7 @@ static inline void GX2InitAttribStream(GX2AttribStream* attr, uint32_t location,
attr->type = GX2_ATTRIB_INDEX_PER_VERTEX; attr->type = GX2_ATTRIB_INDEX_PER_VERTEX;
attr->aluDivisor = 0; attr->aluDivisor = 0;
attr->mask = attribute_dest_comp_selector[format & 0xff]; attr->mask = attribute_dest_comp_selector[format & 0xff];
attr->endianSwap = GX2_ENDIAN_SWAP_DEFAULT; attr->endianSwap = GX2_ENDIAN_SWAP_DEFAULT;
} }
static inline void GX2InitTexture(GX2Texture *tex, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevels, GX2SurfaceFormat format, GX2SurfaceDim dim, GX2TileMode tile) { static inline void GX2InitTexture(GX2Texture *tex, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevels, GX2SurfaceFormat format, GX2SurfaceDim dim, GX2TileMode tile) {
@ -139,14 +139,14 @@ static inline void GX2InitTexture(GX2Texture *tex, uint32_t width, uint32_t heig
tex->surface.alignment = 0; tex->surface.alignment = 0;
tex->surface.pitch = 0; tex->surface.pitch = 0;
uint32_t i; uint32_t i;
for(i = 0; i < 13; i++) for (i = 0; i < 13; i++)
tex->surface.mipLevelOffset[i] = 0; tex->surface.mipLevelOffset[i] = 0;
tex->viewFirstMip = 0; tex->viewFirstMip = 0;
tex->viewNumMips = mipLevels; tex->viewNumMips = mipLevels;
tex->viewFirstSlice = 0; tex->viewFirstSlice = 0;
tex->viewNumSlices = depth; tex->viewNumSlices = depth;
tex->compMap = texture_comp_selector[format & 0x3f]; tex->compMap = texture_comp_selector[format & 0x3f];
for(i = 0; i < 5; i++) for (i = 0; i < 5; i++)
tex->regs[i] = 0; tex->regs[i] = 0;
GX2CalcSurfaceSizeAndAlignment(&tex->surface); GX2CalcSurfaceSizeAndAlignment(&tex->surface);

View File

@ -24,15 +24,19 @@ extern "C" {
#include <malloc.h> #include <malloc.h>
void libgui_memoryInitialize(void); void libgui_memoryInitialize(void);
void libgui_memoryRelease(void); void libgui_memoryRelease(void);
void * MEM2_alloc(uint32_t size, uint32_t align); void *MEM2_alloc(uint32_t size, uint32_t align);
void MEM2_free(void *ptr); void MEM2_free(void *ptr);
void * MEM1_alloc(uint32_t size, uint32_t align); void *MEM1_alloc(uint32_t size, uint32_t align);
void MEM1_free(void *ptr); void MEM1_free(void *ptr);
void * MEMBucket_alloc(uint32_t size, uint32_t align); void *MEMBucket_alloc(uint32_t size, uint32_t align);
void MEMBucket_free(void *ptr); void MEMBucket_free(void *ptr);
#ifdef __cplusplus #ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -33,55 +33,72 @@ class BufferCircle {
public: public:
//!> Constructor //!> Constructor
BufferCircle(); BufferCircle();
//!> Destructor //!> Destructor
~BufferCircle(); ~BufferCircle();
//!> Set circle size //!> Set circle size
void Resize(int32_t size); void Resize(int32_t size);
//!> Get the circle size //!> Get the circle size
int32_t Size() { int32_t Size() {
return SoundBuffer.size(); return SoundBuffer.size();
}; };
//!> Set/resize the buffer size //!> Set/resize the buffer size
void SetBufferBlockSize(int32_t size); void SetBufferBlockSize(int32_t size);
//!> Remove a buffer //!> Remove a buffer
void RemoveBuffer(int32_t pos); void RemoveBuffer(int32_t pos);
//!> Set all buffers clear //!> Set all buffers clear
void ClearBuffer(); void ClearBuffer();
//!> Free all buffers //!> Free all buffers
void FreeBuffer(); void FreeBuffer();
//!> Switch to next buffer //!> Switch to next buffer
void LoadNext(); void LoadNext();
//!> Get the current buffer //!> Get the current buffer
uint8_t * GetBuffer() { uint8_t *GetBuffer() {
return GetBuffer(which); return GetBuffer(which);
}; };
//!> Get a buffer at a position //!> Get a buffer at a position
uint8_t * GetBuffer(int32_t pos) { uint8_t *GetBuffer(int32_t pos) {
if(!Valid(pos)) return NULL; if (!Valid(pos)) return NULL;
else return SoundBuffer[pos]; else return SoundBuffer[pos];
}; };
//!> Get current buffer size //!> Get current buffer size
uint32_t GetBufferSize() { uint32_t GetBufferSize() {
return GetBufferSize(which); return GetBufferSize(which);
}; };
//!> Get buffer size at position //!> Get buffer size at position
uint32_t GetBufferSize(int32_t pos) { uint32_t GetBufferSize(int32_t pos) {
if(!Valid(pos)) return 0; if (!Valid(pos)) return 0;
else return BufferSize[pos]; else return BufferSize[pos];
}; };
//!> Is current buffer ready //!> Is current buffer ready
bool IsBufferReady() { bool IsBufferReady() {
return IsBufferReady(which); return IsBufferReady(which);
}; };
//!> Is a buffer at a position ready //!> Is a buffer at a position ready
bool IsBufferReady(int32_t pos) { bool IsBufferReady(int32_t pos) {
if(!Valid(pos)) return false; if (!Valid(pos)) return false;
else return BufferReady[pos]; else return BufferReady[pos];
}; };
//!> Set a buffer at a position to a ready state //!> Set a buffer at a position to a ready state
void SetBufferReady(int32_t pos, bool st); void SetBufferReady(int32_t pos, bool st);
//!> Set the buffersize at a position //!> Set the buffersize at a position
void SetBufferSize(int32_t pos, int32_t size); void SetBufferSize(int32_t pos, int32_t size);
//!> Get the current position in the circle //!> Get the current position in the circle
uint16_t Which() { uint16_t Which() {
return which; return which;
@ -89,12 +106,14 @@ public:
//!> Get the next location //!> Get the next location
inline uint16_t Next() { inline uint16_t Next() {
return (which+1 >= Size()) ? 0 : which+1; return (which + 1 >= Size()) ? 0 : which + 1;
} }
inline uint16_t Prev() { inline uint16_t Prev() {
if(Size() == 0) return 0; if (Size() == 0) return 0;
else return ((int32_t)which-1 < 0) ? Size()-1 : which-1; else return ((int32_t) which - 1 < 0) ? Size() - 1 : which - 1;
} }
protected: protected:
//!> Check if the position is a valid position in the vector //!> Check if the position is a valid position in the vector
bool Valid(int32_t pos) { bool Valid(int32_t pos) {

View File

@ -29,18 +29,24 @@
class Mp3Decoder : public SoundDecoder { class Mp3Decoder : public SoundDecoder {
public: public:
Mp3Decoder(const char * filepath); Mp3Decoder(const char *filepath);
Mp3Decoder(const uint8_t * sound, int32_t len);
Mp3Decoder(const uint8_t *sound, int32_t len);
virtual ~Mp3Decoder(); virtual ~Mp3Decoder();
int32_t Rewind(); int32_t Rewind();
int32_t Read(uint8_t * buffer, int32_t buffer_size, int32_t pos);
int32_t Read(uint8_t *buffer, int32_t buffer_size, int32_t pos);
protected: protected:
void OpenFile(); void OpenFile();
struct mad_stream Stream; struct mad_stream Stream;
struct mad_frame Frame; struct mad_frame Frame;
struct mad_synth Synth; struct mad_synth Synth;
mad_timer_t Timer; mad_timer_t Timer;
uint8_t * GuardPtr; uint8_t *GuardPtr;
uint8_t * ReadBuffer; uint8_t *ReadBuffer;
uint32_t SynthPos; uint32_t SynthPos;
}; };

View File

@ -30,13 +30,19 @@
class OggDecoder : public SoundDecoder { class OggDecoder : public SoundDecoder {
public: public:
OggDecoder(const char * filepath); OggDecoder(const char *filepath);
OggDecoder(const uint8_t * snd, int32_t len);
OggDecoder(const uint8_t *snd, int32_t len);
virtual ~OggDecoder(); virtual ~OggDecoder();
int32_t Rewind(); int32_t Rewind();
int32_t Read(uint8_t * buffer, int32_t buffer_size, int32_t pos);
int32_t Read(uint8_t *buffer, int32_t buffer_size, int32_t pos);
protected: protected:
void OpenFile(); void OpenFile();
OggVorbis_File ogg_file; OggVorbis_File ogg_file;
vorbis_info *ogg_info; vorbis_info *ogg_info;
}; };

View File

@ -35,61 +35,83 @@ class CFile;
class SoundDecoder { class SoundDecoder {
public: public:
SoundDecoder(); SoundDecoder();
SoundDecoder(const std::string & filepath);
SoundDecoder(const uint8_t * buffer, int32_t size); SoundDecoder(const std::string &filepath);
SoundDecoder(const uint8_t *buffer, int32_t size);
virtual ~SoundDecoder(); virtual ~SoundDecoder();
virtual void Lock() { virtual void Lock() {
mutex.lock(); mutex.lock();
} }
virtual void Unlock() { virtual void Unlock() {
mutex.unlock(); mutex.unlock();
} }
virtual int32_t Read(uint8_t * buffer, int32_t buffer_size, int32_t pos);
virtual int32_t Read(uint8_t *buffer, int32_t buffer_size, int32_t pos);
virtual int32_t Tell() { virtual int32_t Tell() {
return CurPos; return CurPos;
} }
virtual int32_t Seek(int32_t pos); virtual int32_t Seek(int32_t pos);
virtual int32_t Rewind(); virtual int32_t Rewind();
virtual uint16_t GetFormat() { virtual uint16_t GetFormat() {
return Format; return Format;
} }
virtual uint16_t GetSampleRate() { virtual uint16_t GetSampleRate() {
return SampleRate; return SampleRate;
} }
virtual void Decode(); virtual void Decode();
virtual bool IsBufferReady() { virtual bool IsBufferReady() {
return SoundBuffer.IsBufferReady(); return SoundBuffer.IsBufferReady();
} }
virtual uint8_t * GetBuffer() {
virtual uint8_t *GetBuffer() {
return SoundBuffer.GetBuffer(); return SoundBuffer.GetBuffer();
} }
virtual uint32_t GetBufferSize() { virtual uint32_t GetBufferSize() {
return SoundBuffer.GetBufferSize(); return SoundBuffer.GetBufferSize();
} }
virtual void LoadNext() { virtual void LoadNext() {
SoundBuffer.LoadNext(); SoundBuffer.LoadNext();
} }
virtual bool IsEOF() { virtual bool IsEOF() {
return EndOfFile; return EndOfFile;
} }
virtual void SetLoop(bool l) { virtual void SetLoop(bool l) {
Loop = l; Loop = l;
EndOfFile = false; EndOfFile = false;
} }
virtual uint8_t GetSoundType() { virtual uint8_t GetSoundType() {
return SoundType; return SoundType;
} }
virtual void ClearBuffer() { virtual void ClearBuffer() {
SoundBuffer.ClearBuffer(); SoundBuffer.ClearBuffer();
whichLoad = 0; whichLoad = 0;
} }
virtual bool IsStereo() { virtual bool IsStereo() {
return (GetFormat() & CHANNELS_STEREO) != 0; return (GetFormat() & CHANNELS_STEREO) != 0;
} }
virtual bool Is16Bit() { virtual bool Is16Bit() {
return ((GetFormat() & 0xFF) == FORMAT_PCM_16_BIT); return ((GetFormat() & 0xFF) == FORMAT_PCM_16_BIT);
} }
virtual bool IsDecoding() { virtual bool IsDecoding() {
return Decoding; return Decoding;
} }
@ -113,9 +135,10 @@ public:
}; };
protected: protected:
void Init(); void Init();
void Upsample(int16_t *src, int16_t *dst, uint32_t nr_src_samples, uint32_t nr_dst_samples); void Upsample(int16_t *src, int16_t *dst, uint32_t nr_src_samples, uint32_t nr_dst_samples);
CFile * file_fd; CFile *file_fd;
BufferCircle SoundBuffer; BufferCircle SoundBuffer;
uint8_t SoundType; uint8_t SoundType;
uint16_t whichLoad; uint16_t whichLoad;

View File

@ -33,11 +33,11 @@
#include <gui/sounds/Voice.h> #include <gui/sounds/Voice.h>
#include <sndcore2/voice.h> #include <sndcore2/voice.h>
#define MAX_DECODERS 16 // can be increased up to 96 #define MAX_DECODERS 16 // can be increased up to 96
class SoundHandler : public CThread { class SoundHandler : public CThread {
public: public:
static SoundHandler * instance() { static SoundHandler *instance() {
if (!handlerInstance) if (!handlerInstance)
handlerInstance = new SoundHandler(); handlerInstance = new SoundHandler();
return handlerInstance; return handlerInstance;
@ -48,42 +48,49 @@ public:
handlerInstance = NULL; handlerInstance = NULL;
} }
void AddDecoder(int32_t voice, const char * filepath); void AddDecoder(int32_t voice, const char *filepath);
void AddDecoder(int32_t voice, const uint8_t * snd, int32_t len);
void AddDecoder(int32_t voice, const uint8_t *snd, int32_t len);
void RemoveDecoder(int32_t voice); void RemoveDecoder(int32_t voice);
SoundDecoder * getDecoder(int32_t i) { SoundDecoder *getDecoder(int32_t i) {
return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]);
}; };
Voice * getVoice(int32_t i) {
Voice *getVoice(int32_t i) {
return ((i < 0 || i >= MAX_DECODERS) ? NULL : voiceList[i]); return ((i < 0 || i >= MAX_DECODERS) ? NULL : voiceList[i]);
}; };
void ThreadSignal() { void ThreadSignal() {
resumeThread(); resumeThread();
}; };
bool IsDecoding() { bool IsDecoding() {
return Decoding; return Decoding;
}; };
protected: protected:
SoundHandler(); SoundHandler();
~SoundHandler(); ~SoundHandler();
static void axFrameCallback(void); static void axFrameCallback(void);
void executeThread(void); void executeThread(void);
void ClearDecoderList(); void ClearDecoderList();
SoundDecoder * GetSoundDecoder(const char * filepath); SoundDecoder *GetSoundDecoder(const char *filepath);
SoundDecoder * GetSoundDecoder(const uint8_t * sound, int32_t length);
static SoundHandler * handlerInstance; SoundDecoder *GetSoundDecoder(const uint8_t *sound, int32_t length);
static SoundHandler *handlerInstance;
bool Decoding; bool Decoding;
bool ExitRequested; bool ExitRequested;
Voice * voiceList[MAX_DECODERS]; Voice *voiceList[MAX_DECODERS];
SoundDecoder * DecoderList[MAX_DECODERS]; SoundDecoder *DecoderList[MAX_DECODERS];
}; };
#endif #endif

View File

@ -36,12 +36,12 @@ public:
}; };
Voice(int32_t prio) Voice(int32_t prio)
: state(STATE_STOPPED) { : state(STATE_STOPPED) {
lastLoopCounter = 0; lastLoopCounter = 0;
nextBufferSize = 0; nextBufferSize = 0;
voice = AXAcquireVoice(prio, 0, 0); voice = AXAcquireVoice(prio, 0, 0);
if(voice) { if (voice) {
AXVoiceBegin(voice); AXVoiceBegin(voice);
AXSetVoiceType(voice, 0); AXSetVoiceType(voice, 0);
setVolume(0x80000000); setVolume(0x80000000);
@ -62,13 +62,13 @@ public:
} }
~Voice() { ~Voice() {
if(voice) { if (voice) {
AXFreeVoice(voice); AXFreeVoice(voice);
} }
} }
void play(const uint8_t *buffer, uint32_t bufferSize, const uint8_t *nextBuffer, uint32_t nextBufSize, uint16_t format, uint32_t sampleRate) { void play(const uint8_t *buffer, uint32_t bufferSize, const uint8_t *nextBuffer, uint32_t nextBufSize, uint16_t format, uint32_t sampleRate) {
if(!voice) if (!voice)
return; return;
memset(&voiceBuffer, 0, sizeof(voiceBuffer)); memset(&voiceBuffer, 0, sizeof(voiceBuffer));
@ -86,7 +86,7 @@ public:
uint32_t samplesPerSec = AXGetInputSamplesPerSec(); uint32_t samplesPerSec = AXGetInputSamplesPerSec();
memset(&ratioBits, 0, sizeof(ratioBits)); memset(&ratioBits, 0, sizeof(ratioBits));
ratioBits.ratio = (uint32_t)(0x00010000 * ((float)sampleRate / (float)samplesPerSec)); ratioBits.ratio = (uint32_t) (0x00010000 * ((float) sampleRate / (float) samplesPerSec));
AXSetVoiceOffsets(voice, &voiceBuffer); AXSetVoiceOffsets(voice, &voiceBuffer);
AXSetVoiceSrc(voice, &ratioBits); AXSetVoiceSrc(voice, &ratioBits);
@ -95,12 +95,12 @@ public:
} }
void stop() { void stop() {
if(voice) if (voice)
AXSetVoiceState(voice, 0); AXSetVoiceState(voice, 0);
} }
void setVolume(uint32_t vol) { void setVolume(uint32_t vol) {
if(voice) { if (voice) {
AXVoiceVeData data; AXVoiceVeData data;
data.volume = vol >> 16; data.volume = vol >> 16;
data.delta = vol & 0xFFFF; data.delta = vol & 0xFFFF;
@ -110,7 +110,7 @@ public:
void setNextBuffer(const uint8_t *buffer, uint32_t bufferSize) { void setNextBuffer(const uint8_t *buffer, uint32_t bufferSize) {
voiceBuffer.loopOffset = ((buffer - (const uint8_t*)voiceBuffer.data) >> 1); voiceBuffer.loopOffset = ((buffer - (const uint8_t *) voiceBuffer.data) >> 1);
nextBufferSize = bufferSize; nextBufferSize = bufferSize;
AXSetVoiceLoopOffset(voice, voiceBuffer.loopOffset); AXSetVoiceLoopOffset(voice, voiceBuffer.loopOffset);
@ -118,27 +118,29 @@ public:
bool isBufferSwitched() { bool isBufferSwitched() {
uint32_t loopCounter = AXGetVoiceLoopCount(voice); uint32_t loopCounter = AXGetVoiceLoopCount(voice);
if(lastLoopCounter != loopCounter) { if (lastLoopCounter != loopCounter) {
lastLoopCounter = loopCounter; lastLoopCounter = loopCounter;
AXSetVoiceEndOffset(voice, voiceBuffer.loopOffset + (nextBufferSize >> 1) - 1); AXSetVoiceEndOffset(voice, voiceBuffer.loopOffset + (nextBufferSize >> 1) - 1);
return true; return true;
} }
return false; return false;
} }
uint32_t getInternState() const { uint32_t getInternState() const {
if(voice) if (voice)
return ((uint32_t *)voice)[1]; return ((uint32_t *) voice)[1];
return 0; return 0;
} }
uint32_t getState() const { uint32_t getState() const {
return state; return state;
} }
void setState(uint32_t s) { void setState(uint32_t s) {
state = s; state = s;
} }
void * getVoice() const { void *getVoice() const {
return voice; return voice;
} }

View File

@ -52,13 +52,19 @@ typedef struct {
class WavDecoder : public SoundDecoder { class WavDecoder : public SoundDecoder {
public: public:
WavDecoder(const char * filepath); WavDecoder(const char *filepath);
WavDecoder(const uint8_t * snd, int32_t len);
WavDecoder(const uint8_t *snd, int32_t len);
virtual ~WavDecoder(); virtual ~WavDecoder();
int32_t Read(uint8_t * buffer, int32_t buffer_size, int32_t pos);
int32_t Read(uint8_t *buffer, int32_t buffer_size, int32_t pos);
protected: protected:
void OpenFile(); void OpenFile();
void CloseFile(); void CloseFile();
uint32_t DataOffset; uint32_t DataOffset;
uint32_t DataSize; uint32_t DataSize;
bool Is16Bit; bool Is16Bit;

View File

@ -23,23 +23,20 @@
class CThread { class CThread {
public: public:
typedef void (* Callback)(CThread *thread, void *arg); typedef void (*Callback)(CThread *thread, void *arg);
//! constructor //! constructor
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL) CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
: pThread(NULL) : pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
, pThreadStack(NULL)
, pCallback(callback)
, pCallbackArg(callbackArg) {
//! save attribute assignment //! save attribute assignment
iAttributes = iAttr; iAttributes = iAttr;
//! allocate the thread //! allocate the thread
pThread = (OSThread*)memalign(8, sizeof(OSThread)); pThread = (OSThread *) memalign(8, sizeof(OSThread));
//! allocate the stack //! allocate the stack
pThreadStack = (uint8_t *) memalign(0x20, iStackSize); pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
//! create the thread //! create the thread
if(pThread && pThreadStack) if (pThread && pThreadStack)
OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes); OSCreateThread(pThread, &CThread::threadCallback, 1, (char *) this, pThreadStack + iStackSize, iStackSize, iPriority, iAttributes);
} }
//! destructor //! destructor
@ -48,71 +45,80 @@ public:
} }
static CThread *create(CThread::Callback callback, void *callbackArg, int32_t iAttr = eAttributeNone, int32_t iPriority = 16, int32_t iStackSize = 0x8000) { static CThread *create(CThread::Callback callback, void *callbackArg, int32_t iAttr = eAttributeNone, int32_t iPriority = 16, int32_t iStackSize = 0x8000) {
return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) ); return (new CThread(iAttr, iPriority, iStackSize, callback, callbackArg));
} }
//! Get thread ID //! Get thread ID
virtual void* getThread() const { virtual void *getThread() const {
return pThread; return pThread;
} }
//! Thread entry function //! Thread entry function
virtual void executeThread(void) { virtual void executeThread(void) {
if(pCallback) if (pCallback)
pCallback(this, pCallbackArg); pCallback(this, pCallbackArg);
} }
//! Suspend thread //! Suspend thread
virtual void suspendThread(void) { virtual void suspendThread(void) {
if(isThreadSuspended()) if (isThreadSuspended())
return; return;
if(pThread) if (pThread)
OSSuspendThread(pThread); OSSuspendThread(pThread);
} }
//! Resume thread //! Resume thread
virtual void resumeThread(void) { virtual void resumeThread(void) {
if(!isThreadSuspended()) if (!isThreadSuspended())
return; return;
if(pThread) if (pThread)
OSResumeThread(pThread); OSResumeThread(pThread);
} }
//! Set thread priority //! Set thread priority
virtual void setThreadPriority(int32_t prio) { virtual void setThreadPriority(int32_t prio) {
if(pThread) if (pThread)
OSSetThreadPriority(pThread, prio); OSSetThreadPriority(pThread, prio);
} }
//! Check if thread is suspended //! Check if thread is suspended
virtual bool isThreadSuspended(void) const { virtual bool isThreadSuspended(void) const {
if(pThread) if (pThread)
return OSIsThreadSuspended(pThread); return OSIsThreadSuspended(pThread);
return false; return false;
} }
//! Check if thread is terminated //! Check if thread is terminated
virtual bool isThreadTerminated(void) const { virtual bool isThreadTerminated(void) const {
if(pThread) if (pThread)
return OSIsThreadTerminated(pThread); return OSIsThreadTerminated(pThread);
return false; return false;
} }
//! Check if thread is running //! Check if thread is running
virtual bool isThreadRunning(void) const { virtual bool isThreadRunning(void) const {
return !isThreadSuspended() && !isThreadRunning(); return !isThreadSuspended() && !isThreadRunning();
} }
//! Shutdown thread //! Shutdown thread
virtual void shutdownThread(void) { virtual void shutdownThread(void) {
//! wait for thread to finish //! wait for thread to finish
if(pThread && !(iAttributes & eAttributeDetach)) { if (pThread && !(iAttributes & eAttributeDetach)) {
if(isThreadSuspended()) if (isThreadSuspended())
resumeThread(); resumeThread();
OSJoinThread(pThread, NULL); OSJoinThread(pThread, NULL);
} }
//! free the thread stack buffer //! free the thread stack buffer
if(pThreadStack) if (pThreadStack)
free(pThreadStack); free(pThreadStack);
if(pThread) if (pThread)
free(pThread); free(pThread);
pThread = NULL; pThread = NULL;
pThreadStack = NULL; pThreadStack = NULL;
} }
//! Thread attributes //! Thread attributes
enum eCThreadAttributes { enum eCThreadAttributes {
eAttributeNone = 0x07, eAttributeNone = 0x07,
@ -128,6 +134,7 @@ private:
((CThread *) argv)->executeThread(); ((CThread *) argv)->executeThread();
return 0; return 0;
} }
int32_t iAttributes; int32_t iAttributes;
OSThread *pThread; OSThread *pThread;
uint8_t *pThreadStack; uint8_t *pThreadStack;

View File

@ -33,6 +33,7 @@
class CVideo { class CVideo {
public: public:
CVideo(int32_t forceTvScanMode = -1, int32_t forceDrcScanMode = -1); CVideo(int32_t forceTvScanMode = -1, int32_t forceDrcScanMode = -1);
virtual ~CVideo(); virtual ~CVideo();
void prepareTvRendering(void) { void prepareTvRendering(void) {
@ -64,7 +65,7 @@ public:
} }
void setStencilRender(bool bEnable) { void setStencilRender(bool bEnable) {
if(bEnable) { if (bEnable) {
GX2SetStencilMask(0xff, 0xff, 0x01, 0xff, 0xff, 0x01); GX2SetStencilMask(0xff, 0xff, 0x01, 0xff, 0xff, 0x01);
GX2SetDepthStencilControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_LEQUAL, GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_ALWAYS, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_REPLACE, GX2SetDepthStencilControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_LEQUAL, GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_ALWAYS, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_REPLACE,
GX2_COMPARE_FUNC_ALWAYS, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_REPLACE); GX2_COMPARE_FUNC_ALWAYS, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_REPLACE);
@ -94,13 +95,14 @@ public:
} }
void tvEnable(bool bEnable) { void tvEnable(bool bEnable) {
if(tvEnabled != bEnable) { if (tvEnabled != bEnable) {
GX2SetTVEnable(bEnable ? GX2_ENABLE : GX2_DISABLE); GX2SetTVEnable(bEnable ? GX2_ENABLE : GX2_DISABLE);
tvEnabled = bEnable; tvEnabled = bEnable;
} }
} }
void drcEnable(bool bEnable) { void drcEnable(bool bEnable) {
if(drcEnabled != bEnable) { if (drcEnabled != bEnable) {
GX2SetDRCEnable(bEnable ? GX2_ENABLE : GX2_DISABLE); GX2SetDRCEnable(bEnable ? GX2_ENABLE : GX2_DISABLE);
drcEnabled = bEnable; drcEnabled = bEnable;
} }
@ -113,6 +115,7 @@ public:
uint32_t getTvWidth(void) const { uint32_t getTvWidth(void) const {
return tvColorBuffer.surface.width; return tvColorBuffer.surface.width;
} }
uint32_t getTvHeight(void) const { uint32_t getTvHeight(void) const {
return tvColorBuffer.surface.height; return tvColorBuffer.surface.height;
} }
@ -120,28 +123,32 @@ public:
uint32_t getDrcWidth(void) const { uint32_t getDrcWidth(void) const {
return drcColorBuffer.surface.width; return drcColorBuffer.surface.width;
} }
uint32_t getDrcHeight(void) const { uint32_t getDrcHeight(void) const {
return drcColorBuffer.surface.height; return drcColorBuffer.surface.height;
} }
const glm::mat4 & getProjectionMtx(void) const { const glm::mat4 &getProjectionMtx(void) const {
return projectionMtx; return projectionMtx;
} }
const glm::mat4 & getViewMtx(void) const {
const glm::mat4 &getViewMtx(void) const {
return viewMtx; return viewMtx;
} }
float getWidthScaleFactor(void) const { float getWidthScaleFactor(void) const {
return widthScaleFactor; return widthScaleFactor;
} }
float getHeightScaleFactor(void) const { float getHeightScaleFactor(void) const {
return heightScaleFactor; return heightScaleFactor;
} }
float getDepthScaleFactor(void) const { float getDepthScaleFactor(void) const {
return depthScaleFactor; return depthScaleFactor;
} }
void screenPosToWorldRay(float posX, float posY, glm::vec3 & rayOrigin, glm::vec3 & rayDirection) { void screenPosToWorldRay(float posX, float posY, glm::vec3 &rayOrigin, glm::vec3 &rayDirection) {
//! normalize positions //! normalize positions
posX = 2.0f * posX * getWidthScaleFactor(); posX = 2.0f * posX * getWidthScaleFactor();
posY = 2.0f * posY * getHeightScaleFactor(); posY = 2.0f * posY * getHeightScaleFactor();
@ -162,11 +169,13 @@ public:
rayOrigin = glm::vec3(rayStartWorld); rayOrigin = glm::vec3(rayStartWorld);
rayDirection = glm::normalize(rayDirectionWorld); rayDirection = glm::normalize(rayDirectionWorld);
} }
private: private:
static void *GX2RAlloc(uint32_t flags, uint32_t size, uint32_t align); static void *GX2RAlloc(uint32_t flags, uint32_t size, uint32_t align);
static void GX2RFree(uint32_t flags, void* p);
void renderFXAA(const GX2Texture * texture, const GX2Sampler *sampler); static void GX2RFree(uint32_t flags, void *p);
void renderFXAA(const GX2Texture *texture, const GX2Sampler *sampler);
void *gx2CommandBuffer; void *gx2CommandBuffer;

View File

@ -26,34 +26,38 @@ class CursorDrawer {
public: public:
static CursorDrawer *getInstance() { static CursorDrawer *getInstance() {
if(!instance) if (!instance)
instance = new CursorDrawer(); instance = new CursorDrawer();
return instance; return instance;
} }
static void destroyInstance() { static void destroyInstance() {
if(instance) { if (instance) {
delete instance; delete instance;
instance = NULL; instance = NULL;
} }
} }
static void draw(float x, float y) { static void draw(float x, float y) {
CursorDrawer * cur_instance = getInstance(); CursorDrawer *cur_instance = getInstance();
if(cur_instance == NULL) return; if (cur_instance == NULL) return;
cur_instance->draw_Cursor(x,y); cur_instance->draw_Cursor(x, y);
} }
private: private:
//!Constructor //!Constructor
CursorDrawer(); CursorDrawer();
//!Destructor //!Destructor
~CursorDrawer(); ~CursorDrawer();
static CursorDrawer *instance; static CursorDrawer *instance;
void draw_Cursor(float x, float y); void draw_Cursor(float x, float y);
void init_colorVtxs(); void init_colorVtxs();
uint8_t * colorVtxs = NULL; uint8_t *colorVtxs = NULL;
}; };
#endif #endif

View File

@ -24,6 +24,7 @@
class ColorShader : public Shader { class ColorShader : public Shader {
private: private:
ColorShader(); ColorShader();
virtual ~ColorShader(); virtual ~ColorShader();
static const uint32_t cuAttributeCount = 2; static const uint32_t cuAttributeCount = 2;
@ -47,13 +48,14 @@ public:
static const uint32_t cuColorVtxsSize = 4 * cuColorAttrSize; static const uint32_t cuColorVtxsSize = 4 * cuColorAttrSize;
static ColorShader *instance() { static ColorShader *instance() {
if(!shaderInstance) { if (!shaderInstance) {
shaderInstance = new ColorShader(); shaderInstance = new ColorShader();
} }
return shaderInstance; return shaderInstance;
} }
static void destroyInstance() { static void destroyInstance() {
if(shaderInstance) { if (shaderInstance) {
delete shaderInstance; delete shaderInstance;
shaderInstance = NULL; shaderInstance = NULL;
} }
@ -65,8 +67,8 @@ public:
pixelShader.setShader(); pixelShader.setShader();
} }
void setAttributeBuffer(const uint8_t * colorAttr, const float * posVtxs_in = NULL, const uint32_t & vtxCount = 0) const { void setAttributeBuffer(const uint8_t *colorAttr, const float *posVtxs_in = NULL, const uint32_t &vtxCount = 0) const {
if(posVtxs_in && vtxCount) { if (posVtxs_in && vtxCount) {
VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in); VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in);
VertexShader::setAttributeBuffer(1, vtxCount * cuColorAttrSize, cuColorAttrSize, colorAttr); VertexShader::setAttributeBuffer(1, vtxCount * cuColorAttrSize, cuColorAttrSize, colorAttr);
} else { } else {
@ -75,16 +77,19 @@ public:
} }
} }
void setAngle(const float & val) { void setAngle(const float &val) {
VertexShader::setUniformReg(angleLocation, 4, &val); VertexShader::setUniformReg(angleLocation, 4, &val);
} }
void setOffset(const glm::vec3 & vec) {
void setOffset(const glm::vec3 &vec) {
VertexShader::setUniformReg(offsetLocation, 4, &vec[0]); VertexShader::setUniformReg(offsetLocation, 4, &vec[0]);
} }
void setScale(const glm::vec3 & vec) {
void setScale(const glm::vec3 &vec) {
VertexShader::setUniformReg(scaleLocation, 4, &vec[0]); VertexShader::setUniformReg(scaleLocation, 4, &vec[0]);
} }
void setColorIntensity(const glm::vec4 & vec) {
void setColorIntensity(const glm::vec4 &vec) {
PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]); PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]);
} }
}; };

View File

@ -24,13 +24,14 @@
class FXAAShader : public Shader { class FXAAShader : public Shader {
public: public:
static FXAAShader *instance() { static FXAAShader *instance() {
if(!shaderInstance) { if (!shaderInstance) {
shaderInstance = new FXAAShader(); shaderInstance = new FXAAShader();
} }
return shaderInstance; return shaderInstance;
} }
static void destroyInstance() { static void destroyInstance() {
if(shaderInstance) { if (shaderInstance) {
delete shaderInstance; delete shaderInstance;
shaderInstance = NULL; shaderInstance = NULL;
} }
@ -47,17 +48,18 @@ public:
VertexShader::setAttributeBuffer(1, ciTexCoordsVtxsSize, cuTexCoordAttrSize, texCoords); VertexShader::setAttributeBuffer(1, ciTexCoordsVtxsSize, cuTexCoordAttrSize, texCoords);
} }
void setResolution(const glm::vec2 & vec) { void setResolution(const glm::vec2 &vec) {
PixelShader::setUniformReg(resolutionLocation, 4, &vec[0]); PixelShader::setUniformReg(resolutionLocation, 4, &vec[0]);
} }
void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const {
GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); GX2SetPixelTexture((GX2Texture *) texture, samplerLocation);
GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); GX2SetPixelSampler((GX2Sampler *) sampler, samplerLocation);
} }
private: private:
FXAAShader(); FXAAShader();
virtual ~FXAAShader(); virtual ~FXAAShader();
static const uint32_t cuAttributeCount = 2; static const uint32_t cuAttributeCount = 2;

View File

@ -21,21 +21,21 @@
class FetchShader : public Shader { class FetchShader : public Shader {
public: public:
FetchShader(GX2AttribStream * attributes, uint32_t attrCount, GX2FetchShaderType type = GX2_FETCH_SHADER_TESSELLATION_NONE, GX2TessellationMode tess = GX2_TESSELLATION_MODE_DISCRETE) FetchShader(GX2AttribStream *attributes, uint32_t attrCount, GX2FetchShaderType type = GX2_FETCH_SHADER_TESSELLATION_NONE, GX2TessellationMode tess = GX2_TESSELLATION_MODE_DISCRETE)
: fetchShader(NULL) : fetchShader(NULL), fetchShaderProgramm(NULL) {
, fetchShaderProgramm(NULL) {
uint32_t shaderSize = GX2CalcFetchShaderSizeEx(attrCount, type, tess); uint32_t shaderSize = GX2CalcFetchShaderSizeEx(attrCount, type, tess);
fetchShaderProgramm = (uint8_t*)memalign(GX2_SHADER_PROGRAM_ALIGNMENT, shaderSize); fetchShaderProgramm = (uint8_t *) memalign(GX2_SHADER_PROGRAM_ALIGNMENT, shaderSize);
if(fetchShaderProgramm) { if (fetchShaderProgramm) {
fetchShader = new GX2FetchShader; fetchShader = new GX2FetchShader;
GX2InitFetchShaderEx(fetchShader, fetchShaderProgramm, attrCount, attributes, type, tess); GX2InitFetchShaderEx(fetchShader, fetchShaderProgramm, attrCount, attributes, type, tess);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, fetchShaderProgramm, shaderSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, fetchShaderProgramm, shaderSize);
} }
} }
virtual ~FetchShader() { virtual ~FetchShader() {
if(fetchShaderProgramm) if (fetchShaderProgramm)
free(fetchShaderProgramm); free(fetchShaderProgramm);
if(fetchShader) if (fetchShader)
delete fetchShader; delete fetchShader;
} }

View File

@ -22,53 +22,54 @@
class PixelShader : public Shader { class PixelShader : public Shader {
public: public:
PixelShader() PixelShader()
: pixelShader((GX2PixelShader*) memalign(0x40, sizeof(GX2PixelShader))) { : pixelShader((GX2PixelShader *) memalign(0x40, sizeof(GX2PixelShader))) {
if(pixelShader) { if (pixelShader) {
memset(pixelShader, 0, sizeof(GX2PixelShader)); memset(pixelShader, 0, sizeof(GX2PixelShader));
pixelShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER; pixelShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER;
} }
} }
virtual ~PixelShader() { virtual ~PixelShader() {
if(pixelShader) { if (pixelShader) {
if(pixelShader->program) if (pixelShader->program)
free(pixelShader->program); free(pixelShader->program);
for(uint32_t i = 0; i < pixelShader->uniformBlockCount; i++) for (uint32_t i = 0; i < pixelShader->uniformBlockCount; i++)
free((void*)pixelShader->uniformBlocks[i].name); free((void *) pixelShader->uniformBlocks[i].name);
if(pixelShader->uniformBlocks) if (pixelShader->uniformBlocks)
free((void*)pixelShader->uniformBlocks); free((void *) pixelShader->uniformBlocks);
for(uint32_t i = 0; i < pixelShader->uniformVarCount; i++) for (uint32_t i = 0; i < pixelShader->uniformVarCount; i++)
free((void*)pixelShader->uniformVars[i].name); free((void *) pixelShader->uniformVars[i].name);
if(pixelShader->uniformVars) if (pixelShader->uniformVars)
free((void*)pixelShader->uniformVars); free((void *) pixelShader->uniformVars);
if(pixelShader->initialValues) if (pixelShader->initialValues)
free((void*)pixelShader->initialValues); free((void *) pixelShader->initialValues);
for(uint32_t i = 0; i < pixelShader->samplerVarCount; i++) for (uint32_t i = 0; i < pixelShader->samplerVarCount; i++)
free((void*)pixelShader->samplerVars[i].name); free((void *) pixelShader->samplerVars[i].name);
if(pixelShader->samplerVars) if (pixelShader->samplerVars)
free((void*)pixelShader->samplerVars); free((void *) pixelShader->samplerVars);
if(pixelShader->loopVars) if (pixelShader->loopVars)
free((void*)pixelShader->loopVars); free((void *) pixelShader->loopVars);
free(pixelShader); free(pixelShader);
} }
} }
void setProgram(const uint32_t * program, const uint32_t & programSize, const uint32_t * regs, const uint32_t & regsSize) { void setProgram(const uint32_t *program, const uint32_t &programSize, const uint32_t *regs, const uint32_t &regsSize) {
if(!pixelShader) if (!pixelShader)
return; return;
//! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100 //! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100
pixelShader->size = programSize; pixelShader->size = programSize;
pixelShader->program = (uint8_t*)memalign(GX2_SHADER_PROGRAM_ALIGNMENT, pixelShader->size); pixelShader->program = (uint8_t *) memalign(GX2_SHADER_PROGRAM_ALIGNMENT, pixelShader->size);
if(pixelShader->program) { if (pixelShader->program) {
memcpy(pixelShader->program, program, pixelShader->size); memcpy(pixelShader->program, program, pixelShader->size);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, pixelShader->program, pixelShader->size); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, pixelShader->program, pixelShader->size);
} }
@ -76,50 +77,51 @@ public:
memcpy(&pixelShader->regs, regs, regsSize); memcpy(&pixelShader->regs, regs, regsSize);
} }
void addUniformVar(const GX2UniformVar & var) { void addUniformVar(const GX2UniformVar &var) {
if(!pixelShader) if (!pixelShader)
return; return;
uint32_t idx = pixelShader->uniformVarCount; uint32_t idx = pixelShader->uniformVarCount;
GX2UniformVar* newVar = (GX2UniformVar*) malloc((pixelShader->uniformVarCount + 1) * sizeof(GX2UniformVar)); GX2UniformVar *newVar = (GX2UniformVar *) malloc((pixelShader->uniformVarCount + 1) * sizeof(GX2UniformVar));
if(newVar) { if (newVar) {
if(pixelShader->uniformVars) { if (pixelShader->uniformVars) {
memcpy(newVar, pixelShader->uniformVars, pixelShader->uniformVarCount * sizeof(GX2UniformVar)); memcpy(newVar, pixelShader->uniformVars, pixelShader->uniformVarCount * sizeof(GX2UniformVar));
free(pixelShader->uniformVars); free(pixelShader->uniformVars);
} }
pixelShader->uniformVars = newVar; pixelShader->uniformVars = newVar;
memcpy(pixelShader->uniformVars + idx, &var, sizeof(GX2UniformVar)); memcpy(pixelShader->uniformVars + idx, &var, sizeof(GX2UniformVar));
pixelShader->uniformVars[idx].name = (char*) malloc(strlen(var.name) + 1); pixelShader->uniformVars[idx].name = (char *) malloc(strlen(var.name) + 1);
strcpy((char*)pixelShader->uniformVars[idx].name, var.name); strcpy((char *) pixelShader->uniformVars[idx].name, var.name);
pixelShader->uniformVarCount++; pixelShader->uniformVarCount++;
} }
} }
void addSamplerVar(const GX2SamplerVar & var) { void addSamplerVar(const GX2SamplerVar &var) {
if(!pixelShader) if (!pixelShader)
return; return;
uint32_t idx = pixelShader->samplerVarCount; uint32_t idx = pixelShader->samplerVarCount;
GX2SamplerVar* newVar = (GX2SamplerVar*) malloc((pixelShader->samplerVarCount + 1) * sizeof(GX2SamplerVar)); GX2SamplerVar *newVar = (GX2SamplerVar *) malloc((pixelShader->samplerVarCount + 1) * sizeof(GX2SamplerVar));
if(newVar) { if (newVar) {
if(pixelShader->samplerVars) { if (pixelShader->samplerVars) {
memcpy(newVar, pixelShader->samplerVars, pixelShader->samplerVarCount * sizeof(GX2SamplerVar)); memcpy(newVar, pixelShader->samplerVars, pixelShader->samplerVarCount * sizeof(GX2SamplerVar));
free(pixelShader->samplerVars); free(pixelShader->samplerVars);
} }
pixelShader->samplerVars = newVar; pixelShader->samplerVars = newVar;
memcpy(pixelShader->samplerVars + idx, &var, sizeof(GX2SamplerVar)); memcpy(pixelShader->samplerVars + idx, &var, sizeof(GX2SamplerVar));
pixelShader->samplerVars[idx].name = (char*) malloc(strlen(var.name) + 1); pixelShader->samplerVars[idx].name = (char *) malloc(strlen(var.name) + 1);
strcpy((char*)pixelShader->samplerVars[idx].name, var.name); strcpy((char *) pixelShader->samplerVars[idx].name, var.name);
pixelShader->samplerVarCount++; pixelShader->samplerVarCount++;
} }
} }
GX2PixelShader * getPixelShader() const {
GX2PixelShader *getPixelShader() const {
return pixelShader; return pixelShader;
} }
@ -127,9 +129,10 @@ public:
GX2SetPixelShader(pixelShader); GX2SetPixelShader(pixelShader);
} }
static inline void setUniformReg(uint32_t location, uint32_t size, const void * reg) { static inline void setUniformReg(uint32_t location, uint32_t size, const void *reg) {
GX2SetPixelUniformReg(location, size, (uint32_t *)reg); GX2SetPixelUniformReg(location, size, (uint32_t *) reg);
} }
protected: protected:
GX2PixelShader *pixelShader; GX2PixelShader *pixelShader;
}; };

View File

@ -29,40 +29,42 @@
class Shader { class Shader {
protected: protected:
Shader() {} Shader() {}
virtual ~Shader() {} virtual ~Shader() {}
public: public:
static const uint16_t cuVertexAttrSize = sizeof(float) * 3; static const uint16_t cuVertexAttrSize = sizeof(float) * 3;
static const uint16_t cuTexCoordAttrSize = sizeof(float) * 2; static const uint16_t cuTexCoordAttrSize = sizeof(float) * 2;
static const uint16_t cuColorAttrSize = sizeof(uint8_t) * 4; static const uint16_t cuColorAttrSize = sizeof(uint8_t) * 4;
static void setLineWidth(const float & width) { static void setLineWidth(const float &width) {
GX2SetLineWidth(width); GX2SetLineWidth(width);
} }
static void draw(int32_t primitive = GX2_PRIMITIVE_MODE_QUADS, uint32_t vtxCount = 4) { static void draw(int32_t primitive = GX2_PRIMITIVE_MODE_QUADS, uint32_t vtxCount = 4) {
switch(primitive) { switch (primitive) {
default: default:
case GX2_PRIMITIVE_MODE_QUADS: { case GX2_PRIMITIVE_MODE_QUADS: {
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, vtxCount, 0, 1); GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, vtxCount, 0, 1);
break; break;
} }
case GX2_PRIMITIVE_MODE_TRIANGLES: { case GX2_PRIMITIVE_MODE_TRIANGLES: {
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, vtxCount, 0, 1); GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, vtxCount, 0, 1);
break; break;
} }
case GX2_PRIMITIVE_MODE_TRIANGLE_FAN: { case GX2_PRIMITIVE_MODE_TRIANGLE_FAN: {
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLE_FAN, vtxCount, 0, 1); GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLE_FAN, vtxCount, 0, 1);
break; break;
} }
case GX2_PRIMITIVE_MODE_LINES: { case GX2_PRIMITIVE_MODE_LINES: {
GX2DrawEx(GX2_PRIMITIVE_MODE_LINES, vtxCount, 0, 1); GX2DrawEx(GX2_PRIMITIVE_MODE_LINES, vtxCount, 0, 1);
break; break;
} }
case GX2_PRIMITIVE_MODE_LINE_STRIP: { case GX2_PRIMITIVE_MODE_LINE_STRIP: {
GX2DrawEx(GX2_PRIMITIVE_MODE_LINE_STRIP, vtxCount, 0, 1); GX2DrawEx(GX2_PRIMITIVE_MODE_LINE_STRIP, vtxCount, 0, 1);
break; break;
} }
//! TODO: add other primitives later //! TODO: add other primitives later
}; };
} }
}; };

View File

@ -24,9 +24,10 @@
class Shader3D : public Shader { class Shader3D : public Shader {
private: private:
Shader3D(); Shader3D();
virtual ~Shader3D(); virtual ~Shader3D();
static Shader3D * shaderInstance; static Shader3D *shaderInstance;
static const unsigned char cuAttributeCount = 2; static const unsigned char cuAttributeCount = 2;
static const uint32_t ciPositionVtxsSize = 4 * cuVertexAttrSize; static const uint32_t ciPositionVtxsSize = 4 * cuVertexAttrSize;
@ -51,13 +52,14 @@ private:
uint32_t samplerLocation; uint32_t samplerLocation;
public: public:
static Shader3D *instance() { static Shader3D *instance() {
if(!shaderInstance) { if (!shaderInstance) {
shaderInstance = new Shader3D(); shaderInstance = new Shader3D();
} }
return shaderInstance; return shaderInstance;
} }
static void destroyInstance() { static void destroyInstance() {
if(shaderInstance) { if (shaderInstance) {
delete shaderInstance; delete shaderInstance;
shaderInstance = NULL; shaderInstance = NULL;
} }
@ -69,8 +71,8 @@ public:
pixelShader.setShader(); pixelShader.setShader();
} }
void setAttributeBuffer(const uint32_t & vtxCount = 0, const float * posVtxs_in = NULL, const float * texCoords_in = NULL) const { void setAttributeBuffer(const uint32_t &vtxCount = 0, const float *posVtxs_in = NULL, const float *texCoords_in = NULL) const {
if(posVtxs_in && texCoords_in && vtxCount) { if (posVtxs_in && texCoords_in && vtxCount) {
VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in); VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in);
VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in); VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in);
} else { } else {
@ -80,28 +82,33 @@ public:
} }
} }
void setProjectionMtx(const glm::mat4 & mtx) { void setProjectionMtx(const glm::mat4 &mtx) {
VertexShader::setUniformReg(projectionMatrixLocation, 16, &mtx[0][0]); VertexShader::setUniformReg(projectionMatrixLocation, 16, &mtx[0][0]);
} }
void setViewMtx(const glm::mat4 & mtx) {
void setViewMtx(const glm::mat4 &mtx) {
VertexShader::setUniformReg(viewMatrixLocation, 16, &mtx[0][0]); VertexShader::setUniformReg(viewMatrixLocation, 16, &mtx[0][0]);
} }
void setModelViewMtx(const glm::mat4 & mtx) {
void setModelViewMtx(const glm::mat4 &mtx) {
VertexShader::setUniformReg(modelMatrixLocation, 16, &mtx[0][0]); VertexShader::setUniformReg(modelMatrixLocation, 16, &mtx[0][0]);
} }
void setColorIntensity(const glm::vec4 & vec) {
void setColorIntensity(const glm::vec4 &vec) {
PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]); PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]);
} }
void setAlphaFadeOut(const glm::vec4 & vec) {
void setAlphaFadeOut(const glm::vec4 &vec) {
PixelShader::setUniformReg(fadeOutLocation, 4, &vec[0]); PixelShader::setUniformReg(fadeOutLocation, 4, &vec[0]);
} }
void setDistanceFadeOut(const float & value) {
void setDistanceFadeOut(const float &value) {
PixelShader::setUniformReg(fadeDistanceLocation, 4, &value); PixelShader::setUniformReg(fadeDistanceLocation, 4, &value);
} }
void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const {
GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); GX2SetPixelTexture((GX2Texture *) texture, samplerLocation);
GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); GX2SetPixelSampler((GX2Sampler *) sampler, samplerLocation);
} }
}; };

View File

@ -20,12 +20,14 @@
#include <gui/video/shaders/VertexShader.h> #include <gui/video/shaders/VertexShader.h>
#include <gui/video/shaders/PixelShader.h> #include <gui/video/shaders/PixelShader.h>
#include <gui/video/shaders/FetchShader.h> #include <gui/video/shaders/FetchShader.h>
class ShaderFractalColor : public Shader { class ShaderFractalColor : public Shader {
private: private:
ShaderFractalColor(); ShaderFractalColor();
virtual ~ShaderFractalColor(); virtual ~ShaderFractalColor();
static ShaderFractalColor * shaderInstance; static ShaderFractalColor *shaderInstance;
static const unsigned char cuAttributeCount = 3; static const unsigned char cuAttributeCount = 3;
static const uint32_t ciPositionVtxsSize = 4 * cuVertexAttrSize; static const uint32_t ciPositionVtxsSize = 4 * cuVertexAttrSize;
@ -53,13 +55,14 @@ private:
uint32_t fractalLocation; uint32_t fractalLocation;
public: public:
static ShaderFractalColor *instance() { static ShaderFractalColor *instance() {
if(!shaderInstance) { if (!shaderInstance) {
shaderInstance = new ShaderFractalColor(); shaderInstance = new ShaderFractalColor();
} }
return shaderInstance; return shaderInstance;
} }
static void destroyInstance() { static void destroyInstance() {
if(shaderInstance) { if (shaderInstance) {
delete shaderInstance; delete shaderInstance;
shaderInstance = NULL; shaderInstance = NULL;
} }
@ -71,8 +74,8 @@ public:
pixelShader.setShader(); pixelShader.setShader();
} }
void setAttributeBuffer(const uint32_t & vtxCount = 0, const float * posVtxs_in = NULL, const float * texCoords_in = NULL, const uint8_t * colorVtxs_in = NULL) const { void setAttributeBuffer(const uint32_t &vtxCount = 0, const float *posVtxs_in = NULL, const float *texCoords_in = NULL, const uint8_t *colorVtxs_in = NULL) const {
if(posVtxs_in && texCoords_in && vtxCount) { if (posVtxs_in && texCoords_in && vtxCount) {
VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in); VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in);
VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in); VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in);
VertexShader::setAttributeBuffer(2, vtxCount * cuColorAttrSize, cuColorAttrSize, colorVtxs_in); VertexShader::setAttributeBuffer(2, vtxCount * cuColorAttrSize, cuColorAttrSize, colorVtxs_in);
@ -84,26 +87,31 @@ public:
} }
} }
void setProjectionMtx(const glm::mat4 & mtx) { void setProjectionMtx(const glm::mat4 &mtx) {
VertexShader::setUniformReg(projectionMatrixLocation, 16, &mtx[0][0]); VertexShader::setUniformReg(projectionMatrixLocation, 16, &mtx[0][0]);
} }
void setViewMtx(const glm::mat4 & mtx) {
void setViewMtx(const glm::mat4 &mtx) {
VertexShader::setUniformReg(viewMatrixLocation, 16, &mtx[0][0]); VertexShader::setUniformReg(viewMatrixLocation, 16, &mtx[0][0]);
} }
void setModelViewMtx(const glm::mat4 & mtx) {
void setModelViewMtx(const glm::mat4 &mtx) {
VertexShader::setUniformReg(modelMatrixLocation, 16, &mtx[0][0]); VertexShader::setUniformReg(modelMatrixLocation, 16, &mtx[0][0]);
} }
void setBlurBorder(const float & blurBorderSize) { void setBlurBorder(const float &blurBorderSize) {
PixelShader::setUniformReg(blurLocation, 4, &blurBorderSize); PixelShader::setUniformReg(blurLocation, 4, &blurBorderSize);
} }
void setColorIntensity(const glm::vec4 & vec) {
void setColorIntensity(const glm::vec4 &vec) {
PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]); PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]);
} }
void setAlphaFadeOut(const glm::vec4 & vec) {
void setAlphaFadeOut(const glm::vec4 &vec) {
PixelShader::setUniformReg(fadeOutLocation, 4, &vec[0]); PixelShader::setUniformReg(fadeOutLocation, 4, &vec[0]);
} }
void setFractalColor(const int & fractalColorEnable) {
void setFractalColor(const int &fractalColorEnable) {
PixelShader::setUniformReg(fractalLocation, 4, &fractalColorEnable); PixelShader::setUniformReg(fractalLocation, 4, &fractalColorEnable);
} }
}; };

View File

@ -25,6 +25,7 @@
class Texture2DShader : public Shader { class Texture2DShader : public Shader {
private: private:
Texture2DShader(); Texture2DShader();
virtual ~Texture2DShader(); virtual ~Texture2DShader();
static const uint32_t cuAttributeCount = 2; static const uint32_t cuAttributeCount = 2;
@ -50,13 +51,14 @@ private:
uint32_t texCoordLocation; uint32_t texCoordLocation;
public: public:
static Texture2DShader *instance() { static Texture2DShader *instance() {
if(!shaderInstance) { if (!shaderInstance) {
shaderInstance = new Texture2DShader(); shaderInstance = new Texture2DShader();
} }
return shaderInstance; return shaderInstance;
} }
static void destroyInstance() { static void destroyInstance() {
if(shaderInstance) { if (shaderInstance) {
delete shaderInstance; delete shaderInstance;
shaderInstance = NULL; shaderInstance = NULL;
} }
@ -68,8 +70,8 @@ public:
pixelShader.setShader(); pixelShader.setShader();
} }
void setAttributeBuffer(const float * texCoords_in = NULL, const float * posVtxs_in = NULL, const uint32_t & vtxCount = 0) const { void setAttributeBuffer(const float *texCoords_in = NULL, const float *posVtxs_in = NULL, const uint32_t &vtxCount = 0) const {
if(posVtxs_in && texCoords_in && vtxCount) { if (posVtxs_in && texCoords_in && vtxCount) {
VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in); VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in);
VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in); VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in);
} else { } else {
@ -78,25 +80,29 @@ public:
} }
} }
void setAngle(const float & val) { void setAngle(const float &val) {
VertexShader::setUniformReg(angleLocation, 4, &val); VertexShader::setUniformReg(angleLocation, 4, &val);
} }
void setOffset(const glm::vec3 & vec) {
void setOffset(const glm::vec3 &vec) {
VertexShader::setUniformReg(offsetLocation, 4, &vec[0]); VertexShader::setUniformReg(offsetLocation, 4, &vec[0]);
} }
void setScale(const glm::vec3 & vec) {
void setScale(const glm::vec3 &vec) {
VertexShader::setUniformReg(scaleLocation, 4, &vec[0]); VertexShader::setUniformReg(scaleLocation, 4, &vec[0]);
} }
void setColorIntensity(const glm::vec4 & vec) {
void setColorIntensity(const glm::vec4 &vec) {
PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]); PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]);
} }
void setBlurring(const glm::vec3 & vec) {
void setBlurring(const glm::vec3 &vec) {
PixelShader::setUniformReg(blurLocation, 4, &vec[0]); PixelShader::setUniformReg(blurLocation, 4, &vec[0]);
} }
void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const {
GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); GX2SetPixelTexture((GX2Texture *) texture, samplerLocation);
GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); GX2SetPixelSampler((GX2Sampler *) sampler, samplerLocation);
} }
}; };

View File

@ -24,64 +24,62 @@
class VertexShader : public Shader { class VertexShader : public Shader {
public: public:
VertexShader(uint32_t numAttr) VertexShader(uint32_t numAttr)
: attributesCount( numAttr ) : attributesCount(numAttr), attributes(new GX2AttribStream[attributesCount]), vertexShader((GX2VertexShader *) memalign(0x40, sizeof(GX2VertexShader))) {
, attributes( new GX2AttribStream[attributesCount] ) if (vertexShader) {
, vertexShader( (GX2VertexShader*) memalign(0x40, sizeof(GX2VertexShader)) ) {
if(vertexShader) {
memset(vertexShader, 0, sizeof(GX2VertexShader)); memset(vertexShader, 0, sizeof(GX2VertexShader));
vertexShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER; vertexShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER;
} }
} }
virtual ~VertexShader() { virtual ~VertexShader() {
delete [] attributes; delete[] attributes;
if(vertexShader) { if (vertexShader) {
if(vertexShader->program) if (vertexShader->program)
free(vertexShader->program); free(vertexShader->program);
for(uint32_t i = 0; i < vertexShader->uniformBlockCount; i++) for (uint32_t i = 0; i < vertexShader->uniformBlockCount; i++)
free((void*)vertexShader->uniformBlocks[i].name); free((void *) vertexShader->uniformBlocks[i].name);
if(vertexShader->uniformBlocks) if (vertexShader->uniformBlocks)
free((void*)vertexShader->uniformBlocks); free((void *) vertexShader->uniformBlocks);
for(uint32_t i = 0; i < vertexShader->uniformVarCount; i++) for (uint32_t i = 0; i < vertexShader->uniformVarCount; i++)
free((void*)vertexShader->uniformVars[i].name); free((void *) vertexShader->uniformVars[i].name);
if(vertexShader->uniformVars) if (vertexShader->uniformVars)
free((void*)vertexShader->uniformVars); free((void *) vertexShader->uniformVars);
if(vertexShader->initialValues) if (vertexShader->initialValues)
free((void*)vertexShader->initialValues); free((void *) vertexShader->initialValues);
for(uint32_t i = 0; i < vertexShader->samplerVarCount; i++) for (uint32_t i = 0; i < vertexShader->samplerVarCount; i++)
free((void*)vertexShader->samplerVars[i].name); free((void *) vertexShader->samplerVars[i].name);
if(vertexShader->samplerVars) if (vertexShader->samplerVars)
free((void*)vertexShader->samplerVars); free((void *) vertexShader->samplerVars);
for(uint32_t i = 0; i < vertexShader->attribVarCount; i++) for (uint32_t i = 0; i < vertexShader->attribVarCount; i++)
free((void*)vertexShader->attribVars[i].name); free((void *) vertexShader->attribVars[i].name);
if(vertexShader->attribVars) if (vertexShader->attribVars)
free((void*)vertexShader->attribVars); free((void *) vertexShader->attribVars);
if(vertexShader->loopVars) if (vertexShader->loopVars)
free((void*)vertexShader->loopVars); free((void *) vertexShader->loopVars);
free(vertexShader); free(vertexShader);
} }
} }
void setProgram(const uint32_t * program, const uint32_t & programSize, const uint32_t * regs, const uint32_t & regsSize) { void setProgram(const uint32_t *program, const uint32_t &programSize, const uint32_t *regs, const uint32_t &regsSize) {
if(!vertexShader) if (!vertexShader)
return; return;
//! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100 //! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100
vertexShader->size = programSize; vertexShader->size = programSize;
vertexShader->program = (uint8_t*) memalign(GX2_SHADER_PROGRAM_ALIGNMENT, vertexShader->size); vertexShader->program = (uint8_t *) memalign(GX2_SHADER_PROGRAM_ALIGNMENT, vertexShader->size);
if(vertexShader->program) { if (vertexShader->program) {
memcpy(vertexShader->program, program, vertexShader->size); memcpy(vertexShader->program, program, vertexShader->size);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, vertexShader->program, vertexShader->size); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, vertexShader->program, vertexShader->size);
} }
@ -89,52 +87,52 @@ public:
memcpy(&vertexShader->regs, regs, regsSize); memcpy(&vertexShader->regs, regs, regsSize);
} }
void addUniformVar(const GX2UniformVar & var) { void addUniformVar(const GX2UniformVar &var) {
if(!vertexShader) if (!vertexShader)
return; return;
uint32_t idx = vertexShader->uniformVarCount; uint32_t idx = vertexShader->uniformVarCount;
GX2UniformVar* newVar = (GX2UniformVar*) malloc((vertexShader->uniformVarCount + 1) * sizeof(GX2UniformVar)); GX2UniformVar *newVar = (GX2UniformVar *) malloc((vertexShader->uniformVarCount + 1) * sizeof(GX2UniformVar));
if(newVar) { if (newVar) {
if(vertexShader->uniformVarCount > 0) { if (vertexShader->uniformVarCount > 0) {
memcpy(newVar, vertexShader->uniformVars, vertexShader->uniformVarCount * sizeof(GX2UniformVar)); memcpy(newVar, vertexShader->uniformVars, vertexShader->uniformVarCount * sizeof(GX2UniformVar));
free(vertexShader->uniformVars); free(vertexShader->uniformVars);
} }
vertexShader->uniformVars = newVar; vertexShader->uniformVars = newVar;
memcpy(vertexShader->uniformVars + idx, &var, sizeof(GX2UniformVar)); memcpy(vertexShader->uniformVars + idx, &var, sizeof(GX2UniformVar));
vertexShader->uniformVars[idx].name = (char*) malloc(strlen(var.name) + 1); vertexShader->uniformVars[idx].name = (char *) malloc(strlen(var.name) + 1);
strcpy((char*)vertexShader->uniformVars[idx].name, var.name); strcpy((char *) vertexShader->uniformVars[idx].name, var.name);
vertexShader->uniformVarCount++; vertexShader->uniformVarCount++;
} }
} }
void addAttribVar(const GX2AttribVar & var) { void addAttribVar(const GX2AttribVar &var) {
if(!vertexShader) if (!vertexShader)
return; return;
uint32_t idx = vertexShader->attribVarCount; uint32_t idx = vertexShader->attribVarCount;
GX2AttribVar* newVar = (GX2AttribVar*) malloc((vertexShader->attribVarCount + 1) * sizeof(GX2AttribVar)); GX2AttribVar *newVar = (GX2AttribVar *) malloc((vertexShader->attribVarCount + 1) * sizeof(GX2AttribVar));
if(newVar) { if (newVar) {
if(vertexShader->attribVarCount > 0) { if (vertexShader->attribVarCount > 0) {
memcpy(newVar, vertexShader->attribVars, vertexShader->attribVarCount * sizeof(GX2AttribVar)); memcpy(newVar, vertexShader->attribVars, vertexShader->attribVarCount * sizeof(GX2AttribVar));
free(vertexShader->attribVars); free(vertexShader->attribVars);
} }
vertexShader->attribVars = newVar; vertexShader->attribVars = newVar;
memcpy(vertexShader->attribVars + idx, &var, sizeof(GX2AttribVar)); memcpy(vertexShader->attribVars + idx, &var, sizeof(GX2AttribVar));
vertexShader->attribVars[idx].name = (char*) malloc(strlen(var.name) + 1); vertexShader->attribVars[idx].name = (char *) malloc(strlen(var.name) + 1);
strcpy((char*)vertexShader->attribVars[idx].name, var.name); strcpy((char *) vertexShader->attribVars[idx].name, var.name);
vertexShader->attribVarCount++; vertexShader->attribVarCount++;
} }
} }
static inline void setAttributeBuffer(uint32_t bufferIdx, uint32_t bufferSize, uint32_t stride, const void * buffer) { static inline void setAttributeBuffer(uint32_t bufferIdx, uint32_t bufferSize, uint32_t stride, const void *buffer) {
GX2SetAttribBuffer(bufferIdx, bufferSize, stride, (void*)buffer); GX2SetAttribBuffer(bufferIdx, bufferSize, stride, (void *) buffer);
} }
GX2VertexShader *getVertexShader() const { GX2VertexShader *getVertexShader() const {
@ -145,19 +143,21 @@ public:
GX2SetVertexShader(vertexShader); GX2SetVertexShader(vertexShader);
} }
GX2AttribStream * getAttributeBuffer(uint32_t idx = 0) const { GX2AttribStream *getAttributeBuffer(uint32_t idx = 0) const {
if(idx >= attributesCount) { if (idx >= attributesCount) {
return NULL; return NULL;
} }
return &attributes[idx]; return &attributes[idx];
} }
uint32_t getAttributesCount() const { uint32_t getAttributesCount() const {
return attributesCount; return attributesCount;
} }
static void setUniformReg(uint32_t location, uint32_t size, const void * reg) { static void setUniformReg(uint32_t location, uint32_t size, const void *reg) {
GX2SetVertexUniformReg(location, size, (uint32_t*)reg); GX2SetVertexUniformReg(location, size, (uint32_t *) reg);
} }
protected: protected:
uint32_t attributesCount; uint32_t attributesCount;
GX2AttribStream *attributes; GX2AttribStream *attributes;

View File

@ -12,12 +12,12 @@ CFile::CFile() {
pos = 0; pos = 0;
} }
CFile::CFile(const std::string & filepath, eOpenTypes mode) { CFile::CFile(const std::string &filepath, eOpenTypes mode) {
iFd = -1; iFd = -1;
this->open(filepath, mode); this->open(filepath, mode);
} }
CFile::CFile(const uint8_t * mem, int32_t size) { CFile::CFile(const uint8_t *mem, int32_t size) {
iFd = -1; iFd = -1;
this->open(mem, size); this->open(mem, size);
} }
@ -26,27 +26,27 @@ CFile::~CFile() {
this->close(); this->close();
} }
int32_t CFile::open(const std::string & filepath, eOpenTypes mode) { int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {
this->close(); this->close();
int32_t openMode = 0; int32_t openMode = 0;
// This depend on the devoptab implementation. // This depend on the devoptab implementation.
// see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference // see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference
switch(mode) { switch (mode) {
default: default:
case ReadOnly: // file must exist case ReadOnly: // file must exist
openMode = O_RDONLY; openMode = O_RDONLY;
break; break;
case WriteOnly: // file will be created / zerod case WriteOnly: // file will be created / zerod
openMode = O_TRUNC | O_CREAT | O_WRONLY; openMode = O_TRUNC | O_CREAT | O_WRONLY;
break; break;
case ReadWrite: // file must exist case ReadWrite: // file must exist
openMode = O_RDWR; openMode = O_RDWR;
break; break;
case Append: // append to file, file will be created if missing. write only case Append: // append to file, file will be created if missing. write only
openMode = O_CREAT | O_APPEND | O_WRONLY; openMode = O_CREAT | O_APPEND | O_WRONLY;
break; break;
} }
//! Using fopen works only on the first launch as expected //! Using fopen works only on the first launch as expected
@ -54,7 +54,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
//! the .data sections which is needed for a normal application to re-init //! the .data sections which is needed for a normal application to re-init
//! this will be added with launching as RPX //! this will be added with launching as RPX
iFd = ::open(filepath.c_str(), openMode); iFd = ::open(filepath.c_str(), openMode);
if(iFd < 0) if (iFd < 0)
return iFd; return iFd;
@ -64,7 +64,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
return 0; return 0;
} }
int32_t CFile::open(const uint8_t * mem, int32_t size) { int32_t CFile::open(const uint8_t *mem, int32_t size) {
this->close(); this->close();
mem_file = mem; mem_file = mem;
@ -74,7 +74,7 @@ int32_t CFile::open(const uint8_t * mem, int32_t size) {
} }
void CFile::close() { void CFile::close() {
if(iFd >= 0) if (iFd >= 0)
::close(iFd); ::close(iFd);
iFd = -1; iFd = -1;
@ -83,24 +83,24 @@ void CFile::close() {
pos = 0; pos = 0;
} }
int32_t CFile::read(uint8_t * ptr, size_t size) { int32_t CFile::read(uint8_t *ptr, size_t size) {
if(iFd >= 0) { if (iFd >= 0) {
int32_t ret = ::read(iFd, ptr,size); int32_t ret = ::read(iFd, ptr, size);
if(ret > 0) if (ret > 0)
pos += ret; pos += ret;
return ret; return ret;
} }
int32_t readsize = size; int32_t readsize = size;
if(readsize > (int64_t) (filesize-pos)) if (readsize > (int64_t) (filesize - pos))
readsize = filesize-pos; readsize = filesize - pos;
if(readsize <= 0) if (readsize <= 0)
return readsize; return readsize;
if(mem_file != NULL) { if (mem_file != NULL) {
memcpy(ptr, mem_file+pos, readsize); memcpy(ptr, mem_file + pos, readsize);
pos += readsize; pos += readsize;
return readsize; return readsize;
} }
@ -108,12 +108,12 @@ int32_t CFile::read(uint8_t * ptr, size_t size) {
return -1; return -1;
} }
int32_t CFile::write(const uint8_t * ptr, size_t size) { int32_t CFile::write(const uint8_t *ptr, size_t size) {
if(iFd >= 0) { if (iFd >= 0) {
size_t done = 0; size_t done = 0;
while(done < size) { while (done < size) {
int32_t ret = ::write(iFd, ptr, size - done); int32_t ret = ::write(iFd, ptr, size - done);
if(ret <= 0) if (ret <= 0)
return ret; return ret;
ptr += ret; ptr += ret;
@ -130,25 +130,25 @@ int32_t CFile::seek(long int offset, int32_t origin) {
int32_t ret = 0; int32_t ret = 0;
int64_t newPos = pos; int64_t newPos = pos;
if(origin == SEEK_SET) { if (origin == SEEK_SET) {
newPos = offset; newPos = offset;
} else if(origin == SEEK_CUR) { } else if (origin == SEEK_CUR) {
newPos += offset; newPos += offset;
} else if(origin == SEEK_END) { } else if (origin == SEEK_END) {
newPos = filesize+offset; newPos = filesize + offset;
} }
if(newPos < 0) { if (newPos < 0) {
pos = 0; pos = 0;
} else { } else {
pos = newPos; pos = newPos;
} }
if(iFd >= 0) if (iFd >= 0)
ret = ::lseek(iFd, pos, SEEK_SET); ret = ::lseek(iFd, pos, SEEK_SET);
if(mem_file != NULL) { if (mem_file != NULL) {
if(pos > filesize) { if (pos > filesize) {
pos = filesize; pos = filesize;
} }
} }
@ -163,8 +163,8 @@ int32_t CFile::fwrite(const char *format, ...) {
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
result = this->write((uint8_t *)tmp, strlen(tmp)); result = this->write((uint8_t *) tmp, strlen(tmp));
} }
va_end(va); va_end(va);

View File

@ -18,18 +18,22 @@ public:
}; };
CFile(); CFile();
CFile(const std::string & filepath, eOpenTypes mode);
CFile(const uint8_t * memory, int32_t memsize); CFile(const std::string &filepath, eOpenTypes mode);
CFile(const uint8_t *memory, int32_t memsize);
virtual ~CFile(); virtual ~CFile();
int32_t open(const std::string & filepath, eOpenTypes mode); int32_t open(const std::string &filepath, eOpenTypes mode);
int32_t open(const uint8_t * memory, int32_t memsize);
int32_t open(const uint8_t *memory, int32_t memsize);
BOOL isOpen() const { BOOL isOpen() const {
if(iFd >= 0) if (iFd >= 0)
return true; return true;
if(mem_file) if (mem_file)
return true; return true;
return false; return false;
@ -37,23 +41,29 @@ public:
void close(); void close();
int32_t read(uint8_t * ptr, size_t size); int32_t read(uint8_t *ptr, size_t size);
int32_t write(const uint8_t * ptr, size_t size);
int32_t write(const uint8_t *ptr, size_t size);
int32_t fwrite(const char *format, ...); int32_t fwrite(const char *format, ...);
int32_t seek(long int offset, int32_t origin); int32_t seek(long int offset, int32_t origin);
uint64_t tell() { uint64_t tell() {
return pos; return pos;
}; };
uint64_t size() { uint64_t size() {
return filesize; return filesize;
}; };
void rewind() { void rewind() {
this->seek(0, SEEK_SET); this->seek(0, SEEK_SET);
}; };
protected: protected:
int32_t iFd; int32_t iFd;
const uint8_t * mem_file; const uint8_t *mem_file;
uint64_t filesize; uint64_t filesize;
uint64_t pos; uint64_t pos;
}; };

View File

@ -31,14 +31,14 @@ using namespace std;
/** /**
* Default constructor for the FreeTypeGX class for WiiXplorer. * Default constructor for the FreeTypeGX class for WiiXplorer.
*/ */
FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace) { FreeTypeGX::FreeTypeGX(const uint8_t *fontBuffer, FT_Long bufferSize, bool lastFace) {
int32_t faceIndex = 0; int32_t faceIndex = 0;
ftPointSize = 0; ftPointSize = 0;
GX2InitSampler(&ftSampler, GX2_TEX_CLAMP_MODE_CLAMP_BORDER, GX2_TEX_XY_FILTER_MODE_LINEAR); GX2InitSampler(&ftSampler, GX2_TEX_CLAMP_MODE_CLAMP_BORDER, GX2_TEX_XY_FILTER_MODE_LINEAR);
FT_Init_FreeType(&ftLibrary); FT_Init_FreeType(&ftLibrary);
if(lastFace) { if (lastFace) {
FT_New_Memory_Face(ftLibrary, (FT_Byte *)fontBuffer, bufferSize, -1, &ftFace); FT_New_Memory_Face(ftLibrary, (FT_Byte *) fontBuffer, bufferSize, -1, &ftFace);
faceIndex = ftFace->num_faces - 1; // Use the last face faceIndex = ftFace->num_faces - 1; // Use the last face
FT_Done_Face(ftFace); FT_Done_Face(ftFace);
ftFace = NULL; ftFace = NULL;
@ -67,10 +67,10 @@ FreeTypeGX::~FreeTypeGX() {
* @return Wide character representation of supplied character string. * @return Wide character representation of supplied character string.
*/ */
wchar_t* FreeTypeGX::charToWideChar(const char* strChar) { wchar_t *FreeTypeGX::charToWideChar(const char *strChar) {
if (!strChar) return NULL; if (!strChar) return NULL;
wchar_t *strWChar = new (std::nothrow) wchar_t[strlen(strChar) + 1]; wchar_t *strWChar = new(std::nothrow) wchar_t[strlen(strChar) + 1];
if (!strWChar) return NULL; if (!strWChar) return NULL;
int32_t bt = mbstowcs(strWChar, strChar, strlen(strChar)); int32_t bt = mbstowcs(strWChar, strChar, strlen(strChar));
@ -80,14 +80,13 @@ wchar_t* FreeTypeGX::charToWideChar(const char* strChar) {
} }
wchar_t *tempDest = strWChar; wchar_t *tempDest = strWChar;
while ((*tempDest++ = *strChar++)) while ((*tempDest++ = *strChar++));
;
return strWChar; return strWChar;
} }
char *FreeTypeGX::wideCharToUTF8(const wchar_t* strChar) { char *FreeTypeGX::wideCharToUTF8(const wchar_t *strChar) {
if(!strChar) { if (!strChar) {
return NULL; return NULL;
} }
@ -106,8 +105,8 @@ char *FreeTypeGX::wideCharToUTF8(const wchar_t* strChar) {
len += 4; len += 4;
} }
char *pOut = new (std::nothrow) char[len]; char *pOut = new(std::nothrow) char[len];
if(!pOut) if (!pOut)
return NULL; return NULL;
size_t n = 0; size_t n = 0;
@ -115,19 +114,19 @@ char *FreeTypeGX::wideCharToUTF8(const wchar_t* strChar) {
for (size_t i = 0; strChar[i]; ++i) { for (size_t i = 0; strChar[i]; ++i) {
wc = strChar[i]; wc = strChar[i];
if (wc < 0x80) if (wc < 0x80)
pOut[n++] = (char)wc; pOut[n++] = (char) wc;
else if (wc < 0x800) { else if (wc < 0x800) {
pOut[n++] = (char)((wc >> 6) | 0xC0); pOut[n++] = (char) ((wc >> 6) | 0xC0);
pOut[n++] = (char)((wc & 0x3F) | 0x80); pOut[n++] = (char) ((wc & 0x3F) | 0x80);
} else if (wc < 0x10000) { } else if (wc < 0x10000) {
pOut[n++] = (char)((wc >> 12) | 0xE0); pOut[n++] = (char) ((wc >> 12) | 0xE0);
pOut[n++] = (char)(((wc >> 6) & 0x3F) | 0x80); pOut[n++] = (char) (((wc >> 6) & 0x3F) | 0x80);
pOut[n++] = (char)((wc & 0x3F) | 0x80); pOut[n++] = (char) ((wc & 0x3F) | 0x80);
} else { } else {
pOut[n++] = (char)(((wc >> 18) & 0x07) | 0xF0); pOut[n++] = (char) (((wc >> 18) & 0x07) | 0xF0);
pOut[n++] = (char)(((wc >> 12) & 0x3F) | 0x80); pOut[n++] = (char) (((wc >> 12) & 0x3F) | 0x80);
pOut[n++] = (char)(((wc >> 6) & 0x3F) | 0x80); pOut[n++] = (char) (((wc >> 6) & 0x3F) | 0x80);
pOut[n++] = (char)((wc & 0x3F) | 0x80); pOut[n++] = (char) ((wc & 0x3F) | 0x80);
} }
} }
return pOut; return pOut;
@ -139,13 +138,13 @@ char *FreeTypeGX::wideCharToUTF8(const wchar_t* strChar) {
* This routine clears all members of the font map structure and frees all allocated memory back to the system. * This routine clears all members of the font map structure and frees all allocated memory back to the system.
*/ */
void FreeTypeGX::unloadFont() { void FreeTypeGX::unloadFont() {
map<int16_t, ftGX2Data >::iterator itr; map<int16_t, ftGX2Data>::iterator itr;
map<wchar_t, ftgxCharData>::iterator itr2; map<wchar_t, ftgxCharData>::iterator itr2;
for (itr = fontData.begin(); itr != fontData.end(); itr++) { for (itr = fontData.begin(); itr != fontData.end(); itr++) {
for (itr2 = itr->second.ftgxCharMap.begin(); itr2 != itr->second.ftgxCharMap.end(); itr2++) { for (itr2 = itr->second.ftgxCharMap.begin(); itr2 != itr->second.ftgxCharMap.end(); itr2++) {
if(itr2->second.texture) { if (itr2->second.texture) {
if(itr2->second.texture->surface.image) if (itr2->second.texture->surface.image)
free(itr2->second.texture->surface.image); free(itr2->second.texture->surface.image);
delete itr2->second.texture; delete itr2->second.texture;
@ -166,7 +165,7 @@ void FreeTypeGX::unloadFont() {
* @param charCode The requested glyph's character code. * @param charCode The requested glyph's character code.
* @return A pointer to the allocated font structure. * @return A pointer to the allocated font structure.
*/ */
ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize) { ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize) {
map<int16_t, ftGX2Data>::iterator itr = fontData.find(pixelSize); map<int16_t, ftGX2Data>::iterator itr = fontData.find(pixelSize);
if (itr != fontData.end()) { if (itr != fontData.end()) {
map<wchar_t, ftgxCharData>::iterator itr2 = itr->second.ftgxCharMap.find(charCode); map<wchar_t, ftgxCharData>::iterator itr2 = itr->second.ftgxCharMap.find(charCode);
@ -195,9 +194,9 @@ ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize) {
textureWidth = ALIGN4(glyphBitmap->width); textureWidth = ALIGN4(glyphBitmap->width);
textureHeight = ALIGN4(glyphBitmap->rows); textureHeight = ALIGN4(glyphBitmap->rows);
if(textureWidth == 0) if (textureWidth == 0)
textureWidth = 4; textureWidth = 4;
if(textureHeight == 0) if (textureHeight == 0)
textureHeight = 4; textureHeight = 4;
ftgxCharData *charData = &ftData->ftgxCharMap[charCode]; ftgxCharData *charData = &ftData->ftgxCharMap[charCode];
@ -211,7 +210,7 @@ ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize) {
//! Initialize texture //! Initialize texture
charData->texture = new GX2Texture; charData->texture = new GX2Texture;
GX2InitTexture(charData->texture, textureWidth, textureHeight, 1, 0, GX2_SURFACE_FORMAT_UNORM_R5_G5_B5_A1, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED); GX2InitTexture(charData->texture, textureWidth, textureHeight, 1, 0, GX2_SURFACE_FORMAT_UNORM_R5_G5_B5_A1, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED);
loadGlyphData(glyphBitmap, charData); loadGlyphData(glyphBitmap, charData);
@ -251,17 +250,17 @@ uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize) {
void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) { void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) {
charData->texture->surface.image = (uint8_t *) memalign(charData->texture->surface.alignment, charData->texture->surface.imageSize); charData->texture->surface.image = (uint8_t *) memalign(charData->texture->surface.alignment, charData->texture->surface.imageSize);
if(!charData->texture->surface.image) if (!charData->texture->surface.image)
return; return;
memset(charData->texture->surface.image, 0x00, charData->texture->surface.imageSize); memset(charData->texture->surface.image, 0x00, charData->texture->surface.imageSize);
uint8_t *src = (uint8_t *)bmp->buffer; uint8_t *src = (uint8_t *) bmp->buffer;
uint16_t *dst = (uint16_t *)charData->texture->surface.image; uint16_t *dst = (uint16_t *) charData->texture->surface.image;
uint32_t x, y; uint32_t x, y;
for(y = 0; y < bmp->rows; y++) { for (y = 0; y < bmp->rows; y++) {
for(x = 0; x < bmp->width; x++) { for (x = 0; x < bmp->width; x++) {
uint8_t intensity = src[y * bmp->width + x] >> 3; uint8_t intensity = src[y * bmp->width + x] >> 3;
dst[y * charData->texture->surface.pitch + x] = intensity ? ((intensity << 11) | (intensity << 6) | (intensity << 1) | 1) : 0; dst[y * charData->texture->surface.pitch + x] = intensity ? ((intensity << 11) | (intensity << 6) | (intensity << 1) | 1) : 0;
} }
@ -299,27 +298,27 @@ int16_t FreeTypeGX::getStyleOffsetHeight(int16_t format, uint16_t pixelSize) {
if (itr == fontData.end()) return 0; if (itr == fontData.end()) return 0;
switch (format & FTGX_ALIGN_MASK) { switch (format & FTGX_ALIGN_MASK) {
case FTGX_ALIGN_TOP: case FTGX_ALIGN_TOP:
return itr->second.ftgxAlign.descender; return itr->second.ftgxAlign.descender;
case FTGX_ALIGN_MIDDLE: case FTGX_ALIGN_MIDDLE:
default: default:
return (itr->second.ftgxAlign.ascender + itr->second.ftgxAlign.descender + 1) >> 1; return (itr->second.ftgxAlign.ascender + itr->second.ftgxAlign.descender + 1) >> 1;
case FTGX_ALIGN_BOTTOM: case FTGX_ALIGN_BOTTOM:
return itr->second.ftgxAlign.ascender; return itr->second.ftgxAlign.ascender;
case FTGX_ALIGN_BASELINE: case FTGX_ALIGN_BASELINE:
return 0; return 0;
case FTGX_ALIGN_GLYPH_TOP: case FTGX_ALIGN_GLYPH_TOP:
return itr->second.ftgxAlign.max; return itr->second.ftgxAlign.max;
case FTGX_ALIGN_GLYPH_MIDDLE: case FTGX_ALIGN_GLYPH_MIDDLE:
return (itr->second.ftgxAlign.max + itr->second.ftgxAlign.min + 1) >> 1; return (itr->second.ftgxAlign.max + itr->second.ftgxAlign.min + 1) >> 1;
case FTGX_ALIGN_GLYPH_BOTTOM: case FTGX_ALIGN_GLYPH_BOTTOM:
return itr->second.ftgxAlign.min; return itr->second.ftgxAlign.min;
} }
return 0; return 0;
} }
@ -338,7 +337,8 @@ int16_t FreeTypeGX::getStyleOffsetHeight(int16_t format, uint16_t pixelSize) {
* @return The number of characters printed. * @return The number of characters printed.
*/ */
uint16_t FreeTypeGX::drawText(CVideo *video, int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, const glm::vec4 & color, uint16_t textStyle, uint16_t textWidth, const float &textBlur, const float & colorBlurIntensity, const glm::vec4 & blurColor, const float & internalRenderingScale) { uint16_t FreeTypeGX::drawText(CVideo *video, int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, const glm::vec4 &color, uint16_t textStyle, uint16_t textWidth, const float &textBlur, const float &colorBlurIntensity,
const glm::vec4 &blurColor, const float &internalRenderingScale) {
if (!text) if (!text)
return 0; return 0;
@ -356,7 +356,7 @@ uint16_t FreeTypeGX::drawText(CVideo *video, int16_t x, int16_t y, int16_t z, co
int32_t i = 0; int32_t i = 0;
while (text[i]) { while (text[i]) {
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize); ftgxCharData *glyphData = cacheGlyphData(text[i], pixelSize);
if (glyphData != NULL) { if (glyphData != NULL) {
if (ftKerningEnabled && i > 0) { if (ftKerningEnabled && i > 0) {
@ -364,7 +364,7 @@ uint16_t FreeTypeGX::drawText(CVideo *video, int16_t x, int16_t y, int16_t z, co
x_pos += (pairDelta.x >> 6); x_pos += (pairDelta.x >> 6);
} }
copyTextureToFramebuffer(video, glyphData->texture,x_pos + glyphData->renderOffsetX + x_offset, y + glyphData->renderOffsetY - y_offset, z, color, textBlur, colorBlurIntensity, blurColor,internalRenderingScale); copyTextureToFramebuffer(video, glyphData->texture, x_pos + glyphData->renderOffsetX + x_offset, y + glyphData->renderOffsetY - y_offset, z, color, textBlur, colorBlurIntensity, blurColor, internalRenderingScale);
x_pos += glyphData->glyphAdvanceX; x_pos += glyphData->glyphAdvanceX;
++printed; ++printed;
@ -393,7 +393,7 @@ uint16_t FreeTypeGX::getWidth(const wchar_t *text, int16_t pixelSize) {
int32_t i = 0; int32_t i = 0;
while (text[i]) { while (text[i]) {
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize); ftgxCharData *glyphData = cacheGlyphData(text[i], pixelSize);
if (glyphData != NULL) { if (glyphData != NULL) {
if (ftKerningEnabled && (i > 0)) { if (ftKerningEnabled && (i > 0)) {
@ -413,7 +413,7 @@ uint16_t FreeTypeGX::getWidth(const wchar_t *text, int16_t pixelSize) {
*/ */
uint16_t FreeTypeGX::getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar) { uint16_t FreeTypeGX::getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar) {
uint16_t strWidth = 0; uint16_t strWidth = 0;
ftgxCharData * glyphData = cacheGlyphData(wChar, pixelSize); ftgxCharData *glyphData = cacheGlyphData(wChar, pixelSize);
if (glyphData != NULL) { if (glyphData != NULL) {
if (ftKerningEnabled && prevChar != 0x0000) { if (ftKerningEnabled && prevChar != 0x0000) {
@ -463,7 +463,7 @@ void FreeTypeGX::getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widt
while (text[i]) { while (text[i]) {
if (widthLimit > 0 && currWidth >= widthLimit) break; if (widthLimit > 0 && currWidth >= widthLimit) break;
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize); ftgxCharData *glyphData = cacheGlyphData(text[i], pixelSize);
if (glyphData != NULL) { if (glyphData != NULL) {
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax; strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
@ -497,20 +497,21 @@ void FreeTypeGX::getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widt
* @param screenY The screen Y coordinate at which to output the rendered texture. * @param screenY The screen Y coordinate at which to output the rendered texture.
* @param color Color to apply to the texture. * @param color Color to apply to the texture.
*/ */
void FreeTypeGX::copyTextureToFramebuffer(CVideo *pVideo, GX2Texture *texture, int16_t x, int16_t y, int16_t z, const glm::vec4 & color, const float & defaultBlur, const float & blurIntensity, const glm::vec4 & blurColor, const float & internalRenderingScale) { void FreeTypeGX::copyTextureToFramebuffer(CVideo *pVideo, GX2Texture *texture, int16_t x, int16_t y, int16_t z, const glm::vec4 &color, const float &defaultBlur, const float &blurIntensity, const glm::vec4 &blurColor,
const float &internalRenderingScale) {
static const float imageAngle = 0.0f; static const float imageAngle = 0.0f;
static const float blurScale = (2.0f/ (internalRenderingScale)); static const float blurScale = (2.0f / (internalRenderingScale));
float offsetLeft = blurScale * ((float)x + 0.5f * (float)texture->surface.width) * (float)pVideo->getWidthScaleFactor(); float offsetLeft = blurScale * ((float) x + 0.5f * (float) texture->surface.width) * (float) pVideo->getWidthScaleFactor();
float offsetTop = blurScale * ((float)y - 0.5f * (float)texture->surface.height) * (float)pVideo->getHeightScaleFactor(); float offsetTop = blurScale * ((float) y - 0.5f * (float) texture->surface.height) * (float) pVideo->getHeightScaleFactor();
float widthScale = blurScale * (float)texture->surface.width * pVideo->getWidthScaleFactor(); float widthScale = blurScale * (float) texture->surface.width * pVideo->getWidthScaleFactor();
float heightScale = blurScale * (float)texture->surface.height * pVideo->getHeightScaleFactor(); float heightScale = blurScale * (float) texture->surface.height * pVideo->getHeightScaleFactor();
glm::vec3 positionOffsets( offsetLeft, offsetTop, (float)z ); glm::vec3 positionOffsets(offsetLeft, offsetTop, (float) z);
//! blur doubles due to blur we have to scale the texture //! blur doubles due to blur we have to scale the texture
glm::vec3 scaleFactor( widthScale, heightScale, 1.0f ); glm::vec3 scaleFactor(widthScale, heightScale, 1.0f);
glm::vec3 blurDirection; glm::vec3 blurDirection;
blurDirection[2] = 1.0f; blurDirection[2] = 1.0f;
@ -522,7 +523,7 @@ void FreeTypeGX::copyTextureToFramebuffer(CVideo *pVideo, GX2Texture *texture, i
Texture2DShader::instance()->setScale(scaleFactor); Texture2DShader::instance()->setScale(scaleFactor);
Texture2DShader::instance()->setTextureAndSampler(texture, &ftSampler); Texture2DShader::instance()->setTextureAndSampler(texture, &ftSampler);
if(blurIntensity > 0.0f) { if (blurIntensity > 0.0f) {
//! glow blur color //! glow blur color
Texture2DShader::instance()->setColorIntensity(blurColor); Texture2DShader::instance()->setColorIntensity(blurColor);

View File

@ -2,8 +2,8 @@
#include <gui/video/CVideo.h> #include <gui/video/CVideo.h>
#include <gui/video/shaders/Shader3D.h> #include <gui/video/shaders/Shader3D.h>
GameBgImage::GameBgImage(const std::string & filename, GuiImageData *preloadImage) GameBgImage::GameBgImage(const std::string &filename, GuiImageData *preloadImage)
: GuiImageAsync(filename, preloadImage) { : GuiImageAsync(filename, preloadImage) {
identity = glm::mat4(1.0f); identity = glm::mat4(1.0f);
alphaFadeOut = glm::vec4(1.0f, 0.075f, 5.305f, 2.0f); alphaFadeOut = glm::vec4(1.0f, 0.075f, 5.305f, 2.0f);
} }
@ -12,18 +12,18 @@ GameBgImage::~GameBgImage() {
} }
void GameBgImage::draw(CVideo *pVideo) { void GameBgImage::draw(CVideo *pVideo) {
if(!getImageData() || !getImageData()->getTexture()) if (!getImageData() || !getImageData()->getTexture())
return; return;
//! first setup 2D GUI positions //! first setup 2D GUI positions
float currPosX = getCenterX(); float currPosX = getCenterX();
float currPosY = getCenterY(); float currPosY = getCenterY();
float currPosZ = getDepth(); float currPosZ = getDepth();
float currScaleX = getScaleX() * (float)getWidth() * pVideo->getWidthScaleFactor(); float currScaleX = getScaleX() * (float) getWidth() * pVideo->getWidthScaleFactor();
float currScaleY = getScaleY() * (float)getHeight() * pVideo->getHeightScaleFactor(); float currScaleY = getScaleY() * (float) getHeight() * pVideo->getHeightScaleFactor();
float currScaleZ = getScaleZ() * (float)getWidth() * pVideo->getDepthScaleFactor(); float currScaleZ = getScaleZ() * (float) getWidth() * pVideo->getDepthScaleFactor();
glm::mat4 m_modelView = glm::translate(identity, glm::vec3(currPosX,currPosY, currPosZ)); glm::mat4 m_modelView = glm::translate(identity, glm::vec3(currPosX, currPosY, currPosZ));
m_modelView = glm::scale(m_modelView, glm::vec3(currScaleX, currScaleY, currScaleZ)); m_modelView = glm::scale(m_modelView, glm::vec3(currScaleX, currScaleY, currScaleZ));
Shader3D::instance()->setShaders(); Shader3D::instance()->setShaders();

View File

@ -7,7 +7,7 @@ static const float bgRepeat = 1000.0f;
static const float bgTexRotate = 39.0f; static const float bgTexRotate = 39.0f;
GridBackground::GridBackground(GuiImageData *img) GridBackground::GridBackground(GuiImageData *img)
: GuiImage(img) { : GuiImage(img) {
colorIntensity = glm::vec4(1.0f, 1.0f, 1.0f, 0.9f); colorIntensity = glm::vec4(1.0f, 1.0f, 1.0f, 0.9f);
alphaFadeOut = glm::vec4(0.0f); alphaFadeOut = glm::vec4(0.0f);
distanceFadeOut = 0.15f; distanceFadeOut = 0.15f;
@ -15,18 +15,18 @@ GridBackground::GridBackground(GuiImageData *img)
vtxCount = 4; vtxCount = 4;
//! texture and vertex coordinates //! texture and vertex coordinates
float *m_posVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, vtxCount * Shader3D::cuVertexAttrSize); float *m_posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, vtxCount * Shader3D::cuVertexAttrSize);
float *m_texCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, vtxCount * Shader3D::cuTexCoordAttrSize); float *m_texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, vtxCount * Shader3D::cuTexCoordAttrSize);
if(m_posVtxs) { if (m_posVtxs) {
int32_t i = 0; int32_t i = 0;
m_posVtxs[i++] = -1.0f; m_posVtxs[i++] = -1.0f;
m_posVtxs[i++] = 0.0f; m_posVtxs[i++] = 0.0f;
m_posVtxs[i++] = 1.0f; m_posVtxs[i++] = 1.0f;
m_posVtxs[i++] = 1.0f; m_posVtxs[i++] = 1.0f;
m_posVtxs[i++] = 0.0f; m_posVtxs[i++] = 0.0f;
m_posVtxs[i++] = 1.0f; m_posVtxs[i++] = 1.0f;
m_posVtxs[i++] = 1.0f; m_posVtxs[i++] = 1.0f;
m_posVtxs[i++] = 0.0f; m_posVtxs[i++] = 0.0f;
m_posVtxs[i++] = -1.0f; m_posVtxs[i++] = -1.0f;
m_posVtxs[i++] = -1.0f; m_posVtxs[i++] = -1.0f;
@ -35,7 +35,7 @@ GridBackground::GridBackground(GuiImageData *img)
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, m_posVtxs, vtxCount * Shader3D::cuVertexAttrSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, m_posVtxs, vtxCount * Shader3D::cuVertexAttrSize);
} }
if(m_texCoords) { if (m_texCoords) {
glm::vec2 texCoordVec[4]; glm::vec2 texCoordVec[4];
texCoordVec[0][0] = -0.5f * bgRepeat; texCoordVec[0][0] = -0.5f * bgRepeat;
texCoordVec[0][1] = 0.5f * bgRepeat; texCoordVec[0][1] = 0.5f * bgRepeat;
@ -50,14 +50,14 @@ GridBackground::GridBackground(GuiImageData *img)
const float sinRot = sinf(DegToRad(bgTexRotate)); const float sinRot = sinf(DegToRad(bgTexRotate));
glm::mat2 texRotateMtx({ glm::mat2 texRotateMtx({
cosRot, -sinRot, cosRot, -sinRot,
sinRot, cosRot sinRot, cosRot
}); });
for(int32_t i = 0; i < 4; i++) { for (int32_t i = 0; i < 4; i++) {
texCoordVec[i] = texRotateMtx * texCoordVec[i]; texCoordVec[i] = texRotateMtx * texCoordVec[i];
m_texCoords[i*2 + 0] = texCoordVec[i][0]; m_texCoords[i * 2 + 0] = texCoordVec[i][0];
m_texCoords[i*2 + 1] = texCoordVec[i][1]; m_texCoords[i * 2 + 1] = texCoordVec[i][1];
} }
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, m_texCoords, vtxCount * Shader3D::cuTexCoordAttrSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, m_texCoords, vtxCount * Shader3D::cuTexCoordAttrSize);
@ -73,21 +73,21 @@ GridBackground::~GridBackground() {
imageData = NULL; imageData = NULL;
//! main image vertexes //! main image vertexes
if(posVtxs) { if (posVtxs) {
free((void*)posVtxs); free((void *) posVtxs);
posVtxs = NULL; posVtxs = NULL;
} }
if(texCoords) { if (texCoords) {
free((void*)texCoords); free((void *) texCoords);
texCoords = NULL; texCoords = NULL;
} }
} }
void GridBackground::draw(CVideo *pVideo, const glm::mat4 & modelView) { void GridBackground::draw(CVideo *pVideo, const glm::mat4 &modelView) {
//! first setup 2D GUI positions //! first setup 2D GUI positions
float currScaleX = bgRepeat * scaleX * (float)getWidth() * pVideo->getWidthScaleFactor(); float currScaleX = bgRepeat * scaleX * (float) getWidth() * pVideo->getWidthScaleFactor();
float currScaleY = 1.0f; float currScaleY = 1.0f;
float currScaleZ = bgRepeat * scaleZ * (float)getHeight() * pVideo->getDepthScaleFactor(); float currScaleZ = bgRepeat * scaleZ * (float) getHeight() * pVideo->getDepthScaleFactor();
m_modelView = glm::scale(modelView, glm::vec3(currScaleX, currScaleY, currScaleZ)); m_modelView = glm::scale(modelView, glm::vec3(currScaleX, currScaleY, currScaleZ));

View File

@ -32,13 +32,13 @@ GuiButton::GuiButton(float w, float h) {
icon = NULL; icon = NULL;
iconOver = NULL; iconOver = NULL;
for(int32_t i = 0; i < 4; i++) { for (int32_t i = 0; i < 4; i++) {
label[i] = NULL; label[i] = NULL;
labelOver[i] = NULL; labelOver[i] = NULL;
labelHold[i] = NULL; labelHold[i] = NULL;
labelClick[i] = NULL; labelClick[i] = NULL;
} }
for(int32_t i = 0; i < iMaxGuiTriggers; i++) { for (int32_t i = 0; i < iMaxGuiTriggers; i++) {
trigger[i] = NULL; trigger[i] = NULL;
} }
@ -58,64 +58,74 @@ GuiButton::GuiButton(float w, float h) {
GuiButton::~GuiButton() { GuiButton::~GuiButton() {
} }
void GuiButton::setImage(GuiImage* img) { void GuiButton::setImage(GuiImage *img) {
image = img; image = img;
if(img) img->setParent(this); if (img) img->setParent(this);
}
void GuiButton::setImageOver(GuiImage* img) {
imageOver = img;
if(img) img->setParent(this);
}
void GuiButton::setImageHold(GuiImage* img) {
imageHold = img;
if(img) img->setParent(this);
}
void GuiButton::setImageClick(GuiImage* img) {
imageClick = img;
if(img) img->setParent(this);
}
void GuiButton::setIcon(GuiImage* img) {
icon = img;
if(img) img->setParent(this);
}
void GuiButton::setIconOver(GuiImage* img) {
iconOver = img;
if(img) img->setParent(this);
} }
void GuiButton::setLabel(GuiText* txt, int32_t n) { void GuiButton::setImageOver(GuiImage *img) {
imageOver = img;
if (img) img->setParent(this);
}
void GuiButton::setImageHold(GuiImage *img) {
imageHold = img;
if (img) img->setParent(this);
}
void GuiButton::setImageClick(GuiImage *img) {
imageClick = img;
if (img) img->setParent(this);
}
void GuiButton::setIcon(GuiImage *img) {
icon = img;
if (img) img->setParent(this);
}
void GuiButton::setIconOver(GuiImage *img) {
iconOver = img;
if (img) img->setParent(this);
}
void GuiButton::setLabel(GuiText *txt, int32_t n) {
label[n] = txt; label[n] = txt;
if(txt) txt->setParent(this); if (txt) txt->setParent(this);
} }
void GuiButton::setLabelOver(GuiText* txt, int32_t n) {
void GuiButton::setLabelOver(GuiText *txt, int32_t n) {
labelOver[n] = txt; labelOver[n] = txt;
if(txt) txt->setParent(this); if (txt) txt->setParent(this);
} }
void GuiButton::setLabelHold(GuiText* txt, int32_t n) {
void GuiButton::setLabelHold(GuiText *txt, int32_t n) {
labelHold[n] = txt; labelHold[n] = txt;
if(txt) txt->setParent(this); if (txt) txt->setParent(this);
} }
void GuiButton::setLabelClick(GuiText* txt, int32_t n) {
void GuiButton::setLabelClick(GuiText *txt, int32_t n) {
labelClick[n] = txt; labelClick[n] = txt;
if(txt) txt->setParent(this); if (txt) txt->setParent(this);
} }
void GuiButton::setSoundOver(GuiSound * snd) {
void GuiButton::setSoundOver(GuiSound *snd) {
soundOver = snd; soundOver = snd;
} }
void GuiButton::setSoundHold(GuiSound * snd) {
void GuiButton::setSoundHold(GuiSound *snd) {
soundHold = snd; soundHold = snd;
} }
void GuiButton::setSoundClick(GuiSound * snd) { void GuiButton::setSoundClick(GuiSound *snd) {
soundClick = snd; soundClick = snd;
} }
void GuiButton::setTrigger(GuiTrigger * t, int32_t idx) { void GuiButton::setTrigger(GuiTrigger *t, int32_t idx) {
if(idx >= 0 && idx < iMaxGuiTriggers) { if (idx >= 0 && idx < iMaxGuiTriggers) {
trigger[idx] = t; trigger[idx] = t;
} else { } else {
for(int32_t i = 0; i < iMaxGuiTriggers; i++) { for (int32_t i = 0; i < iMaxGuiTriggers; i++) {
if(!trigger[i]) { if (!trigger[i]) {
trigger[i] = t; trigger[i] = t;
break; break;
} }
@ -133,49 +143,49 @@ void GuiButton::resetState(void) {
* Draw the button on screen * Draw the button on screen
*/ */
void GuiButton::draw(CVideo *v) { void GuiButton::draw(CVideo *v) {
if(!this->isVisible()) if (!this->isVisible())
return; return;
// draw image // draw image
if((isDrawOverOnlyWhenSelected() && (isStateSet(STATE_SELECTED) && imageOver)) || if ((isDrawOverOnlyWhenSelected() && (isStateSet(STATE_SELECTED) && imageOver)) ||
(!isDrawOverOnlyWhenSelected() && (isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && imageOver))) (!isDrawOverOnlyWhenSelected() && (isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && imageOver)))
imageOver->draw(v); imageOver->draw(v);
else if(image) else if (image)
image->draw(v); image->draw(v);
if((isDrawOverOnlyWhenSelected() && (isStateSet(STATE_SELECTED) && iconOver)) || if ((isDrawOverOnlyWhenSelected() && (isStateSet(STATE_SELECTED) && iconOver)) ||
(!isDrawOverOnlyWhenSelected() && (isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && iconOver))) (!isDrawOverOnlyWhenSelected() && (isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && iconOver)))
iconOver->draw(v); iconOver->draw(v);
else if(icon) else if (icon)
icon->draw(v); icon->draw(v);
// draw text // draw text
for(int32_t i = 0; i < 4; i++) { for (int32_t i = 0; i < 4; i++) {
if(isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && labelOver[i]) if (isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && labelOver[i])
labelOver[i]->draw(v); labelOver[i]->draw(v);
else if(label[i]) else if (label[i])
label[i]->draw(v); label[i]->draw(v);
} }
} }
void GuiButton::update(GuiController * c) { void GuiButton::update(GuiController *c) {
if(!c || isStateSet(STATE_DISABLED|STATE_HIDDEN|STATE_DISABLE_INPUT, c->chanIdx)) if (!c || isStateSet(STATE_DISABLED | STATE_HIDDEN | STATE_DISABLE_INPUT, c->chanIdx))
return; return;
else if(parentElement && (parentElement->isStateSet(STATE_DISABLED|STATE_HIDDEN|STATE_DISABLE_INPUT, c->chanIdx))) else if (parentElement && (parentElement->isStateSet(STATE_DISABLED | STATE_HIDDEN | STATE_DISABLE_INPUT, c->chanIdx)))
return; return;
if(selectable) { if (selectable) {
if(c->data.validPointer && this->isInside(c->data.x, c->data.y)) { if (c->data.validPointer && this->isInside(c->data.x, c->data.y)) {
if(!isStateSet(STATE_OVER, c->chanIdx)) { if (!isStateSet(STATE_OVER, c->chanIdx)) {
setState(STATE_OVER, c->chanIdx); setState(STATE_OVER, c->chanIdx);
//if(this->isRumbleActive()) //if(this->isRumbleActive())
// this->rumble(t->chan); // this->rumble(t->chan);
if(soundOver) if (soundOver)
soundOver->Play(); soundOver->Play();
if(effectsOver && !effects) { if (effectsOver && !effects) {
// initiate effects // initiate effects
effects = effectsOver; effects = effectsOver;
effectAmount = effectAmountOver; effectAmount = effectAmountOver;
@ -184,11 +194,11 @@ void GuiButton::update(GuiController * c) {
pointedOn(this, c); pointedOn(this, c);
} }
} else if(isStateSet(STATE_OVER, c->chanIdx)) { } else if (isStateSet(STATE_OVER, c->chanIdx)) {
this->clearState(STATE_OVER, c->chanIdx); this->clearState(STATE_OVER, c->chanIdx);
pointedOff(this, c); pointedOff(this, c);
if(effectTarget == effectTargetOver && effectAmount == effectAmountOver) { if (effectTarget == effectTargetOver && effectAmount == effectAmountOver) {
// initiate effects (in reverse) // initiate effects (in reverse)
effects = effectsOver; effects = effectsOver;
effectAmount = -effectAmountOver; effectAmount = -effectAmountOver;
@ -197,24 +207,24 @@ void GuiButton::update(GuiController * c) {
} }
} }
for(int32_t i = 0; i < iMaxGuiTriggers; i++) { for (int32_t i = 0; i < iMaxGuiTriggers; i++) {
if(!trigger[i]) if (!trigger[i])
continue; continue;
// button triggers // button triggers
if(clickable) { if (clickable) {
int32_t isClicked = trigger[i]->clicked(c); int32_t isClicked = trigger[i]->clicked(c);
if( !clickedTrigger && (isClicked != GuiTrigger::CLICKED_NONE) if (!clickedTrigger && (isClicked != GuiTrigger::CLICKED_NONE)
&& (trigger[i]->isClickEverywhere() || (isStateSet(STATE_SELECTED | STATE_OVER, c->chanIdx) && trigger[i]->isSelectionClickEverywhere()) || this->isInside(c->data.x, c->data.y))) { && (trigger[i]->isClickEverywhere() || (isStateSet(STATE_SELECTED | STATE_OVER, c->chanIdx) && trigger[i]->isSelectionClickEverywhere()) || this->isInside(c->data.x, c->data.y))) {
if(soundClick) if (soundClick)
soundClick->Play(); soundClick->Play();
clickedTrigger = trigger[i]; clickedTrigger = trigger[i];
if(!isStateSet(STATE_CLICKED, c->chanIdx)) { if (!isStateSet(STATE_CLICKED, c->chanIdx)) {
if(isClicked == GuiTrigger::CLICKED_TOUCH) { if (isClicked == GuiTrigger::CLICKED_TOUCH) {
setState(STATE_CLICKED_TOUCH, c->chanIdx); setState(STATE_CLICKED_TOUCH, c->chanIdx);
} else { } else {
setState(STATE_CLICKED, c->chanIdx); setState(STATE_CLICKED, c->chanIdx);
@ -222,8 +232,9 @@ void GuiButton::update(GuiController * c) {
} }
clicked(this, c, trigger[i]); clicked(this, c, trigger[i]);
} else if((isStateSet(STATE_CLICKED, c->chanIdx) || isStateSet(STATE_CLICKED_TOUCH, c->chanIdx)) && (clickedTrigger == trigger[i]) && !isStateSet(STATE_HELD, c->chanIdx) && !trigger[i]->held(c) && ((isClicked == GuiTrigger::CLICKED_NONE) || trigger[i]->released(c))) { } else if ((isStateSet(STATE_CLICKED, c->chanIdx) || isStateSet(STATE_CLICKED_TOUCH, c->chanIdx)) && (clickedTrigger == trigger[i]) && !isStateSet(STATE_HELD, c->chanIdx) && !trigger[i]->held(c) &&
if((isStateSet(STATE_CLICKED_TOUCH, c->chanIdx) && this->isInside(c->data.x, c->data.y)) || (isStateSet(STATE_CLICKED, c->chanIdx))) { ((isClicked == GuiTrigger::CLICKED_NONE) || trigger[i]->released(c))) {
if ((isStateSet(STATE_CLICKED_TOUCH, c->chanIdx) && this->isInside(c->data.x, c->data.y)) || (isStateSet(STATE_CLICKED, c->chanIdx))) {
clickedTrigger = NULL; clickedTrigger = NULL;
clearState(STATE_CLICKED, c->chanIdx); clearState(STATE_CLICKED, c->chanIdx);
released(this, c, trigger[i]); released(this, c, trigger[i]);
@ -231,20 +242,20 @@ void GuiButton::update(GuiController * c) {
} }
} }
if(holdable) { if (holdable) {
bool isHeld = trigger[i]->held(c); bool isHeld = trigger[i]->held(c);
if( (!heldTrigger || heldTrigger == trigger[i]) && isHeld if ((!heldTrigger || heldTrigger == trigger[i]) && isHeld
&& (trigger[i]->isHoldEverywhere() || (isStateSet(STATE_SELECTED | STATE_OVER, c->chanIdx) && trigger[i]->isSelectionClickEverywhere()) || this->isInside(c->data.x, c->data.y))) { && (trigger[i]->isHoldEverywhere() || (isStateSet(STATE_SELECTED | STATE_OVER, c->chanIdx) && trigger[i]->isSelectionClickEverywhere()) || this->isInside(c->data.x, c->data.y))) {
heldTrigger = trigger[i]; heldTrigger = trigger[i];
if(!isStateSet(STATE_HELD, c->chanIdx)) if (!isStateSet(STATE_HELD, c->chanIdx))
setState(STATE_HELD, c->chanIdx); setState(STATE_HELD, c->chanIdx);
held(this, c, trigger[i]); held(this, c, trigger[i]);
} else if(isStateSet(STATE_HELD, c->chanIdx) && (heldTrigger == trigger[i]) && (!isHeld || trigger[i]->released(c))) { } else if (isStateSet(STATE_HELD, c->chanIdx) && (heldTrigger == trigger[i]) && (!isHeld || trigger[i]->released(c))) {
//! click is removed at this point and converted to held //! click is removed at this point and converted to held
if(clickedTrigger == trigger[i]) { if (clickedTrigger == trigger[i]) {
clickedTrigger = NULL; clickedTrigger = NULL;
clearState(STATE_CLICKED, c->chanIdx); clearState(STATE_CLICKED, c->chanIdx);
} }

View File

@ -17,12 +17,13 @@
#include <gui/GuiCheckBox.h> #include <gui/GuiCheckBox.h>
#include <gui/GuiImage.h> #include <gui/GuiImage.h>
#include <gui/GuiImageData.h> #include <gui/GuiImageData.h>
/** /**
* Constructor for the GuiCheckBox class. * Constructor for the GuiCheckBox class.
*/ */
GuiCheckBox::GuiCheckBox(GuiImage * background, bool checked, float width,float height) GuiCheckBox::GuiCheckBox(GuiImage *background, bool checked, float width, float height)
: GuiToggle(checked,width,height) { : GuiToggle(checked, width, height) {
setImageBackground(background); setImageBackground(background);
} }
@ -33,31 +34,31 @@ GuiCheckBox::~GuiCheckBox() {
} }
void GuiCheckBox::setImageBackground(GuiImage* img) { void GuiCheckBox::setImageBackground(GuiImage *img) {
backgroundImg = img; backgroundImg = img;
if(img) { if (img) {
img->setParent(this); img->setParent(this);
} }
} }
void GuiCheckBox::setImageSelected(GuiImage* img) { void GuiCheckBox::setImageSelected(GuiImage *img) {
selectedImg = img; selectedImg = img;
if(img) { if (img) {
img->setParent(this); img->setParent(this);
} }
} }
void GuiCheckBox::setImageHighlighted(GuiImage* img) { void GuiCheckBox::setImageHighlighted(GuiImage *img) {
highlightedImg = img; highlightedImg = img;
if(img) { if (img) {
img->setParent(this); img->setParent(this);
} }
setIconOver(img); setIconOver(img);
} }
void GuiCheckBox::update(GuiController * c) { void GuiCheckBox::update(GuiController *c) {
if(bChanged) { if (bChanged) {
if(selected) { if (selected) {
GuiButton::setImage(selectedImg); GuiButton::setImage(selectedImg);
} else { } else {
GuiButton::setImage(backgroundImg); GuiButton::setImage(backgroundImg);

View File

@ -22,10 +22,10 @@
* Constructor for the GuiDragListener class. * Constructor for the GuiDragListener class.
*/ */
GuiDragListener::GuiDragListener(float w,float h) { GuiDragListener::GuiDragListener(float w, float h) {
width = w; width = w;
height = h; height = h;
for(int32_t i = 0; i < iMaxGuiTriggers; i++) { for (int32_t i = 0; i < iMaxGuiTriggers; i++) {
trigger[i] = NULL; trigger[i] = NULL;
} }
} }
@ -37,15 +37,15 @@ GuiDragListener::~GuiDragListener() {
} }
void GuiDragListener::setState(int32_t i, int32_t c) { void GuiDragListener::setState(int32_t i, int32_t c) {
GuiElement::setState(i,c); GuiElement::setState(i, c);
} }
void GuiDragListener::setTrigger(GuiTrigger * t, int32_t idx) { void GuiDragListener::setTrigger(GuiTrigger *t, int32_t idx) {
if(idx >= 0 && idx < iMaxGuiTriggers) { if (idx >= 0 && idx < iMaxGuiTriggers) {
trigger[idx] = t; trigger[idx] = t;
} else { } else {
for(int32_t i = 0; i < iMaxGuiTriggers; i++) { for (int32_t i = 0; i < iMaxGuiTriggers; i++) {
if(!trigger[i]) { if (!trigger[i]) {
trigger[i] = t; trigger[i] = t;
break; break;
} }
@ -53,27 +53,27 @@ void GuiDragListener::setTrigger(GuiTrigger * t, int32_t idx) {
} }
} }
void GuiDragListener::update(GuiController * c) { void GuiDragListener::update(GuiController *c) {
if(!c || isStateSet(STATE_DISABLED|STATE_HIDDEN|STATE_DISABLE_INPUT, c->chanIdx)) if (!c || isStateSet(STATE_DISABLED | STATE_HIDDEN | STATE_DISABLE_INPUT, c->chanIdx))
return; return;
else if(parentElement && (parentElement->isStateSet(STATE_DISABLED|STATE_HIDDEN|STATE_DISABLE_INPUT, c->chanIdx))) else if (parentElement && (parentElement->isStateSet(STATE_DISABLED | STATE_HIDDEN | STATE_DISABLE_INPUT, c->chanIdx)))
return; return;
for(int32_t i = 0; i < iMaxGuiTriggers; i++) { for (int32_t i = 0; i < iMaxGuiTriggers; i++) {
if(!trigger[i]) { if (!trigger[i]) {
continue; continue;
} }
bool isHeld = trigger[i]->held(c); bool isHeld = trigger[i]->held(c);
if(isHeld && this->isInside(c->data.x, c->data.y)) { if (isHeld && this->isInside(c->data.x, c->data.y)) {
int32_t dx = c->data.x - c->lastData.x; int32_t dx = c->data.x - c->lastData.x;
int32_t dy = c->data.y - c->lastData.y; int32_t dy = c->data.y - c->lastData.y;
if(dx == 0 && dy == 0) continue; if (dx == 0 && dy == 0) continue;
dragged(this, c, trigger[i],dx,dy); dragged(this, c, trigger[i], dx, dy);
} }
} }
} }

View File

@ -33,7 +33,7 @@ GuiElement::GuiElement() {
scaleX = 1.0f; scaleX = 1.0f;
scaleY = 1.0f; scaleY = 1.0f;
scaleZ = 1.0f; scaleZ = 1.0f;
for(int32_t i = 0; i < 5; i++) for (int32_t i = 0; i < 5; i++)
state[i] = STATE_DEFAULT; state[i] = STATE_DEFAULT;
stateChan = -1; stateChan = -1;
parentElement = NULL; parentElement = NULL;
@ -69,7 +69,7 @@ float GuiElement::getLeft() {
float pLeft = 0; float pLeft = 0;
float pScaleX = 1.0f; float pScaleX = 1.0f;
if(parentElement) { if (parentElement) {
pWidth = parentElement->getWidth(); pWidth = parentElement->getWidth();
pLeft = parentElement->getLeft(); pLeft = parentElement->getLeft();
pScaleX = parentElement->getScaleX(); pScaleX = parentElement->getScaleX();
@ -80,9 +80,9 @@ float GuiElement::getLeft() {
float x = pLeft; float x = pLeft;
//! TODO: the conversion from int to float and back to int is bad for performance, change that //! TODO: the conversion from int to float and back to int is bad for performance, change that
if(alignment & ALIGN_CENTER) { if (alignment & ALIGN_CENTER) {
x = pLeft + pWidth * 0.5f * pScaleX - width * 0.5f * getScaleX(); x = pLeft + pWidth * 0.5f * pScaleX - width * 0.5f * getScaleX();
} else if(alignment & ALIGN_RIGHT) { } else if (alignment & ALIGN_RIGHT) {
x = pLeft + pWidth * pScaleX - width * getScaleX(); x = pLeft + pWidth * pScaleX - width * getScaleX();
} }
@ -99,7 +99,7 @@ float GuiElement::getTop() {
float pTop = 0; float pTop = 0;
float pScaleY = 1.0f; float pScaleY = 1.0f;
if(parentElement) { if (parentElement) {
pHeight = parentElement->getHeight(); pHeight = parentElement->getHeight();
pTop = parentElement->getTop(); pTop = parentElement->getTop();
pScaleY = parentElement->getScaleY(); pScaleY = parentElement->getScaleY();
@ -110,9 +110,9 @@ float GuiElement::getTop() {
float y = pTop; float y = pTop;
//! TODO: the conversion from int to float and back to int is bad for performance, change that //! TODO: the conversion from int to float and back to int is bad for performance, change that
if(alignment & ALIGN_MIDDLE) { if (alignment & ALIGN_MIDDLE) {
y = pTop + pHeight * 0.5f * pScaleY - getHeight() * 0.5f * getScaleY(); y = pTop + pHeight * 0.5f * pScaleY - getHeight() * 0.5f * getScaleY();
} else if(alignment & ALIGN_BOTTOM) { } else if (alignment & ALIGN_BOTTOM) {
y = pTop + pHeight * pScaleY - getHeight() * getScaleY(); y = pTop + pHeight * pScaleY - getHeight() * getScaleY();
} }
@ -120,33 +120,33 @@ float GuiElement::getTop() {
} }
void GuiElement::setEffect(int32_t eff, int32_t amount, int32_t target) { void GuiElement::setEffect(int32_t eff, int32_t amount, int32_t target) {
if(eff & EFFECT_SLIDE_IN) { if (eff & EFFECT_SLIDE_IN) {
// these calculations overcompensate a little // these calculations overcompensate a little
if(eff & EFFECT_SLIDE_TOP) { if (eff & EFFECT_SLIDE_TOP) {
if(eff & EFFECT_SLIDE_FROM) if (eff & EFFECT_SLIDE_FROM)
yoffsetDyn = (int32_t) -getHeight()*scaleY; yoffsetDyn = (int32_t) -getHeight() * scaleY;
else else
yoffsetDyn = -screenheight; yoffsetDyn = -screenheight;
} else if(eff & EFFECT_SLIDE_LEFT) { } else if (eff & EFFECT_SLIDE_LEFT) {
if(eff & EFFECT_SLIDE_FROM) if (eff & EFFECT_SLIDE_FROM)
xoffsetDyn = (int32_t) -getWidth()*scaleX; xoffsetDyn = (int32_t) -getWidth() * scaleX;
else else
xoffsetDyn = -screenwidth; xoffsetDyn = -screenwidth;
} else if(eff & EFFECT_SLIDE_BOTTOM) { } else if (eff & EFFECT_SLIDE_BOTTOM) {
if(eff & EFFECT_SLIDE_FROM) if (eff & EFFECT_SLIDE_FROM)
yoffsetDyn = (int32_t) getHeight()*scaleY; yoffsetDyn = (int32_t) getHeight() * scaleY;
else else
yoffsetDyn = screenheight; yoffsetDyn = screenheight;
} else if(eff & EFFECT_SLIDE_RIGHT) { } else if (eff & EFFECT_SLIDE_RIGHT) {
if(eff & EFFECT_SLIDE_FROM) if (eff & EFFECT_SLIDE_FROM)
xoffsetDyn = (int32_t) getWidth()*scaleX; xoffsetDyn = (int32_t) getWidth() * scaleX;
else else
xoffsetDyn = screenwidth; xoffsetDyn = screenwidth;
} }
} }
if((eff & EFFECT_FADE) && amount > 0) { if ((eff & EFFECT_FADE) && amount > 0) {
alphaDyn = 0; alphaDyn = 0;
} else if((eff & EFFECT_FADE) && amount < 0) { } else if ((eff & EFFECT_FADE) && amount < 0) {
alphaDyn = alpha; alphaDyn = alpha;
} }
effects |= eff; effects |= eff;
@ -176,105 +176,106 @@ void GuiElement::resetEffects() {
effectAmountOver = 0; effectAmountOver = 0;
effectTargetOver = 0; effectTargetOver = 0;
} }
void GuiElement::updateEffects() { void GuiElement::updateEffects() {
if(!this->isVisible() && parentElement) if (!this->isVisible() && parentElement)
return; return;
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_SLIDE_FROM)) { if (effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_SLIDE_FROM)) {
if(effects & EFFECT_SLIDE_IN) { if (effects & EFFECT_SLIDE_IN) {
if(effects & EFFECT_SLIDE_LEFT) { if (effects & EFFECT_SLIDE_LEFT) {
xoffsetDyn += effectAmount; xoffsetDyn += effectAmount;
if(xoffsetDyn >= 0) { if (xoffsetDyn >= 0) {
xoffsetDyn = 0; xoffsetDyn = 0;
effects = 0; effects = 0;
effectFinished(this); effectFinished(this);
} }
} else if(effects & EFFECT_SLIDE_RIGHT) { } else if (effects & EFFECT_SLIDE_RIGHT) {
xoffsetDyn -= effectAmount; xoffsetDyn -= effectAmount;
if(xoffsetDyn <= 0) { if (xoffsetDyn <= 0) {
xoffsetDyn = 0; xoffsetDyn = 0;
effects = 0; effects = 0;
effectFinished(this); effectFinished(this);
} }
} else if(effects & EFFECT_SLIDE_TOP) { } else if (effects & EFFECT_SLIDE_TOP) {
yoffsetDyn += effectAmount; yoffsetDyn += effectAmount;
if(yoffsetDyn >= 0) { if (yoffsetDyn >= 0) {
yoffsetDyn = 0; yoffsetDyn = 0;
effects = 0; effects = 0;
effectFinished(this); effectFinished(this);
} }
} else if(effects & EFFECT_SLIDE_BOTTOM) { } else if (effects & EFFECT_SLIDE_BOTTOM) {
yoffsetDyn -= effectAmount; yoffsetDyn -= effectAmount;
if(yoffsetDyn <= 0) { if (yoffsetDyn <= 0) {
yoffsetDyn = 0; yoffsetDyn = 0;
effects = 0; effects = 0;
effectFinished(this); effectFinished(this);
} }
} }
} else { } else {
if(effects & EFFECT_SLIDE_LEFT) { if (effects & EFFECT_SLIDE_LEFT) {
xoffsetDyn -= effectAmount; xoffsetDyn -= effectAmount;
if(xoffsetDyn <= -screenwidth) { if (xoffsetDyn <= -screenwidth) {
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} else if((effects & EFFECT_SLIDE_FROM) && xoffsetDyn <= -getWidth()) { } else if ((effects & EFFECT_SLIDE_FROM) && xoffsetDyn <= -getWidth()) {
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} }
} else if(effects & EFFECT_SLIDE_RIGHT) { } else if (effects & EFFECT_SLIDE_RIGHT) {
xoffsetDyn += effectAmount; xoffsetDyn += effectAmount;
if(xoffsetDyn >= screenwidth) { if (xoffsetDyn >= screenwidth) {
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} else if((effects & EFFECT_SLIDE_FROM) && xoffsetDyn >= getWidth()*scaleX) { } else if ((effects & EFFECT_SLIDE_FROM) && xoffsetDyn >= getWidth() * scaleX) {
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} }
} else if(effects & EFFECT_SLIDE_TOP) { } else if (effects & EFFECT_SLIDE_TOP) {
yoffsetDyn -= effectAmount; yoffsetDyn -= effectAmount;
if(yoffsetDyn <= -screenheight) { if (yoffsetDyn <= -screenheight) {
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} else if((effects & EFFECT_SLIDE_FROM) && yoffsetDyn <= -getHeight()) { } else if ((effects & EFFECT_SLIDE_FROM) && yoffsetDyn <= -getHeight()) {
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} }
} else if(effects & EFFECT_SLIDE_BOTTOM) { } else if (effects & EFFECT_SLIDE_BOTTOM) {
yoffsetDyn += effectAmount; yoffsetDyn += effectAmount;
if(yoffsetDyn >= screenheight) { if (yoffsetDyn >= screenheight) {
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} else if((effects & EFFECT_SLIDE_FROM) && yoffsetDyn >= getHeight()) { } else if ((effects & EFFECT_SLIDE_FROM) && yoffsetDyn >= getHeight()) {
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} }
} }
} }
} else if(effects & EFFECT_FADE) { } else if (effects & EFFECT_FADE) {
alphaDyn += effectAmount * (1.0f / 255.0f); alphaDyn += effectAmount * (1.0f / 255.0f);
if(effectAmount < 0 && alphaDyn <= 0) { if (effectAmount < 0 && alphaDyn <= 0) {
alphaDyn = 0; alphaDyn = 0;
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} else if(effectAmount > 0 && alphaDyn >= alpha) { } else if (effectAmount > 0 && alphaDyn >= alpha) {
alphaDyn = alpha; alphaDyn = alpha;
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);
} }
} else if(effects & EFFECT_SCALE) { } else if (effects & EFFECT_SCALE) {
scaleDyn += effectAmount * 0.01f; scaleDyn += effectAmount * 0.01f;
if((effectAmount < 0 && scaleDyn <= (effectTarget * 0.01f)) if ((effectAmount < 0 && scaleDyn <= (effectTarget * 0.01f))
|| (effectAmount > 0 && scaleDyn >= (effectTarget * 0.01f))) { || (effectAmount > 0 && scaleDyn >= (effectTarget * 0.01f))) {
scaleDyn = effectTarget * 0.01f; scaleDyn = effectTarget * 0.01f;
effects = 0; // shut off effect effects = 0; // shut off effect
effectFinished(this); effectFinished(this);

View File

@ -22,7 +22,7 @@ GuiFrame::GuiFrame(GuiFrame *p) {
height = 0; height = 0;
dim = false; dim = false;
if(parent) if (parent)
parent->append(this); parent->append(this);
} }
@ -32,18 +32,18 @@ GuiFrame::GuiFrame(float w, float h, GuiFrame *p) {
height = h; height = h;
dim = false; dim = false;
if(parent) if (parent)
parent->append(this); parent->append(this);
} }
GuiFrame::~GuiFrame() { GuiFrame::~GuiFrame() {
closing(this); closing(this);
if(parent) if (parent)
parent->remove(this); parent->remove(this);
} }
void GuiFrame::append(GuiElement* e) { void GuiFrame::append(GuiElement *e) {
if (e == NULL) if (e == NULL)
return; return;
@ -52,22 +52,22 @@ void GuiFrame::append(GuiElement* e) {
e->setParent(this); e->setParent(this);
} }
void GuiFrame::insert(GuiElement* e, uint32_t index) { void GuiFrame::insert(GuiElement *e, uint32_t index) {
if (e == NULL || (index >= elements.size())) if (e == NULL || (index >= elements.size()))
return; return;
remove(e); remove(e);
elements.insert(elements.begin()+index, e); elements.insert(elements.begin() + index, e);
e->setParent(this); e->setParent(this);
} }
void GuiFrame::remove(GuiElement* e) { void GuiFrame::remove(GuiElement *e) {
if (e == NULL) if (e == NULL)
return; return;
for (uint32_t i = 0; i < elements.size(); ++i) { for (uint32_t i = 0; i < elements.size(); ++i) {
if(e == elements[i]) { if (e == elements[i]) {
elements.erase(elements.begin()+i); elements.erase(elements.begin() + i);
break; break;
} }
} }
@ -85,7 +85,7 @@ void GuiFrame::dimBackground(bool d) {
dim = d; dim = d;
} }
GuiElement* GuiFrame::getGuiElementAt(uint32_t index) const { GuiElement *GuiFrame::getGuiElementAt(uint32_t index) const {
if (index >= elements.size()) if (index >= elements.size())
return NULL; return NULL;
return elements[index]; return elements[index];
@ -131,7 +131,7 @@ int32_t GuiFrame::getSelected() {
// find selected element // find selected element
int32_t found = -1; int32_t found = -1;
for (uint32_t i = 0; i < elements.size(); ++i) { for (uint32_t i = 0; i < elements.size(); ++i) {
if(elements[i]->isStateSet(STATE_SELECTED | STATE_OVER)) { if (elements[i]->isStateSet(STATE_SELECTED | STATE_OVER)) {
found = i; found = i;
break; break;
} }
@ -139,11 +139,11 @@ int32_t GuiFrame::getSelected() {
return found; return found;
} }
void GuiFrame::draw(CVideo * v) { void GuiFrame::draw(CVideo *v) {
if(!this->isVisible() && parentElement) if (!this->isVisible() && parentElement)
return; return;
if(parentElement && dim == true) { if (parentElement && dim == true) {
//GXColor dimColor = (GXColor){0, 0, 0, 0x70}; //GXColor dimColor = (GXColor){0, 0, 0, 0x70};
//Menu_DrawRectangle(0, 0, GetZPosition(), screenwidth,screenheight, &dimColor, false, true); //Menu_DrawRectangle(0, 0, GetZPosition(), screenwidth,screenheight, &dimColor, false, true);
} }
@ -157,7 +157,7 @@ void GuiFrame::draw(CVideo * v) {
} }
void GuiFrame::updateEffects() { void GuiFrame::updateEffects() {
if(!this->isVisible() && parentElement) if (!this->isVisible() && parentElement)
return; return;
GuiElement::updateEffects(); GuiElement::updateEffects();
@ -171,7 +171,7 @@ void GuiFrame::updateEffects() {
} }
void GuiFrame::process() { void GuiFrame::process() {
if(!this->isVisible() && parentElement) if (!this->isVisible() && parentElement)
return; return;
GuiElement::process(); GuiElement::process();
@ -184,8 +184,8 @@ void GuiFrame::process() {
} }
} }
void GuiFrame::update(GuiController * c) { void GuiFrame::update(GuiController *c) {
if(isStateSet(STATE_DISABLED) && parentElement) if (isStateSet(STATE_DISABLED) && parentElement)
return; return;
//! update appended items next frame //! update appended items next frame

View File

@ -20,10 +20,10 @@
#include <gui/video/shaders/ColorShader.h> #include <gui/video/shaders/ColorShader.h>
#include "utils/utils.h" #include "utils/utils.h"
static const float fPiDiv180 = ((float)M_PI / 180.0f); static const float fPiDiv180 = ((float) M_PI / 180.0f);
GuiImage::GuiImage(GuiImageData * img) { GuiImage::GuiImage(GuiImageData *img) {
if(img && img->getTexture()) { if (img && img->getTexture()) {
width = img->getWidth(); width = img->getWidth();
height = img->getHeight(); height = img->getHeight();
} }
@ -32,14 +32,14 @@ GuiImage::GuiImage(GuiImageData * img) {
imageData = img; imageData = img;
} }
GuiImage::GuiImage(int32_t w, int32_t h, const GX2Color & c, int32_t type) { GuiImage::GuiImage(int32_t w, int32_t h, const GX2Color &c, int32_t type) {
internalInit(w, h); internalInit(w, h);
imgType = type; imgType = type;
colorCount = ColorShader::cuColorVtxsSize / ColorShader::cuColorAttrSize; colorCount = ColorShader::cuColorVtxsSize / ColorShader::cuColorAttrSize;
colorVtxs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, colorCount * ColorShader::cuColorAttrSize); colorVtxs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, colorCount * ColorShader::cuColorAttrSize);
if(colorVtxs) { if (colorVtxs) {
for(uint32_t i = 0; i < colorCount; i++) for (uint32_t i = 0; i < colorCount; i++)
setImageColor(c, i); setImageColor(c, i);
} }
} }
@ -48,12 +48,12 @@ GuiImage::GuiImage(int32_t w, int32_t h, const GX2Color *c, uint32_t color_count
internalInit(w, h); internalInit(w, h);
imgType = type; imgType = type;
colorCount = ColorShader::cuColorVtxsSize / ColorShader::cuColorAttrSize; colorCount = ColorShader::cuColorVtxsSize / ColorShader::cuColorAttrSize;
if(colorCount < color_count) if (colorCount < color_count)
colorCount = color_count; colorCount = color_count;
colorVtxs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, colorCount * ColorShader::cuColorAttrSize); colorVtxs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, colorCount * ColorShader::cuColorAttrSize);
if(colorVtxs) { if (colorVtxs) {
for(uint32_t i = 0; i < colorCount; i++) { for (uint32_t i = 0; i < colorCount; i++) {
// take the last as reference if not enough colors defined // take the last as reference if not enough colors defined
int32_t idx = (i < color_count) ? i : (color_count - 1); int32_t idx = (i < color_count) ? i : (color_count - 1);
setImageColor(c[idx], i); setImageColor(c[idx], i);
@ -65,7 +65,7 @@ GuiImage::GuiImage(int32_t w, int32_t h, const GX2Color *c, uint32_t color_count
* Destructor for the GuiImage class. * Destructor for the GuiImage class.
*/ */
GuiImage::~GuiImage() { GuiImage::~GuiImage() {
if(colorVtxs) { if (colorVtxs) {
free(colorVtxs); free(colorVtxs);
colorVtxs = NULL; colorVtxs = NULL;
} }
@ -93,11 +93,11 @@ void GuiImage::internalInit(int32_t w, int32_t h) {
colorIntensity = glm::vec4(1.0f); colorIntensity = glm::vec4(1.0f);
} }
void GuiImage::setImageData(GuiImageData * img) { void GuiImage::setImageData(GuiImageData *img) {
imageData = img; imageData = img;
width = 0; width = 0;
height = 0; height = 0;
if(img && img->getTexture()) { if (img && img->getTexture()) {
width = img->getWidth(); width = img->getWidth();
height = img->getHeight(); height = img->getHeight();
} }
@ -105,46 +105,46 @@ void GuiImage::setImageData(GuiImageData * img) {
} }
GX2Color GuiImage::getPixel(int32_t x, int32_t y) { GX2Color GuiImage::getPixel(int32_t x, int32_t y) {
if(!imageData || this->getWidth() <= 0 || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight()) if (!imageData || this->getWidth() <= 0 || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight())
return (GX2Color) { return (GX2Color) {
0, 0, 0, 0 0, 0, 0, 0
}; };
uint32_t pitch = imageData->getTexture()->surface.pitch; uint32_t pitch = imageData->getTexture()->surface.pitch;
uint32_t *imagePtr = (uint32_t*)imageData->getTexture()->surface.image; uint32_t *imagePtr = (uint32_t *) imageData->getTexture()->surface.image;
uint32_t color_u32 = imagePtr[y * pitch + x]; uint32_t color_u32 = imagePtr[y * pitch + x];
GX2Color color; GX2Color color;
color.r = (color_u32 >> 24) & 0xFF; color.r = (color_u32 >> 24) & 0xFF;
color.g = (color_u32 >> 16) & 0xFF; color.g = (color_u32 >> 16) & 0xFF;
color.b = (color_u32 >> 8) & 0xFF; color.b = (color_u32 >> 8) & 0xFF;
color.a = (color_u32 >> 0) & 0xFF; color.a = (color_u32 >> 0) & 0xFF;
return color; return color;
} }
void GuiImage::setPixel(int32_t x, int32_t y, const GX2Color & color) { void GuiImage::setPixel(int32_t x, int32_t y, const GX2Color &color) {
if(!imageData || this->getWidth() <= 0 || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight()) if (!imageData || this->getWidth() <= 0 || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight())
return; return;
uint32_t pitch = imageData->getTexture()->surface.pitch; uint32_t pitch = imageData->getTexture()->surface.pitch;
uint32_t *imagePtr = (uint32_t*)imageData->getTexture()->surface.image; uint32_t *imagePtr = (uint32_t *) imageData->getTexture()->surface.image;
imagePtr[y * pitch + x] = (color.r << 24) | (color.g << 16) | (color.b << 8) | (color.a << 0); imagePtr[y * pitch + x] = (color.r << 24) | (color.g << 16) | (color.b << 8) | (color.a << 0);
} }
void GuiImage::setImageColor(const GX2Color & c, int32_t idx) { void GuiImage::setImageColor(const GX2Color &c, int32_t idx) {
if(!colorVtxs) { if (!colorVtxs) {
return; return;
} }
if(idx >= 0 && idx < (int32_t)colorCount) { if (idx >= 0 && idx < (int32_t) colorCount) {
colorVtxs[(idx << 2) + 0] = c.r; colorVtxs[(idx << 2) + 0] = c.r;
colorVtxs[(idx << 2) + 1] = c.g; colorVtxs[(idx << 2) + 1] = c.g;
colorVtxs[(idx << 2) + 2] = c.b; colorVtxs[(idx << 2) + 2] = c.b;
colorVtxs[(idx << 2) + 3] = c.a; colorVtxs[(idx << 2) + 3] = c.a;
colorVtxsDirty = true; colorVtxsDirty = true;
} else if(colorVtxs) { } else if (colorVtxs) {
for(uint32_t i = 0; i < (ColorShader::cuColorVtxsSize / sizeof(uint8_t)); i += 4) { for (uint32_t i = 0; i < (ColorShader::cuColorVtxsSize / sizeof(uint8_t)); i += 4) {
colorVtxs[i + 0] = c.r; colorVtxs[i + 0] = c.r;
colorVtxs[i + 1] = c.g; colorVtxs[i + 1] = c.g;
colorVtxs[i + 2] = c.b; colorVtxs[i + 2] = c.b;
@ -165,10 +165,10 @@ void GuiImage::setPrimitiveVertex(int32_t prim, const float *posVtx, const float
posVtxs = posVtx; posVtxs = posVtx;
texCoords = texCoord; texCoords = texCoord;
if(imgType == IMAGE_COLOR) { if (imgType == IMAGE_COLOR) {
uint8_t * newColorVtxs = (uint8_t *) memalign(0x40, ColorShader::cuColorAttrSize * vtxCount); uint8_t *newColorVtxs = (uint8_t *) memalign(0x40, ColorShader::cuColorAttrSize * vtxCount);
for(uint32_t i = 0; i < vtxCount; i++) { for (uint32_t i = 0; i < vtxCount; i++) {
int32_t newColorIdx = (i << 2); int32_t newColorIdx = (i << 2);
int32_t colorIdx = (i < colorCount) ? (newColorIdx) : ((colorCount - 1) << 2); int32_t colorIdx = (i < colorCount) ? (newColorIdx) : ((colorCount - 1) << 2);
@ -186,7 +186,7 @@ void GuiImage::setPrimitiveVertex(int32_t prim, const float *posVtx, const float
} }
void GuiImage::draw(CVideo *pVideo) { void GuiImage::draw(CVideo *pVideo) {
if(!this->isVisible() || tileVertical == 0 || tileHorizontal == 0) if (!this->isVisible() || tileVertical == 0 || tileHorizontal == 0)
return; return;
float currScaleX = getScaleX(); float currScaleX = getScaleX();
@ -238,13 +238,13 @@ void GuiImage::draw(CVideo *pVideo) {
// Menu_DrawImgCut(image, width, height, format, currLeft, currTop+height*i, currZ, imageangle, currScaleX, currScaleY, currAlpha, cutBoundsRect.x1(), cutBoundsRect.x2(), cutBoundsRect.y1(), cutBoundsRect.y2()); // Menu_DrawImgCut(image, width, height, format, currLeft, currTop+height*i, currZ, imageangle, currScaleX, currScaleY, currAlpha, cutBoundsRect.x1(), cutBoundsRect.x2(), cutBoundsRect.y1(), cutBoundsRect.y2());
// } // }
// } // }
if(colorVtxsDirty && colorVtxs) { if (colorVtxsDirty && colorVtxs) {
//! flush color vertex only on main GX2 thread //! flush color vertex only on main GX2 thread
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVtxs, colorCount * ColorShader::cuColorAttrSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVtxs, colorCount * ColorShader::cuColorAttrSize);
colorVtxsDirty = false; colorVtxsDirty = false;
} }
if(imgType == IMAGE_COLOR && colorVtxs) { if (imgType == IMAGE_COLOR && colorVtxs) {
ColorShader::instance()->setShaders(); ColorShader::instance()->setShaders();
ColorShader::instance()->setAttributeBuffer(colorVtxs, posVtxs, vtxCount); ColorShader::instance()->setAttributeBuffer(colorVtxs, posVtxs, vtxCount);
ColorShader::instance()->setAngle(imageAngle); ColorShader::instance()->setAngle(imageAngle);
@ -252,7 +252,7 @@ void GuiImage::draw(CVideo *pVideo) {
ColorShader::instance()->setScale(scaleFactor); ColorShader::instance()->setScale(scaleFactor);
ColorShader::instance()->setColorIntensity(colorIntensity); ColorShader::instance()->setColorIntensity(colorIntensity);
ColorShader::instance()->draw(primitive, vtxCount); ColorShader::instance()->draw(primitive, vtxCount);
} else if(imageData) { } else if (imageData) {
Texture2DShader::instance()->setShaders(); Texture2DShader::instance()->setShaders();
Texture2DShader::instance()->setAttributeBuffer(texCoords, posVtxs, vtxCount); Texture2DShader::instance()->setAttributeBuffer(texCoords, posVtxs, vtxCount);
Texture2DShader::instance()->setAngle(imageAngle); Texture2DShader::instance()->setAngle(imageAngle);

View File

@ -19,34 +19,27 @@
#include "../fs/CFile.hpp" #include "../fs/CFile.hpp"
std::vector<GuiImageAsync *> GuiImageAsync::imageQueue; std::vector<GuiImageAsync *> GuiImageAsync::imageQueue;
CThread * GuiImageAsync::pThread = NULL; CThread *GuiImageAsync::pThread = NULL;
std::recursive_mutex * GuiImageAsync::pMutex = NULL; std::recursive_mutex *GuiImageAsync::pMutex = NULL;
uint32_t GuiImageAsync::threadRefCounter = 0; uint32_t GuiImageAsync::threadRefCounter = 0;
bool GuiImageAsync::bExitRequested = false; bool GuiImageAsync::bExitRequested = false;
GuiImageAsync * GuiImageAsync::pInUse = NULL; GuiImageAsync *GuiImageAsync::pInUse = NULL;
GuiImageAsync::GuiImageAsync(const uint8_t *imageBuffer, const uint32_t & imageBufferSize, GuiImageData * preloadImg) GuiImageAsync::GuiImageAsync(const uint8_t *imageBuffer, const uint32_t &imageBufferSize, GuiImageData *preloadImg)
: GuiImage(preloadImg) : GuiImage(preloadImg), imgData(NULL), imgBuffer(imageBuffer), imgBufferSize(imageBufferSize) {
, imgData(NULL)
, imgBuffer(imageBuffer)
, imgBufferSize(imageBufferSize) {
threadInit(); threadInit();
threadAddImage(this); threadAddImage(this);
} }
GuiImageAsync::GuiImageAsync(const std::string & file, GuiImageData * preloadImg) GuiImageAsync::GuiImageAsync(const std::string &file, GuiImageData *preloadImg)
: GuiImage(preloadImg) : GuiImage(preloadImg), imgData(NULL), filename(file), imgBuffer(NULL), imgBufferSize(0) {
, imgData(NULL)
, filename(file)
, imgBuffer(NULL)
, imgBufferSize(0) {
threadInit(); threadInit();
threadAddImage(this); threadAddImage(this);
} }
GuiImageAsync::~GuiImageAsync() { GuiImageAsync::~GuiImageAsync() {
threadRemoveImage(this); threadRemoveImage(this);
while(pInUse == this) while (pInUse == this)
OSSleepTicks(OSMicrosecondsToTicks(1000)); OSSleepTicks(OSMicrosecondsToTicks(1000));
if (imgData) if (imgData)
@ -64,8 +57,8 @@ void GuiImageAsync::threadAddImage(GuiImageAsync *Image) {
void GuiImageAsync::threadRemoveImage(GuiImageAsync *image) { void GuiImageAsync::threadRemoveImage(GuiImageAsync *image) {
pMutex->lock(); pMutex->lock();
for(uint32_t i = 0; i < imageQueue.size(); ++i) { for (uint32_t i = 0; i < imageQueue.size(); ++i) {
if(imageQueue[i] == image) { if (imageQueue[i] == image) {
imageQueue.erase(imageQueue.begin() + i); imageQueue.erase(imageQueue.begin() + i);
break; break;
} }
@ -80,11 +73,11 @@ void GuiImageAsync::clearQueue() {
} }
void GuiImageAsync::guiImageAsyncThread(CThread *thread, void *arg) { void GuiImageAsync::guiImageAsyncThread(CThread *thread, void *arg) {
while(!bExitRequested) { while (!bExitRequested) {
if(imageQueue.empty() && !bExitRequested) if (imageQueue.empty() && !bExitRequested)
pThread->suspendThread(); pThread->suspendThread();
if(!imageQueue.empty() && !bExitRequested) { if (!imageQueue.empty() && !bExitRequested) {
pMutex->lock(); pMutex->lock();
pInUse = imageQueue.front(); pInUse = imageQueue.front();
imageQueue.erase(imageQueue.begin()); imageQueue.erase(imageQueue.begin());
@ -94,39 +87,39 @@ void GuiImageAsync::guiImageAsyncThread(CThread *thread, void *arg) {
continue; continue;
if(pInUse->imgBuffer && pInUse->imgBufferSize) { if (pInUse->imgBuffer && pInUse->imgBufferSize) {
pInUse->imgData = new GuiImageData(pInUse->imgBuffer, pInUse->imgBufferSize); pInUse->imgData = new GuiImageData(pInUse->imgBuffer, pInUse->imgBufferSize);
} else { } else {
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
uint64_t bufferSize = 0; uint64_t bufferSize = 0;
CFile file(pInUse->filename, CFile::ReadOnly); CFile file(pInUse->filename, CFile::ReadOnly);
if(file.isOpen()) { if (file.isOpen()) {
uint64_t filesize = file.size(); uint64_t filesize = file.size();
buffer = (uint8_t *) malloc(filesize); buffer = (uint8_t *) malloc(filesize);
if (buffer != NULL) { if (buffer != NULL) {
uint32_t blocksize = 0x4000; uint32_t blocksize = 0x4000;
uint32_t done = 0; uint32_t done = 0;
int32_t readBytes = 0; int32_t readBytes = 0;
while(done < filesize) { while (done < filesize) {
if(done + blocksize > filesize) { if (done + blocksize > filesize) {
blocksize = filesize - done; blocksize = filesize - done;
} }
readBytes = file.read(buffer + done, blocksize); readBytes = file.read(buffer + done, blocksize);
if(readBytes <= 0) if (readBytes <= 0)
break; break;
done += readBytes; done += readBytes;
} }
if(done == filesize){ if (done == filesize) {
bufferSize = filesize; bufferSize = filesize;
}else{ } else {
free(buffer); free(buffer);
} }
} }
file.close(); file.close();
} }
if(buffer != NULL && bufferSize > 0) { if (buffer != NULL && bufferSize > 0) {
pInUse->imgData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); pInUse->imgData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR);
//! free original image buffer which is converted to texture now and not needed anymore //! free original image buffer which is converted to texture now and not needed anymore
@ -134,8 +127,8 @@ void GuiImageAsync::guiImageAsyncThread(CThread *thread, void *arg) {
} }
} }
if(pInUse->imgData) { if (pInUse->imgData) {
if(pInUse->imgData->getTexture()) { if (pInUse->imgData->getTexture()) {
pInUse->width = pInUse->imgData->getWidth(); pInUse->width = pInUse->imgData->getWidth();
pInUse->height = pInUse->imgData->getHeight(); pInUse->height = pInUse->imgData->getHeight();
pInUse->imageData = pInUse->imgData; pInUse->imageData = pInUse->imgData;
@ -162,11 +155,11 @@ void GuiImageAsync::threadInit() {
} }
void GuiImageAsync::threadExit() { void GuiImageAsync::threadExit() {
if(threadRefCounter) { if (threadRefCounter) {
--threadRefCounter; --threadRefCounter;
} }
if(/*(threadRefCounter == 0) &&*/ (pThread != NULL)) { if (/*(threadRefCounter == 0) &&*/ (pThread != NULL)) {
bExitRequested = true; bExitRequested = true;
delete pThread; delete pThread;
delete pMutex; delete pMutex;

View File

@ -19,6 +19,7 @@
#include <stdint.h> #include <stdint.h>
#include <gui/GuiImageData.h> #include <gui/GuiImageData.h>
#include <gui/memory.h> #include <gui/memory.h>
/** /**
* Constructor for the GuiImageData class. * Constructor for the GuiImageData class.
*/ */
@ -31,7 +32,7 @@ GuiImageData::GuiImageData() {
/** /**
* Constructor for the GuiImageData class. * Constructor for the GuiImageData class.
*/ */
GuiImageData::GuiImageData(const uint8_t * img, int32_t imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) { GuiImageData::GuiImageData(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) {
texture = NULL; texture = NULL;
sampler = NULL; sampler = NULL;
loadImage(img, imgSize, textureClamp, textureFormat); loadImage(img, imgSize, textureClamp, textureFormat);
@ -45,32 +46,32 @@ GuiImageData::~GuiImageData() {
} }
void GuiImageData::releaseData(void) { void GuiImageData::releaseData(void) {
if(texture) { if (texture) {
if(texture->surface.image) { if (texture->surface.image) {
switch(memoryType) { switch (memoryType) {
default: default:
case eMemTypeMEM2: case eMemTypeMEM2:
free(texture->surface.image); free(texture->surface.image);
break; break;
case eMemTypeMEM1: case eMemTypeMEM1:
MEM1_free(texture->surface.image); MEM1_free(texture->surface.image);
break; break;
case eMemTypeMEMBucket: case eMemTypeMEMBucket:
MEMBucket_free(texture->surface.image); MEMBucket_free(texture->surface.image);
break; break;
} }
} }
delete texture; delete texture;
texture = NULL; texture = NULL;
} }
if(sampler) { if (sampler) {
delete sampler; delete sampler;
sampler = NULL; sampler = NULL;
} }
} }
void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) { void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) {
if(!img || (imgSize < 8)) if (!img || (imgSize < 8))
return; return;
releaseData(); releaseData();
@ -80,21 +81,21 @@ void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMod
//! not needed for now therefore comment out to safe ELF size //! not needed for now therefore comment out to safe ELF size
//! if needed uncomment, adds 200 kb to the ELF size //! if needed uncomment, adds 200 kb to the ELF size
// IMAGE_JPEG // IMAGE_JPEG
gdImg = gdImageCreateFromJpegPtr(imgSize, (uint8_t*) img); gdImg = gdImageCreateFromJpegPtr(imgSize, (uint8_t *) img);
} else if (img[0] == 'B' && img[1] == 'M') { } else if (img[0] == 'B' && img[1] == 'M') {
// IMAGE_BMP // IMAGE_BMP
gdImg = gdImageCreateFromBmpPtr(imgSize, (uint8_t*) img); gdImg = gdImageCreateFromBmpPtr(imgSize, (uint8_t *) img);
} else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G') { } else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G') {
// IMAGE_PNG // IMAGE_PNG
gdImg = gdImageCreateFromPngPtr(imgSize, (uint8_t*) img); gdImg = gdImageCreateFromPngPtr(imgSize, (uint8_t *) img);
} }
//!This must be last since it can also intefere with outher formats //!This must be last since it can also intefere with outher formats
else if(img[0] == 0x00) { else if (img[0] == 0x00) {
// Try loading TGA image // Try loading TGA image
gdImg = gdImageCreateFromTgaPtr(imgSize, (uint8_t*) img); gdImg = gdImageCreateFromTgaPtr(imgSize, (uint8_t *) img);
} }
if(gdImg == 0) if (gdImg == 0)
return; return;
uint32_t width = (gdImageSX(gdImg)); uint32_t width = (gdImageSX(gdImg));
@ -102,10 +103,10 @@ void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMod
//! Initialize texture //! Initialize texture
texture = new GX2Texture; texture = new GX2Texture;
GX2InitTexture(texture, width, height, 1, 0, textureFormat, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED); GX2InitTexture(texture, width, height, 1, 0, textureFormat, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED);
//! if this fails something went horribly wrong //! if this fails something went horribly wrong
if(texture->surface.imageSize == 0) { if (texture->surface.imageSize == 0) {
delete texture; delete texture;
texture = NULL; texture = NULL;
gdImageDestroy(gdImg); gdImageDestroy(gdImg);
@ -116,17 +117,17 @@ void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMod
memoryType = eMemTypeMEM2; memoryType = eMemTypeMEM2;
texture->surface.image = memalign(texture->surface.alignment, texture->surface.imageSize); texture->surface.image = memalign(texture->surface.alignment, texture->surface.imageSize);
//! try MEM1 on failure //! try MEM1 on failure
if(!texture->surface.image) { if (!texture->surface.image) {
memoryType = eMemTypeMEM1; memoryType = eMemTypeMEM1;
texture->surface.image = MEM1_alloc(texture->surface.imageSize, texture->surface.alignment); texture->surface.image = MEM1_alloc(texture->surface.imageSize, texture->surface.alignment);
} }
//! try MEM bucket on failure //! try MEM bucket on failure
if(!texture->surface.image) { if (!texture->surface.image) {
memoryType = eMemTypeMEMBucket; memoryType = eMemTypeMEMBucket;
texture->surface.image = MEMBucket_alloc(texture->surface.imageSize, texture->surface.alignment); texture->surface.image = MEMBucket_alloc(texture->surface.imageSize, texture->surface.alignment);
} }
//! check if memory is available for image //! check if memory is available for image
if(!texture->surface.image) { if (!texture->surface.image) {
gdImageDestroy(gdImg); gdImageDestroy(gdImg);
delete texture; delete texture;
texture = NULL; texture = NULL;
@ -135,14 +136,14 @@ void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMod
//! set mip map data pointer //! set mip map data pointer
texture->surface.mipmaps = NULL; texture->surface.mipmaps = NULL;
//! convert image to texture //! convert image to texture
switch(textureFormat) { switch (textureFormat) {
default: default:
case GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8: case GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8:
gdImageToUnormR8G8B8A8(gdImg, (uint32_t*)texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch); gdImageToUnormR8G8B8A8(gdImg, (uint32_t *) texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch);
break; break;
case GX2_SURFACE_FORMAT_UNORM_R5_G6_B5: case GX2_SURFACE_FORMAT_UNORM_R5_G6_B5:
gdImageToUnormR5G6B5(gdImg, (uint16_t*)texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch); gdImageToUnormR5G6B5(gdImg, (uint16_t *) texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch);
break; break;
} }
//! free memory of image as its not needed anymore //! free memory of image as its not needed anymore
@ -156,12 +157,12 @@ void GuiImageData::loadImage(const uint8_t *img, int32_t imgSize, GX2TexClampMod
} }
void GuiImageData::gdImageToUnormR8G8B8A8(gdImagePtr gdImg, uint32_t *imgBuffer, uint32_t width, uint32_t height, uint32_t pitch) { void GuiImageData::gdImageToUnormR8G8B8A8(gdImagePtr gdImg, uint32_t *imgBuffer, uint32_t width, uint32_t height, uint32_t pitch) {
for(uint32_t y = 0; y < height; ++y) { for (uint32_t y = 0; y < height; ++y) {
for(uint32_t x = 0; x < width; ++x) { for (uint32_t x = 0; x < width; ++x) {
uint32_t pixel = gdImageGetPixel(gdImg, x, y); uint32_t pixel = gdImageGetPixel(gdImg, x, y);
uint8_t a = 254 - 2*((uint8_t)gdImageAlpha(gdImg, pixel)); uint8_t a = 254 - 2 * ((uint8_t) gdImageAlpha(gdImg, pixel));
if(a == 254) a++; if (a == 254) a++;
uint8_t r = gdImageRed(gdImg, pixel); uint8_t r = gdImageRed(gdImg, pixel);
uint8_t g = gdImageGreen(gdImg, pixel); uint8_t g = gdImageGreen(gdImg, pixel);
@ -174,8 +175,8 @@ void GuiImageData::gdImageToUnormR8G8B8A8(gdImagePtr gdImg, uint32_t *imgBuffer,
//! TODO: figure out why this seems to not work correct yet //! TODO: figure out why this seems to not work correct yet
void GuiImageData::gdImageToUnormR5G6B5(gdImagePtr gdImg, uint16_t *imgBuffer, uint32_t width, uint32_t height, uint32_t pitch) { void GuiImageData::gdImageToUnormR5G6B5(gdImagePtr gdImg, uint16_t *imgBuffer, uint32_t width, uint32_t height, uint32_t pitch) {
for(uint32_t y = 0; y < height; ++y) { for (uint32_t y = 0; y < height; ++y) {
for(uint32_t x = 0; x < width; ++x) { for (uint32_t x = 0; x < width; ++x) {
uint32_t pixel = gdImageGetPixel(gdImg, x, y); uint32_t pixel = gdImageGetPixel(gdImg, x, y);
uint8_t r = gdImageRed(gdImg, pixel); uint8_t r = gdImageRed(gdImg, pixel);

View File

@ -30,7 +30,7 @@ static inline float getRandMinusOneToOneF32() {
} }
GuiParticleImage::GuiParticleImage(int32_t w, int32_t h, uint32_t particleCount, float minRadius, float maxRadius, float minSpeed, float maxSpeed) GuiParticleImage::GuiParticleImage(int32_t w, int32_t h, uint32_t particleCount, float minRadius, float maxRadius, float minSpeed, float maxSpeed)
: GuiImage(NULL) { : GuiImage(NULL) {
width = w; width = w;
height = h; height = h;
imgType = IMAGE_COLOR; imgType = IMAGE_COLOR;
@ -42,7 +42,7 @@ GuiParticleImage::GuiParticleImage(int32_t w, int32_t h, uint32_t particleCount,
posVertexs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ColorShader::cuVertexAttrSize * CIRCLE_VERTEX_COUNT); posVertexs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ColorShader::cuVertexAttrSize * CIRCLE_VERTEX_COUNT);
colorVertexs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ColorShader::cuColorAttrSize * CIRCLE_VERTEX_COUNT); colorVertexs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ColorShader::cuColorAttrSize * CIRCLE_VERTEX_COUNT);
for(uint32_t i = 0; i < CIRCLE_VERTEX_COUNT; i++) { for (uint32_t i = 0; i < CIRCLE_VERTEX_COUNT; i++) {
posVertexs[i * 3 + 0] = cosf(DegToRad(i * 360.0f / CIRCLE_VERTEX_COUNT)); posVertexs[i * 3 + 0] = cosf(DegToRad(i * 360.0f / CIRCLE_VERTEX_COUNT));
posVertexs[i * 3 + 1] = sinf(DegToRad(i * 360.0f / CIRCLE_VERTEX_COUNT)); posVertexs[i * 3 + 1] = sinf(DegToRad(i * 360.0f / CIRCLE_VERTEX_COUNT));
posVertexs[i * 3 + 2] = 0.0f; posVertexs[i * 3 + 2] = 0.0f;
@ -57,7 +57,7 @@ GuiParticleImage::GuiParticleImage(int32_t w, int32_t h, uint32_t particleCount,
particles.resize(particleCount); particles.resize(particleCount);
for(uint32_t i = 0; i < particleCount; i++) { for (uint32_t i = 0; i < particleCount; i++) {
particles[i].position.x = getRandMinusOneToOneF32() * getWidth() * 0.5f; particles[i].position.x = getRandMinusOneToOneF32() * getWidth() * 0.5f;
particles[i].position.y = getRandMinusOneToOneF32() * getHeight() * 0.5f; particles[i].position.y = getRandMinusOneToOneF32() * getHeight() * 0.5f;
particles[i].position.z = 0.0f; particles[i].position.z = 0.0f;
@ -74,7 +74,7 @@ GuiParticleImage::~GuiParticleImage() {
} }
void GuiParticleImage::draw(CVideo *pVideo) { void GuiParticleImage::draw(CVideo *pVideo) {
if(!this->isVisible()) if (!this->isVisible())
return; return;
@ -88,8 +88,8 @@ void GuiParticleImage::draw(CVideo *pVideo) {
//! add other colors intensities parameters //! add other colors intensities parameters
colorIntensity[3] = getAlpha(); colorIntensity[3] = getAlpha();
for(uint32_t i = 0; i < particles.size(); ++i) { for (uint32_t i = 0; i < particles.size(); ++i) {
if(particles[i].position.y > (getHeight() * 0.5f + 30.0f)) { if (particles[i].position.y > (getHeight() * 0.5f + 30.0f)) {
particles[i].position.x = getRandMinusOneToOneF32() * getWidth() * 0.5f; particles[i].position.x = getRandMinusOneToOneF32() * getWidth() * 0.5f;
particles[i].position.y = -getHeight() * 0.5f - 30.0f; particles[i].position.y = -getHeight() * 0.5f - 30.0f;
particles[i].colors = glm::vec4(1.0f, 1.0f, 1.0f, (getRandZeroToOneF32() * 0.6f) + 0.05f); particles[i].colors = glm::vec4(1.0f, 1.0f, 1.0f, (getRandZeroToOneF32() * 0.6f) + 0.05f);
@ -97,7 +97,7 @@ void GuiParticleImage::draw(CVideo *pVideo) {
particles[i].speed = (getRandZeroToOneF32() * (maxSpeed - minSpeed)) + minSpeed; particles[i].speed = (getRandZeroToOneF32() * (maxSpeed - minSpeed)) + minSpeed;
particles[i].direction = getRandMinusOneToOneF32(); particles[i].direction = getRandMinusOneToOneF32();
} }
if(particles[i].position.x < (-getWidth() * 0.5f - 50.0f)) { if (particles[i].position.x < (-getWidth() * 0.5f - 50.0f)) {
particles[i].position.x = -particles[i].position.x; particles[i].position.x = -particles[i].position.x;
} }

View File

@ -25,8 +25,7 @@
#include "utils/utils.h" #include "utils/utils.h"
GuiScrollbar::GuiScrollbar(int32_t h) GuiScrollbar::GuiScrollbar(int32_t h)
: touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH) : touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH), wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A) {
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A) {
SelItem = 0; SelItem = 0;
SelInd = 0; SelInd = 0;
PageSize = 0; PageSize = 0;
@ -74,17 +73,17 @@ GuiScrollbar::~GuiScrollbar() {
} }
void GuiScrollbar::ScrollOneUp() { void GuiScrollbar::ScrollOneUp() {
if(SelItem == 0 && SelInd > 0) { if (SelItem == 0 && SelInd > 0) {
// move list up by 1 // move list up by 1
--SelInd; --SelInd;
} else if(SelInd+SelItem > 0) { } else if (SelInd + SelItem > 0) {
--SelItem; --SelItem;
} }
} }
void GuiScrollbar::ScrollOneDown() { void GuiScrollbar::ScrollOneDown() {
if(SelInd+SelItem + 1 < EntrieCount) { if (SelInd + SelItem + 1 < EntrieCount) {
if(SelItem == PageSize-1) { if (SelItem == PageSize - 1) {
// move list down by 1 // move list down by 1
SelInd++; SelInd++;
} else { } else {
@ -94,7 +93,7 @@ void GuiScrollbar::ScrollOneDown() {
} }
void GuiScrollbar::OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiScrollbar::OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(ScrollState < ScrollSpeed) if (ScrollState < ScrollSpeed)
return; return;
ScrollOneUp(); ScrollOneUp();
@ -104,7 +103,7 @@ void GuiScrollbar::OnUpButtonClick(GuiButton *button, const GuiController *contr
} }
void GuiScrollbar::OnDownButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiScrollbar::OnDownButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(ScrollState < ScrollSpeed) if (ScrollState < ScrollSpeed)
return; return;
ScrollOneDown(); ScrollOneDown();
@ -114,11 +113,11 @@ void GuiScrollbar::OnDownButtonClick(GuiButton *button, const GuiController *con
} }
void GuiScrollbar::OnBoxButtonHold(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiScrollbar::OnBoxButtonHold(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(EntrieCount == 0) { if (EntrieCount == 0) {
return; return;
} }
if(!controller->data.validPointer) { if (!controller->data.validPointer) {
return; return;
} }
@ -126,22 +125,22 @@ void GuiScrollbar::OnBoxButtonHold(GuiButton *button, const GuiController *contr
int32_t positionWiimote = LIMIT(y - MinHeight, 0, MaxHeight - MinHeight); int32_t positionWiimote = LIMIT(y - MinHeight, 0, MaxHeight - MinHeight);
int32_t newSelected = (EntrieCount - 1) - (int32_t) ((float) positionWiimote / (float) (MaxHeight-MinHeight) * (float) (EntrieCount-1)); int32_t newSelected = (EntrieCount - 1) - (int32_t) ((float) positionWiimote / (float) (MaxHeight - MinHeight) * (float) (EntrieCount - 1));
int32_t diff = newSelected-SelInd-SelItem; int32_t diff = newSelected - SelInd - SelItem;
if(newSelected <= 0) { if (newSelected <= 0) {
SelItem = 0; SelItem = 0;
SelInd = 0; SelInd = 0;
} else if(newSelected >= EntrieCount-1) { } else if (newSelected >= EntrieCount - 1) {
SelItem = (PageSize-1 < EntrieCount-1) ? PageSize-1 : EntrieCount-1; SelItem = (PageSize - 1 < EntrieCount - 1) ? PageSize - 1 : EntrieCount - 1;
SelInd = EntrieCount-PageSize; SelInd = EntrieCount - PageSize;
} else if(newSelected < PageSize && SelInd == 0 && diff < 0) { } else if (newSelected < PageSize && SelInd == 0 && diff < 0) {
SelItem = std::max(SelItem+diff, (int32_t)0); SelItem = std::max(SelItem + diff, (int32_t) 0);
} else if(EntrieCount-newSelected < PageSize && SelInd == EntrieCount-PageSize && diff > 0) { } else if (EntrieCount - newSelected < PageSize && SelInd == EntrieCount - PageSize && diff > 0) {
SelItem = std::min(SelItem+diff, PageSize-1); SelItem = std::min(SelItem + diff, PageSize - 1);
} else { } else {
SelInd = LIMIT(SelInd+diff, 0, ((EntrieCount-PageSize < 0) ? 0 : EntrieCount-PageSize)); SelInd = LIMIT(SelInd + diff, 0, ((EntrieCount - PageSize < 0) ? 0 : EntrieCount - PageSize));
} }
ScrollState = 0; ScrollState = 0;
@ -149,7 +148,7 @@ void GuiScrollbar::OnBoxButtonHold(GuiButton *button, const GuiController *contr
} }
void GuiScrollbar::SetPageSize(int32_t size) { void GuiScrollbar::SetPageSize(int32_t size) {
if(PageSize == size) if (PageSize == size)
return; return;
PageSize = size; PageSize = size;
@ -157,15 +156,15 @@ void GuiScrollbar::SetPageSize(int32_t size) {
} }
void GuiScrollbar::SetSelectedItem(int32_t pos) { void GuiScrollbar::SetSelectedItem(int32_t pos) {
if(SelItem == pos) if (SelItem == pos)
return; return;
SelItem = LIMIT(pos, 0, EntrieCount-1); SelItem = LIMIT(pos, 0, EntrieCount - 1);
listChanged(SelItem, SelInd); listChanged(SelItem, SelInd);
} }
void GuiScrollbar::SetSelectedIndex(int32_t pos) { void GuiScrollbar::SetSelectedIndex(int32_t pos) {
if(SelInd == pos) if (SelInd == pos)
return; return;
SelInd = pos; SelInd = pos;
@ -173,7 +172,7 @@ void GuiScrollbar::SetSelectedIndex(int32_t pos) {
} }
void GuiScrollbar::SetEntrieCount(int32_t cnt) { void GuiScrollbar::SetEntrieCount(int32_t cnt) {
if(EntrieCount == cnt) if (EntrieCount == cnt)
return; return;
EntrieCount = cnt; EntrieCount = cnt;
@ -181,18 +180,18 @@ void GuiScrollbar::SetEntrieCount(int32_t cnt) {
} }
void GuiScrollbar::setScrollboxPosition(int32_t SelItem, int32_t SelInd) { void GuiScrollbar::setScrollboxPosition(int32_t SelItem, int32_t SelInd) {
int32_t position = MaxHeight-(MaxHeight-MinHeight)*(SelInd+SelItem)/(EntrieCount-1); int32_t position = MaxHeight - (MaxHeight - MinHeight) * (SelInd + SelItem) / (EntrieCount - 1);
if(position < MinHeight || (SelInd+SelItem >= EntrieCount-1)) if (position < MinHeight || (SelInd + SelItem >= EntrieCount - 1))
position = MinHeight; position = MinHeight;
else if(position > MaxHeight || (SelInd+SelItem) == 0) else if (position > MaxHeight || (SelInd + SelItem) == 0)
position = MaxHeight; position = MaxHeight;
scrollbarBoxBtn->setPosition(0, position); scrollbarBoxBtn->setPosition(0, position);
} }
void GuiScrollbar::draw(CVideo * video) { void GuiScrollbar::draw(CVideo *video) {
if(scrollbarLineImage) { if (scrollbarLineImage) {
scrollbarLineImage->draw(video); scrollbarLineImage->draw(video);
} }
arrowUpBtn->draw(video); arrowUpBtn->draw(video);
@ -202,8 +201,8 @@ void GuiScrollbar::draw(CVideo * video) {
updateEffects(); updateEffects();
} }
void GuiScrollbar::update(GuiController * t) { void GuiScrollbar::update(GuiController *t) {
if(this->isStateSet(STATE_DISABLED)) if (this->isStateSet(STATE_DISABLED))
return; return;
arrowUpBtn->update(t); arrowUpBtn->update(t);

View File

@ -26,18 +26,11 @@
* Constructor for the GuiCheckBox class. * Constructor for the GuiCheckBox class.
*/ */
GuiSelectBox::GuiSelectBox(GuiImage * background,std::string caption,float width,float height,GuiFrame *parent) GuiSelectBox::GuiSelectBox(GuiImage *background, std::string caption, float width, float height, GuiFrame *parent)
: GuiFrame(width,height,parent) : GuiFrame(width, height, parent), selected(0), captionText(caption), topValueButton(0, 0), touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH),
,selected(0) wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A), buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true),
,captionText(caption) buttonBTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_B, true), buttonUpTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_UP | GuiTrigger::STICK_L_UP, true),
,topValueButton(0,0) buttonDownTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true), DPADButtons(0, 0) {
,touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
,wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
,buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true)
,buttonBTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_B, true)
,buttonUpTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_UP | GuiTrigger::STICK_L_UP, true)
,buttonDownTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true)
,DPADButtons(0,0) {
setImageTopBackground(background); setImageTopBackground(background);
showValues = false; showValues = false;
bChanged = false; bChanged = false;
@ -45,7 +38,7 @@ GuiSelectBox::GuiSelectBox(GuiImage * background,std::string caption,float width
opened = false; opened = false;
topValueText.setFontSize(32); topValueText.setFontSize(32);
topValueText.setAlignment(ALIGN_LEFT); topValueText.setAlignment(ALIGN_LEFT);
topValueText.setPosition(10,-7); topValueText.setPosition(10, -7);
topValueButton.setLabel(&topValueText); topValueButton.setLabel(&topValueText);
topValueButton.setTrigger(&touchTrigger); topValueButton.setTrigger(&touchTrigger);
topValueButton.setTrigger(&wpadTouchTrigger); topValueButton.setTrigger(&wpadTouchTrigger);
@ -68,14 +61,14 @@ GuiSelectBox::GuiSelectBox(GuiImage * background,std::string caption,float width
bChanged = true; bChanged = true;
} }
void GuiSelectBox::setSize(float width,float height) { void GuiSelectBox::setSize(float width, float height) {
GuiFrame::setSize(width,height); GuiFrame::setSize(width, height);
topValueButton.setSize(width,height); topValueButton.setSize(width, height);
} }
void GuiSelectBox::OnValueClicked(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiSelectBox::OnValueClicked(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
for(uint32_t i = 0; i < valueButtons.size(); ++i) { for (uint32_t i = 0; i < valueButtons.size(); ++i) {
if(valueButtons[i].valueButton == button) { if (valueButtons[i].valueButton == button) {
selected = i; selected = i;
SelectValue(i); SelectValue(i);
break; break;
@ -84,16 +77,16 @@ void GuiSelectBox::OnValueClicked(GuiButton *button, const GuiController *contro
} }
void GuiSelectBox::SelectValue(uint32_t value) { void GuiSelectBox::SelectValue(uint32_t value) {
if(value < valueButtons.size()) { if (value < valueButtons.size()) {
const wchar_t* w_text = valueButtons[value].valueButtonText->getText(); const wchar_t *w_text = valueButtons[value].valueButtonText->getText();
std::wstring ws(w_text); std::wstring ws(w_text);
std::string text(ws.begin(), ws.end()); std::string text(ws.begin(), ws.end());
topValueText.setText(text.c_str()); topValueText.setText(text.c_str());
std::string real_value = buttonToValue[valueButtons[value].valueButton]; std::string real_value = buttonToValue[valueButtons[value].valueButton];
if(real_value.compare(std::string()) == 0) real_value = "<error>"; if (real_value.compare(std::string()) == 0) real_value = "<error>";
valueChanged(this,real_value); valueChanged(this, real_value);
ShowHideValues(false); ShowHideValues(false);
} }
} }
@ -108,31 +101,31 @@ void GuiSelectBox::ShowHideValues(bool showhide) {
} }
void GuiSelectBox::OnDPADClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiSelectBox::OnDPADClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(opened == true) { if (opened == true) {
if(trigger == &buttonATrigger) { if (trigger == &buttonATrigger) {
//! do not auto launch when wiimote is pointing to screen and presses A //! do not auto launch when wiimote is pointing to screen and presses A
if((controller->chan & (GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5)) && controller->data.validPointer) { if ((controller->chan & (GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5)) && controller->data.validPointer) {
return; return;
} }
SelectValue(selected); SelectValue(selected);
} else if(trigger == &buttonBTrigger) { } else if (trigger == &buttonBTrigger) {
if(button == &DPADButtons) { if (button == &DPADButtons) {
ShowHideValues(false); ShowHideValues(false);
} else { } else {
} }
} else if(trigger == &buttonUpTrigger) { } else if (trigger == &buttonUpTrigger) {
if(selected > 0 ) selected--; if (selected > 0) selected--;
bSelectedChanged = true; bSelectedChanged = true;
} else if(trigger == &buttonDownTrigger) { } else if (trigger == &buttonDownTrigger) {
selected++; selected++;
if(selected >= valueButtons.size()) selected = valueButtons.size() - 1; if (selected >= valueButtons.size()) selected = valueButtons.size() - 1;
bSelectedChanged = true; bSelectedChanged = true;
} }
} }
} }
void GuiSelectBox::Init(std::map<std::string,std::string> values, int32_t valueID) { void GuiSelectBox::Init(std::map<std::string, std::string> values, int32_t valueID) {
if((uint32_t)valueID >= values.size()) { if ((uint32_t) valueID >= values.size()) {
valueID = 0; valueID = 0;
} }
@ -141,7 +134,7 @@ void GuiSelectBox::Init(std::map<std::string,std::string> values, int32_t valueI
DeleteValueData(); DeleteValueData();
if(valueImageData == NULL || valueSelectedImageData == NULL || valueHighlightedImageData == NULL) { if (valueImageData == NULL || valueSelectedImageData == NULL || valueHighlightedImageData == NULL) {
return; return;
} }
@ -150,8 +143,8 @@ void GuiSelectBox::Init(std::map<std::string,std::string> values, int32_t valueI
int32_t i = 0; int32_t i = 0;
float imgScale = 1.0f; float imgScale = 1.0f;
std::map<std::string, std::string>::iterator itr; std::map<std::string, std::string>::iterator itr;
for(itr = values.begin(); itr != values.end(); itr++) { for (itr = values.begin(); itr != values.end(); itr++) {
if(i == valueID) { if (i == valueID) {
topValueText.setText(itr->first.c_str()); topValueText.setText(itr->first.c_str());
} }
@ -160,7 +153,7 @@ void GuiSelectBox::Init(std::map<std::string,std::string> values, int32_t valueI
valueButtons[i].valueButtonHighlightedImg = new GuiImage(valueHighlightedImageData); valueButtons[i].valueButtonHighlightedImg = new GuiImage(valueHighlightedImageData);
valueButtons[i].valueButton = new GuiButton(valueButtons[i].valueButtonImg->getWidth() * imgScale, valueButtons[i].valueButtonImg->getHeight() * imgScale); valueButtons[i].valueButton = new GuiButton(valueButtons[i].valueButtonImg->getWidth() * imgScale, valueButtons[i].valueButtonImg->getHeight() * imgScale);
valueButtons[i].valueButtonText = new GuiText(itr->first.c_str(),32,glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); valueButtons[i].valueButtonText = new GuiText(itr->first.c_str(), 32, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
valueButtons[i].valueButtonText->setMaxWidth(valueButtons[i].valueButtonImg->getWidth() * imgScale - 20.0f, GuiText::WRAP); valueButtons[i].valueButtonText->setMaxWidth(valueButtons[i].valueButtonImg->getWidth() * imgScale - 20.0f, GuiText::WRAP);
valueButtons[i].valueButtonText->setPosition(0, 0); valueButtons[i].valueButtonText->setPosition(0, 0);
@ -172,7 +165,7 @@ void GuiSelectBox::Init(std::map<std::string,std::string> values, int32_t valueI
valueButtons[i].valueButton->setIconOver(valueButtons[i].valueButtonHighlightedImg); valueButtons[i].valueButton->setIconOver(valueButtons[i].valueButtonHighlightedImg);
valueButtons[i].valueButton->setTrigger(&touchTrigger); valueButtons[i].valueButton->setTrigger(&touchTrigger);
valueButtons[i].valueButton->setTrigger(&wpadTouchTrigger); valueButtons[i].valueButton->setTrigger(&wpadTouchTrigger);
valueButtons[i].valueButton->clicked.connect(this,&GuiSelectBox::OnValueClicked); valueButtons[i].valueButton->clicked.connect(this, &GuiSelectBox::OnValueClicked);
valueButtons[i].valueButton->setSoundClick(buttonClickSound); valueButtons[i].valueButton->setSoundClick(buttonClickSound);
valueButtons[i].valueButton->setLabel(valueButtons[i].valueButtonText); valueButtons[i].valueButton->setLabel(valueButtons[i].valueButtonText);
@ -181,11 +174,11 @@ void GuiSelectBox::Init(std::map<std::string,std::string> values, int32_t valueI
buttonToValue[valueButtons[i].valueButton] = itr->second; buttonToValue[valueButtons[i].valueButton] = itr->second;
float topHeight = 0; float topHeight = 0;
if(topBackgroundImg != NULL) { if (topBackgroundImg != NULL) {
topHeight = topBackgroundImg->getHeight(); topHeight = topBackgroundImg->getHeight();
} }
int32_t ypos = (((valueButtons[i].valueButtonImg->getHeight()*getScale()) * (i))+ (topHeight-5)*getScale())*-1.0f; int32_t ypos = (((valueButtons[i].valueButtonImg->getHeight() * getScale()) * (i)) + (topHeight - 5) * getScale()) * -1.0f;
valueButtons[i].valueButton->setPosition(0, ypos); valueButtons[i].valueButton->setPosition(0, ypos);
valuesFrame.append(valueButtons[i].valueButton); valuesFrame.append(valueButtons[i].valueButton);
@ -198,7 +191,7 @@ void GuiSelectBox::Init(std::map<std::string,std::string> values, int32_t valueI
} }
void GuiSelectBox::DeleteValueData() { void GuiSelectBox::DeleteValueData() {
for(uint32_t i = 0; i < valueButtons.size(); ++i) { for (uint32_t i = 0; i < valueButtons.size(); ++i) {
valuesFrame.remove(valueButtons[i].valueButton); valuesFrame.remove(valueButtons[i].valueButton);
delete valueButtons[i].valueButtonImg; delete valueButtons[i].valueButtonImg;
delete valueButtons[i].valueButtonCheckedImg; delete valueButtons[i].valueButtonCheckedImg;
@ -230,14 +223,14 @@ void GuiSelectBox::OnValueCloseEffectFinish(GuiElement *element) {
} }
float GuiSelectBox::getTopValueHeight() { float GuiSelectBox::getTopValueHeight() {
if(topBackgroundImg == NULL) { if (topBackgroundImg == NULL) {
return 0.0f; return 0.0f;
} }
return topBackgroundImg->getHeight(); return topBackgroundImg->getHeight();
} }
float GuiSelectBox::getTopValueWidth() { float GuiSelectBox::getTopValueWidth() {
if(topBackgroundImg == NULL) { if (topBackgroundImg == NULL) {
return 0.0f; return 0.0f;
} }
return topBackgroundImg->getWidth(); return topBackgroundImg->getWidth();
@ -257,12 +250,12 @@ void GuiSelectBox::OnValueOpenEffectFinish(GuiElement *element) {
opened = true; opened = true;
} }
void GuiSelectBox::update(GuiController * c) { void GuiSelectBox::update(GuiController *c) {
if(bChanged) { if (bChanged) {
showhide(this,showValues); showhide(this, showValues);
if(showValues) { if (showValues) {
for(uint32_t i = 0; i < valueButtons.size(); ++i) { //TODO: only set when it really changed for (uint32_t i = 0; i < valueButtons.size(); ++i) { //TODO: only set when it really changed
if(i == selected) { if (i == selected) {
valueButtons[i].valueButton->setImage(valueButtons[i].valueButtonCheckedImg); valueButtons[i].valueButton->setImage(valueButtons[i].valueButtonCheckedImg);
} else { } else {
valueButtons[i].valueButton->setImage(valueButtons[i].valueButtonImg); valueButtons[i].valueButton->setImage(valueButtons[i].valueButtonImg);
@ -282,9 +275,9 @@ void GuiSelectBox::update(GuiController * c) {
bChanged = false; bChanged = false;
} }
if(bSelectedChanged) { if (bSelectedChanged) {
for(uint32_t i = 0; i < valueButtons.size(); ++i) { for (uint32_t i = 0; i < valueButtons.size(); ++i) {
if(i == selected) { if (i == selected) {
valueButtons[i].valueButton->setState(STATE_SELECTED); valueButtons[i].valueButton->setState(STATE_SELECTED);
} else { } else {
valueButtons[i].valueButton->clearState(STATE_SELECTED); valueButtons[i].valueButton->clearState(STATE_SELECTED);

View File

@ -20,36 +20,36 @@
#include <gui/GuiSound.h> #include <gui/GuiSound.h>
#include <gui/sounds/SoundHandler.hpp> #include <gui/sounds/SoundHandler.hpp>
GuiSound::GuiSound(const char * filepath) { GuiSound::GuiSound(const char *filepath) {
voice = -1; voice = -1;
Load(filepath); Load(filepath);
} }
GuiSound::GuiSound(const uint8_t * snd, int32_t length) { GuiSound::GuiSound(const uint8_t *snd, int32_t length) {
voice = -1; voice = -1;
Load(snd, length); Load(snd, length);
} }
GuiSound::~GuiSound() { GuiSound::~GuiSound() {
if(voice >= 0) { if (voice >= 0) {
SoundHandler::instance()->RemoveDecoder(voice); SoundHandler::instance()->RemoveDecoder(voice);
} }
} }
bool GuiSound::Load(const char * filepath) { bool GuiSound::Load(const char *filepath) {
if(voice >= 0) { if (voice >= 0) {
SoundHandler::instance()->RemoveDecoder(voice); SoundHandler::instance()->RemoveDecoder(voice);
voice = -1; voice = -1;
} }
//! find next free decoder //! find next free decoder
for(int32_t i = 0; i < MAX_DECODERS; i++) { for (int32_t i = 0; i < MAX_DECODERS; i++) {
SoundDecoder * decoder = SoundHandler::instance()->getDecoder(i); SoundDecoder *decoder = SoundHandler::instance()->getDecoder(i);
if(decoder == NULL) { if (decoder == NULL) {
SoundHandler::instance()->AddDecoder(i, filepath); SoundHandler::instance()->AddDecoder(i, filepath);
decoder = SoundHandler::instance()->getDecoder(i); decoder = SoundHandler::instance()->getDecoder(i);
if(decoder) { if (decoder) {
voice = i; voice = i;
SoundHandler::instance()->ThreadSignal(); SoundHandler::instance()->ThreadSignal();
} }
@ -57,29 +57,29 @@ bool GuiSound::Load(const char * filepath) {
} }
} }
if(voice < 0) { if (voice < 0) {
return false; return false;
} }
return true; return true;
} }
bool GuiSound::Load(const uint8_t * snd, int32_t len) { bool GuiSound::Load(const uint8_t *snd, int32_t len) {
if(voice >= 0) { if (voice >= 0) {
SoundHandler::instance()->RemoveDecoder(voice); SoundHandler::instance()->RemoveDecoder(voice);
voice = -1; voice = -1;
} }
if(!snd) if (!snd)
return false; return false;
//! find next free decoder //! find next free decoder
for(int32_t i = 0; i < MAX_DECODERS; i++) { for (int32_t i = 0; i < MAX_DECODERS; i++) {
SoundDecoder * decoder = SoundHandler::instance()->getDecoder(i); SoundDecoder *decoder = SoundHandler::instance()->getDecoder(i);
if(decoder == NULL) { if (decoder == NULL) {
SoundHandler::instance()->AddDecoder(i, snd, len); SoundHandler::instance()->AddDecoder(i, snd, len);
decoder = SoundHandler::instance()->getDecoder(i); decoder = SoundHandler::instance()->getDecoder(i);
if(decoder) { if (decoder) {
voice = i; voice = i;
SoundHandler::instance()->ThreadSignal(); SoundHandler::instance()->ThreadSignal();
} }
@ -87,7 +87,7 @@ bool GuiSound::Load(const uint8_t * snd, int32_t len) {
} }
} }
if(voice < 0) { if (voice < 0) {
return false; return false;
} }
@ -97,25 +97,25 @@ bool GuiSound::Load(const uint8_t * snd, int32_t len) {
void GuiSound::Play() { void GuiSound::Play() {
Stop(); Stop();
Voice * v = SoundHandler::instance()->getVoice(voice); Voice *v = SoundHandler::instance()->getVoice(voice);
if(v) if (v)
v->setState(Voice::STATE_START); v->setState(Voice::STATE_START);
} }
void GuiSound::Stop() { void GuiSound::Stop() {
Voice * v = SoundHandler::instance()->getVoice(voice); Voice *v = SoundHandler::instance()->getVoice(voice);
if(v) { if (v) {
if((v->getState() != Voice::STATE_STOP) && (v->getState() != Voice::STATE_STOPPED)) if ((v->getState() != Voice::STATE_STOP) && (v->getState() != Voice::STATE_STOPPED))
v->setState(Voice::STATE_STOP); v->setState(Voice::STATE_STOP);
while(v->getState() != Voice::STATE_STOPPED) while (v->getState() != Voice::STATE_STOPPED)
OSSleepTicks(OSMicrosecondsToTicks(1000)); OSSleepTicks(OSMicrosecondsToTicks(1000));
} }
SoundDecoder * decoder = SoundHandler::instance()->getDecoder(voice); SoundDecoder *decoder = SoundHandler::instance()->getDecoder(voice);
if(decoder) { if (decoder) {
decoder->Lock(); decoder->Lock();
decoder->Rewind(); decoder->Rewind();
decoder->ClearBuffer(); decoder->ClearBuffer();
@ -125,45 +125,45 @@ void GuiSound::Stop() {
} }
void GuiSound::Pause() { void GuiSound::Pause() {
if(!IsPlaying()) if (!IsPlaying())
return; return;
Voice * v = SoundHandler::instance()->getVoice(voice); Voice *v = SoundHandler::instance()->getVoice(voice);
if(v) if (v)
v->setState(Voice::STATE_STOP); v->setState(Voice::STATE_STOP);
} }
void GuiSound::Resume() { void GuiSound::Resume() {
if(IsPlaying()) if (IsPlaying())
return; return;
Voice * v = SoundHandler::instance()->getVoice(voice); Voice *v = SoundHandler::instance()->getVoice(voice);
if(v) if (v)
v->setState(Voice::STATE_START); v->setState(Voice::STATE_START);
} }
bool GuiSound::IsPlaying() { bool GuiSound::IsPlaying() {
Voice * v = SoundHandler::instance()->getVoice(voice); Voice *v = SoundHandler::instance()->getVoice(voice);
if(v) { if (v) {
return v->getState() == Voice::STATE_PLAYING; return v->getState() == Voice::STATE_PLAYING;
} }
return false; return false;
} }
void GuiSound::SetVolume(uint32_t vol) { void GuiSound::SetVolume(uint32_t vol) {
if(vol > 100) if (vol > 100)
vol = 100; vol = 100;
uint32_t volumeConv = ( (0x8000 * vol) / 100 ) << 16; uint32_t volumeConv = ((0x8000 * vol) / 100) << 16;
Voice * v = SoundHandler::instance()->getVoice(voice); Voice *v = SoundHandler::instance()->getVoice(voice);
if(v) if (v)
v->setVolume(volumeConv); v->setVolume(volumeConv);
} }
void GuiSound::SetLoop(bool l) { void GuiSound::SetLoop(bool l) {
SoundDecoder * decoder = SoundHandler::instance()->getDecoder(voice); SoundDecoder *decoder = SoundHandler::instance()->getDecoder(voice);
if(decoder) if (decoder)
decoder->SetLoop(l); decoder->SetLoop(l);
} }

View File

@ -17,14 +17,16 @@
#include <gui/GuiSwitch.h> #include <gui/GuiSwitch.h>
#include <gui/GuiImage.h> #include <gui/GuiImage.h>
#include <gui/GuiImageData.h> #include <gui/GuiImageData.h>
/** /**
* Constructor for the GuiSwitch class. * Constructor for the GuiSwitch class.
*/ */
GuiSwitch::GuiSwitch(GuiImage * background,bool checked,float w, float h) GuiSwitch::GuiSwitch(GuiImage *background, bool checked, float w, float h)
: GuiToggle(checked,w,h) { : GuiToggle(checked, w, h) {
setImageBackground(background); setImageBackground(background);
} }
/** /**
* Destructor for the GuiSwitch class. * Destructor for the GuiSwitch class.
*/ */
@ -32,43 +34,43 @@ GuiSwitch::~GuiSwitch() {
} }
void GuiSwitch::setImageBackground(GuiImage* img) { void GuiSwitch::setImageBackground(GuiImage *img) {
backgroundImg = img; backgroundImg = img;
if(img) { if (img) {
img->setParent(this); img->setParent(this);
} }
setImage(img); setImage(img);
} }
void GuiSwitch::setImageOn(GuiImage* img) { void GuiSwitch::setImageOn(GuiImage *img) {
onImg = img; onImg = img;
if(img) { if (img) {
img->setParent(this); img->setParent(this);
img->setAlignment(ALIGN_RIGHT); img->setAlignment(ALIGN_RIGHT);
} }
} }
void GuiSwitch::setImageOff(GuiImage* img) { void GuiSwitch::setImageOff(GuiImage *img) {
offImg = img; offImg = img;
if(img) { if (img) {
img->setParent(this); img->setParent(this);
img->setAlignment(ALIGN_LEFT); img->setAlignment(ALIGN_LEFT);
} }
} }
void GuiSwitch::setImageHighlighted(GuiImage* img) { void GuiSwitch::setImageHighlighted(GuiImage *img) {
highlightedImg = img; highlightedImg = img;
setIconOver(img); setIconOver(img);
} }
void GuiSwitch::draw(CVideo *v) { void GuiSwitch::draw(CVideo *v) {
GuiToggle::draw(v); GuiToggle::draw(v);
if(getValue()) { if (getValue()) {
if(onImg != NULL) { if (onImg != NULL) {
onImg->draw(v); onImg->draw(v);
} }
} else { } else {
if(offImg != NULL) { if (offImg != NULL) {
offImg->draw(v); offImg->draw(v);
} }
} }

View File

@ -18,18 +18,18 @@
#include <gui/FreeTypeGX.h> #include <gui/FreeTypeGX.h>
#include <gui/video/CVideo.h> #include <gui/video/CVideo.h>
FreeTypeGX * GuiText::presentFont = NULL; FreeTypeGX *GuiText::presentFont = NULL;
int32_t GuiText::presetSize = 28; int32_t GuiText::presetSize = 28;
float GuiText::presetInternalRenderingScale = 2.0f; //Lets render the font at the doubled size. This make it even smoother! float GuiText::presetInternalRenderingScale = 2.0f; //Lets render the font at the doubled size. This make it even smoother!
int32_t GuiText::presetMaxWidth = 0xFFFF; int32_t GuiText::presetMaxWidth = 0xFFFF;
int32_t GuiText::presetAlignment = ALIGN_CENTER | ALIGN_MIDDLE; int32_t GuiText::presetAlignment = ALIGN_CENTER | ALIGN_MIDDLE;
GX2ColorF32 GuiText::presetColor = (GX2ColorF32) { GX2ColorF32 GuiText::presetColor = (GX2ColorF32) {
1.0f, 1.0f, 1.0f, 1.0f 1.0f, 1.0f, 1.0f, 1.0f
}; };
#define TEXT_SCROLL_DELAY 6 #define TEXT_SCROLL_DELAY 6
#define TEXT_SCROLL_INITIAL_DELAY 10 #define TEXT_SCROLL_INITIAL_DELAY 10
#define MAX_LINES_TO_DRAW 10 #define MAX_LINES_TO_DRAW 10
/** /**
* Constructor for the GuiText class. * Constructor for the GuiText class.
@ -57,7 +57,7 @@ GuiText::GuiText() {
internalRenderingScale = presetInternalRenderingScale; internalRenderingScale = presetInternalRenderingScale;
} }
GuiText::GuiText(const char * t, int32_t s, const glm::vec4 & c) { GuiText::GuiText(const char *t, int32_t s, const glm::vec4 &c) {
text = NULL; text = NULL;
size = s; size = s;
currentSize = size; currentSize = size;
@ -78,16 +78,16 @@ GuiText::GuiText(const char * t, int32_t s, const glm::vec4 & c) {
blurGlowColor = glm::vec4(0.0f); blurGlowColor = glm::vec4(0.0f);
internalRenderingScale = presetInternalRenderingScale; internalRenderingScale = presetInternalRenderingScale;
if(t) { if (t) {
text = FreeTypeGX::charToWideChar(t); text = FreeTypeGX::charToWideChar(t);
if(!text) if (!text)
return; return;
textWidth = font->getWidth(text, currentSize); textWidth = font->getWidth(text, currentSize);
} }
} }
GuiText::GuiText(const wchar_t * t, int32_t s, const glm::vec4 & c) { GuiText::GuiText(const wchar_t *t, int32_t s, const glm::vec4 &c) {
text = NULL; text = NULL;
size = s; size = s;
currentSize = size; currentSize = size;
@ -108,9 +108,9 @@ GuiText::GuiText(const wchar_t * t, int32_t s, const glm::vec4 & c) {
blurGlowColor = glm::vec4(0.0f); blurGlowColor = glm::vec4(0.0f);
internalRenderingScale = presetInternalRenderingScale; internalRenderingScale = presetInternalRenderingScale;
if(t) { if (t) {
text = new (std::nothrow) wchar_t[wcslen(t)+1]; text = new(std::nothrow) wchar_t[wcslen(t) + 1];
if(!text) if (!text)
return; return;
wcscpy(text, t); wcscpy(text, t);
@ -122,7 +122,7 @@ GuiText::GuiText(const wchar_t * t, int32_t s, const glm::vec4 & c) {
/** /**
* Constructor for the GuiText class, uses presets * Constructor for the GuiText class, uses presets
*/ */
GuiText::GuiText(const char * t) { GuiText::GuiText(const char *t) {
text = NULL; text = NULL;
size = presetSize; size = presetSize;
currentSize = size; currentSize = size;
@ -143,9 +143,9 @@ GuiText::GuiText(const char * t) {
blurGlowColor = glm::vec4(0.0f); blurGlowColor = glm::vec4(0.0f);
internalRenderingScale = presetInternalRenderingScale; internalRenderingScale = presetInternalRenderingScale;
if(t) { if (t) {
text = FreeTypeGX::charToWideChar(t); text = FreeTypeGX::charToWideChar(t);
if(!text) if (!text)
return; return;
textWidth = font->getWidth(text, currentSize); textWidth = font->getWidth(text, currentSize);
@ -157,16 +157,16 @@ GuiText::GuiText(const char * t) {
* Destructor for the GuiText class. * Destructor for the GuiText class.
*/ */
GuiText::~GuiText() { GuiText::~GuiText() {
if(text) if (text)
delete [] text; delete[] text;
text = NULL; text = NULL;
clearDynamicText(); clearDynamicText();
} }
void GuiText::setText(const char * t) { void GuiText::setText(const char *t) {
if(text) if (text)
delete [] text; delete[] text;
text = NULL; text = NULL;
clearDynamicText(); clearDynamicText();
@ -174,9 +174,9 @@ void GuiText::setText(const char * t) {
textScrollPos = 0; textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
if(t) { if (t) {
text = FreeTypeGX::charToWideChar(t); text = FreeTypeGX::charToWideChar(t);
if(!text) if (!text)
return; return;
textWidth = font->getWidth(text, currentSize); textWidth = font->getWidth(text, currentSize);
@ -184,7 +184,7 @@ void GuiText::setText(const char * t) {
} }
void GuiText::setTextf(const char *format, ...) { void GuiText::setTextf(const char *format, ...) {
if(!format) { if (!format) {
setText((char *) NULL); setText((char *) NULL);
return; return;
} }
@ -193,19 +193,19 @@ void GuiText::setTextf(const char *format, ...) {
char *tmp = new char[max_len]; char *tmp = new char[max_len];
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vsnprintf(tmp, max_len, format, va) >= 0) && tmp) { if ((vsnprintf(tmp, max_len, format, va) >= 0) && tmp) {
setText(tmp); setText(tmp);
} }
va_end(va); va_end(va);
if(tmp) if (tmp)
delete [] tmp; delete[] tmp;
} }
void GuiText::setText(const wchar_t * t) { void GuiText::setText(const wchar_t *t) {
if(text) if (text)
delete [] text; delete[] text;
text = NULL; text = NULL;
clearDynamicText(); clearDynamicText();
@ -213,9 +213,9 @@ void GuiText::setText(const wchar_t * t) {
textScrollPos = 0; textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
if(t) { if (t) {
text = new (std::nothrow) wchar_t[wcslen(t)+1]; text = new(std::nothrow) wchar_t[wcslen(t) + 1];
if(!text) if (!text)
return; return;
wcscpy(text, t); wcscpy(text, t);
@ -225,18 +225,18 @@ void GuiText::setText(const wchar_t * t) {
} }
void GuiText::clearDynamicText() { void GuiText::clearDynamicText() {
for(uint32_t i = 0; i < textDyn.size(); i++) { for (uint32_t i = 0; i < textDyn.size(); i++) {
if(textDyn[i]) if (textDyn[i])
delete [] textDyn[i]; delete[] textDyn[i];
} }
textDyn.clear(); textDyn.clear();
textDynWidth.clear(); textDynWidth.clear();
} }
void GuiText::setPresets(int32_t sz, const glm::vec4 & c, int32_t w, int32_t a) { void GuiText::setPresets(int32_t sz, const glm::vec4 &c, int32_t w, int32_t a) {
presetSize = sz; presetSize = sz;
presetColor = (GX2ColorF32) { presetColor = (GX2ColorF32) {
(float)c.r / 255.0f, (float)c.g / 255.0f, (float)c.b / 255.0f, (float)c.a / 255.0f (float) c.r / 255.0f, (float) c.g / 255.0f, (float) c.b / 255.0f, (float) c.a / 255.0f
}; };
presetMaxWidth = w; presetMaxWidth = w;
presetAlignment = a; presetAlignment = a;
@ -254,7 +254,7 @@ void GuiText::setMaxWidth(int32_t width, int32_t w) {
maxWidth = width; maxWidth = width;
wrapMode = w; wrapMode = w;
if(w == SCROLL_HORIZONTAL) { if (w == SCROLL_HORIZONTAL) {
textScrollPos = 0; textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
textScrollDelay = TEXT_SCROLL_DELAY; textScrollDelay = TEXT_SCROLL_DELAY;
@ -263,26 +263,26 @@ void GuiText::setMaxWidth(int32_t width, int32_t w) {
clearDynamicText(); clearDynamicText();
} }
void GuiText::setColor(const glm::vec4 & c) { void GuiText::setColor(const glm::vec4 &c) {
color = c; color = c;
alpha = c[3]; alpha = c[3];
} }
void GuiText::setBlurGlowColor(float blur, const glm::vec4 & c) { void GuiText::setBlurGlowColor(float blur, const glm::vec4 &c) {
blurGlowColor = c; blurGlowColor = c;
blurGlowIntensity = blur; blurGlowIntensity = blur;
blurAlpha = c[3]; blurAlpha = c[3];
} }
int32_t GuiText::getTextWidth(int32_t ind) { int32_t GuiText::getTextWidth(int32_t ind) {
if(ind < 0 || ind >= (int32_t) textDyn.size()) if (ind < 0 || ind >= (int32_t) textDyn.size())
return this->getTextWidth(); return this->getTextWidth();
return font->getWidth(textDyn[ind], currentSize); return font->getWidth(textDyn[ind], currentSize);
} }
const wchar_t * GuiText::getDynText(int32_t ind) { const wchar_t *GuiText::getDynText(int32_t ind) {
if(ind < 0 || ind >= (int32_t) textDyn.size()) if (ind < 0 || ind >= (int32_t) textDyn.size())
return text; return text;
return textDyn[ind]; return textDyn[ind];
@ -292,7 +292,7 @@ const wchar_t * GuiText::getDynText(int32_t ind) {
* Change font * Change font
*/ */
bool GuiText::setFont(FreeTypeGX *f) { bool GuiText::setFont(FreeTypeGX *f) {
if(!f) if (!f)
return false; return false;
font = f; font = f;
@ -301,16 +301,16 @@ bool GuiText::setFont(FreeTypeGX *f) {
} }
std::string GuiText::toUTF8(void) const { std::string GuiText::toUTF8(void) const {
if(!text) if (!text)
return std::string(); return std::string();
char *pUtf8 = FreeTypeGX::wideCharToUTF8(text); char *pUtf8 = FreeTypeGX::wideCharToUTF8(text);
if(!pUtf8) if (!pUtf8)
return std::string(); return std::string();
std::string strOutput(pUtf8); std::string strOutput(pUtf8);
delete [] pUtf8; delete[] pUtf8;
return strOutput; return strOutput;
} }
@ -320,8 +320,8 @@ void GuiText::makeDottedText() {
textDyn.resize(pos + 1); textDyn.resize(pos + 1);
int32_t i = 0, currentWidth = 0; int32_t i = 0, currentWidth = 0;
textDyn[pos] = new (std::nothrow) wchar_t[maxWidth]; textDyn[pos] = new(std::nothrow) wchar_t[maxWidth];
if(!textDyn[pos]) { if (!textDyn[pos]) {
textDyn.resize(pos); textDyn.resize(pos);
return; return;
} }
@ -349,8 +349,8 @@ void GuiText::scrollText(uint32_t frameCount) {
int32_t i = 0, currentWidth = 0; int32_t i = 0, currentWidth = 0;
textDyn.resize(pos + 1); textDyn.resize(pos + 1);
textDyn[pos] = new (std::nothrow) wchar_t[maxWidth]; textDyn[pos] = new(std::nothrow) wchar_t[maxWidth];
if(!textDyn[pos]) { if (!textDyn[pos]) {
textDyn.resize(pos); textDyn.resize(pos);
return; return;
} }
@ -388,9 +388,9 @@ void GuiText::scrollText(uint32_t frameCount) {
int32_t pos = textDyn.size() - 1; int32_t pos = textDyn.size() - 1;
if (!textDyn[pos]) if (!textDyn[pos])
textDyn[pos] = new (std::nothrow) wchar_t[maxWidth]; textDyn[pos] = new(std::nothrow) wchar_t[maxWidth];
if(!textDyn[pos]) { if (!textDyn[pos]) {
textDyn.resize(pos); textDyn.resize(pos);
return; return;
} }
@ -407,7 +407,7 @@ void GuiText::scrollText(uint32_t frameCount) {
currentWidth += font->getCharWidth(L' ', currentSize, L' '); currentWidth += font->getCharWidth(L' ', currentSize, L' ');
ch = 0; ch = 0;
if(currentWidth >= maxWidth) if (currentWidth >= maxWidth)
break; break;
} }
@ -432,8 +432,8 @@ void GuiText::wrapText() {
while (text[ch] && linenum < linestodraw) { while (text[ch] && linenum < linestodraw) {
if (linenum >= (int32_t) textDyn.size()) { if (linenum >= (int32_t) textDyn.size()) {
textDyn.resize(linenum + 1); textDyn.resize(linenum + 1);
textDyn[linenum] = new (std::nothrow) wchar_t[maxWidth]; textDyn[linenum] = new(std::nothrow) wchar_t[maxWidth];
if(!textDyn[linenum]) { if (!textDyn[linenum]) {
textDyn.resize(linenum); textDyn.resize(linenum);
break; break;
} }
@ -445,7 +445,7 @@ void GuiText::wrapText() {
currentWidth += font->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0x0000); currentWidth += font->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0x0000);
if (currentWidth >= maxWidth || (text[ch] == '\n')) { if (currentWidth >= maxWidth || (text[ch] == '\n')) {
if(text[ch] == '\n') { if (text[ch] == '\n') {
lastSpace = -1; lastSpace = -1;
lastSpaceIndex = -1; lastSpaceIndex = -1;
} else if (lastSpace >= 0) { } else if (lastSpace >= 0) {
@ -456,7 +456,7 @@ void GuiText::wrapText() {
} }
if (linenum + 1 == linestodraw && text[ch + 1] != 0x0000) { if (linenum + 1 == linestodraw && text[ch + 1] != 0x0000) {
if(i < 2) if (i < 2)
i = 2; i = 2;
textDyn[linenum][i - 2] = '.'; textDyn[linenum][i - 2] = '.';
@ -482,10 +482,10 @@ void GuiText::wrapText() {
* Draw the text on screen * Draw the text on screen
*/ */
void GuiText::draw(CVideo *pVideo) { void GuiText::draw(CVideo *pVideo) {
if(!text) if (!text)
return; return;
if(!isVisible()) if (!isVisible())
return; return;
color[3] = getAlpha(); color[3] = getAlpha();
@ -496,64 +496,62 @@ void GuiText::draw(CVideo *pVideo) {
int32_t newSize = size * getScale() * finalRenderingScale; int32_t newSize = size * getScale() * finalRenderingScale;
int32_t normal_size = size * getScale(); int32_t normal_size = size * getScale();
if(newSize != currentSize) { if (newSize != currentSize) {
currentSize = normal_size; currentSize = normal_size;
if(text) if (text)
textWidth = font->getWidth(text, normal_size); textWidth = font->getWidth(text, normal_size);
} }
float x_pos = getCenterX() * finalRenderingScale; float x_pos = getCenterX() * finalRenderingScale;
float y_pos = getCenterY() * finalRenderingScale; float y_pos = getCenterY() * finalRenderingScale;
if(maxWidth > 0 && maxWidth <= textWidth) { if (maxWidth > 0 && maxWidth <= textWidth) {
if(wrapMode == DOTTED) { // text dotted if (wrapMode == DOTTED) { // text dotted
if(textDyn.size() == 0) if (textDyn.size() == 0)
makeDottedText(); makeDottedText();
if(textDynWidth.size() != textDyn.size()) { if (textDynWidth.size() != textDyn.size()) {
textDynWidth.resize(textDyn.size()); textDynWidth.resize(textDyn.size());
for(uint32_t i = 0; i < textDynWidth.size(); i++) for (uint32_t i = 0; i < textDynWidth.size(); i++)
textDynWidth[i] = font->getWidth(textDyn[i], newSize); textDynWidth[i] = font->getWidth(textDyn[i], newSize);
} }
if(textDyn.size() > 0) if (textDyn.size() > 0)
font->drawText(pVideo, x_pos, y_pos, getDepth(), textDyn[textDyn.size()-1], newSize, color, alignment, textDynWidth[textDyn.size()-1], defaultBlur, blurGlowIntensity, blurGlowColor,finalRenderingScale); font->drawText(pVideo, x_pos, y_pos, getDepth(), textDyn[textDyn.size() - 1], newSize, color, alignment, textDynWidth[textDyn.size() - 1], defaultBlur, blurGlowIntensity, blurGlowColor, finalRenderingScale);
} } else if (wrapMode == SCROLL_HORIZONTAL) {
else if(wrapMode == SCROLL_HORIZONTAL) {
scrollText(pVideo->getFrameCount()); scrollText(pVideo->getFrameCount());
if(textDyn.size() > 0) if (textDyn.size() > 0)
font->drawText(pVideo, x_pos, y_pos, getDepth(), textDyn[textDyn.size()-1], newSize, color, alignment, maxWidth*finalRenderingScale, defaultBlur, blurGlowIntensity, blurGlowColor,finalRenderingScale); font->drawText(pVideo, x_pos, y_pos, getDepth(), textDyn[textDyn.size() - 1], newSize, color, alignment, maxWidth * finalRenderingScale, defaultBlur, blurGlowIntensity, blurGlowColor, finalRenderingScale);
} else if(wrapMode == WRAP) { } else if (wrapMode == WRAP) {
int32_t lineheight = newSize + 6; int32_t lineheight = newSize + 6;
int32_t yoffset = 0; int32_t yoffset = 0;
int32_t voffset = 0; int32_t voffset = 0;
if(textDyn.size() == 0) if (textDyn.size() == 0)
wrapText(); wrapText();
if(textDynWidth.size() != textDyn.size()) { if (textDynWidth.size() != textDyn.size()) {
textDynWidth.resize(textDyn.size()); textDynWidth.resize(textDyn.size());
for(uint32_t i = 0; i < textDynWidth.size(); i++) for (uint32_t i = 0; i < textDynWidth.size(); i++)
textDynWidth[i] = font->getWidth(textDyn[i], newSize); textDynWidth[i] = font->getWidth(textDyn[i], newSize);
} }
if(alignment & ALIGN_MIDDLE) if (alignment & ALIGN_MIDDLE)
voffset = (lineheight * (textDyn.size()-1)) >> 1; voffset = (lineheight * (textDyn.size() - 1)) >> 1;
for(uint32_t i = 0; i < textDyn.size(); i++) { for (uint32_t i = 0; i < textDyn.size(); i++) {
font->drawText(pVideo, x_pos, y_pos + voffset + yoffset, getDepth(), textDyn[i], newSize, color, alignment, textDynWidth[i], defaultBlur, blurGlowIntensity, blurGlowColor,finalRenderingScale); font->drawText(pVideo, x_pos, y_pos + voffset + yoffset, getDepth(), textDyn[i], newSize, color, alignment, textDynWidth[i], defaultBlur, blurGlowIntensity, blurGlowColor, finalRenderingScale);
yoffset -= lineheight; yoffset -= lineheight;
} }
} }
} else { } else {
uint16_t newtextWidth = font->getWidth(text, newSize); uint16_t newtextWidth = font->getWidth(text, newSize);
font->drawText(pVideo, x_pos, y_pos, getDepth(), text, newSize, color, alignment, newtextWidth, defaultBlur, blurGlowIntensity, blurGlowColor,finalRenderingScale); font->drawText(pVideo, x_pos, y_pos, getDepth(), text, newSize, color, alignment, newtextWidth, defaultBlur, blurGlowIntensity, blurGlowColor, finalRenderingScale);
} }
} }

View File

@ -15,15 +15,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <gui/GuiToggle.h> #include <gui/GuiToggle.h>
/** /**
* Constructor for the GuiToggle class. * Constructor for the GuiToggle class.
*/ */
GuiToggle::GuiToggle(bool checked,float width,float height) GuiToggle::GuiToggle(bool checked, float width, float height)
: GuiButton(width,height) { : GuiButton(width, height) {
bChanged = false; bChanged = false;
selected = checked; selected = checked;
clicked.connect(this,&GuiToggle::OnToggleClick); clicked.connect(this, &GuiToggle::OnToggleClick);
} }
/** /**
@ -35,8 +36,8 @@ GuiToggle::~GuiToggle() {
} }
void GuiToggle::OnToggleClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiToggle::OnToggleClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(!isStateSet(STATE_DISABLED | STATE_HIDDEN | STATE_DISABLE_INPUT)) { if (!isStateSet(STATE_DISABLED | STATE_HIDDEN | STATE_DISABLE_INPUT)) {
if(selected) { if (selected) {
setUnchecked(); setUnchecked();
} else { } else {
setChecked(); setChecked();
@ -44,7 +45,7 @@ void GuiToggle::OnToggleClick(GuiButton *button, const GuiController *controller
} }
} }
void GuiToggle::update(GuiController * c) { void GuiToggle::update(GuiController *c) {
GuiButton::update(c); GuiButton::update(c);
} }

View File

@ -22,21 +22,11 @@
* Constructor for the GuiTrigger class. * Constructor for the GuiTrigger class.
*/ */
GuiTrigger::GuiTrigger() GuiTrigger::GuiTrigger()
: chan(CHANNEL_ALL) : chan(CHANNEL_ALL), btns(BUTTON_NONE), bClickEverywhere(false), bHoldEverywhere(false), bSelectionClickEverywhere(false), bLastTouched(false) {
, btns(BUTTON_NONE)
, bClickEverywhere(false)
, bHoldEverywhere(false)
, bSelectionClickEverywhere(false)
, bLastTouched(false) {
} }
GuiTrigger::GuiTrigger(uint32_t ch, uint32_t btn, bool clickEverywhere, bool holdEverywhere, bool selectionClickEverywhere) GuiTrigger::GuiTrigger(uint32_t ch, uint32_t btn, bool clickEverywhere, bool holdEverywhere, bool selectionClickEverywhere)
: chan(ch) : chan(ch), btns(btn), bClickEverywhere(clickEverywhere), bHoldEverywhere(holdEverywhere), bSelectionClickEverywhere(selectionClickEverywhere), bLastTouched(false) {
, btns(btn)
, bClickEverywhere(clickEverywhere)
, bHoldEverywhere(holdEverywhere)
, bSelectionClickEverywhere(selectionClickEverywhere)
, bLastTouched(false) {
} }
/** /**
@ -56,74 +46,74 @@ void GuiTrigger::setTrigger(uint32_t ch, uint32_t btn) {
} }
bool GuiTrigger::left(const GuiController *controller) const { bool GuiTrigger::left(const GuiController *controller) const {
if((controller->chan & chan) == 0) { if ((controller->chan & chan) == 0) {
return false; return false;
} }
if((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_LEFT | STICK_L_LEFT)) { if ((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_LEFT | STICK_L_LEFT)) {
return true; return true;
} }
return false; return false;
} }
bool GuiTrigger::right(const GuiController *controller) const { bool GuiTrigger::right(const GuiController *controller) const {
if((controller->chan & chan) == 0) { if ((controller->chan & chan) == 0) {
return false; return false;
} }
if((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_RIGHT | STICK_L_RIGHT)) { if ((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_RIGHT | STICK_L_RIGHT)) {
return true; return true;
} }
return false; return false;
} }
bool GuiTrigger::up(const GuiController *controller) const { bool GuiTrigger::up(const GuiController *controller) const {
if((controller->chan & chan) == 0) { if ((controller->chan & chan) == 0) {
return false; return false;
} }
if((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_UP | STICK_L_UP)) { if ((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_UP | STICK_L_UP)) {
return true; return true;
} }
return false; return false;
} }
bool GuiTrigger::down(const GuiController *controller) const { bool GuiTrigger::down(const GuiController *controller) const {
if((controller->chan & chan) == 0) { if ((controller->chan & chan) == 0) {
return false; return false;
} }
if((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_DOWN | STICK_L_DOWN)) { if ((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_DOWN | STICK_L_DOWN)) {
return true; return true;
} }
return false; return false;
} }
int32_t GuiTrigger::clicked(const GuiController *controller) const { int32_t GuiTrigger::clicked(const GuiController *controller) const {
if((controller->chan & chan) == 0) { if ((controller->chan & chan) == 0) {
return CLICKED_NONE; return CLICKED_NONE;
} }
int32_t bResult = CLICKED_NONE; int32_t bResult = CLICKED_NONE;
if(controller->data.touched && controller->data.validPointer && (btns & VPAD_TOUCH) && !controller->lastData.touched) { if (controller->data.touched && controller->data.validPointer && (btns & VPAD_TOUCH) && !controller->lastData.touched) {
bResult = CLICKED_TOUCH; bResult = CLICKED_TOUCH;
} }
if(controller->data.buttons_d & btns) { if (controller->data.buttons_d & btns) {
bResult = CLICKED_BUTTON; bResult = CLICKED_BUTTON;
} }
return bResult; return bResult;
} }
bool GuiTrigger::held(const GuiController *controller) const { bool GuiTrigger::held(const GuiController *controller) const {
if((controller->chan & chan) == 0) { if ((controller->chan & chan) == 0) {
return false; return false;
} }
bool bResult = false; bool bResult = false;
if(controller->data.touched && (btns & VPAD_TOUCH) && controller->data.validPointer && controller->lastData.touched && controller->lastData.validPointer) { if (controller->data.touched && (btns & VPAD_TOUCH) && controller->data.validPointer && controller->lastData.touched && controller->lastData.validPointer) {
bResult = true; bResult = true;
} }
if(controller->data.buttons_h & btns) { if (controller->data.buttons_h & btns) {
bResult = true; bResult = true;
} }
@ -131,20 +121,20 @@ bool GuiTrigger::held(const GuiController *controller) const {
} }
bool GuiTrigger::released(const GuiController *controller) const { bool GuiTrigger::released(const GuiController *controller) const {
if((controller->chan & chan) == 0) { if ((controller->chan & chan) == 0) {
return false; return false;
} }
if(clicked(controller) || held(controller)) if (clicked(controller) || held(controller))
return false; return false;
bool bResult = false; bool bResult = false;
if(!controller->data.touched && (btns & VPAD_TOUCH) && controller->lastData.touched && controller->lastData.validPointer) { if (!controller->data.touched && (btns & VPAD_TOUCH) && controller->lastData.touched && controller->lastData.validPointer) {
bResult = true; bResult = true;
} }
if(controller->data.buttons_r & btns) { if (controller->data.buttons_r & btns) {
bResult = true; bResult = true;
} }

View File

@ -40,13 +40,13 @@ BufferCircle::~BufferCircle() {
} }
void BufferCircle::SetBufferBlockSize(int32_t size) { void BufferCircle::SetBufferBlockSize(int32_t size) {
if(size < 0) if (size < 0)
return; return;
BufferBlockSize = size; BufferBlockSize = size;
for(int32_t i = 0; i < Size(); i++) { for (int32_t i = 0; i < Size(); i++) {
if(SoundBuffer[i] != NULL) if (SoundBuffer[i] != NULL)
free(SoundBuffer[i]); free(SoundBuffer[i]);
SoundBuffer[i] = (uint8_t *) memalign(32, ALIGN32(BufferBlockSize)); SoundBuffer[i] = (uint8_t *) memalign(32, ALIGN32(BufferBlockSize));
@ -56,8 +56,8 @@ void BufferCircle::SetBufferBlockSize(int32_t size) {
} }
void BufferCircle::Resize(int32_t size) { void BufferCircle::Resize(int32_t size) {
while(size < Size()) while (size < Size())
RemoveBuffer(Size()-1); RemoveBuffer(Size() - 1);
int32_t oldSize = Size(); int32_t oldSize = Size();
@ -65,8 +65,8 @@ void BufferCircle::Resize(int32_t size) {
BufferSize.resize(size); BufferSize.resize(size);
BufferReady.resize(size); BufferReady.resize(size);
for(int32_t i = oldSize; i < Size(); i++) { for (int32_t i = oldSize; i < Size(); i++) {
if(BufferBlockSize > 0) if (BufferBlockSize > 0)
SoundBuffer[i] = (uint8_t *) memalign(32, ALIGN32(BufferBlockSize)); SoundBuffer[i] = (uint8_t *) memalign(32, ALIGN32(BufferBlockSize));
else else
SoundBuffer[i] = NULL; SoundBuffer[i] = NULL;
@ -76,19 +76,19 @@ void BufferCircle::Resize(int32_t size) {
} }
void BufferCircle::RemoveBuffer(int32_t pos) { void BufferCircle::RemoveBuffer(int32_t pos) {
if(!Valid(pos)) if (!Valid(pos))
return; return;
if(SoundBuffer[pos] != NULL) if (SoundBuffer[pos] != NULL)
free(SoundBuffer[pos]); free(SoundBuffer[pos]);
SoundBuffer.erase(SoundBuffer.begin()+pos); SoundBuffer.erase(SoundBuffer.begin() + pos);
BufferSize.erase(BufferSize.begin()+pos); BufferSize.erase(BufferSize.begin() + pos);
BufferReady.erase(BufferReady.begin()+pos); BufferReady.erase(BufferReady.begin() + pos);
} }
void BufferCircle::ClearBuffer() { void BufferCircle::ClearBuffer() {
for(int32_t i = 0; i < Size(); i++) { for (int32_t i = 0; i < Size(); i++) {
BufferSize[i] = 0; BufferSize[i] = 0;
BufferReady[i] = false; BufferReady[i] = false;
} }
@ -96,8 +96,8 @@ void BufferCircle::ClearBuffer() {
} }
void BufferCircle::FreeBuffer() { void BufferCircle::FreeBuffer() {
for(int32_t i = 0; i < Size(); i++) { for (int32_t i = 0; i < Size(); i++) {
if(SoundBuffer[i] != NULL) if (SoundBuffer[i] != NULL)
free(SoundBuffer[i]); free(SoundBuffer[i]);
SoundBuffer[i] = NULL; SoundBuffer[i] = NULL;
@ -114,14 +114,14 @@ void BufferCircle::LoadNext() {
} }
void BufferCircle::SetBufferReady(int32_t pos, bool state) { void BufferCircle::SetBufferReady(int32_t pos, bool state) {
if(!Valid(pos)) if (!Valid(pos))
return; return;
BufferReady[pos] = state; BufferReady[pos] = state;
} }
void BufferCircle::SetBufferSize(int32_t pos, int32_t size) { void BufferCircle::SetBufferSize(int32_t pos, int32_t size) {
if(!Valid(pos)) if (!Valid(pos))
return; return;
BufferSize[pos] = size; BufferSize[pos] = size;

View File

@ -34,186 +34,167 @@
#include <gui/sounds/Mp3Decoder.hpp> #include <gui/sounds/Mp3Decoder.hpp>
#include "fs/CFile.hpp" #include "fs/CFile.hpp"
Mp3Decoder::Mp3Decoder(const char * filepath) Mp3Decoder::Mp3Decoder(const char *filepath)
: SoundDecoder(filepath) : SoundDecoder(filepath) {
{ SoundType = SOUND_MP3;
SoundType = SOUND_MP3; ReadBuffer = NULL;
ReadBuffer = NULL; mad_timer_reset(&Timer);
mad_timer_reset(&Timer); mad_stream_init(&Stream);
mad_stream_init(&Stream); mad_frame_init(&Frame);
mad_frame_init(&Frame); mad_synth_init(&Synth);
mad_synth_init(&Synth);
if(!file_fd) if (!file_fd)
return; return;
OpenFile(); OpenFile();
} }
Mp3Decoder::Mp3Decoder(const uint8_t * snd, int32_t len) Mp3Decoder::Mp3Decoder(const uint8_t *snd, int32_t len)
: SoundDecoder(snd, len) : SoundDecoder(snd, len) {
{ SoundType = SOUND_MP3;
SoundType = SOUND_MP3; ReadBuffer = NULL;
ReadBuffer = NULL; mad_timer_reset(&Timer);
mad_timer_reset(&Timer); mad_stream_init(&Stream);
mad_stream_init(&Stream); mad_frame_init(&Frame);
mad_frame_init(&Frame); mad_synth_init(&Synth);
mad_synth_init(&Synth);
if(!file_fd) if (!file_fd)
return; return;
OpenFile(); OpenFile();
} }
Mp3Decoder::~Mp3Decoder() Mp3Decoder::~Mp3Decoder() {
{ ExitRequested = true;
ExitRequested = true; while (Decoding)
while(Decoding) OSSleepTicks(OSMicrosecondsToTicks(100));
OSSleepTicks(OSMicrosecondsToTicks(100));
mad_synth_finish(&Synth); mad_synth_finish(&Synth);
mad_frame_finish(&Frame); mad_frame_finish(&Frame);
mad_stream_finish(&Stream); mad_stream_finish(&Stream);
if(ReadBuffer) if (ReadBuffer)
free(ReadBuffer); free(ReadBuffer);
ReadBuffer = NULL; ReadBuffer = NULL;
} }
void Mp3Decoder::OpenFile() void Mp3Decoder::OpenFile() {
{ GuardPtr = NULL;
GuardPtr = NULL; ReadBuffer = (uint8_t *) memalign(32, SoundBlockSize * SoundBlocks);
ReadBuffer = (uint8_t *) memalign(32, SoundBlockSize*SoundBlocks); if (!ReadBuffer) {
if(!ReadBuffer) if (file_fd)
{ delete file_fd;
if(file_fd) file_fd = NULL;
delete file_fd; return;
file_fd = NULL; }
return;
}
uint8_t dummybuff[4096]; uint8_t dummybuff[4096];
int32_t ret = Read(dummybuff, 4096, 0); int32_t ret = Read(dummybuff, 4096, 0);
if(ret <= 0) if (ret <= 0) {
{ if (file_fd)
if(file_fd) delete file_fd;
delete file_fd; file_fd = NULL;
file_fd = NULL; return;
return; }
}
SampleRate = (uint32_t) Frame.header.samplerate; SampleRate = (uint32_t) Frame.header.samplerate;
Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? (FORMAT_PCM_16_BIT | CHANNELS_STEREO) : (FORMAT_PCM_16_BIT | CHANNELS_MONO)); Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? (FORMAT_PCM_16_BIT | CHANNELS_STEREO) : (FORMAT_PCM_16_BIT | CHANNELS_MONO));
Rewind(); Rewind();
} }
int32_t Mp3Decoder::Rewind() int32_t Mp3Decoder::Rewind() {
{ mad_synth_finish(&Synth);
mad_synth_finish(&Synth); mad_frame_finish(&Frame);
mad_frame_finish(&Frame); mad_stream_finish(&Stream);
mad_stream_finish(&Stream); mad_timer_reset(&Timer);
mad_timer_reset(&Timer); mad_stream_init(&Stream);
mad_stream_init(&Stream); mad_frame_init(&Frame);
mad_frame_init(&Frame); mad_synth_init(&Synth);
mad_synth_init(&Synth); SynthPos = 0;
SynthPos = 0; GuardPtr = NULL;
GuardPtr = NULL;
if(!file_fd) if (!file_fd)
return -1; return -1;
return SoundDecoder::Rewind(); return SoundDecoder::Rewind();
} }
static inline int16_t FixedToShort(mad_fixed_t Fixed) static inline int16_t FixedToShort(mad_fixed_t Fixed) {
{ /* Clipping */
/* Clipping */ if (Fixed >= MAD_F_ONE)
if(Fixed>=MAD_F_ONE) return (SHRT_MAX);
return(SHRT_MAX); if (Fixed <= -MAD_F_ONE)
if(Fixed<=-MAD_F_ONE) return (-SHRT_MAX);
return(-SHRT_MAX);
Fixed=Fixed>>(MAD_F_FRACBITS-15); Fixed = Fixed >> (MAD_F_FRACBITS - 15);
return((int16_t)Fixed); return ((int16_t) Fixed);
} }
int32_t Mp3Decoder::Read(uint8_t * buffer, int32_t buffer_size, int32_t pos) int32_t Mp3Decoder::Read(uint8_t *buffer, int32_t buffer_size, int32_t pos) {
{ if (!file_fd)
if(!file_fd) return -1;
return -1;
if(Format == (FORMAT_PCM_16_BIT | CHANNELS_STEREO)) if (Format == (FORMAT_PCM_16_BIT | CHANNELS_STEREO))
buffer_size &= ~0x0003; buffer_size &= ~0x0003;
else else
buffer_size &= ~0x0001; buffer_size &= ~0x0001;
uint8_t * write_pos = buffer; uint8_t *write_pos = buffer;
uint8_t * write_end = buffer+buffer_size; uint8_t *write_end = buffer + buffer_size;
while(1) while (1) {
{ while (SynthPos < Synth.pcm.length) {
while(SynthPos < Synth.pcm.length) if (write_pos >= write_end)
{ return write_pos - buffer;
if(write_pos >= write_end)
return write_pos-buffer;
*((int16_t *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]); *((int16_t *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
write_pos += 2; write_pos += 2;
if(MAD_NCHANNELS(&Frame.header) == 2) if (MAD_NCHANNELS(&Frame.header) == 2) {
{ *((int16_t *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
*((int16_t *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]); write_pos += 2;
write_pos += 2; }
} SynthPos++;
SynthPos++; }
}
if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN) if (Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN) {
{ uint8_t *ReadStart = ReadBuffer;
uint8_t * ReadStart = ReadBuffer; int32_t ReadSize = SoundBlockSize * SoundBlocks;
int32_t ReadSize = SoundBlockSize*SoundBlocks; int32_t Remaining = 0;
int32_t Remaining = 0;
if(Stream.next_frame != NULL) if (Stream.next_frame != NULL) {
{ Remaining = Stream.bufend - Stream.next_frame;
Remaining = Stream.bufend - Stream.next_frame; memmove(ReadBuffer, Stream.next_frame, Remaining);
memmove(ReadBuffer, Stream.next_frame, Remaining); ReadStart += Remaining;
ReadStart += Remaining; ReadSize -= Remaining;
ReadSize -= Remaining; }
}
ReadSize = file_fd->read(ReadStart, ReadSize); ReadSize = file_fd->read(ReadStart, ReadSize);
if(ReadSize <= 0) if (ReadSize <= 0) {
{ GuardPtr = ReadStart;
GuardPtr = ReadStart; memset(GuardPtr, 0, MAD_BUFFER_GUARD);
memset(GuardPtr, 0, MAD_BUFFER_GUARD); ReadSize = MAD_BUFFER_GUARD;
ReadSize = MAD_BUFFER_GUARD; }
}
CurPos += ReadSize; CurPos += ReadSize;
mad_stream_buffer(&Stream, ReadBuffer, Remaining+ReadSize); mad_stream_buffer(&Stream, ReadBuffer, Remaining + ReadSize);
} }
if(mad_frame_decode(&Frame,&Stream)) if (mad_frame_decode(&Frame, &Stream)) {
{ if (MAD_RECOVERABLE(Stream.error)) {
if(MAD_RECOVERABLE(Stream.error)) if (Stream.error != MAD_ERROR_LOSTSYNC || !GuardPtr)
{ continue;
if(Stream.error != MAD_ERROR_LOSTSYNC || !GuardPtr) } else {
continue; if (Stream.error != MAD_ERROR_BUFLEN)
} return -1;
else else if (Stream.error == MAD_ERROR_BUFLEN && GuardPtr)
{ return -1;
if(Stream.error != MAD_ERROR_BUFLEN) }
return -1; }
else if(Stream.error == MAD_ERROR_BUFLEN && GuardPtr)
return -1;
}
}
mad_timer_add(&Timer,Frame.header.duration); mad_timer_add(&Timer, Frame.header.duration);
mad_synth_frame(&Synth,&Frame); mad_synth_frame(&Synth, &Frame);
SynthPos = 0; SynthPos = 0;
} }
return 0; return 0;
} }

View File

@ -30,8 +30,8 @@
#include <gui/sounds/OggDecoder.hpp> #include <gui/sounds/OggDecoder.hpp>
#include "fs/CFile.hpp" #include "fs/CFile.hpp"
static int ogg_read(void * punt, int bytes, int blocks, int *f) { static int ogg_read(void *punt, int bytes, int blocks, int *f) {
return ((CFile *) f)->read((uint8_t *) punt, bytes*blocks); return ((CFile *) f)->read((uint8_t *) punt, bytes * blocks);
} }
static int ogg_seek(int *f, ogg_int64_t offset, int mode) { static int ogg_seek(int *f, ogg_int64_t offset, int mode) {
@ -48,27 +48,27 @@ static long ogg_tell(int *f) {
} }
static ov_callbacks callbacks = { static ov_callbacks callbacks = {
(size_t (*)(void *, size_t, size_t, void *)) ogg_read, (size_t (*)(void *, size_t, size_t, void *)) ogg_read,
(int (*)(void *, ogg_int64_t, int)) ogg_seek, (int (*)(void *, ogg_int64_t, int)) ogg_seek,
(int (*)(void *)) ogg_close, (int (*)(void *)) ogg_close,
(long (*)(void *)) ogg_tell (long (*)(void *)) ogg_tell
}; };
OggDecoder::OggDecoder(const char * filepath) OggDecoder::OggDecoder(const char *filepath)
: SoundDecoder(filepath) { : SoundDecoder(filepath) {
SoundType = SOUND_OGG; SoundType = SOUND_OGG;
if(!file_fd) if (!file_fd)
return; return;
OpenFile(); OpenFile();
} }
OggDecoder::OggDecoder(const uint8_t * snd, int32_t len) OggDecoder::OggDecoder(const uint8_t *snd, int32_t len)
: SoundDecoder(snd, len) { : SoundDecoder(snd, len) {
SoundType = SOUND_OGG; SoundType = SOUND_OGG;
if(!file_fd) if (!file_fd)
return; return;
OpenFile(); OpenFile();
@ -76,10 +76,10 @@ OggDecoder::OggDecoder(const uint8_t * snd, int32_t len)
OggDecoder::~OggDecoder() { OggDecoder::~OggDecoder() {
ExitRequested = true; ExitRequested = true;
while(Decoding) while (Decoding)
OSSleepTicks(OSMicrosecondsToTicks(100)); OSSleepTicks(OSMicrosecondsToTicks(100));
if(file_fd) if (file_fd)
ov_clear(&ogg_file); ov_clear(&ogg_file);
} }
@ -91,7 +91,7 @@ void OggDecoder::OpenFile() {
} }
ogg_info = ov_info(&ogg_file, -1); ogg_info = ov_info(&ogg_file, -1);
if(!ogg_info) { if (!ogg_info) {
ov_clear(&ogg_file); ov_clear(&ogg_file);
delete file_fd; delete file_fd;
file_fd = NULL; file_fd = NULL;
@ -103,7 +103,7 @@ void OggDecoder::OpenFile() {
} }
int32_t OggDecoder::Rewind() { int32_t OggDecoder::Rewind() {
if(!file_fd) if (!file_fd)
return -1; return -1;
int32_t ret = ov_time_seek(&ogg_file, 0); int32_t ret = ov_time_seek(&ogg_file, 0);
@ -113,15 +113,15 @@ int32_t OggDecoder::Rewind() {
return ret; return ret;
} }
int32_t OggDecoder::Read(uint8_t * buffer, int32_t buffer_size, int32_t pos) { int32_t OggDecoder::Read(uint8_t *buffer, int32_t buffer_size, int32_t pos) {
if(!file_fd) if (!file_fd)
return -1; return -1;
int32_t bitstream = 0; int32_t bitstream = 0;
int32_t read = (int32_t) ov_read(&ogg_file, (char *) buffer, (int) buffer_size, (int *)&bitstream); int32_t read = (int32_t) ov_read(&ogg_file, (char *) buffer, (int) buffer_size, (int *) &bitstream);
if(read > 0) if (read > 0)
CurPos += read; CurPos += read;
return read; return read;

View File

@ -32,36 +32,36 @@ SoundDecoder::SoundDecoder() {
Init(); Init();
} }
SoundDecoder::SoundDecoder(const std::string & filepath) { SoundDecoder::SoundDecoder(const std::string &filepath) {
file_fd = new CFile(filepath, CFile::ReadOnly); file_fd = new CFile(filepath, CFile::ReadOnly);
Init(); Init();
} }
SoundDecoder::SoundDecoder(const uint8_t * buffer, int32_t size) { SoundDecoder::SoundDecoder(const uint8_t *buffer, int32_t size) {
file_fd = new CFile(buffer, size); file_fd = new CFile(buffer, size);
Init(); Init();
} }
SoundDecoder::~SoundDecoder() { SoundDecoder::~SoundDecoder() {
ExitRequested = true; ExitRequested = true;
while(Decoding) while (Decoding)
OSSleepTicks(OSMicrosecondsToTicks(1000)); OSSleepTicks(OSMicrosecondsToTicks(1000));
//! lock unlock once to make sure it's really not decoding //! lock unlock once to make sure it's really not decoding
Lock(); Lock();
Unlock(); Unlock();
if(file_fd) if (file_fd)
delete file_fd; delete file_fd;
file_fd = NULL; file_fd = NULL;
if(ResampleBuffer) if (ResampleBuffer)
free(ResampleBuffer); free(ResampleBuffer);
} }
int32_t SoundDecoder::Seek(int32_t pos) { int32_t SoundDecoder::Seek(int32_t pos) {
CurPos = pos; CurPos = pos;
return file_fd->seek(CurPos, SEEK_SET); return file_fd->seek(CurPos, SEEK_SET);
} }
void SoundDecoder::Init() { void SoundDecoder::Init() {
@ -89,7 +89,7 @@ int32_t SoundDecoder::Rewind() {
return 0; return 0;
} }
int32_t SoundDecoder::Read(uint8_t * buffer, int32_t buffer_size, int32_t pos) { int32_t SoundDecoder::Read(uint8_t *buffer, int32_t buffer_size, int32_t pos) {
int32_t ret = file_fd->read(buffer, buffer_size); int32_t ret = file_fd->read(buffer, buffer_size);
CurPos += ret; CurPos += ret;
@ -97,13 +97,13 @@ int32_t SoundDecoder::Read(uint8_t * buffer, int32_t buffer_size, int32_t pos) {
} }
void SoundDecoder::EnableUpsample(void) { void SoundDecoder::EnableUpsample(void) {
if( (ResampleBuffer == NULL) if ((ResampleBuffer == NULL)
&& IsStereo() && Is16Bit() && IsStereo() && Is16Bit()
&& SampleRate != 32000 && SampleRate != 32000
&& SampleRate != 48000) { && SampleRate != 48000) {
ResampleBuffer = (uint8_t*)memalign(32, SoundBlockSize); ResampleBuffer = (uint8_t *) memalign(32, SoundBlockSize);
ResampleRatio = ( FixedPointScale * SampleRate ) / 48000; ResampleRatio = (FixedPointScale * SampleRate) / 48000;
SoundBlockSize = ( SoundBlockSize * ResampleRatio ) / FixedPointScale; SoundBlockSize = (SoundBlockSize * ResampleRatio) / FixedPointScale;
SoundBlockSize &= ~0x03; SoundBlockSize &= ~0x03;
// set new sample rate // set new sample rate
SampleRate = 48000; SampleRate = 48000;
@ -113,19 +113,19 @@ void SoundDecoder::EnableUpsample(void) {
void SoundDecoder::Upsample(int16_t *src, int16_t *dst, uint32_t nr_src_samples, uint32_t nr_dst_samples) { void SoundDecoder::Upsample(int16_t *src, int16_t *dst, uint32_t nr_src_samples, uint32_t nr_dst_samples) {
int32_t timer = 0; int32_t timer = 0;
for(uint32_t i = 0, n = 0; i < nr_dst_samples; i += 2) { for (uint32_t i = 0, n = 0; i < nr_dst_samples; i += 2) {
if((n+3) < nr_src_samples) { if ((n + 3) < nr_src_samples) {
// simple fixed point linear interpolation // simple fixed point linear interpolation
dst[i] = src[n] + ( ((src[n+2] - src[n] ) * timer) >> FixedPointShift ); dst[i] = src[n] + (((src[n + 2] - src[n]) * timer) >> FixedPointShift);
dst[i+1] = src[n+1] + ( ((src[n+3] - src[n+1]) * timer) >> FixedPointShift ); dst[i + 1] = src[n + 1] + (((src[n + 3] - src[n + 1]) * timer) >> FixedPointShift);
} else { } else {
dst[i] = src[n]; dst[i] = src[n];
dst[i+1] = src[n+1]; dst[i + 1] = src[n + 1];
} }
timer += ResampleRatio; timer += ResampleRatio;
if(timer >= (int32_t)FixedPointScale) { if (timer >= (int32_t) FixedPointScale) {
n += 2; n += 2;
timer -= FixedPointScale; timer -= FixedPointScale;
} }
@ -133,35 +133,35 @@ void SoundDecoder::Upsample(int16_t *src, int16_t *dst, uint32_t nr_src_samples,
} }
void SoundDecoder::Decode() { void SoundDecoder::Decode() {
if(!file_fd || ExitRequested || EndOfFile) if (!file_fd || ExitRequested || EndOfFile)
return; return;
// check if we are not at the pre-last buffer (last buffer is playing) // check if we are not at the pre-last buffer (last buffer is playing)
uint16_t whichPlaying = SoundBuffer.Which(); uint16_t whichPlaying = SoundBuffer.Which();
if( ((whichPlaying == 0) && (whichLoad == SoundBuffer.Size()-2)) if (((whichPlaying == 0) && (whichLoad == SoundBuffer.Size() - 2))
|| ((whichPlaying == 1) && (whichLoad == SoundBuffer.Size()-1)) || ((whichPlaying == 1) && (whichLoad == SoundBuffer.Size() - 1))
|| (whichLoad == (whichPlaying-2))) { || (whichLoad == (whichPlaying - 2))) {
return; return;
} }
Decoding = true; Decoding = true;
int32_t done = 0; int32_t done = 0;
uint8_t * write_buf = SoundBuffer.GetBuffer(whichLoad); uint8_t *write_buf = SoundBuffer.GetBuffer(whichLoad);
if(!write_buf) { if (!write_buf) {
ExitRequested = true; ExitRequested = true;
Decoding = false; Decoding = false;
return; return;
} }
if(ResampleTo48kHz && !ResampleBuffer) if (ResampleTo48kHz && !ResampleBuffer)
EnableUpsample(); EnableUpsample();
while(done < SoundBlockSize) { while (done < SoundBlockSize) {
int32_t ret = Read(&write_buf[done], SoundBlockSize-done, Tell()); int32_t ret = Read(&write_buf[done], SoundBlockSize - done, Tell());
if(ret <= 0) { if (ret <= 0) {
if(Loop) { if (Loop) {
Rewind(); Rewind();
continue; continue;
} else { } else {
@ -173,36 +173,36 @@ void SoundDecoder::Decode() {
done += ret; done += ret;
} }
if(done > 0) { if (done > 0) {
// check if we need to resample // check if we need to resample
if(ResampleBuffer && ResampleRatio) { if (ResampleBuffer && ResampleRatio) {
memcpy(ResampleBuffer, write_buf, done); memcpy(ResampleBuffer, write_buf, done);
int32_t src_samples = done >> 1; int32_t src_samples = done >> 1;
int32_t dest_samples = ( src_samples * FixedPointScale ) / ResampleRatio; int32_t dest_samples = (src_samples * FixedPointScale) / ResampleRatio;
dest_samples &= ~0x01; dest_samples &= ~0x01;
Upsample((int16_t*)ResampleBuffer, (int16_t*)write_buf, src_samples, dest_samples); Upsample((int16_t *) ResampleBuffer, (int16_t *) write_buf, src_samples, dest_samples);
done = dest_samples << 1; done = dest_samples << 1;
} }
//! TODO: remove this later and add STEREO support with two voices, for now we convert to MONO //! TODO: remove this later and add STEREO support with two voices, for now we convert to MONO
if(IsStereo()) { if (IsStereo()) {
int16_t* monoBuf = (int16_t*)write_buf; int16_t *monoBuf = (int16_t *) write_buf;
done = done >> 1; done = done >> 1;
for(int32_t i = 0; i < done; i++) for (int32_t i = 0; i < done; i++)
monoBuf[i] = monoBuf[i << 1]; monoBuf[i] = monoBuf[i << 1];
} }
DCFlushRange(write_buf, done); DCFlushRange(write_buf, done);
SoundBuffer.SetBufferSize(whichLoad, done); SoundBuffer.SetBufferSize(whichLoad, done);
SoundBuffer.SetBufferReady(whichLoad, true); SoundBuffer.SetBufferReady(whichLoad, true);
if(++whichLoad >= SoundBuffer.Size()) if (++whichLoad >= SoundBuffer.Size())
whichLoad = 0; whichLoad = 0;
} }
// check if next in queue needs to be filled as well and do so // check if next in queue needs to be filled as well and do so
if(!SoundBuffer.IsBufferReady(whichLoad)) if (!SoundBuffer.IsBufferReady(whichLoad))
Decode(); Decode();
Decoding = false; Decoding = false;

View File

@ -32,13 +32,13 @@
#include <gui/sounds/OggDecoder.hpp> #include <gui/sounds/OggDecoder.hpp>
#include <sndcore2/core.h> #include <sndcore2/core.h>
SoundHandler * SoundHandler::handlerInstance = NULL; SoundHandler *SoundHandler::handlerInstance = NULL;
SoundHandler::SoundHandler() SoundHandler::SoundHandler()
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x8000) { : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x8000) {
Decoding = false; Decoding = false;
ExitRequested = false; ExitRequested = false;
for(uint32_t i = 0; i < MAX_DECODERS; ++i) { for (uint32_t i = 0; i < MAX_DECODERS; ++i) {
DecoderList[i] = NULL; DecoderList[i] = NULL;
voiceList[i] = NULL; voiceList[i] = NULL;
} }
@ -46,7 +46,7 @@ SoundHandler::SoundHandler()
resumeThread(); resumeThread();
//! wait for initialization //! wait for initialization
while(!isThreadSuspended()) while (!isThreadSuspended())
OSSleepTicks(OSMicrosecondsToTicks(1000)); OSSleepTicks(OSMicrosecondsToTicks(1000));
} }
@ -57,40 +57,40 @@ SoundHandler::~SoundHandler() {
ClearDecoderList(); ClearDecoderList();
} }
void SoundHandler::AddDecoder(int32_t voice, const char * filepath) { void SoundHandler::AddDecoder(int32_t voice, const char *filepath) {
if(voice < 0 || voice >= MAX_DECODERS) if (voice < 0 || voice >= MAX_DECODERS)
return; return;
if(DecoderList[voice] != NULL) if (DecoderList[voice] != NULL)
RemoveDecoder(voice); RemoveDecoder(voice);
DecoderList[voice] = GetSoundDecoder(filepath); DecoderList[voice] = GetSoundDecoder(filepath);
} }
void SoundHandler::AddDecoder(int32_t voice, const uint8_t * snd, int32_t len) { void SoundHandler::AddDecoder(int32_t voice, const uint8_t *snd, int32_t len) {
if(voice < 0 || voice >= MAX_DECODERS) if (voice < 0 || voice >= MAX_DECODERS)
return; return;
if(DecoderList[voice] != NULL) if (DecoderList[voice] != NULL)
RemoveDecoder(voice); RemoveDecoder(voice);
DecoderList[voice] = GetSoundDecoder(snd, len); DecoderList[voice] = GetSoundDecoder(snd, len);
} }
void SoundHandler::RemoveDecoder(int32_t voice) { void SoundHandler::RemoveDecoder(int32_t voice) {
if(voice < 0 || voice >= MAX_DECODERS) if (voice < 0 || voice >= MAX_DECODERS)
return; return;
if(DecoderList[voice] != NULL) { if (DecoderList[voice] != NULL) {
if(voiceList[voice] && voiceList[voice]->getState() != Voice::STATE_STOPPED) { if (voiceList[voice] && voiceList[voice]->getState() != Voice::STATE_STOPPED) {
if(voiceList[voice]->getState() != Voice::STATE_STOP) if (voiceList[voice]->getState() != Voice::STATE_STOP)
voiceList[voice]->setState(Voice::STATE_STOP); voiceList[voice]->setState(Voice::STATE_STOP);
// it shouldn't take longer than 3 ms actually but we wait up to 20 // it shouldn't take longer than 3 ms actually but we wait up to 20
// on application quit the AX frame callback is not called anymore // on application quit the AX frame callback is not called anymore
// therefore this would end in endless loop if no timeout is defined // therefore this would end in endless loop if no timeout is defined
int timeOut = 20; int timeOut = 20;
while(--timeOut && (voiceList[voice]->getState() != Voice::STATE_STOPPED)) while (--timeOut && (voiceList[voice]->getState() != Voice::STATE_STOPPED))
OSSleepTicks(OSMicrosecondsToTicks(1000)); OSSleepTicks(OSMicrosecondsToTicks(1000));
} }
SoundDecoder *decoder = DecoderList[voice]; SoundDecoder *decoder = DecoderList[voice];
@ -102,87 +102,87 @@ void SoundHandler::RemoveDecoder(int32_t voice) {
} }
void SoundHandler::ClearDecoderList() { void SoundHandler::ClearDecoderList() {
for(uint32_t i = 0; i < MAX_DECODERS; ++i) for (uint32_t i = 0; i < MAX_DECODERS; ++i)
RemoveDecoder(i); RemoveDecoder(i);
} }
static inline bool CheckMP3Signature(const uint8_t * buffer) { static inline bool CheckMP3Signature(const uint8_t *buffer) {
const char MP3_Magic[][3] = { const char MP3_Magic[][3] = {
{'I', 'D', '3'}, //'ID3' {'I', 'D', '3'}, //'ID3'
{0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'), {0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
{0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'), {0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'),
{0xff, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'), {0xff, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
{0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'), {0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'),
{0xff, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), {0xff, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
{0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), {0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
{0xff, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), {0xff, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
{0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), {0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
{0xff, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), {0xff, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
{0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), {0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
{0xff, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'), {0xff, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'),
{0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', 'mp3', 'audio/mpeg'), {0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', 'mp3', 'audio/mpeg'),
}; };
if(buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] && if (buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] &&
buffer[2] == MP3_Magic[0][2]) { buffer[2] == MP3_Magic[0][2]) {
return true; return true;
} }
for(int32_t i = 1; i < 13; i++) { for (int32_t i = 1; i < 13; i++) {
if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1]) if (buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1])
return true; return true;
} }
return false; return false;
} }
SoundDecoder * SoundHandler::GetSoundDecoder(const char * filepath) { SoundDecoder *SoundHandler::GetSoundDecoder(const char *filepath) {
uint32_t magic; uint32_t magic;
CFile f(filepath, CFile::ReadOnly); CFile f(filepath, CFile::ReadOnly);
if(f.size() == 0) if (f.size() == 0)
return NULL; return NULL;
do { do {
f.read((uint8_t *) &magic, 1); f.read((uint8_t *) &magic, 1);
} while(((uint8_t *) &magic)[0] == 0 && f.tell() < f.size()); } while (((uint8_t *) &magic)[0] == 0 && f.tell() < f.size());
if(f.tell() == f.size()) if (f.tell() == f.size())
return NULL; return NULL;
f.seek(f.tell()-1, SEEK_SET); f.seek(f.tell() - 1, SEEK_SET);
f.read((uint8_t *) &magic, 4); f.read((uint8_t *) &magic, 4);
f.close(); f.close();
if(magic == 0x4f676753) { // 'OggS' if (magic == 0x4f676753) { // 'OggS'
return new OggDecoder(filepath); return new OggDecoder(filepath);
} else if(magic == 0x52494646) { // 'RIFF' } else if (magic == 0x52494646) { // 'RIFF'
return new WavDecoder(filepath); return new WavDecoder(filepath);
} else if(CheckMP3Signature((uint8_t *) &magic) == true) { } else if (CheckMP3Signature((uint8_t *) &magic) == true) {
return new Mp3Decoder(filepath); return new Mp3Decoder(filepath);
} }
return new SoundDecoder(filepath); return new SoundDecoder(filepath);
} }
SoundDecoder * SoundHandler::GetSoundDecoder(const uint8_t * sound, int32_t length) { SoundDecoder *SoundHandler::GetSoundDecoder(const uint8_t *sound, int32_t length) {
const uint8_t * check = sound; const uint8_t *check = sound;
int32_t counter = 0; int32_t counter = 0;
while(check[0] == 0 && counter < length) { while (check[0] == 0 && counter < length) {
check++; check++;
counter++; counter++;
} }
if(counter >= length) if (counter >= length)
return NULL; return NULL;
uint32_t * magic = (uint32_t *) check; uint32_t *magic = (uint32_t *) check;
if(magic[0] == 0x4f676753) { // 'OggS' if (magic[0] == 0x4f676753) { // 'OggS'
return new OggDecoder(sound, length); return new OggDecoder(sound, length);
} else if(magic[0] == 0x52494646) { // 'RIFF' } else if (magic[0] == 0x52494646) { // 'RIFF'
return new WavDecoder(sound, length); return new WavDecoder(sound, length);
} else if(CheckMP3Signature(check) == true) { } else if (CheckMP3Signature(check) == true) {
return new Mp3Decoder(sound, length); return new Mp3Decoder(sound, length);
} }
@ -211,8 +211,8 @@ void SoundHandler::executeThread() {
// The problem with last voice on 500 was caused by it having priority 0 // The problem with last voice on 500 was caused by it having priority 0
// We would need to change this priority distribution if for some reason // We would need to change this priority distribution if for some reason
// we would need MAX_DECODERS > Voice::PRIO_MAX // we would need MAX_DECODERS > Voice::PRIO_MAX
for(uint32_t i = 0; i < MAX_DECODERS; ++i) { for (uint32_t i = 0; i < MAX_DECODERS; ++i) {
int32_t priority = (MAX_DECODERS - i) * Voice::PRIO_MAX / MAX_DECODERS; int32_t priority = (MAX_DECODERS - i) * Voice::PRIO_MAX / MAX_DECODERS;
voiceList[i] = new Voice(priority); // allocate voice 0 with highest priority voiceList[i] = new Voice(priority); // allocate voice 0 with highest priority
} }
@ -223,28 +223,28 @@ void SoundHandler::executeThread() {
while (!ExitRequested) { while (!ExitRequested) {
suspendThread(); suspendThread();
for(i = 0; i < MAX_DECODERS; ++i) { for (i = 0; i < MAX_DECODERS; ++i) {
if(DecoderList[i] == NULL) if (DecoderList[i] == NULL)
continue; continue;
Decoding = true; Decoding = true;
if(DecoderList[i]) if (DecoderList[i])
DecoderList[i]->Lock(); DecoderList[i]->Lock();
if(DecoderList[i]) if (DecoderList[i])
DecoderList[i]->Decode(); DecoderList[i]->Decode();
if(DecoderList[i]) if (DecoderList[i])
DecoderList[i]->Unlock(); DecoderList[i]->Unlock();
} }
Decoding = false; Decoding = false;
} }
for(uint32_t i = 0; i < MAX_DECODERS; ++i) for (uint32_t i = 0; i < MAX_DECODERS; ++i)
voiceList[i]->stop(); voiceList[i]->stop();
AXRegisterAppFrameCallback(NULL); AXRegisterAppFrameCallback(NULL);
AXQuit(); AXQuit();
for(uint32_t i = 0; i < MAX_DECODERS; ++i) { for (uint32_t i = 0; i < MAX_DECODERS; ++i) {
delete voiceList[i]; delete voiceList[i];
voiceList[i] = NULL; voiceList[i] = NULL;
} }
@ -255,59 +255,59 @@ void SoundHandler::axFrameCallback(void) {
Voice *voice = handlerInstance->getVoice(i); Voice *voice = handlerInstance->getVoice(i);
switch (voice->getState()) { switch (voice->getState()) {
default: default:
case Voice::STATE_STOPPED: case Voice::STATE_STOPPED:
break; break;
case Voice::STATE_START: { case Voice::STATE_START: {
SoundDecoder * decoder = handlerInstance->getDecoder(i); SoundDecoder *decoder = handlerInstance->getDecoder(i);
decoder->Lock(); decoder->Lock();
if(decoder->IsBufferReady()) { if (decoder->IsBufferReady()) {
const uint8_t *buffer = decoder->GetBuffer(); const uint8_t *buffer = decoder->GetBuffer();
const uint32_t bufferSize = decoder->GetBufferSize(); const uint32_t bufferSize = decoder->GetBufferSize();
decoder->LoadNext();
const uint8_t *nextBuffer = NULL;
uint32_t nextBufferSize = 0;
if(decoder->IsBufferReady()) {
nextBuffer = decoder->GetBuffer();
nextBufferSize = decoder->GetBufferSize();
decoder->LoadNext(); decoder->LoadNext();
}
voice->play(buffer, bufferSize, nextBuffer, nextBufferSize, decoder->GetFormat() & 0xff, decoder->GetSampleRate()); const uint8_t *nextBuffer = NULL;
uint32_t nextBufferSize = 0;
handlerInstance->ThreadSignal(); if (decoder->IsBufferReady()) {
nextBuffer = decoder->GetBuffer();
voice->setState(Voice::STATE_PLAYING); nextBufferSize = decoder->GetBufferSize();
}
decoder->Unlock();
break;
}
case Voice::STATE_PLAYING:
if(voice->getInternState() == 1) {
if(voice->isBufferSwitched()) {
SoundDecoder * decoder = handlerInstance->getDecoder(i);
decoder->Lock();
if(decoder->IsBufferReady()) {
voice->setNextBuffer(decoder->GetBuffer(), decoder->GetBufferSize());
decoder->LoadNext(); decoder->LoadNext();
handlerInstance->ThreadSignal();
} else if(decoder->IsEOF()) {
voice->setState(Voice::STATE_STOP);
} }
decoder->Unlock();
voice->play(buffer, bufferSize, nextBuffer, nextBufferSize, decoder->GetFormat() & 0xff, decoder->GetSampleRate());
handlerInstance->ThreadSignal();
voice->setState(Voice::STATE_PLAYING);
} }
} else { decoder->Unlock();
voice->setState(Voice::STATE_STOPPED); break;
} }
break; case Voice::STATE_PLAYING:
case Voice::STATE_STOP: if (voice->getInternState() == 1) {
if(voice->getInternState() != 0) if (voice->isBufferSwitched()) {
voice->stop(); SoundDecoder *decoder = handlerInstance->getDecoder(i);
voice->setState(Voice::STATE_STOPPED); decoder->Lock();
break; if (decoder->IsBufferReady()) {
voice->setNextBuffer(decoder->GetBuffer(), decoder->GetBufferSize());
decoder->LoadNext();
handlerInstance->ThreadSignal();
} else if (decoder->IsEOF()) {
voice->setState(Voice::STATE_STOP);
}
decoder->Unlock();
}
} else {
voice->setState(Voice::STATE_STOPPED);
}
break;
case Voice::STATE_STOP:
if (voice->getInternState() != 0)
voice->stop();
voice->setState(Voice::STATE_STOPPED);
break;
} }
} }
} }

View File

@ -28,25 +28,25 @@
#include "fs/CFile.hpp" #include "fs/CFile.hpp"
#include "utils/utils.h" #include "utils/utils.h"
WavDecoder::WavDecoder(const char * filepath) WavDecoder::WavDecoder(const char *filepath)
: SoundDecoder(filepath) { : SoundDecoder(filepath) {
SoundType = SOUND_WAV; SoundType = SOUND_WAV;
SampleRate = 48000; SampleRate = 48000;
Format = CHANNELS_STEREO | FORMAT_PCM_16_BIT; Format = CHANNELS_STEREO | FORMAT_PCM_16_BIT;
if(!file_fd) if (!file_fd)
return; return;
OpenFile(); OpenFile();
} }
WavDecoder::WavDecoder(const uint8_t * snd, int32_t len) WavDecoder::WavDecoder(const uint8_t *snd, int32_t len)
: SoundDecoder(snd, len) { : SoundDecoder(snd, len) {
SoundType = SOUND_WAV; SoundType = SOUND_WAV;
SampleRate = 48000; SampleRate = 48000;
Format = CHANNELS_STEREO | FORMAT_PCM_16_BIT; Format = CHANNELS_STEREO | FORMAT_PCM_16_BIT;
if(!file_fd) if (!file_fd)
return; return;
OpenFile(); OpenFile();
@ -68,24 +68,24 @@ void WavDecoder::OpenFile() {
if (Header.magicRIFF != 0x52494646) { // 'RIFF' if (Header.magicRIFF != 0x52494646) { // 'RIFF'
CloseFile(); CloseFile();
return; return;
} else if(Header.magicWAVE != 0x57415645) { // 'WAVE' } else if (Header.magicWAVE != 0x57415645) { // 'WAVE'
CloseFile(); CloseFile();
return; return;
} else if(FmtChunk.magicFMT != 0x666d7420) { // 'fmt ' } else if (FmtChunk.magicFMT != 0x666d7420) { // 'fmt '
CloseFile(); CloseFile();
return; return;
} }
DataOffset = sizeof(SWaveHdr)+le32(FmtChunk.size)+8; DataOffset = sizeof(SWaveHdr) + le32(FmtChunk.size) + 8;
file_fd->seek(DataOffset, SEEK_SET); file_fd->seek(DataOffset, SEEK_SET);
SWaveChunk DataChunk; SWaveChunk DataChunk;
file_fd->read((uint8_t *) &DataChunk, sizeof(SWaveChunk)); file_fd->read((uint8_t *) &DataChunk, sizeof(SWaveChunk));
while(DataChunk.magicDATA != 0x64617461) { // 'data' while (DataChunk.magicDATA != 0x64617461) { // 'data'
DataOffset += 8+le32(DataChunk.size); DataOffset += 8 + le32(DataChunk.size);
file_fd->seek(DataOffset, SEEK_SET); file_fd->seek(DataOffset, SEEK_SET);
int32_t ret = file_fd->read((uint8_t *) &DataChunk, sizeof(SWaveChunk)); int32_t ret = file_fd->read((uint8_t *) &DataChunk, sizeof(SWaveChunk));
if(ret <= 0) { if (ret <= 0) {
CloseFile(); CloseFile();
return; return;
} }
@ -107,30 +107,30 @@ void WavDecoder::OpenFile() {
} }
void WavDecoder::CloseFile() { void WavDecoder::CloseFile() {
if(file_fd) if (file_fd)
delete file_fd; delete file_fd;
file_fd = NULL; file_fd = NULL;
} }
int32_t WavDecoder::Read(uint8_t * buffer, int32_t buffer_size, int32_t pos) { int32_t WavDecoder::Read(uint8_t *buffer, int32_t buffer_size, int32_t pos) {
if(!file_fd) if (!file_fd)
return -1; return -1;
if(CurPos >= (int32_t) DataSize) if (CurPos >= (int32_t) DataSize)
return 0; return 0;
file_fd->seek(DataOffset+CurPos, SEEK_SET); file_fd->seek(DataOffset + CurPos, SEEK_SET);
if(buffer_size > (int32_t) DataSize-CurPos) if (buffer_size > (int32_t) DataSize - CurPos)
buffer_size = DataSize-CurPos; buffer_size = DataSize - CurPos;
int32_t read = file_fd->read(buffer, buffer_size); int32_t read = file_fd->read(buffer, buffer_size);
if(read > 0) { if (read > 0) {
if (Is16Bit) { if (Is16Bit) {
read &= ~0x0001; read &= ~0x0001;
for (uint32_t i = 0; i < (uint32_t) (read / sizeof (uint16_t)); ++i) for (uint32_t i = 0; i < (uint32_t) (read / sizeof(uint16_t)); ++i)
((uint16_t *) buffer)[i] = le16(((uint16_t *) buffer)[i]); ((uint16_t *) buffer)[i] = le16(((uint16_t *) buffer)[i]);
} }
CurPos += read; CurPos += read;

View File

@ -39,30 +39,30 @@ static MEMHeapHandle mem1_heap = NULL;
static MEMHeapHandle bucket_heap = NULL; static MEMHeapHandle bucket_heap = NULL;
void libgui_memoryInitialize(void) { void libgui_memoryInitialize(void) {
if(!mem1_heap) { if (!mem1_heap) {
MEMHeapHandle mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1); MEMHeapHandle mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1);
uint32_t mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4); uint32_t mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4);
void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4); void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4);
if(mem1_memory) if (mem1_memory)
mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0); mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0);
} }
if(!bucket_heap) { if (!bucket_heap) {
MEMHeapHandle bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET); MEMHeapHandle bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET);
uint32_t bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4); uint32_t bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4);
void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4); void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4);
if(bucket_memory) if (bucket_memory)
bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0); bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0);
} }
} }
void libgui_memoryRelease(void) { void libgui_memoryRelease(void) {
if(mem1_heap) { if (mem1_heap) {
MEMDestroyExpHeap(mem1_heap); MEMDestroyExpHeap(mem1_heap);
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3); MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3);
mem1_heap = NULL; mem1_heap = NULL;
} }
if(bucket_heap) { if (bucket_heap) {
MEMDestroyExpHeap(bucket_heap); MEMDestroyExpHeap(bucket_heap);
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3); MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3);
bucket_heap = NULL; bucket_heap = NULL;
@ -156,7 +156,7 @@ void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
//!------------------------------------------------------------------------------------------- //!-------------------------------------------------------------------------------------------
//! some wrappers //! some wrappers
//!------------------------------------------------------------------------------------------- //!-------------------------------------------------------------------------------------------
void * MEM2_alloc(uint32_t size, uint32_t align) { void *MEM2_alloc(uint32_t size, uint32_t align) {
return memalign(align, size); return memalign(align, size);
} }
@ -164,7 +164,7 @@ void MEM2_free(void *ptr) {
free(ptr); free(ptr);
} }
void * MEM1_alloc(uint32_t size, uint32_t align) { void *MEM1_alloc(uint32_t size, uint32_t align) {
if (align < 4) if (align < 4)
align = 4; align = 4;
return MEMAllocFromExpHeapEx(mem1_heap, size, align); return MEMAllocFromExpHeapEx(mem1_heap, size, align);
@ -174,7 +174,7 @@ void MEM1_free(void *ptr) {
MEMFreeToExpHeap(mem1_heap, ptr); MEMFreeToExpHeap(mem1_heap, ptr);
} }
void * MEMBucket_alloc(uint32_t size, uint32_t align) { void *MEMBucket_alloc(uint32_t size, uint32_t align) {
if (align < 4) if (align < 4)
align = 4; align = 4;
return MEMAllocFromExpHeapEx(bucket_heap, size, align); return MEMAllocFromExpHeapEx(bucket_heap, size, align);

View File

@ -7,12 +7,12 @@
extern "C" { extern "C" {
#endif #endif
#define LIMIT(x, min, max) \ #define LIMIT(x, min, max) \
({ \ ({ \
typeof( x ) _x = x; \ typeof( x ) _x = x; \
typeof( min ) _min = min; \ typeof( min ) _min = min; \
typeof( max ) _max = max; \ typeof( max ) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
}) })
#define DegToRad(a) ( (a) * 0.01745329252f ) #define DegToRad(a) ( (a) * 0.01745329252f )
@ -26,7 +26,7 @@ extern "C" {
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) #define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
//Needs to have log_init() called beforehand. //Needs to have log_init() called beforehand.
void dumpHex(const void* data, size_t size); void dumpHex(const void *data, size_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -35,7 +35,7 @@ CVideo::CVideo(int32_t forceTvScanMode, int32_t forceDrcScanMode) {
//! initialize GX2 command buffer //! initialize GX2 command buffer
uint32_t gx2_init_attributes[9]; uint32_t gx2_init_attributes[9];
gx2_init_attributes[0] = GX2_INIT_CMD_BUF_BASE; gx2_init_attributes[0] = GX2_INIT_CMD_BUF_BASE;
gx2_init_attributes[1] = (uint32_t)gx2CommandBuffer; gx2_init_attributes[1] = (uint32_t) gx2CommandBuffer;
gx2_init_attributes[2] = GX2_INIT_CMD_BUF_POOL_SIZE; gx2_init_attributes[2] = GX2_INIT_CMD_BUF_POOL_SIZE;
gx2_init_attributes[3] = GX2_COMMAND_BUFFER_SIZE; gx2_init_attributes[3] = GX2_COMMAND_BUFFER_SIZE;
gx2_init_attributes[4] = GX2_INIT_ARGC; gx2_init_attributes[4] = GX2_INIT_ARGC;
@ -48,56 +48,56 @@ CVideo::CVideo(int32_t forceTvScanMode, int32_t forceDrcScanMode) {
uint32_t scanBufferSize = 0; uint32_t scanBufferSize = 0;
uint32_t scaleNeeded = 0; uint32_t scaleNeeded = 0;
int32_t tvScanMode = ((forceTvScanMode >= 0) ? forceTvScanMode : (int32_t)GX2GetSystemTVScanMode()); int32_t tvScanMode = ((forceTvScanMode >= 0) ? forceTvScanMode : (int32_t) GX2GetSystemTVScanMode());
int32_t drcScanMode = ((forceDrcScanMode >= 0) ? forceDrcScanMode : (int32_t)GX2GetSystemDRCScanMode()); int32_t drcScanMode = ((forceDrcScanMode >= 0) ? forceDrcScanMode : (int32_t) GX2GetSystemDRCScanMode());
int32_t tvRenderMode; int32_t tvRenderMode;
uint32_t tvWidth = 0; uint32_t tvWidth = 0;
uint32_t tvHeight = 0; uint32_t tvHeight = 0;
switch(tvScanMode) { switch (tvScanMode) {
case GX2_TV_SCAN_MODE_480I: case GX2_TV_SCAN_MODE_480I:
case GX2_TV_SCAN_MODE_480P: case GX2_TV_SCAN_MODE_480P:
tvWidth = 854; tvWidth = 854;
tvHeight = 480; tvHeight = 480;
tvRenderMode = GX2_TV_RENDER_MODE_WIDE_480P; tvRenderMode = GX2_TV_RENDER_MODE_WIDE_480P;
break; break;
case GX2_TV_SCAN_MODE_1080I: case GX2_TV_SCAN_MODE_1080I:
case GX2_TV_SCAN_MODE_1080P: case GX2_TV_SCAN_MODE_1080P:
tvWidth = 1920; tvWidth = 1920;
tvHeight = 1080; tvHeight = 1080;
tvRenderMode = GX2_TV_RENDER_MODE_WIDE_1080P; tvRenderMode = GX2_TV_RENDER_MODE_WIDE_1080P;
break; break;
case GX2_TV_SCAN_MODE_720P: case GX2_TV_SCAN_MODE_720P:
default: default:
tvWidth = 1280; tvWidth = 1280;
tvHeight = 720; tvHeight = 720;
tvRenderMode = GX2_TV_RENDER_MODE_WIDE_720P; tvRenderMode = GX2_TV_RENDER_MODE_WIDE_720P;
break; break;
} }
int32_t tvAAMode = GX2_AA_MODE1X; int32_t tvAAMode = GX2_AA_MODE1X;
int32_t drcAAMode = GX2_AA_MODE4X; int32_t drcAAMode = GX2_AA_MODE4X;
//! calculate the scale factor for later texture resize //! calculate the scale factor for later texture resize
widthScaleFactor = 1.0f / (float)tvWidth; widthScaleFactor = 1.0f / (float) tvWidth;
heightScaleFactor = 1.0f / (float)tvHeight; heightScaleFactor = 1.0f / (float) tvHeight;
depthScaleFactor = widthScaleFactor; depthScaleFactor = widthScaleFactor;
//! calculate the size needed for the TV scan buffer and allocate the buffer from bucket memory //! calculate the size needed for the TV scan buffer and allocate the buffer from bucket memory
GX2CalcTVSize((GX2TVRenderMode)tvRenderMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &scanBufferSize, &scaleNeeded); GX2CalcTVSize((GX2TVRenderMode) tvRenderMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &scanBufferSize, &scaleNeeded);
tvScanBuffer = MEMBucket_alloc(scanBufferSize, GX2_SCAN_BUFFER_ALIGNMENT); tvScanBuffer = MEMBucket_alloc(scanBufferSize, GX2_SCAN_BUFFER_ALIGNMENT);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvScanBuffer, scanBufferSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvScanBuffer, scanBufferSize);
GX2SetTVBuffer(tvScanBuffer, scanBufferSize, (GX2TVRenderMode)tvRenderMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE); GX2SetTVBuffer(tvScanBuffer, scanBufferSize, (GX2TVRenderMode) tvRenderMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE);
//! calculate the size needed for the DRC scan buffer and allocate the buffer from bucket memory //! calculate the size needed for the DRC scan buffer and allocate the buffer from bucket memory
GX2CalcDRCSize((GX2DrcRenderMode)drcScanMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &scanBufferSize, &scaleNeeded); GX2CalcDRCSize((GX2DrcRenderMode) drcScanMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &scanBufferSize, &scaleNeeded);
drcScanBuffer = MEMBucket_alloc(scanBufferSize, GX2_SCAN_BUFFER_ALIGNMENT); drcScanBuffer = MEMBucket_alloc(scanBufferSize, GX2_SCAN_BUFFER_ALIGNMENT);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcScanBuffer, scanBufferSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcScanBuffer, scanBufferSize);
GX2SetDRCBuffer(drcScanBuffer, scanBufferSize, (GX2DrcRenderMode)drcScanMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE); GX2SetDRCBuffer(drcScanBuffer, scanBufferSize, (GX2DrcRenderMode) drcScanMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE);
//! Setup color buffer for TV rendering //! Setup color buffer for TV rendering
GX2InitColorBuffer(&tvColorBuffer, GX2_SURFACE_DIM_TEXTURE_2D, tvWidth, tvHeight, 1, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, (GX2AAMode)tvAAMode); GX2InitColorBuffer(&tvColorBuffer, GX2_SURFACE_DIM_TEXTURE_2D, tvWidth, tvHeight, 1, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, (GX2AAMode) tvAAMode);
tvColorBuffer.surface.image = MEM1_alloc(tvColorBuffer.surface.imageSize, tvColorBuffer.surface.alignment); tvColorBuffer.surface.image = MEM1_alloc(tvColorBuffer.surface.imageSize, tvColorBuffer.surface.alignment);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvColorBuffer.surface.image, tvColorBuffer.surface.imageSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvColorBuffer.surface.image, tvColorBuffer.surface.imageSize);
@ -106,7 +106,7 @@ CVideo::CVideo(int32_t forceTvScanMode, int32_t forceDrcScanMode) {
//! Setup TV depth buffer (can be the same for both if rendered one after another) //! Setup TV depth buffer (can be the same for both if rendered one after another)
uint32_t size, align; uint32_t size, align;
GX2InitDepthBuffer(&tvDepthBuffer, GX2_SURFACE_DIM_TEXTURE_2D, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_FLOAT_R32, (GX2AAMode)tvAAMode); GX2InitDepthBuffer(&tvDepthBuffer, GX2_SURFACE_DIM_TEXTURE_2D, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_FLOAT_R32, (GX2AAMode) tvAAMode);
tvDepthBuffer.surface.image = MEM1_alloc(tvDepthBuffer.surface.imageSize, tvDepthBuffer.surface.alignment); tvDepthBuffer.surface.image = MEM1_alloc(tvDepthBuffer.surface.imageSize, tvDepthBuffer.surface.alignment);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvDepthBuffer.surface.image, tvDepthBuffer.surface.imageSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvDepthBuffer.surface.image, tvDepthBuffer.surface.imageSize);
@ -117,12 +117,12 @@ CVideo::CVideo(int32_t forceTvScanMode, int32_t forceDrcScanMode) {
GX2InitDepthBufferHiZEnable(&tvDepthBuffer, GX2_ENABLE); GX2InitDepthBufferHiZEnable(&tvDepthBuffer, GX2_ENABLE);
//! Setup color buffer for DRC rendering //! Setup color buffer for DRC rendering
GX2InitColorBuffer(&drcColorBuffer, GX2_SURFACE_DIM_TEXTURE_2D, 854, 480, 1, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, (GX2AAMode)drcAAMode); GX2InitColorBuffer(&drcColorBuffer, GX2_SURFACE_DIM_TEXTURE_2D, 854, 480, 1, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, (GX2AAMode) drcAAMode);
drcColorBuffer.surface.image = MEM1_alloc(drcColorBuffer.surface.imageSize, drcColorBuffer.surface.alignment); drcColorBuffer.surface.image = MEM1_alloc(drcColorBuffer.surface.imageSize, drcColorBuffer.surface.alignment);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcColorBuffer.surface.image, drcColorBuffer.surface.imageSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcColorBuffer.surface.image, drcColorBuffer.surface.imageSize);
//! Setup DRC depth buffer (can be the same for both if rendered one after another) //! Setup DRC depth buffer (can be the same for both if rendered one after another)
GX2InitDepthBuffer(&drcDepthBuffer, GX2_SURFACE_DIM_TEXTURE_2D, drcColorBuffer.surface.width, drcColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_FLOAT_R32, (GX2AAMode)drcAAMode); GX2InitDepthBuffer(&drcDepthBuffer, GX2_SURFACE_DIM_TEXTURE_2D, drcColorBuffer.surface.width, drcColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_FLOAT_R32, (GX2AAMode) drcAAMode);
drcDepthBuffer.surface.image = MEM1_alloc(drcDepthBuffer.surface.imageSize, drcDepthBuffer.surface.alignment); drcDepthBuffer.surface.image = MEM1_alloc(drcDepthBuffer.surface.imageSize, drcDepthBuffer.surface.alignment);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcDepthBuffer.surface.image, drcDepthBuffer.surface.imageSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcDepthBuffer.surface.image, drcDepthBuffer.surface.imageSize);
@ -138,7 +138,7 @@ CVideo::CVideo(int32_t forceTvScanMode, int32_t forceDrcScanMode) {
uint32_t auxSize, auxAlign; uint32_t auxSize, auxAlign;
GX2CalcColorBufferAuxInfo(&tvColorBuffer, &auxSize, &auxAlign); GX2CalcColorBufferAuxInfo(&tvColorBuffer, &auxSize, &auxAlign);
tvColorBuffer.aaBuffer = MEM1_alloc(auxSize, auxAlign); tvColorBuffer.aaBuffer = MEM1_alloc(auxSize, auxAlign);
if(!tvColorBuffer.aaBuffer) if (!tvColorBuffer.aaBuffer)
tvColorBuffer.aaBuffer = MEM2_alloc(auxSize, auxAlign); tvColorBuffer.aaBuffer = MEM2_alloc(auxSize, auxAlign);
tvColorBuffer.aaSize = auxSize; tvColorBuffer.aaSize = auxSize;
@ -150,7 +150,7 @@ CVideo::CVideo(int32_t forceTvScanMode, int32_t forceDrcScanMode) {
uint32_t auxSize, auxAlign; uint32_t auxSize, auxAlign;
GX2CalcColorBufferAuxInfo(&drcColorBuffer, &auxSize, &auxAlign); GX2CalcColorBufferAuxInfo(&drcColorBuffer, &auxSize, &auxAlign);
drcColorBuffer.aaBuffer = MEM1_alloc(auxSize, auxAlign); drcColorBuffer.aaBuffer = MEM1_alloc(auxSize, auxAlign);
if(!drcColorBuffer.aaBuffer) if (!drcColorBuffer.aaBuffer)
drcColorBuffer.aaBuffer = MEM2_alloc(auxSize, auxAlign); drcColorBuffer.aaBuffer = MEM2_alloc(auxSize, auxAlign);
drcColorBuffer.aaSize = auxSize; drcColorBuffer.aaSize = auxSize;
memset(drcColorBuffer.aaBuffer, GX2_AA_BUFFER_CLEAR_VALUE, auxSize); memset(drcColorBuffer.aaBuffer, GX2_AA_BUFFER_CLEAR_VALUE, auxSize);
@ -158,11 +158,11 @@ CVideo::CVideo(int32_t forceTvScanMode, int32_t forceDrcScanMode) {
} }
//! allocate memory and setup context state TV //! allocate memory and setup context state TV
tvContextState = (GX2ContextState*)MEM2_alloc(sizeof(GX2ContextState), GX2_CONTEXT_STATE_ALIGNMENT); tvContextState = (GX2ContextState *) MEM2_alloc(sizeof(GX2ContextState), GX2_CONTEXT_STATE_ALIGNMENT);
GX2SetupContextStateEx(tvContextState, GX2_TRUE); GX2SetupContextStateEx(tvContextState, GX2_TRUE);
//! allocate memory and setup context state DRC //! allocate memory and setup context state DRC
drcContextState = (GX2ContextState*)MEM2_alloc(sizeof(GX2ContextState), GX2_CONTEXT_STATE_ALIGNMENT); drcContextState = (GX2ContextState *) MEM2_alloc(sizeof(GX2ContextState), GX2_CONTEXT_STATE_ALIGNMENT);
GX2SetupContextStateEx(drcContextState, GX2_TRUE); GX2SetupContextStateEx(drcContextState, GX2_TRUE);
//! set initial context state and render buffers //! set initial context state and render buffers
@ -223,14 +223,14 @@ CVideo::~CVideo() {
MEM2_free(tvContextState); MEM2_free(tvContextState);
MEM2_free(drcContextState); MEM2_free(drcContextState);
//! free aux buffer //! free aux buffer
if(tvColorBuffer.aaBuffer) { if (tvColorBuffer.aaBuffer) {
if(((uint32_t)tvColorBuffer.aaBuffer & 0xF0000000) == 0xF0000000) if (((uint32_t) tvColorBuffer.aaBuffer & 0xF0000000) == 0xF0000000)
MEM1_free(tvColorBuffer.aaBuffer); MEM1_free(tvColorBuffer.aaBuffer);
else else
MEM2_free(tvColorBuffer.aaBuffer); MEM2_free(tvColorBuffer.aaBuffer);
} }
if(drcColorBuffer.aaBuffer) { if (drcColorBuffer.aaBuffer) {
if(((uint32_t)drcColorBuffer.aaBuffer & 0xF0000000) == 0xF0000000) if (((uint32_t) drcColorBuffer.aaBuffer & 0xF0000000) == 0xF0000000)
MEM1_free(drcColorBuffer.aaBuffer); MEM1_free(drcColorBuffer.aaBuffer);
else else
MEM2_free(drcColorBuffer.aaBuffer); MEM2_free(drcColorBuffer.aaBuffer);
@ -243,11 +243,11 @@ CVideo::~CVideo() {
Texture2DShader::destroyInstance(); Texture2DShader::destroyInstance();
} }
void CVideo::renderFXAA(const GX2Texture * texture, const GX2Sampler *sampler) { void CVideo::renderFXAA(const GX2Texture *texture, const GX2Sampler *sampler) {
resolution[0] = texture->surface.width; resolution[0] = texture->surface.width;
resolution[1] = texture->surface.height; resolution[1] = texture->surface.height;
GX2Invalidate((GX2InvalidateMode)(GX2_INVALIDATE_MODE_COLOR_BUFFER | GX2_INVALIDATE_MODE_TEXTURE), texture->surface.image, texture->surface.imageSize); GX2Invalidate((GX2InvalidateMode) (GX2_INVALIDATE_MODE_COLOR_BUFFER | GX2_INVALIDATE_MODE_TEXTURE), texture->surface.image, texture->surface.imageSize);
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_ALWAYS); GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_ALWAYS);
FXAAShader::instance()->setShaders(); FXAAShader::instance()->setShaders();

View File

@ -38,41 +38,41 @@ CursorDrawer::~CursorDrawer() {
Shader3D::destroyInstance(); Shader3D::destroyInstance();
ShaderFractalColor::destroyInstance(); ShaderFractalColor::destroyInstance();
Texture2DShader::destroyInstance(); Texture2DShader::destroyInstance();
if(this->colorVtxs) { if (this->colorVtxs) {
free(this->colorVtxs); free(this->colorVtxs);
this->colorVtxs = NULL; this->colorVtxs = NULL;
} }
} }
void CursorDrawer::init_colorVtxs() { void CursorDrawer::init_colorVtxs() {
if(!this->colorVtxs) { if (!this->colorVtxs) {
this->colorVtxs = (uint8_t*)memalign(0x40, sizeof(uint8_t) * 16); this->colorVtxs = (uint8_t *) memalign(0x40, sizeof(uint8_t) * 16);
if(this->colorVtxs == NULL) return; if (this->colorVtxs == NULL) return;
} }
memset(this->colorVtxs,0xFF,16*sizeof(uint8_t)); memset(this->colorVtxs, 0xFF, 16 * sizeof(uint8_t));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, this->colorVtxs, 16 * sizeof(uint8_t)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, this->colorVtxs, 16 * sizeof(uint8_t));
} }
// Could be improved. It be more generic. // Could be improved. It be more generic.
void CursorDrawer::draw_Cursor(float x,float y) { void CursorDrawer::draw_Cursor(float x, float y) {
if(this->colorVtxs == NULL) { if (this->colorVtxs == NULL) {
init_colorVtxs(); init_colorVtxs();
return; return;
} }
float widthScaleFactor = 1.0f / (float)1280; float widthScaleFactor = 1.0f / (float) 1280;
float heightScaleFactor = 1.0f / (float)720; float heightScaleFactor = 1.0f / (float) 720;
int32_t width = 20; int32_t width = 20;
glm::vec3 positionOffsets = glm::vec3(0.0f); glm::vec3 positionOffsets = glm::vec3(0.0f);
positionOffsets[0] = (x-((1280)/2)+(width/2)) * widthScaleFactor * 2.0f; positionOffsets[0] = (x - ((1280) / 2) + (width / 2)) * widthScaleFactor * 2.0f;
positionOffsets[1] = -(y-((720)/2)+(width/2)) * heightScaleFactor * 2.0f; positionOffsets[1] = -(y - ((720) / 2) + (width / 2)) * heightScaleFactor * 2.0f;
glm::vec3 scale(width*widthScaleFactor,width*heightScaleFactor,1.0f); glm::vec3 scale(width * widthScaleFactor, width * heightScaleFactor, 1.0f);
ColorShader::instance()->setShaders(); ColorShader::instance()->setShaders();
ColorShader::instance()->setAttributeBuffer(this->colorVtxs, NULL, 4); ColorShader::instance()->setAttributeBuffer(this->colorVtxs, NULL, 4);

View File

@ -19,102 +19,102 @@
#include <gui/video/shaders/ColorShader.h> #include <gui/video/shaders/ColorShader.h>
static const uint32_t cpVertexShaderProgram[] = { static const uint32_t cpVertexShaderProgram[] = {
0x00000000,0x00008009,0x20000000,0x000078a0, 0x00000000, 0x00008009, 0x20000000, 0x000078a0,
0x3c200000,0x88060094,0x00c00000,0x88062014, 0x3c200000, 0x88060094, 0x00c00000, 0x88062014,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00a11f00,0xfc00620f,0x02490001,0x80000040, 0x00a11f00, 0xfc00620f, 0x02490001, 0x80000040,
0xfd041f80,0x900c0060,0x83f9223e,0x0000803f, 0xfd041f80, 0x900c0060, 0x83f9223e, 0x0000803f,
0xfe282001,0x10000040,0xfe001f80,0x00080060, 0xfe282001, 0x10000040, 0xfe001f80, 0x00080060,
0xfeac9f80,0xfd00624f,0xdb0f49c0,0xdb0fc940, 0xfeac9f80, 0xfd00624f, 0xdb0f49c0, 0xdb0fc940,
0xfea81f80,0x9000e02f,0x83f9223e,0x00000000, 0xfea81f80, 0x9000e02f, 0x83f9223e, 0x00000000,
0xfe041f80,0x00370000,0xffa01f00,0x80000000, 0xfe041f80, 0x00370000, 0xffa01f00, 0x80000000,
0xff101f00,0x800c0020,0x7f041f80,0x80370000, 0xff101f00, 0x800c0020, 0x7f041f80, 0x80370000,
0x0000103f,0x00000000,0x02c51f00,0x80000000, 0x0000103f, 0x00000000, 0x02c51f00, 0x80000000,
0xfea41f00,0x80000020,0xffa09f00,0x80000040, 0xfea41f00, 0x80000020, 0xffa09f00, 0x80000040,
0xff001f80,0x800c0060,0x398ee33f,0x0000103f, 0xff001f80, 0x800c0060, 0x398ee33f, 0x0000103f,
0x02c41f00,0x9000e00f,0x02c59f01,0x80000020, 0x02c41f00, 0x9000e00f, 0x02c59f01, 0x80000020,
0xfea81f00,0x80000040,0x02c19f80,0x9000e06f, 0xfea81f00, 0x80000040, 0x02c19f80, 0x9000e06f,
0x398ee33f,0x00000000,0x02c11f01,0x80000000, 0x398ee33f, 0x00000000, 0x02c11f01, 0x80000000,
0x02c49f80,0x80000060,0x02e08f01,0xfe0c620f, 0x02c49f80, 0x80000060, 0x02e08f01, 0xfe0c620f,
0x02c01f80,0x7f00622f,0xfe242000,0x10000000, 0x02c01f80, 0x7f00622f, 0xfe242000, 0x10000000,
0xfe20a080,0x10000020,0xf2178647,0x49c0e9fb, 0xfe20a080, 0x10000020, 0xf2178647, 0x49c0e9fb,
0xfbbdb2ab,0x768ac733 0xfbbdb2ab, 0x768ac733
}; };
static const uint32_t cpVertexShaderRegs[] = { static const uint32_t cpVertexShaderRegs[] = {
0x00000103,0x00000000,0x00000000,0x00000001, 0x00000103, 0x00000000, 0x00000000, 0x00000001,
0xffffff00,0xffffffff,0xffffffff,0xffffffff, 0xffffff00, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0xffffffff,0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0x00000000,0xfffffffc, 0xffffffff, 0xffffffff, 0x00000000, 0xfffffffc,
0x00000002,0x00000001,0x00000000,0x000000ff, 0x00000002, 0x00000001, 0x00000000, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x00000000,0x0000000e,0x00000010 0x000000ff, 0x00000000, 0x0000000e, 0x00000010
}; };
static const uint32_t cpPixelShaderProgram[] = { static const uint32_t cpPixelShaderProgram[] = {
0x20000000,0x00000ca0,0x00000000,0x88062094, 0x20000000, 0x00000ca0, 0x00000000, 0x88062094,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00002000,0x90000000,0x0004a000,0x90000020, 0x00002000, 0x90000000, 0x0004a000, 0x90000020,
0x00082001,0x90000040,0x000ca081,0x90000060, 0x00082001, 0x90000040, 0x000ca081, 0x90000060,
0xbb7dd898,0x9746c59c,0xc69b00e7,0x03c36218 0xbb7dd898, 0x9746c59c, 0xc69b00e7, 0x03c36218
}; };
static const uint32_t cpPixelShaderRegs[] = { static const uint32_t cpPixelShaderRegs[] = {
0x00000001,0x00000002,0x14000001,0x00000000, 0x00000001, 0x00000002, 0x14000001, 0x00000000,
0x00000001,0x00000100,0x00000000,0x00000000, 0x00000001, 0x00000100, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x0000000f,0x00000001,0x00000010, 0x00000000, 0x0000000f, 0x00000001, 0x00000010,
0x00000000 0x00000000
}; };
ColorShader * ColorShader::shaderInstance = NULL; ColorShader *ColorShader::shaderInstance = NULL;
ColorShader::ColorShader() ColorShader::ColorShader()
: vertexShader(cuAttributeCount) { : vertexShader(cuAttributeCount) {
//! create pixel shader //! create pixel shader
pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs));
colorIntensityLocation = 0; colorIntensityLocation = 0;
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1
}); });
//! create vertex shader //! create vertex shader
@ -124,22 +124,22 @@ ColorShader::ColorShader()
offsetLocation = 4; offsetLocation = 4;
scaleLocation = 8; scaleLocation = 8;
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1 "unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1
}); });
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1 "unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1
}); });
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1 "unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1
}); });
colorLocation = 1; colorLocation = 1;
positionLocation = 0; positionLocation = 0;
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_color", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation "attr_color", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation
}); });
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation
}); });
//! setup attribute streams //! setup attribute streams
@ -150,28 +150,28 @@ ColorShader::ColorShader()
fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount());
//! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000 //! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000
positionVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuPositionVtxsSize); positionVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuPositionVtxsSize);
if(positionVtxs) { if (positionVtxs) {
//! position vertex structure //! position vertex structure
int32_t i = 0; int32_t i = 0;
positionVtxs[i++] = -1.0f; positionVtxs[i++] = -1.0f;
positionVtxs[i++] = -1.0f; positionVtxs[i++] = -1.0f;
positionVtxs[i++] = 0.0f; positionVtxs[i++] = 0.0f;
positionVtxs[i++] = 1.0f; positionVtxs[i++] = 1.0f;
positionVtxs[i++] = -1.0f; positionVtxs[i++] = -1.0f;
positionVtxs[i++] = 0.0f; positionVtxs[i++] = 0.0f;
positionVtxs[i++] = 1.0f; positionVtxs[i++] = 1.0f;
positionVtxs[i++] = 1.0f; positionVtxs[i++] = 1.0f;
positionVtxs[i++] = 0.0f; positionVtxs[i++] = 0.0f;
positionVtxs[i++] = -1.0f; positionVtxs[i++] = -1.0f;
positionVtxs[i++] = 1.0f; positionVtxs[i++] = 1.0f;
positionVtxs[i++] = 0.0f; positionVtxs[i++] = 0.0f;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, positionVtxs, cuPositionVtxsSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, positionVtxs, cuPositionVtxsSize);
} }
} }
ColorShader::~ColorShader() { ColorShader::~ColorShader() {
if(positionVtxs) { if (positionVtxs) {
free(positionVtxs); free(positionVtxs);
positionVtxs = NULL; positionVtxs = NULL;
} }

View File

@ -19,163 +19,163 @@
#include <gui/video/shaders/FXAAShader.h> #include <gui/video/shaders/FXAAShader.h>
static const uint32_t cpVertexShaderProgram[] = { static const uint32_t cpVertexShaderProgram[] = {
0x00000000,0x00008009,0x20000000,0x000004a0, 0x00000000, 0x00008009, 0x20000000, 0x000004a0,
0x3ca00000,0x88060094,0x00400000,0xff0f2094, 0x3ca00000, 0x88060094, 0x00400000, 0xff0f2094,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xfd001f80,0x900c2060,0x0000803f,0x00000000, 0xfd001f80, 0x900c2060, 0x0000803f, 0x00000000,
0xc1a229f5,0xd0eddc33,0x426618fd,0x8509cfe7 0xc1a229f5, 0xd0eddc33, 0x426618fd, 0x8509cfe7
}; };
static const uint32_t cpVertexShaderRegs[] = { static const uint32_t cpVertexShaderRegs[] = {
0x00000102,0x00000000,0x00000000,0x00000001, 0x00000102, 0x00000000, 0x00000000, 0x00000001,
0xffffffff,0xffffffff,0xffffffff,0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0xffffffff,0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0x00000000,0xfffffffe, 0xffffffff, 0xffffffff, 0x00000000, 0xfffffffe,
0x00000001,0x00000000,0x000000ff,0x000000ff, 0x00000001, 0x00000000, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x00000000,0x0000000e,0x00000010 0x000000ff, 0x00000000, 0x0000000e, 0x00000010
}; };
static const uint32_t cpPixelShaderProgram[] = { static const uint32_t cpPixelShaderProgram[] = {
0x20000000,0x00003ca0,0xa0000000,0x000c8080, 0x20000000, 0x00003ca0, 0xa0000000, 0x000c8080,
0x30000000,0x000010a1,0xa8000000,0x0010c080, 0x30000000, 0x000010a1, 0xa8000000, 0x0010c080,
0x75000000,0x000088a0,0x00800100,0x88062094, 0x75000000, 0x000088a0, 0x00800100, 0x88062094,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00241f02,0x1000e00f,0x00241f00,0x1000e02f, 0x00241f02, 0x1000e00f, 0x00241f00, 0x1000e02f,
0x00201f02,0x00000040,0x00201f00,0x00000060, 0x00201f02, 0x00000040, 0x00201f00, 0x00000060,
0x00011f80,0x10332060,0xff000000,0xff102200, 0x00011f80, 0x10332060, 0xff000000, 0xff102200,
0xfd001f00,0x900cc020,0xffc09f01,0x90004040, 0xfd001f00, 0x900cc020, 0xffc09f01, 0x90004040,
0xffc01f01,0x90000060,0x00051f80,0x1033a040, 0xffc01f01, 0x90000060, 0x00051f80, 0x1033a040,
0x0000803f,0x00000000,0xffe00f00,0x90004000, 0x0000803f, 0x00000000, 0xffe00f00, 0x90004000,
0xff008000,0xff102220,0xffe08f00,0x90000440, 0xff008000, 0xff102220, 0xffe08f00, 0x90000440,
0x010c0000,0x010c4660,0xff008080,0xff004220, 0x010c0000, 0x010c4660, 0xff008080, 0xff004220,
0x01a01f00,0x00280000,0x01a49f00,0x00280020, 0x01a01f00, 0x00280000, 0x01a49f00, 0x00280020,
0x01a81f01,0x00280040,0xfd0c1f00,0x1028e06f, 0x01a81f01, 0x00280040, 0xfd0c1f00, 0x1028e06f,
0x00208081,0x90002000,0x8716993e,0xa245163f, 0x00208081, 0x90002000, 0x8716993e, 0xa245163f,
0xd578e93d,0x00000080,0x03a01f00,0x00280000, 0xd578e93d, 0x00000080, 0x03a01f00, 0x00280000,
0x03a49f00,0x00280020,0x03a81f01,0x1028e04f, 0x03a49f00, 0x00280020, 0x03a81f01, 0x1028e04f,
0xfd0c1f00,0x00280060,0x00a40081,0x90002020, 0xfd0c1f00, 0x00280060, 0x00a40081, 0x90002020,
0x8716993e,0xa245163f,0xd578e93d,0x00000080, 0x8716993e, 0xa245163f, 0xd578e93d, 0x00000080,
0x04a01f00,0x00280000,0x04a49f00,0x1028a02f, 0x04a01f00, 0x00280000, 0x04a49f00, 0x1028a02f,
0x04a81f01,0x00280040,0xfd0c1f00,0x00280060, 0x04a81f01, 0x00280040, 0xfd0c1f00, 0x00280060,
0x7fcc1f80,0x1000c02f,0x8716993e,0xa245163f, 0x7fcc1f80, 0x1000c02f, 0x8716993e, 0xa245163f,
0xd578e93d,0x00000080,0x02a01f00,0x1028e00f, 0xd578e93d, 0x00000080, 0x02a01f00, 0x1028e00f,
0x02a49f00,0x00280020,0x02a81f01,0x00280040, 0x02a49f00, 0x00280020, 0x02a81f01, 0x00280040,
0xfd0c1f00,0x00280060,0x7fcc1f80,0x1000e02f, 0xfd0c1f00, 0x00280060, 0x7fcc1f80, 0x1000e02f,
0x8716993e,0xa245163f,0xd578e93d,0x00000080, 0x8716993e, 0xa245163f, 0xd578e93d, 0x00000080,
0x7dc41f00,0x00020000,0x7fec0f01,0x00020020, 0x7dc41f00, 0x00020000, 0x7fec0f01, 0x00020020,
0x7fc81f00,0x00000040,0x7dc41f00,0x00000060, 0x7fc81f00, 0x00000040, 0x7dc41f00, 0x00000060,
0x7fec0f81,0x9001802f,0xfef88f00,0x1000e00f, 0x7fec0f81, 0x9001802f, 0xfef88f00, 0x1000e00f,
0xfedc8f00,0x00000420,0x7de40f00,0x80010040, 0xfedc8f00, 0x00000420, 0x7de40f00, 0x80010040,
0x7ec49f01,0x00001060,0xfec41f80,0x10024060, 0x7ec49f01, 0x00001060, 0xfec41f80, 0x10024060,
0xfed49f00,0x80020000,0xfe141f00,0x900c802f, 0xfed49f00, 0x80020000, 0xfe141f00, 0x900c802f,
0xfeac1f00,0x80000040,0xfec01f02,0x80020060, 0xfeac1f00, 0x80000040, 0xfec01f02, 0x80020060,
0x7cc41f81,0x90010060,0x0000003d,0x00000000, 0x7cc41f81, 0x90010060, 0x0000003d, 0x00000000,
0xfd001f00,0x900c6000,0xfea89f00,0x80010020, 0xfd001f00, 0x900c6000, 0xfea89f00, 0x80010020,
0xfec09f81,0x00020040,0x0000803f,0x0000003e, 0xfec09f81, 0x00020040, 0x0000803f, 0x0000003e,
0xfec41f81,0x00000020,0xfe041f80,0x00330000, 0xfec41f81, 0x00000020, 0xfe041f80, 0x00330000,
0x7fe01f00,0x80000040,0x7ce41f80,0x80000060, 0x7fe01f00, 0x80000040, 0x7ce41f80, 0x80000060,
0xfea81f00,0x80010000,0xfeac1f80,0x80010020, 0xfea81f00, 0x80010000, 0xfeac1f80, 0x80010020,
0x000000c1,0x00000000,0xfea01f00,0x00020040, 0x000000c1, 0x00000000, 0xfea01f00, 0x00020040,
0xfea41f80,0x00020060,0x00000041,0x00000000, 0xfea41f80, 0x00020060, 0x00000041, 0x00000000,
0x05c81f01,0x9000e00f,0x01cc9f81,0x9000e06f, 0x05c81f01, 0x9000e00f, 0x01cc9f81, 0x9000e06f,
0xfeac1f00,0x01004200,0xfea01f00,0x01044220, 0xfeac1f00, 0x01004200, 0xfea01f00, 0x01044220,
0xfeac9f00,0x01002240,0xfea09f00,0x01042260, 0xfeac9f00, 0x01002240, 0xfea09f00, 0x01042260,
0xfe8c1f80,0x01008600,0xacaa2a3e,0xaaaa2abe, 0xfe8c1f80, 0x01008600, 0xacaa2a3e, 0xaaaa2abe,
0x7f9c1f00,0x0100a200,0x7f801f00,0x01048220, 0x7f9c1f00, 0x0100a200, 0x7f801f00, 0x01048220,
0x7f901f80,0x0104a240,0x02080001,0x7000a00f, 0x7f901f80, 0x0104a240, 0x02080001, 0x7000a00f,
0x02000000,0x7000c04f,0x02048000,0x7000e06f, 0x02000000, 0x7000c04f, 0x02048000, 0x7000e06f,
0x01a81f80,0x9000e00f,0xd578e93d,0x00000000, 0x01a81f80, 0x9000e00f, 0xd578e93d, 0x00000000,
0x04a80001,0x1000c00f,0x04a48000,0x00000020, 0x04a80001, 0x1000c00f, 0x04a48000, 0x00000020,
0x04a00000,0x00000040,0xfe081f00,0xe00c0060, 0x04a00000, 0x00000040, 0xfe081f00, 0xe00c0060,
0xfe0c1f80,0xe00c0000,0x01a41f00,0x7f00620f, 0xfe0c1f80, 0xe00c0000, 0x01a41f00, 0x7f00620f,
0xfea89f00,0xfe0c822f,0xfea49f00,0xff00a24f, 0xfea89f00, 0xfe0c822f, 0xfea49f00, 0xff00a24f,
0x7d001f80,0xe00c0060,0xa245163f,0x0000803e, 0x7d001f80, 0xe00c0060, 0xa245163f, 0x0000803e,
0x7ea01f00,0xfe0ce20f,0x01a09f80,0xfe006a4f, 0x7ea01f00, 0xfe0ce20f, 0x01a09f80, 0xfe006a4f,
0x0000803e,0x8716993e,0xfe088001,0x9001c00f, 0x0000803e, 0x8716993e, 0xfe088001, 0x9001c00f,
0xfe488001,0x1002e44f,0xfea01f80,0x80000000, 0xfe488001, 0x1002e44f, 0xfea01f80, 0x80000000,
0xd578e93d,0x00000000,0x7ca41f00,0x00280000, 0xd578e93d, 0x00000000, 0x7ca41f00, 0x00280000,
0x7da89f00,0x00280020,0xff201f00,0x00280040, 0x7da89f00, 0x00280020, 0xff201f00, 0x00280040,
0xfd081f80,0x00280060,0x8716993e,0xa245163f, 0xfd081f80, 0x00280060, 0x8716993e, 0xa245163f,
0x00000080,0x00000000,0x7fc81f00,0x80060000, 0x00000080, 0x00000000, 0x7fc81f00, 0x80060000,
0xfec00f80,0x80060060,0xfec09f81,0xfb80634f, 0xfec00f80, 0x80060060, 0xfec09f81, 0xfb80634f,
0xfe888f00,0x7e886300,0xfea80f01,0x7f8c6320, 0xfe888f00, 0x7e886300, 0xfea80f01, 0x7f8c6320,
0xfee80f00,0x7d806340,0xfe680080,0x06846f60, 0xfee80f00, 0x7d806340, 0xfe680080, 0x06846f60,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x10000100,0x01101df0,0x00008010,0xecdfea0d, 0x10000100, 0x01101df0, 0x00008010, 0xecdfea0d,
0x10000200,0x03101df0,0x00002050,0xecdfea0d, 0x10000200, 0x03101df0, 0x00002050, 0xecdfea0d,
0x10000000,0x04101df0,0x00003071,0xecdfea0d, 0x10000000, 0x04101df0, 0x00003071, 0xecdfea0d,
0x10000200,0x02101df0,0x0000b070,0xecdfea0d, 0x10000200, 0x02101df0, 0x0000b070, 0xecdfea0d,
0x10000200,0x02101df0,0x00008010,0xecdfea0d, 0x10000200, 0x02101df0, 0x00008010, 0xecdfea0d,
0x10000100,0x00101df0,0x0000a051,0xecdfea0d, 0x10000100, 0x00101df0, 0x0000a051, 0xecdfea0d,
0x10000400,0x04101df0,0x00008010,0xecdfea0d, 0x10000400, 0x04101df0, 0x00008010, 0xecdfea0d,
0x10000500,0x05101df0,0x00000011,0xecdfea0d, 0x10000500, 0x05101df0, 0x00000011, 0xecdfea0d,
0x10000100,0x01101df0,0x00008010,0xecdfea0d, 0x10000100, 0x01101df0, 0x00008010, 0xecdfea0d,
0xfe2e963a,0x0269a9a3,0x38f88096,0x400cf48b 0xfe2e963a, 0x0269a9a3, 0x38f88096, 0x400cf48b
}; };
static const uint32_t cpPixelShaderRegs[] = { static const uint32_t cpPixelShaderRegs[] = {
0x00000007,0x00000002,0x04000101,0x00000000, 0x00000007, 0x00000002, 0x04000101, 0x00000000,
0x00000001,0x00000100,0x00000000,0x00000000, 0x00000001, 0x00000100, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x0000000f,0x00000001,0x00000010, 0x00000000, 0x0000000f, 0x00000001, 0x00000010,
0x00000000 0x00000000
}; };
FXAAShader * FXAAShader::shaderInstance = NULL; FXAAShader *FXAAShader::shaderInstance = NULL;
FXAAShader::FXAAShader() FXAAShader::FXAAShader()
: vertexShader(cuAttributeCount) { : vertexShader(cuAttributeCount) {
//! create pixel shader //! create pixel shader
pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs));
resolutionLocation = 0; resolutionLocation = 0;
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_resolution", GX2_SHADER_VAR_TYPE_FLOAT2, 1, resolutionLocation, -1 "unf_resolution", GX2_SHADER_VAR_TYPE_FLOAT2, 1, resolutionLocation, -1
}); });
samplerLocation = 0; samplerLocation = 0;
pixelShader.addSamplerVar((GX2SamplerVar) { pixelShader.addSamplerVar((GX2SamplerVar) {
"sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation
}); });
//! create vertex shader //! create vertex shader
@ -184,10 +184,10 @@ FXAAShader::FXAAShader()
positionLocation = 0; positionLocation = 0;
texCoordLocation = 1; texCoordLocation = 1;
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation
}); });
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation
}); });
//! setup attribute streams //! setup attribute streams
@ -198,22 +198,22 @@ FXAAShader::FXAAShader()
fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount());
//! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000 //! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000
posVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize); posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize);
texCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize); texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize);
//! position vertex structure and texture coordinate vertex structure //! position vertex structure and texture coordinate vertex structure
int32_t i = 0; int32_t i = 0;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize);
@ -230,11 +230,11 @@ FXAAShader::FXAAShader()
} }
FXAAShader::~FXAAShader() { FXAAShader::~FXAAShader() {
if(posVtxs) { if (posVtxs) {
free(posVtxs); free(posVtxs);
posVtxs = NULL; posVtxs = NULL;
} }
if(texCoords) { if (texCoords) {
free(texCoords); free(texCoords);
texCoords = NULL; texCoords = NULL;
} }

View File

@ -19,176 +19,176 @@
#include <gui/video/shaders/Shader3D.h> #include <gui/video/shaders/Shader3D.h>
static const uint32_t cpVertexShaderProgram[] = { static const uint32_t cpVertexShaderProgram[] = {
0x00000000,0x00008009,0x20000000,0x0000e4a1, 0x00000000, 0x00008009, 0x20000000, 0x0000e4a1,
0x00c00100,0x88048093,0x01c00300,0x98060014, 0x00c00100, 0x88048093, 0x01c00300, 0x98060014,
0x9a000000,0x000058a0,0x3c200200,0x88062094, 0x9a000000, 0x000058a0, 0x3c200200, 0x88062094,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x0765a101,0x9000e00f,0x0761a101,0x9000e02f, 0x0765a101, 0x9000e00f, 0x0761a101, 0x9000e02f,
0x01081f00,0x900ce040,0x01041f00,0x900ce060, 0x01081f00, 0x900ce040, 0x01041f00, 0x900ce060,
0x01001f80,0x900ce000,0x02001f00,0x900c6000, 0x01001f80, 0x900ce000, 0x02001f00, 0x900c6000,
0x02041f00,0x900c6020,0x076da101,0x9000e04f, 0x02041f00, 0x900c6020, 0x076da101, 0x9000e04f,
0x0769a181,0x9000e06f,0x0745a101,0x9000c00f, 0x0769a181, 0x9000e06f, 0x0745a101, 0x9000c00f,
0x0741a181,0x9000c02f,0x074da101,0x9000c04f, 0x0741a181, 0x9000c02f, 0x074da101, 0x9000c04f,
0x0749a181,0x9000c06f,0x0bc9a000,0x7f00e20f, 0x0749a181, 0x9000c06f, 0x0bc9a000, 0x7f00e20f,
0x0bc92080,0x7f04e22f,0x0bc9a001,0x7f08e24f, 0x0bc92080, 0x7f04e22f, 0x0bc9a001, 0x7f08e24f,
0x0bc92081,0x7f0ce26f,0x0725a101,0x9000a00f, 0x0bc92081, 0x7f0ce26f, 0x0725a101, 0x9000a00f,
0x0721a181,0x9000a02f,0x072da101,0x9000a04f, 0x0721a181, 0x9000a02f, 0x072da101, 0x9000a04f,
0x0729a181,0x9000a06f,0x0ac9a000,0x7e00c20f, 0x0729a181, 0x9000a06f, 0x0ac9a000, 0x7e00c20f,
0x0ac92080,0x7e04c22f,0x0ac9a001,0x7e08c24f, 0x0ac92080, 0x7e04c22f, 0x0ac9a001, 0x7e08c24f,
0x0ac92081,0x7e0cc26f,0x0ba5a000,0x7f00e20f, 0x0ac92081, 0x7e0cc26f, 0x0ba5a000, 0x7f00e20f,
0x0ba52080,0x7f04e22f,0x0ba5a001,0x7f08e24f, 0x0ba52080, 0x7f04e22f, 0x0ba5a001, 0x7f08e24f,
0x0ba52081,0x7f0ce26f,0x08eda000,0x9000800f, 0x0ba52081, 0x7f0ce26f, 0x08eda000, 0x9000800f,
0x08ed2080,0x9000802f,0x08eda001,0x9000804f, 0x08ed2080, 0x9000802f, 0x08eda001, 0x9000804f,
0x08ed2081,0x9000806f,0x09c9a000,0x7d00a20f, 0x08ed2081, 0x9000806f, 0x09c9a000, 0x7d00a20f,
0x09c92080,0x7d04a22f,0x09c9a001,0x7d08a24f, 0x09c92080, 0x7d04a22f, 0x09c9a001, 0x7d08a24f,
0x09c92081,0x7d0ca26f,0x0aa5a000,0x7e00c20f, 0x09c92081, 0x7d0ca26f, 0x0aa5a000, 0x7e00c20f,
0x0aa52080,0x7e04c22f,0x0aa5a001,0x7e08c24f, 0x0aa52080, 0x7e04c22f, 0x0aa5a001, 0x7e08c24f,
0x0aa52081,0x7e0cc26f,0x0b81a000,0x7f004200, 0x0aa52081, 0x7e0cc26f, 0x0b81a000, 0x7f004200,
0x0b812080,0x7f044220,0x0b81a001,0x7f082240, 0x0b812080, 0x7f044220, 0x0b81a001, 0x7f082240,
0x0b812081,0x7f0c0260,0x08c9a000,0x7c00820f, 0x0b812081, 0x7f0c0260, 0x08c9a000, 0x7c00820f,
0x08c92080,0x7c04822f,0x08c9a001,0x7c08824f, 0x08c92080, 0x7c04822f, 0x08c9a001, 0x7c08824f,
0x08c92081,0x7c0c826f,0x09a5a000,0x7d00a20f, 0x08c92081, 0x7c0c826f, 0x09a5a000, 0x7d00a20f,
0x09a52080,0x7d04a22f,0x09a5a001,0x7d08a24f, 0x09a52080, 0x7d04a22f, 0x09a5a001, 0x7d08a24f,
0x09a52081,0x7d0ca26f,0x0a81a000,0x7e000200, 0x09a52081, 0x7d0ca26f, 0x0a81a000, 0x7e000200,
0x0a812080,0x7e040220,0x0a81a001,0x7e080240, 0x0a812080, 0x7e040220, 0x0a81a001, 0x7e080240,
0x0a812081,0x7e0c2260,0x0240a001,0x9000c00f, 0x0a812081, 0x7e0c2260, 0x0240a001, 0x9000c00f,
0x0244a001,0x9000c02f,0x0148a001,0x9000c04f, 0x0244a001, 0x9000c02f, 0x0148a001, 0x9000c04f,
0x004ca001,0x9000c06f,0x0264a081,0x9000e02f, 0x004ca001, 0x9000c06f, 0x0264a081, 0x9000e02f,
0x0260a001,0x9000e00f,0x0224a001,0x90002020, 0x0260a001, 0x9000e00f, 0x0224a001, 0x90002020,
0x0168a001,0x9000e04f,0x006ca001,0x9000e06f, 0x0168a001, 0x9000e04f, 0x006ca001, 0x9000e06f,
0x0220a081,0x90002000,0x08a5a000,0x7c00820f, 0x0220a081, 0x90002000, 0x08a5a000, 0x7c00820f,
0x08a52080,0x7c04822f,0x08a5a001,0x7c08824f, 0x08a52080, 0x7c04822f, 0x08a5a001, 0x7c08824f,
0x08a52081,0x7c0c826f,0x0981a000,0x7d008200, 0x08a52081, 0x7c0c826f, 0x0981a000, 0x7d008200,
0x09812080,0x7d048220,0x0981a001,0x7d084240, 0x09812080, 0x7d048220, 0x0981a001, 0x7d084240,
0x09812081,0x7d0c4260,0x02090000,0x7e00c20f, 0x09812081, 0x7d0c4260, 0x02090000, 0x7e00c20f,
0x02098000,0x7e04c22f,0x0128a001,0x9000a04f, 0x02098000, 0x7e04c22f, 0x0128a001, 0x9000a04f,
0x002ca001,0x9000c06f,0x02298081,0x7e0caa6f, 0x002ca001, 0x9000c06f, 0x02298081, 0x7e0caa6f,
0x03090000,0x7f00e20f,0x03098000,0x7f04e22f, 0x03090000, 0x7f00e20f, 0x03098000, 0x7f04e22f,
0x02090001,0x7e08f64f,0x03298001,0x7f0ce26f, 0x02090001, 0x7e08f64f, 0x03298001, 0x7f0ce26f,
0x03090081,0x7f08ca4f,0x0881a000,0x7c00c200, 0x03090081, 0x7f08ca4f, 0x0881a000, 0x7c00c200,
0x08812080,0x7c04e220,0x0881a001,0x7c08a240, 0x08812080, 0x7c04e220, 0x0881a001, 0x7c08a240,
0x08812081,0x7c0c8260,0x0200a001,0x9000800f, 0x08812081, 0x7c0c8260, 0x0200a001, 0x9000800f,
0x0204a001,0x9000802f,0x0108a001,0x9000804f, 0x0204a001, 0x9000802f, 0x0108a001, 0x9000804f,
0x000ca001,0x9000806f,0x01098080,0x0104aa2f, 0x000ca001, 0x9000806f, 0x01098080, 0x0104aa2f,
0x01090000,0x0100a20f,0x02858000,0x7e04c22f, 0x01090000, 0x0100a20f, 0x02858000, 0x7e04c22f,
0x01090001,0x7d08a24f,0x01298081,0x7e0cc26f, 0x01090001, 0x7d08a24f, 0x01298081, 0x7e0cc26f,
0x02850000,0x7e00f60f,0x03858000,0x7f04622f, 0x02850000, 0x7e00f60f, 0x03858000, 0x7f04622f,
0x02450001,0x7f08e24f,0x02458001,0x7d0ca26f, 0x02450001, 0x7f08e24f, 0x02458001, 0x7d0ca26f,
0x03850080,0x7f00ca0f,0x00090000,0x7c004200, 0x03850080, 0x7f00ca0f, 0x00090000, 0x7c004200,
0x00098000,0x7c04b220,0x03450001,0x7e08c24f, 0x00098000, 0x7c04b220, 0x03450001, 0x7e08c24f,
0x03458001,0x7f0ce26f,0x03e18080,0xfe042620, 0x03458001, 0x7f0ce26f, 0x03e18080, 0xfe042620,
0x01850000,0x7d00a200,0x01858000,0x7d04622f, 0x01850000, 0x7d00a200, 0x01858000, 0x7d04622f,
0x00090001,0x7c086240,0x00298081,0x7c0c0260, 0x00090001, 0x7c086240, 0x00298081, 0x7c0c0260,
0x02c10000,0x7f000200,0x02e18000,0x7e040620, 0x02c10000, 0x7f000200, 0x02e18000, 0x7e040620,
0x01450001,0x7d088240,0x01458001,0x7e0c6260, 0x01450001, 0x7d088240, 0x01458001, 0x7e0c6260,
0x01e18080,0xfe04c620,0x03c10000,0x7e002200, 0x01e18080, 0xfe04c620, 0x03c10000, 0x7e002200,
0x03818001,0x7f0c4220,0x02a10001,0x7f081640, 0x03818001, 0x7f0c4220, 0x02a10001, 0x7f081640,
0x02818001,0x7d0c3660,0x03a10081,0x7e082a40, 0x02818001, 0x7d0c3660, 0x03a10081, 0x7e082a40,
0x07080000,0x0100c20f,0x07088000,0x0104622f, 0x07080000, 0x0100c20f, 0x07088000, 0x0104622f,
0x00458001,0x000cea4f,0x07288081,0x0204f66f, 0x00458001, 0x000cea4f, 0x07288081, 0x0204f66f,
0x00850000,0x0200620f,0x00858000,0x05046a2f, 0x00850000, 0x0200620f, 0x00858000, 0x05046a2f,
0x07080001,0x0108c24f,0x01818001,0x030c726f, 0x07080001, 0x0108c24f, 0x01818001, 0x030c726f,
0x07cc8080,0xfe04c22f,0x01c10000,0x0500660f, 0x07cc8080, 0xfe04c22f, 0x01c10000, 0x0500660f,
0x00e18000,0xfe04622f,0x00450001,0x0308624f, 0x00e18000, 0xfe04622f, 0x00450001, 0x0308624f,
0x07cc9f01,0x7f0ce26f,0x00c10080,0xfe00e60f, 0x07cc9f01, 0x7f0ce26f, 0x00c10080, 0xfe00e60f,
0x07cc1f00,0x7e00660f,0x00a10001,0xfe08c22f, 0x07cc1f00, 0x7e00660f, 0x00a10001, 0xfe08c22f,
0x01a10001,0x0408624f,0x00818001,0x7f086a6f, 0x01a10001, 0x0408624f, 0x00818001, 0x7f086a6f,
0x07c09f80,0x7e048200,0x07e00f00,0xfe008220, 0x07c09f80, 0x7e048200, 0x07e00f00, 0xfe008220,
0x07cc1f01,0x7e086a4f,0x07c09f81,0x7f0c8240, 0x07cc1f01, 0x7e086a4f, 0x07c09f81, 0x7f0c8240,
0x07c08f80,0xfe088260,0x2c34800d,0xe3b4f15e, 0x07c08f80, 0xfe088260, 0x2c34800d, 0xe3b4f15e,
0x7642ed30,0x7408600d 0x7642ed30, 0x7408600d
}; };
static const uint32_t cpVertexShaderRegs[] = { static const uint32_t cpVertexShaderRegs[] = {
0x00000108,0x00000000,0x00000002,0x00000001, 0x00000108, 0x00000000, 0x00000002, 0x00000001,
0xffff0001,0xffffffff,0xffffffff,0xffffffff, 0xffff0001, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0xffffffff,0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0x00000000,0xfffffffc, 0xffffffff, 0xffffffff, 0x00000000, 0xfffffffc,
0x00000002,0x00000000,0x00000001,0x000000ff, 0x00000002, 0x00000000, 0x00000001, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x00000000,0x0000000e,0x00000010 0x000000ff, 0x00000000, 0x0000000e, 0x00000010
}; };
static const uint32_t cPixelShaderProgram[] = { static const uint32_t cPixelShaderProgram[] = {
0x20000000,0x000008a4,0x03000000,0x01004085, 0x20000000, 0x000008a4, 0x03000000, 0x01004085,
0x23000000,0x000044a8,0x35000000,0x000000a4, 0x23000000, 0x000044a8, 0x35000000, 0x000000a4,
0x06000000,0x01004085,0x36000000,0x00002ca8, 0x06000000, 0x01004085, 0x36000000, 0x00002ca8,
0x50000000,0x0000c080,0x42000000,0x00001ca0, 0x50000000, 0x0000c080, 0x42000000, 0x00001ca0,
0x00800000,0x88062094,0x00000000,0x00000000, 0x00800000, 0x88062094, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xfd001f80,0x900c0060,0x0000803f,0x00000000, 0xfd001f80, 0x900c0060, 0x0000803f, 0x00000000,
0x02011f80,0x8c110000,0xf8402000,0x9006a00f, 0x02011f80, 0x8c110000, 0xf8402000, 0x9006a00f,
0x02552001,0x00000020,0x01248082,0x80020060, 0x02552001, 0x00000020, 0x01248082, 0x80020060,
0xfe3c1f00,0x1000e04f,0xfe041f80,0x1033c00f, 0xfe3c1f00, 0x1000e04f, 0xfe041f80, 0x1033c00f,
0xfe482081,0x80060020,0xfee40f81,0x0289e30f, 0xfe482081, 0x80060020, 0xfee40f81, 0x0289e30f,
0x02c51f80,0x80060060,0xfeec0f80,0x0285634f, 0x02c51f80, 0x80060060, 0xfeec0f80, 0x0285634f,
0xfec80f80,0x80000060,0xfe4ca081,0x9000e04f, 0xfec80f80, 0x80000060, 0xfe4ca081, 0x9000e04f,
0xfe281f00,0x80060000,0xf8c01f81,0x9006e02f, 0xfe281f00, 0x80060000, 0xf8c01f81, 0x9006e02f,
0xfee00f81,0xfd80636f,0x0000803f,0x00000000, 0xfee00f81, 0xfd80636f, 0x0000803f, 0x00000000,
0x7fc49f81,0xf880e34f,0xfe381f80,0x00000000, 0x7fc49f81, 0xf880e34f, 0xfe381f80, 0x00000000,
0x7de00f81,0xfe800360,0x01011f80,0x8c100000, 0x7de00f81, 0xfe800360, 0x01011f80, 0x8c100000,
0x00a81f00,0x9000e02f,0x00000082,0x80020060, 0x00a81f00, 0x9000e02f, 0x00000082, 0x80020060,
0x00002040,0x00000000,0xfeac9f80,0xfd00624f, 0x00002040, 0x00000000, 0xfeac9f80, 0xfd00624f,
0x3333333f,0x00002040,0xfee88f80,0x0101620f, 0x3333333f, 0x00002040, 0xfee88f80, 0x0101620f,
0x00cc1f80,0x9000e06f,0xf8c09f01,0x80060020, 0x00cc1f80, 0x9000e06f, 0xf8c09f01, 0x80060020,
0xfe2c1f80,0x9006e04f,0xfee48f81,0xf880630f, 0xfe2c1f80, 0x9006e04f, 0xfee48f81, 0xf880630f,
0x7fc81f80,0xfd800360,0x0000803f,0x00000000, 0x7fc81f80, 0xfd800360, 0x0000803f, 0x00000000,
0x000ca001,0x80000000,0x00091f00,0x800c0020, 0x000ca001, 0x80000000, 0x00091f00, 0x800c0020,
0x00051f00,0x800c0040,0x00011f80,0x800c0060, 0x00051f00, 0x800c0040, 0x00011f80, 0x800c0060,
0xfe2c0000,0x90002000,0xfe288000,0x90002020, 0xfe2c0000, 0x90002000, 0xfe288000, 0x90002020,
0xfe240001,0x90002040,0xfe208081,0x90002060, 0xfe240001, 0x90002040, 0xfe208081, 0x90002060,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x10000100,0x01100df0,0x00008010,0xecdfea0d, 0x10000100, 0x01100df0, 0x00008010, 0xecdfea0d,
0x99720984,0x041cab0d,0xa28a9ccd,0x95d199a5 0x99720984, 0x041cab0d, 0xa28a9ccd, 0x95d199a5
}; };
static const uint32_t cPixelShaderRegs[] = { static const uint32_t cPixelShaderRegs[] = {
0x00000102,0x00000002,0x14000002,0x00000000, 0x00000102, 0x00000002, 0x14000002, 0x00000000,
0x00000002,0x00000100,0x00000101,0x00000000, 0x00000002, 0x00000100, 0x00000101, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x0000000f,0x00000001,0x00000010, 0x00000000, 0x0000000f, 0x00000001, 0x00000010,
0x00000000 0x00000000
}; };
Shader3D * Shader3D::shaderInstance = NULL; Shader3D *Shader3D::shaderInstance = NULL;
Shader3D::Shader3D() Shader3D::Shader3D()
: vertexShader(cuAttributeCount) { : vertexShader(cuAttributeCount) {
//! create pixel shader //! create pixel shader
pixelShader.setProgram(cPixelShaderProgram, sizeof(cPixelShaderProgram), cPixelShaderRegs, sizeof(cPixelShaderRegs)); pixelShader.setProgram(cPixelShaderProgram, sizeof(cPixelShaderProgram), cPixelShaderRegs, sizeof(cPixelShaderRegs));
@ -196,18 +196,18 @@ Shader3D::Shader3D()
fadeDistanceLocation = 4; fadeDistanceLocation = 4;
fadeOutLocation = 8; fadeOutLocation = 8;
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1
}); });
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_fade_distance", GX2_SHADER_VAR_TYPE_FLOAT, 1, fadeDistanceLocation, -1 "unf_fade_distance", GX2_SHADER_VAR_TYPE_FLOAT, 1, fadeDistanceLocation, -1
}); });
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_fade_out_alpha", GX2_SHADER_VAR_TYPE_FLOAT4, 1, fadeOutLocation, -1 "unf_fade_out_alpha", GX2_SHADER_VAR_TYPE_FLOAT4, 1, fadeOutLocation, -1
}); });
samplerLocation = 0; samplerLocation = 0;
pixelShader.addSamplerVar((GX2SamplerVar) { pixelShader.addSamplerVar((GX2SamplerVar) {
"sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation
}); });
//! create vertex shader //! create vertex shader
vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs));
@ -216,22 +216,22 @@ Shader3D::Shader3D()
projectionMatrixLocation = 16; projectionMatrixLocation = 16;
viewMatrixLocation = 32; viewMatrixLocation = 32;
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"modelMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, modelMatrixLocation, -1 "modelMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, modelMatrixLocation, -1
}); });
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"viewMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, projectionMatrixLocation, -1 "viewMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, projectionMatrixLocation, -1
}); });
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"projectionMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, viewMatrixLocation, -1 "projectionMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, viewMatrixLocation, -1
}); });
positionLocation = 0; positionLocation = 0;
texCoordLocation = 1; texCoordLocation = 1;
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_position", GX2_SHADER_VAR_TYPE_FLOAT4, 0, positionLocation "attr_position", GX2_SHADER_VAR_TYPE_FLOAT4, 0, positionLocation
}); });
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation
}); });
//! setup attribute streams //! setup attribute streams
@ -243,22 +243,22 @@ Shader3D::Shader3D()
//! initialize default quad texture vertexes as those are very commonly used //! initialize default quad texture vertexes as those are very commonly used
//! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000 //! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000
posVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize); posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize);
texCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize); texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize);
//! position vertex structure and texture coordinate vertex structure //! position vertex structure and texture coordinate vertex structure
int32_t i = 0; int32_t i = 0;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize);
@ -275,11 +275,11 @@ Shader3D::Shader3D()
} }
Shader3D::~Shader3D() { Shader3D::~Shader3D() {
if(posVtxs) { if (posVtxs) {
free(posVtxs); free(posVtxs);
posVtxs = NULL; posVtxs = NULL;
} }
if(texCoords) { if (texCoords) {
free(texCoords); free(texCoords);
texCoords = NULL; texCoords = NULL;
} }

View File

@ -19,269 +19,269 @@
#include <gui/video/shaders/ShaderFractalColor.h> #include <gui/video/shaders/ShaderFractalColor.h>
static const uint32_t cpVertexShaderProgram[] = { static const uint32_t cpVertexShaderProgram[] = {
0x00000000,0x00008009,0x20000000,0x0000eca1, 0x00000000, 0x00008009, 0x20000000, 0x0000eca1,
0x00c00000,0x88068093,0x01400200,0x9a048013, 0x00c00000, 0x88068093, 0x01400200, 0x9a048013,
0x9c000000,0x000044a0,0x3c200000,0x88060094, 0x9c000000, 0x000044a0, 0x3c200000, 0x88060094,
0x02400000,0x88062014,0x00000000,0x00000000, 0x02400000, 0x88062014, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x0765a101,0x9000e00f,0x0761a101,0x9000e02f, 0x0765a101, 0x9000e00f, 0x0761a101, 0x9000e02f,
0x03001f00,0x900c8040,0x03041f80,0x900c8060, 0x03001f00, 0x900c8040, 0x03041f80, 0x900c8060,
0x076da101,0x9000e04f,0x0769a181,0x9000e06f, 0x076da101, 0x9000e04f, 0x0769a181, 0x9000e06f,
0x0745a101,0x9000c00f,0x0741a181,0x9000c02f, 0x0745a101, 0x9000c00f, 0x0741a181, 0x9000c02f,
0x074da101,0x9000c04f,0x0749a181,0x9000c06f, 0x074da101, 0x9000c04f, 0x0749a181, 0x9000c06f,
0x0bc9a000,0x7f00e20f,0x0bc92080,0x7f04e22f, 0x0bc9a000, 0x7f00e20f, 0x0bc92080, 0x7f04e22f,
0x0bc9a001,0x7f08e24f,0x0bc92081,0x7f0ce26f, 0x0bc9a001, 0x7f08e24f, 0x0bc92081, 0x7f0ce26f,
0x0725a101,0x9000a00f,0x0721a181,0x9000a02f, 0x0725a101, 0x9000a00f, 0x0721a181, 0x9000a02f,
0x072da101,0x9000a04f,0x0729a181,0x9000a06f, 0x072da101, 0x9000a04f, 0x0729a181, 0x9000a06f,
0x0ac9a000,0x7e00c20f,0x0ac92080,0x7e04c22f, 0x0ac9a000, 0x7e00c20f, 0x0ac92080, 0x7e04c22f,
0x0ac9a001,0x7e08c24f,0x0ac92081,0x7e0cc26f, 0x0ac9a001, 0x7e08c24f, 0x0ac92081, 0x7e0cc26f,
0x0ba5a000,0x7f00e20f,0x0ba52080,0x7f04e22f, 0x0ba5a000, 0x7f00e20f, 0x0ba52080, 0x7f04e22f,
0x0ba5a001,0x7f08e24f,0x0ba52081,0x7f0ce26f, 0x0ba5a001, 0x7f08e24f, 0x0ba52081, 0x7f0ce26f,
0x08eda000,0x9000800f,0x08ed2080,0x9000802f, 0x08eda000, 0x9000800f, 0x08ed2080, 0x9000802f,
0x08eda001,0x9000804f,0x08ed2081,0x9000806f, 0x08eda001, 0x9000804f, 0x08ed2081, 0x9000806f,
0x09c9a000,0x7d00a20f,0x09c92080,0x7d04a22f, 0x09c9a000, 0x7d00a20f, 0x09c92080, 0x7d04a22f,
0x09c9a001,0x7d08a24f,0x09c92081,0x7d0ca26f, 0x09c9a001, 0x7d08a24f, 0x09c92081, 0x7d0ca26f,
0x0aa5a000,0x7e00c20f,0x0aa52080,0x7e04c22f, 0x0aa5a000, 0x7e00c20f, 0x0aa52080, 0x7e04c22f,
0x0aa5a001,0x7e08c24f,0x0aa52081,0x7e0cc26f, 0x0aa5a001, 0x7e08c24f, 0x0aa52081, 0x7e0cc26f,
0x0b81a000,0x7f006200,0x0b812080,0x7f046220, 0x0b81a000, 0x7f006200, 0x0b812080, 0x7f046220,
0x0b81a001,0x7f080240,0x0b812081,0x7f0c0260, 0x0b81a001, 0x7f080240, 0x0b812081, 0x7f0c0260,
0x08c9a000,0x7c00820f,0x08c92080,0x7c04822f, 0x08c9a000, 0x7c00820f, 0x08c92080, 0x7c04822f,
0x08c9a001,0x7c08824f,0x08c92081,0x7c0c826f, 0x08c9a001, 0x7c08824f, 0x08c92081, 0x7c0c826f,
0x09a5a000,0x7d00a20f,0x09a52080,0x7d04a22f, 0x09a5a000, 0x7d00a20f, 0x09a52080, 0x7d04a22f,
0x09a5a001,0x7d08a24f,0x09a52081,0x7d0ca26f, 0x09a5a001, 0x7d08a24f, 0x09a52081, 0x7d0ca26f,
0x0a81a000,0x7e008200,0x0a812080,0x7e048220, 0x0a81a000, 0x7e008200, 0x0a812080, 0x7e048220,
0x0a81a001,0x7e086240,0x0a812081,0x7e0c4260, 0x0a81a001, 0x7e086240, 0x0a812081, 0x7e0c4260,
0x0340a001,0x9000c00f,0x0344a001,0x9000c02f, 0x0340a001, 0x9000c00f, 0x0344a001, 0x9000c02f,
0x0048a001,0x9000c04f,0x004ca001,0x9000c06f, 0x0048a001, 0x9000c04f, 0x004ca001, 0x9000c06f,
0x0364a081,0x9000e02f,0x0360a001,0x9000e00f, 0x0364a081, 0x9000e02f, 0x0360a001, 0x9000e00f,
0x0324a001,0x90000020,0x0068a001,0x9000e04f, 0x0324a001, 0x90000020, 0x0068a001, 0x9000e04f,
0x006ca001,0x9000e06f,0x0320a081,0x90000000, 0x006ca001, 0x9000e06f, 0x0320a081, 0x90000000,
0x08a5a000,0x7c00820f,0x08a52080,0x7c04822f, 0x08a5a000, 0x7c00820f, 0x08a52080, 0x7c04822f,
0x08a5a001,0x7c08824f,0x08a52081,0x7c0c826f, 0x08a5a001, 0x7c08824f, 0x08a52081, 0x7c0c826f,
0x0981a000,0x7d00a200,0x09812080,0x7d04a220, 0x0981a000, 0x7d00a200, 0x09812080, 0x7d04a220,
0x0981a001,0x7d08a240,0x09812081,0x7d0c6260, 0x0981a001, 0x7d08a240, 0x09812081, 0x7d0c6260,
0x02890000,0x7e00c20f,0x02898000,0x7e04c22f, 0x02890000, 0x7e00c20f, 0x02898000, 0x7e04c22f,
0x0028a001,0x9000a04f,0x002ca001,0x9000c06f, 0x0028a001, 0x9000a04f, 0x002ca001, 0x9000c06f,
0x02498081,0x7e0caa6f,0x03890000,0x7f00e20f, 0x02498081, 0x7e0caa6f, 0x03890000, 0x7f00e20f,
0x03898000,0x7f04e22f,0x02690001,0x7e08f64f, 0x03898000, 0x7f04e22f, 0x02690001, 0x7e08f64f,
0x03498001,0x7f0ce26f,0x03690081,0x7f08ca4f, 0x03498001, 0x7f0ce26f, 0x03690081, 0x7f08ca4f,
0x0881a000,0x7c00c200,0x08812080,0x7c04c220, 0x0881a000, 0x7c00c200, 0x08812080, 0x7c04c220,
0x0881a001,0x7c08e240,0x08812081,0x7c0ca260, 0x0881a001, 0x7c08e240, 0x08812081, 0x7c0ca260,
0x0300a001,0x9000800f,0x0304a001,0x9000802f, 0x0300a001, 0x9000800f, 0x0304a001, 0x9000802f,
0x0008a001,0x9000804f,0x000ca001,0x9000806f, 0x0008a001, 0x9000804f, 0x000ca001, 0x9000806f,
0x01898080,0x0004aa2f,0x01890000,0x0000a20f, 0x01898080, 0x0004aa2f, 0x01890000, 0x0000a20f,
0x02a58000,0x7e04c22f,0x01690001,0x7d08a24f, 0x02a58000, 0x7e04c22f, 0x01690001, 0x7d08a24f,
0x01498081,0x7e0cc26f,0x02a50000,0x7e00f60f, 0x01498081, 0x7e0cc26f, 0x02a50000, 0x7e00f60f,
0x03a58000,0x7f04622f,0x02a50001,0x7f08e24f, 0x03a58000, 0x7f04622f, 0x02a50001, 0x7f08e24f,
0x02658001,0x7d0ca26f,0x03a50080,0x7f00ca0f, 0x02658001, 0x7d0ca26f, 0x03a50080, 0x7f00ca0f,
0x00890000,0x7c00820f,0x00898000,0x7c049220, 0x00890000, 0x7c00820f, 0x00898000, 0x7c049220,
0x03a50001,0x7e08c24f,0x03658001,0x7f0ce26f, 0x03a50001, 0x7e08c24f, 0x03658001, 0x7f0ce26f,
0x03c18080,0xfe04862f,0x01a50000,0x7d008200, 0x03c18080, 0xfe04862f, 0x01a50000, 0x7d008200,
0x01a58000,0x7d04622f,0x00690001,0x7c086240, 0x01a58000, 0x7d04622f, 0x00690001, 0x7c086240,
0x00498081,0x7c0c4260,0x02c10000,0x7f00e20f, 0x00498081, 0x7c0c4260, 0x02c10000, 0x7f00e20f,
0x02c18000,0x7e04c62f,0x01a50001,0x7d080240, 0x02c18000, 0x7e04c62f, 0x01a50001, 0x7d080240,
0x01658001,0x7e0c0260,0x01c18080,0xfe040620, 0x01658001, 0x7e0c0260, 0x01c18080, 0xfe040620,
0x03c10000,0x7e00620f,0x03a18001,0x7f0c622f, 0x03c10000, 0x7e00620f, 0x03a18001, 0x7f0c622f,
0x02e10001,0x7f08764f,0x02a18001,0x7d0c766f, 0x02e10001, 0x7f08764f, 0x02a18001, 0x7d0c766f,
0x03e10081,0x7e084a0f,0x02e80f00,0xfe000e00, 0x03e10081, 0x7e084a0f, 0x02e80f00, 0xfe000e00,
0x02c88f00,0x7c046220,0x02c81f01,0xff00c240, 0x02c88f00, 0x7c046220, 0x02c81f01, 0xff00c240,
0x02c89f01,0xfe04c260,0x00a50080,0x7c00aa00, 0x02c89f01, 0xfe04c260, 0x00a50080, 0x7c00aa00,
0x01c10000,0x0400760f,0x00a58000,0x0404622f, 0x01c10000, 0x0400760f, 0x00a58000, 0x0404622f,
0x00a50001,0x0308e24f,0x00658001,0x020c626f, 0x00a50001, 0x0308e24f, 0x00658001, 0x020c626f,
0x00c10080,0x0500ea0f,0x02c41f00,0x0000620f, 0x00c10080, 0x0500ea0f, 0x02c41f00, 0x0000620f,
0x00c18000,0xfe04c22f,0x01e10001,0x0008624f, 0x00c18000, 0xfe04c22f, 0x01e10001, 0x0008624f,
0x01a18001,0x000c666f,0x00a18081,0xfe0ce66f, 0x01a18001, 0x000c666f, 0x00a18081, 0xfe0ce66f,
0x00e10001,0x7f08620f,0x02048000,0x03046a2f, 0x00e10001, 0x7f08620f, 0x02048000, 0x03046a2f,
0x02c41f01,0x06086a4f,0x02c49f01,0x060c6a6f, 0x02c41f01, 0x06086a4f, 0x02c49f01, 0x060c6a6f,
0x02e00f80,0xfe000220,0x02c08f00,0xfe040200, 0x02e00f80, 0xfe000220, 0x02c08f00, 0xfe040200,
0x02e08f01,0xfe0c0240,0x02c01f80,0xfe080260, 0x02e08f01, 0xfe0c0240, 0x02c01f80, 0xfe080260,
0x8aa480ad,0x2bfc5ca6,0xb5e05b5b,0xd48dc71c 0x8aa480ad, 0x2bfc5ca6, 0xb5e05b5b, 0xd48dc71c
}; };
static const uint32_t cpVertexShaderRegs[] = { static const uint32_t cpVertexShaderRegs[] = {
0x00000108,0x00000000,0x00000004,0x00000001, 0x00000108, 0x00000000, 0x00000004, 0x00000001,
0xff000201,0xffffffff,0xffffffff,0xffffffff, 0xff000201, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0xffffffff,0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0x00000000,0xfffffff8, 0xffffffff, 0xffffffff, 0x00000000, 0xfffffff8,
0x00000003,0x00000001,0x00000000,0x00000002, 0x00000003, 0x00000001, 0x00000000, 0x00000002,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x00000000,0x0000000e,0x00000010 0x000000ff, 0x00000000, 0x0000000e, 0x00000010
}; };
static const uint32_t cpPixelShaderProgram[] = { static const uint32_t cpPixelShaderProgram[] = {
0x20000000,0x000008a4,0x04000000,0x01004085, 0x20000000, 0x000008a4, 0x04000000, 0x01004085,
0x23000000,0x0000eca1,0x9f000000,0x0000e0a8, 0x23000000, 0x0000eca1, 0x9f000000, 0x0000e0a8,
0xd8000000,0x000000a4,0x07000000,0x01004085, 0xd8000000, 0x000000a4, 0x07000000, 0x01004085,
0xd9000000,0x000048a8,0xec000000,0x000000a4, 0xd9000000, 0x000048a8, 0xec000000, 0x000000a4,
0x0a000000,0x01004085,0xed000000,0x000050a8, 0x0a000000, 0x01004085, 0xed000000, 0x000050a8,
0x02010000,0x000030a0,0x00000000,0x88062094, 0x02010000, 0x000030a0, 0x00000000, 0x88062094,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xfd001f80,0x900c0060,0x0000803f,0x00000000, 0xfd001f80, 0x900c0060, 0x0000803f, 0x00000000,
0x03011f80,0x8c210000,0xfd001f00,0x900c0000, 0x03011f80, 0x8c210000, 0xfd001f00, 0x900c0000,
0xfd001f00,0x900ca02f,0x00000002,0x80020040, 0xfd001f00, 0x900ca02f, 0x00000002, 0x80020040,
0x00048002,0x80020060,0xf8001f80,0x900cc04f, 0x00048002, 0x80020060, 0xf8001f80, 0x900cc04f,
0x0000803f,0x00000000,0xfea81f00,0x9000e00f, 0x0000803f, 0x00000000, 0xfea81f00, 0x9000e00f,
0xfeac1f00,0x9000e02f,0xf8001f00,0x900c804f, 0xfeac1f00, 0x9000e02f, 0xf8001f00, 0x900c804f,
0xf8001f80,0x900ca06f,0x00000040,0x00000000, 0xf8001f80, 0x900ca06f, 0x00000040, 0x00000000,
0xfea01f00,0x00280000,0xfea41f00,0x00280020, 0xfea01f00, 0x00280000, 0xfea41f00, 0x00280020,
0xfe041f00,0x00280040,0xfd041f80,0x00280060, 0xfe041f00, 0x00280040, 0xfd041f80, 0x00280060,
0xaf67bb3e,0x00000080,0x7fc41f00,0x00000000, 0xaf67bb3e, 0x00000080, 0x7fc41f00, 0x00000000,
0x7fc01f80,0x00000020,0xfe041f00,0x100ac00f, 0x7fc01f80, 0x00000020, 0xfe041f00, 0x100ac00f,
0xfe001f80,0x100ac02f,0xfea01f00,0x00280000, 0xfe001f80, 0x100ac02f, 0xfea01f00, 0x00280000,
0xfea41f00,0x00280020,0xfe041f00,0x00280040, 0xfea41f00, 0x00280020, 0xfe041f00, 0x00280040,
0xfd041f00,0x1028e06f,0x7fc01f82,0x00000000, 0xfd041f00, 0x1028e06f, 0x7fc01f82, 0x00000000,
0x8c65583e,0x00000080,0x7ea41f00,0x80000000, 0x8c65583e, 0x00000080, 0x7ea41f00, 0x80000000,
0x7ea01f00,0x80000020,0xfee01f00,0x10006040, 0x7ea01f00, 0x80000020, 0xfee01f00, 0x10006040,
0x7fc48f82,0x00000860,0xa7c4623b,0x00000000, 0x7fc48f82, 0x00000860, 0xa7c4623b, 0x00000000,
0xfea81f00,0x1000e00f,0x7fcc9f01,0x10006020, 0xfea81f00, 0x1000e00f, 0x7fcc9f01, 0x10006020,
0xfe001f00,0x000a0040,0xfe041f00,0x000a0060, 0xfe001f00, 0x000a0040, 0xfe041f00, 0x000a0060,
0xfea89f80,0x10008040,0x8c65583e,0x3acd13bf, 0xfea89f80, 0x10008040, 0x8c65583e, 0x3acd13bf,
0xfeb81f00,0x7e04c20f,0xfebc1f00,0x7e00822f, 0xfeb81f00, 0x7e04c20f, 0xfebc1f00, 0x7e00822f,
0x03c89f00,0x80060040,0xfea49f00,0x1000e06f, 0x03c89f00, 0x80060040, 0xfea49f00, 0x1000e06f,
0xfea41f81,0x10006060,0x00809043,0x8c65583e, 0xfea41f81, 0x10006060, 0x00809043, 0x8c65583e,
0x3acd13bf,0x00000000,0xfea81f00,0xf880a30f, 0x3acd13bf, 0x00000000, 0xfea81f00, 0xf880a30f,
0xfe001f00,0x900ca02f,0x7dc41f00,0x1000e04f, 0xfe001f00, 0x900ca02f, 0x7dc41f00, 0x1000e04f,
0xfe081f00,0xfd80636f,0x04081f80,0x900c800f, 0xfe081f00, 0xfd80636f, 0x04081f80, 0x900c800f,
0x0000803f,0x00000000,0xfea81f00,0xf900620f, 0x0000803f, 0x00000000, 0xfea81f00, 0xf900620f,
0xfea41f00,0xf900622f,0xfe0c1f00,0x900ca04f, 0xfea41f00, 0xf900622f, 0xfe0c1f00, 0x900ca04f,
0xfec00f00,0x1000c46f,0xfefc0f80,0x10006000, 0xfec00f00, 0x1000c46f, 0xfefc0f80, 0x10006000,
0x00000842,0x00000000,0xfeac1f00,0xf900620f, 0x00000842, 0x00000000, 0xfeac1f00, 0xf900620f,
0x7fc81f00,0x9000c02f,0x7dc49f00,0x9000e04f, 0x7fc81f00, 0x9000c02f, 0x7dc49f00, 0x9000e04f,
0x7df08f01,0x10008060,0x030c1f80,0x900ca02f, 0x7df08f01, 0x10008060, 0x030c1f80, 0x900ca02f,
0x00000842,0x00000000,0xfea41f00,0x80000000, 0x00000842, 0x00000000, 0xfea41f00, 0x80000000,
0x7ecc1f00,0x9000e02f,0x7e688000,0x80000040, 0x7ecc1f00, 0x9000e02f, 0x7e688000, 0x80000040,
0xfea81f00,0x80000060,0x7d6c8081,0x80000000, 0xfea81f00, 0x80000060, 0x7d6c8081, 0x80000000,
0xa7c4623b,0x00000000,0xfe001f00,0x000a0000, 0xa7c4623b, 0x00000000, 0xfe001f00, 0x000a0000,
0xfe0c1f00,0x000a0020,0xfea41f00,0x80000040, 0xfe0c1f00, 0x000a0020, 0xfea41f00, 0x80000040,
0x03648000,0xfe08626f,0x7d648081,0xff00420f, 0x03648000, 0xfe08626f, 0x7d648081, 0xff00420f,
0xa7c4623b,0x00000000,0xfeb01f00,0x7e04620f, 0xa7c4623b, 0x00000000, 0xfeb01f00, 0x7e04620f,
0xfeb41f00,0x7f08662f,0x7c800001,0xff006e4f, 0xfeb41f00, 0x7f08662f, 0x7c800001, 0xff006e4f,
0xfe081f00,0x000a0060,0x03680081,0xfe0c4e0f, 0xfe081f00, 0x000a0060, 0x03680081, 0xfe0c4e0f,
0x00809043,0x00000000,0xfebc1f00,0x7f04620f, 0x00809043, 0x00000000, 0xfebc1f00, 0x7f04620f,
0x7cc41f00,0x00000020,0x7cc49f00,0x1000e04f, 0x7cc41f00, 0x00000020, 0x7cc49f00, 0x1000e04f,
0xff901f00,0x00000060,0xfe981f80,0x00000000, 0xff901f00, 0x00000060, 0xfe981f80, 0x00000000,
0x00809043,0x00000000,0xfea81f00,0xf900620f, 0x00809043, 0x00000000, 0xfea81f00, 0xf900620f,
0x7cc41f00,0x00000020,0x00c09f00,0x1000c04f, 0x7cc41f00, 0x00000020, 0x00c09f00, 0x1000c04f,
0xfe0c1f00,0x80010060,0xff001f80,0x80010000, 0xfe0c1f00, 0x80010060, 0xff001f80, 0x80010000,
0x00000842,0x00000000,0xfea81f00,0xf900620f, 0x00000842, 0x00000000, 0xfea81f00, 0xf900620f,
0xfecc9f01,0x80000020,0x7fc81f00,0x9000e04f, 0xfecc9f01, 0x80000020, 0x7fc81f00, 0x9000e04f,
0x7dc89f00,0x1000c86f,0xffe01f80,0x80000000, 0x7dc89f00, 0x1000c86f, 0xffe01f80, 0x80000000,
0x00000842,0x00000000,0xfeac1f00,0xf900620f, 0x00000842, 0x00000000, 0xfeac1f00, 0xf900620f,
0x7ec81f00,0x9000802f,0xfec49f00,0x9000a040, 0x7ec81f00, 0x9000802f, 0xfec49f00, 0x9000a040,
0xfea89f00,0x80000060,0xffe01f80,0x9000a060, 0xfea89f00, 0x80000060, 0xffe01f80, 0x9000a060,
0x00000842,0xa7c4623b,0xfea41f00,0x80000000, 0x00000842, 0xa7c4623b, 0xfea41f00, 0x80000000,
0x7ecc1f00,0x9000e02f,0xfe0c1f00,0x000a0040, 0x7ecc1f00, 0x9000e02f, 0xfe0c1f00, 0x000a0040,
0x7c888081,0x80000000,0xa7c4623b,0x00000000, 0x7c888081, 0x80000000, 0xa7c4623b, 0x00000000,
0xfe001f00,0x000a0000,0xfeb81f00,0x7f08622f, 0xfe001f00, 0x000a0000, 0xfeb81f00, 0x7f08622f,
0xfea49f00,0x80000040,0x048c8081,0xff00420f, 0xfea49f00, 0x80000040, 0x048c8081, 0xff00420f,
0x00809043,0xa7c4623b,0xfeb01f00,0x7c04620f, 0x00809043, 0xa7c4623b, 0xfeb01f00, 0x7c04620f,
0x03600000,0xff00622f,0xfea49f00,0x80000040, 0x03600000, 0xff00622f, 0xfea49f00, 0x80000040,
0xfe081f80,0x000a0060,0x00809043,0x0ccec73c, 0xfe081f80, 0x000a0060, 0x00809043, 0x0ccec73c,
0xfebc1f00,0x7f040200,0xfea09f00,0x90000020, 0xfebc1f00, 0x7f040200, 0xfea09f00, 0x90000020,
0xfe941f00,0x10000040,0xfe081f80,0x30080060, 0xfe941f00, 0x10000040, 0xfe081f80, 0x30080060,
0x00809043,0x0ccec73c,0x00041f00,0x20080000, 0x00809043, 0x0ccec73c, 0x00041f00, 0x20080000,
0x00a01f00,0x80000020,0x002c1f02,0x1000e04f, 0x00a01f00, 0x80000020, 0x002c1f02, 0x1000e04f,
0x00081f80,0x80010060,0x0ccec73c,0x00000000, 0x00081f80, 0x80010060, 0x0ccec73c, 0x00000000,
0xfe201f02,0x1000800f,0xfec81f03,0x80020020, 0xfe201f02, 0x1000800f, 0xfec81f03, 0x80020020,
0xfe041f00,0x20080040,0xfe881f00,0x00000060, 0xfe041f00, 0x20080040, 0xfe881f00, 0x00000060,
0xfecc9f81,0x9000a06f,0xfe0c1f00,0x000a0000, 0xfecc9f81, 0x9000a06f, 0xfe0c1f00, 0x000a0000,
0xfe801f00,0x00000020,0xfec01f02,0x80020040, 0xfe801f00, 0x00000020, 0xfec01f02, 0x80020040,
0xfe281f02,0x1000c06f,0xfe841f82,0x1000804f, 0xfe281f02, 0x1000c06f, 0xfe841f82, 0x1000804f,
0xfe041f00,0x000a0000,0x7fc81f02,0x00000020, 0xfe041f00, 0x000a0000, 0x7fc81f02, 0x00000020,
0xfe8c1f00,0x00000040,0xfecc9f03,0x80020060, 0xfe8c1f00, 0x00000040, 0xfecc9f03, 0x80020060,
0xfe881f82,0x1000a00f,0x7cc01f02,0x00000000, 0xfe881f82, 0x1000a00f, 0x7cc01f02, 0x00000000,
0xfe8c1f02,0x1000e02f,0xfec49f00,0x80000040, 0xfe8c1f02, 0x1000e02f, 0xfec49f00, 0x80000040,
0xfe081f00,0x000a0060,0x03c89f80,0x9000e04f, 0xfe081f00, 0x000a0060, 0x03c89f80, 0x9000e04f,
0x7ecc9f03,0x00000000,0xfec01f00,0x80000020, 0x7ecc9f03, 0x00000000, 0xfec01f00, 0x80000020,
0x04c81f00,0x80000040,0x7c880f01,0xfe086a6f, 0x04c81f00, 0x80000040, 0x7c880f01, 0xfe086a6f,
0x7dac8f81,0x9000800f,0x7da00f00,0xfe04620f, 0x7dac8f81, 0x9000800f, 0x7da00f00, 0xfe04620f,
0xfec01f00,0x80000020,0x03c01f00,0x80000840, 0xfec01f00, 0x80000020, 0x03c01f00, 0x80000840,
0x03ac0f00,0xfe08c66f,0xfebc9f80,0xfd00420f, 0x03ac0f00, 0xfe08c66f, 0xfebc9f80, 0xfd00420f,
0xe07be53f,0x5c8e5a3f,0xfeb09f00,0xfd00620f, 0xe07be53f, 0x5c8e5a3f, 0xfeb09f00, 0xfd00620f,
0x05e81f00,0x9000f02f,0x7fe48f00,0xfe04624f, 0x05e81f00, 0x9000f02f, 0x7fe48f00, 0xfe04624f,
0x04ec8f00,0xfe08626f,0x03840f81,0x7f08a20f, 0x04ec8f00, 0xfe08626f, 0x03840f81, 0x7f08a20f,
0xe07be53f,0x5c8e5a3f,0x7e0c1f00,0x900ce00f, 0xe07be53f, 0x5c8e5a3f, 0x7e0c1f00, 0x900ce00f,
0xfe0c1f00,0x900c802f,0x05cc1f00,0x9000e84f, 0xfe0c1f00, 0x900c802f, 0x05cc1f00, 0x9000e84f,
0xfeb89f80,0xfd00626f,0xe07be53f,0x5c8e5a3f, 0xfeb89f80, 0xfd00626f, 0xe07be53f, 0x5c8e5a3f,
0x7cc09f81,0x80000020,0x7fa40f00,0x00280000, 0x7cc09f81, 0x80000020, 0x7fa40f00, 0x00280000,
0xfe848f00,0x00280020,0x7fe80f00,0x00280440, 0xfe848f00, 0x00280020, 0x7fe80f00, 0x00280440,
0xfd001f80,0x00280060,0x00000080,0x00000000, 0xfd001f80, 0x00280060, 0x00000080, 0x00000000,
0xfdc01f80,0xf800620f,0x00000243,0x00000000, 0xfdc01f80, 0xf800620f, 0x00000243, 0x00000000,
0xfea01f80,0x90000060,0x5555d53f,0x00000000, 0xfea01f80, 0x90000060, 0x5555d53f, 0x00000000,
0x02011f80,0x8c110000,0x02448002,0x80020000, 0x02011f80, 0x8c110000, 0x02448002, 0x80020000,
0xf8402000,0x9006a02f,0x02552081,0x00000040, 0xf8402000, 0x9006a02f, 0x02552081, 0x00000040,
0xfe301f00,0x1000e06f,0xfe081f80,0x1033c02f, 0xfe301f00, 0x1000e06f, 0xfe081f80, 0x1033c02f,
0xfe4c2081,0x80060040,0xfee88f81,0x0289e32f, 0xfe4c2081, 0x80060040, 0xfee88f81, 0x0289e32f,
0x02c59f80,0x80060000,0xfee08f80,0x0285636f, 0x02c59f80, 0x80060000, 0xfee08f80, 0x0285636f,
0xfecc8f80,0x80000000,0xfe40a081,0x80000060, 0xfecc8f80, 0x80000000, 0xfe40a081, 0x80000060,
0x00cc9f81,0x9000e04f,0xfe281f00,0x80060000, 0x00cc9f81, 0x9000e04f, 0xfe281f00, 0x80060000,
0xf8c01f81,0x9006c02f,0xfee00f81,0xfd80636f, 0xf8c01f81, 0x9006c02f, 0xfee00f81, 0xfd80636f,
0x0000803f,0x00000000,0x7ec49f81,0xf880e34f, 0x0000803f, 0x00000000, 0x7ec49f81, 0xf880e34f,
0xfe381f80,0x00000000,0x7de40f81,0xfe800360, 0xfe381f80, 0x00000000, 0x7de40f81, 0xfe800360,
0x00011f80,0x8c100000,0xf8001f00,0x900ce00f, 0x00011f80, 0x8c100000, 0xf8001f00, 0x900ce00f,
0x00311f00,0x1000e02f,0x02a41f00,0xf910624f, 0x00311f00, 0x1000e02f, 0x02a41f00, 0xf910624f,
0x02a01f00,0xf910626f,0x00011f80,0x1033e04f, 0x02a01f00, 0xf910626f, 0x00011f80, 0x1033e04f,
0x00000040,0x00000000,0xfecc9f03,0x80020000, 0x00000040, 0x00000000, 0xfecc9f03, 0x80020000,
0xfec81f83,0x80020060,0x7fd49f01,0x00000020, 0xfec81f83, 0x80020060, 0x7fd49f01, 0x00000020,
0x7fd41f80,0x00000040,0xfe081f00,0x80010000, 0x7fd41f80, 0x00000040, 0xfe081f00, 0x80010000,
0xfe041f80,0x80010060,0xfee00f01,0x80000000, 0xfe041f80, 0x80010060, 0xfee00f01, 0x80000000,
0xfeec0f81,0x80000020,0xfec01f00,0x00280000, 0xfeec0f81, 0x80000020, 0xfec01f00, 0x00280000,
0xfec49f00,0x00280020,0x7fe00f00,0x00280040, 0xfec49f00, 0x00280020, 0x7fe00f00, 0x00280040,
0xfd001f80,0x00280060,0x00000080,0x00000000, 0xfd001f80, 0x00280060, 0x00000080, 0x00000000,
0xfe001f80,0x00350000,0x00ec1f82,0x000c0260, 0xfe001f80, 0x00350000, 0x00ec1f82, 0x000c0260,
0x01011f00,0x800c0000,0x01051f00,0x800c0020, 0x01011f00, 0x800c0000, 0x01051f00, 0x800c0020,
0x002c1f00,0x80060040,0xf8008001,0x9006e06f, 0x002c1f00, 0x80060040, 0xf8008001, 0x9006e06f,
0x01091f80,0x800c0000,0x01c01f00,0x90000000, 0x01091f80, 0x800c0000, 0x01c01f00, 0x90000000,
0xfe088001,0xfd80632f,0x01e81f00,0x90000040, 0xfe088001, 0xfd80632f, 0x01e81f00, 0x90000040,
0x01c49f80,0x90000020,0x0000803f,0x00000000, 0x01c49f80, 0x90000020, 0x0000803f, 0x00000000,
0x7fcc9f80,0xf880630f,0xfe20a081,0x80000000, 0x7fcc9f80, 0xf880630f, 0xfe20a081, 0x80000000,
0x01cc1f80,0x90000060,0xc21e82a7,0x62ccc547, 0x01cc1f80, 0x90000060, 0xc21e82a7, 0x62ccc547,
0x1708607c,0x73ea57a6 0x1708607c, 0x73ea57a6
}; };
static const uint32_t cpPixelShaderRegs[] = { static const uint32_t cpPixelShaderRegs[] = {
0x00000106,0x00000002,0x14000003,0x00000000, 0x00000106, 0x00000002, 0x14000003, 0x00000000,
0x00000003,0x00000100,0x00000101,0x00000102, 0x00000003, 0x00000100, 0x00000101, 0x00000102,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x0000000f,0x00000001,0x00000010, 0x00000000, 0x0000000f, 0x00000001, 0x00000010,
0x00000000 0x00000000
}; };
ShaderFractalColor * ShaderFractalColor::shaderInstance = NULL; ShaderFractalColor *ShaderFractalColor::shaderInstance = NULL;
ShaderFractalColor::ShaderFractalColor() ShaderFractalColor::ShaderFractalColor()
: vertexShader(cuAttributeCount) { : vertexShader(cuAttributeCount) {
//! create pixel shader //! create pixel shader
pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs));
@ -290,16 +290,16 @@ ShaderFractalColor::ShaderFractalColor()
fadeOutLocation = 8; fadeOutLocation = 8;
fractalLocation = 12; fractalLocation = 12;
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_blur_border", GX2_SHADER_VAR_TYPE_FLOAT, 1, blurLocation, -1 "unf_blur_border", GX2_SHADER_VAR_TYPE_FLOAT, 1, blurLocation, -1
}); });
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1
}); });
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_fade_out_alpha", GX2_SHADER_VAR_TYPE_FLOAT4, 1, fadeOutLocation, -1 "unf_fade_out_alpha", GX2_SHADER_VAR_TYPE_FLOAT4, 1, fadeOutLocation, -1
}); });
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_fract_alpha", GX2_SHADER_VAR_TYPE_INT, 1, fractalLocation, -1 "unf_fract_alpha", GX2_SHADER_VAR_TYPE_INT, 1, fractalLocation, -1
}); });
//! create vertex shader //! create vertex shader
vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs));
@ -308,26 +308,26 @@ ShaderFractalColor::ShaderFractalColor()
projectionMatrixLocation = 16; projectionMatrixLocation = 16;
viewMatrixLocation = 32; viewMatrixLocation = 32;
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"modelMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, modelMatrixLocation, -1 "modelMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, modelMatrixLocation, -1
}); });
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"projectionMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, projectionMatrixLocation, -1 "projectionMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, projectionMatrixLocation, -1
}); });
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"viewMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, viewMatrixLocation, -1 "viewMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, viewMatrixLocation, -1
}); });
positionLocation = 0; positionLocation = 0;
colorLocation = 1; colorLocation = 1;
texCoordLocation = 2; texCoordLocation = 2;
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_colors", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation "attr_colors", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation
}); });
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation
}); });
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation
}); });
//! setup attribute streams //! setup attribute streams
@ -340,23 +340,23 @@ ShaderFractalColor::ShaderFractalColor()
//! initialize default quad texture vertexes as those are very commonly used //! initialize default quad texture vertexes as those are very commonly used
//! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000 //! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000
posVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize); posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize);
texCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize); texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize);
colorVtxs = (uint8_t*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciColorVtxsSize); colorVtxs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciColorVtxsSize);
//! position vertex structure and texture coordinate vertex structure //! position vertex structure and texture coordinate vertex structure
int32_t i = 0; int32_t i = 0;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize);
@ -372,22 +372,22 @@ ShaderFractalColor::ShaderFractalColor()
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize);
for(i = 0; i < (int32_t)ciColorVtxsSize; i++) for (i = 0; i < (int32_t) ciColorVtxsSize; i++)
colorVtxs[i] = 0xff; colorVtxs[i] = 0xff;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVtxs, ciColorVtxsSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVtxs, ciColorVtxsSize);
} }
ShaderFractalColor::~ShaderFractalColor() { ShaderFractalColor::~ShaderFractalColor() {
if(posVtxs) { if (posVtxs) {
free(posVtxs); free(posVtxs);
posVtxs = NULL; posVtxs = NULL;
} }
if(texCoords) { if (texCoords) {
free(texCoords); free(texCoords);
texCoords = NULL; texCoords = NULL;
} }
if(colorVtxs) { if (colorVtxs) {
free(colorVtxs); free(colorVtxs);
colorVtxs = NULL; colorVtxs = NULL;
} }

View File

@ -19,198 +19,198 @@
#include <gui/video/shaders/Texture2DShader.h> #include <gui/video/shaders/Texture2DShader.h>
static const uint32_t cpVertexShaderProgram[] = { static const uint32_t cpVertexShaderProgram[] = {
0x00000000,0x00008009,0x20000000,0x000080a0, 0x00000000, 0x00008009, 0x20000000, 0x000080a0,
0x3c200100,0x88060094,0x00400000,0x88042014, 0x3c200100, 0x88060094, 0x00400000, 0x88042014,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x02290001,0x80000000,0x02041f00,0x900c0020, 0x02290001, 0x80000000, 0x02041f00, 0x900c0020,
0x00a11f00,0xfc00624f,0xfd041f00,0x900c4060, 0x00a11f00, 0xfc00624f, 0xfd041f00, 0x900c4060,
0x02001f80,0x900c0000,0x83f9223e,0x0000803f, 0x02001f80, 0x900c0000, 0x83f9223e, 0x0000803f,
0xfe081f00,0x00080020,0xfe202081,0x10004040, 0xfe081f00, 0x00080020, 0xfe202081, 0x10004040,
0xfea49f80,0xfd00620f,0xdb0f49c0,0xdb0fc940, 0xfea49f80, 0xfd00620f, 0xdb0f49c0, 0xdb0fc940,
0xfea01f80,0x9000e06f,0x83f9223e,0x00000000, 0xfea01f80, 0x9000e06f, 0x83f9223e, 0x00000000,
0xfe0c1f80,0x00370000,0xffa01f00,0x80000040, 0xfe0c1f80, 0x00370000, 0xffa01f00, 0x80000040,
0xff101f00,0x800c0060,0x7f0c1f80,0x80370040, 0xff101f00, 0x800c0060, 0x7f0c1f80, 0x80370040,
0x0000103f,0x00000000,0xffa01f00,0x80000000, 0x0000103f, 0x00000000, 0xffa01f00, 0x80000000,
0xff001f00,0x800c0020,0x02c51f01,0x80000040, 0xff001f00, 0x800c0020, 0x02c51f01, 0x80000040,
0xfeac9f80,0x80000060,0x0000103f,0x398ee33f, 0xfeac9f80, 0x80000060, 0x0000103f, 0x398ee33f,
0xfea01f00,0x80000000,0x02c19f01,0x9000e02f, 0xfea01f00, 0x80000000, 0x02c19f01, 0x9000e02f,
0x01c41f01,0x9000e04f,0x02c59f80,0x80000060, 0x01c41f01, 0x9000e04f, 0x02c59f80, 0x80000060,
0x398ee33f,0x00000000,0x01c49f01,0x80000020, 0x398ee33f, 0x00000000, 0x01c49f01, 0x80000020,
0x02c11f80,0x80000040,0x01e08f00,0xfe04624f, 0x02c11f80, 0x80000040, 0x01e08f00, 0xfe04624f,
0x01c01f81,0x7f08626f,0xfe2c2000,0x10004000, 0x01c01f81, 0x7f08626f, 0xfe2c2000, 0x10004000,
0xfe28a080,0x10004020,0xeb825790,0xb6f711be, 0xfe28a080, 0x10004020, 0xeb825790, 0xb6f711be,
0x7c0e2df2,0x81173cfa 0x7c0e2df2, 0x81173cfa
}; };
static const uint32_t cpVertexShaderRegs[] = { static const uint32_t cpVertexShaderRegs[] = {
0x00000103,0x00000000,0x00000000,0x00000001, 0x00000103, 0x00000000, 0x00000000, 0x00000001,
0xffffff00,0xffffffff,0xffffffff,0xffffffff, 0xffffff00, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0xffffffff,0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff,0xffffffff,0x00000000,0xfffffffc, 0xffffffff, 0xffffffff, 0x00000000, 0xfffffffc,
0x00000002,0x00000000,0x00000001,0x000000ff, 0x00000002, 0x00000000, 0x00000001, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x000000ff,0x000000ff,0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
0x000000ff,0x00000000,0x0000000e,0x00000010 0x000000ff, 0x00000000, 0x0000000e, 0x00000010
}; };
static const uint32_t cPixelShaderProgram[] = { static const uint32_t cPixelShaderProgram[] = {
0x20000000,0x00000ca4,0x0b000000,0x00000085, 0x20000000, 0x00000ca4, 0x0b000000, 0x00000085,
0x24000000,0x000050a0,0xb0000000,0x000cc080, 0x24000000, 0x000050a0, 0xb0000000, 0x000cc080,
0x39000000,0x00005ca0,0xb8000000,0x000cc080, 0x39000000, 0x00005ca0, 0xb8000000, 0x000cc080,
0x51000000,0x000078a0,0xc0000000,0x000cc080, 0x51000000, 0x000078a0, 0xc0000000, 0x000cc080,
0x70000000,0x000064a0,0xc8000000,0x0008c080, 0x70000000, 0x000064a0, 0xc8000000, 0x0008c080,
0x8a000000,0x00005ca0,0x0e000000,0x01008086, 0x8a000000, 0x00005ca0, 0x0e000000, 0x01008086,
0xce000000,0x0000c080,0xa2000000,0x00000ca8, 0xce000000, 0x0000c080, 0xa2000000, 0x00000ca8,
0x00800000,0x88062094,0x00000000,0x00000000, 0x00800000, 0x88062094, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00051f00,0x80060000,0x00011f80,0x80060040, 0x00051f00, 0x80060000, 0x00011f80, 0x80060040,
0xfec81f80,0xfb802320,0x01041f80,0x8c220000, 0xfec81f80, 0xfb802320, 0x01041f80, 0x8c220000,
0x00a41f00,0xfc10620f,0x010d1f00,0x900c0021, 0x00a41f00, 0xfc10620f, 0x010d1f00, 0x900c0021,
0x00091f00,0x80060040,0x00a01f80,0xfc10626f, 0x00091f00, 0x80060040, 0x00a01f80, 0xfc10626f,
0x00000040,0x00000000,0xfe080000,0xfe8cc300, 0x00000040, 0x00000000, 0xfe080000, 0xfe8cc300,
0xfe088080,0xfe80c320,0x00a11f00,0xfe000200, 0xfe088080, 0xfe80c320, 0x00a11f00, 0xfe000200,
0x00a51f00,0xfe040220,0x00a19f00,0xfe000240, 0x00a51f00, 0xfe040220, 0x00a19f00, 0xfe000240,
0x00a59f00,0xfe040260,0x00a11f81,0xfe002600, 0x00a59f00, 0xfe040260, 0x00a11f81, 0xfe002600,
0x4260e5bc,0xa69bc4bc,0x0ad7a3bc,0x00000000, 0x4260e5bc, 0xa69bc4bc, 0x0ad7a3bc, 0x00000000,
0x00a11f00,0x06004200,0x00a59f00,0x06042220, 0x00a11f00, 0x06004200, 0x00a59f00, 0x06042220,
0x00a51f00,0x06044240,0x00a11f01,0x06008260, 0x00a51f00, 0x06044240, 0x00a11f01, 0x06008260,
0x00a51f81,0x06048620,0x6f1283bc,0x0ad7a3bc, 0x00a51f81, 0x06048620, 0x6f1283bc, 0x0ad7a3bc,
0xa69b44bc,0x00000000,0x00a41f00,0x80000000, 0xa69b44bc, 0x00000000, 0x00a41f00, 0x80000000,
0x00a01f00,0x80000020,0x00ac1f00,0x80000040, 0x00a01f00, 0x80000020, 0x00ac1f00, 0x80000040,
0x00a81f00,0x80000060,0x00a19f80,0x06000600, 0x00a81f00, 0x80000060, 0x00a19f80, 0x06000600,
0xcac3123c,0x6f1203bc,0x03a41f00,0xfe00620f, 0xcac3123c, 0x6f1203bc, 0x03a41f00, 0xfe00620f,
0x03a01f00,0xfe04622f,0x03ac1f00,0xfe08624f, 0x03a01f00, 0xfe04622f, 0x03ac1f00, 0xfe08624f,
0x03a81f00,0xfe0c626f,0x00a59f80,0x06040620, 0x03a81f00, 0xfe0c626f, 0x00a59f80, 0x06040620,
0xcc28913b,0x6f1203bc,0x01a41f00,0xfe00620f, 0xcc28913b, 0x6f1203bc, 0x01a41f00, 0xfe00620f,
0x01a01f00,0xfe04622f,0x01ac1f00,0xfe08624f, 0x01a01f00, 0xfe04622f, 0x01ac1f00, 0xfe08624f,
0x01a81f00,0xfe0c626f,0x00a19f80,0x06002600, 0x01a81f00, 0xfe0c626f, 0x00a19f80, 0x06002600,
0xe8eab03c,0x6f1283bb,0x02ac1f00,0xfe084200, 0xe8eab03c, 0x6f1283bb, 0x02ac1f00, 0xfe084200,
0x02a81f00,0xfe0c4220,0x02a41f00,0xfe004240, 0x02a81f00, 0xfe0c4220, 0x02a41f00, 0xfe004240,
0x02a01f00,0xfe044260,0x00a59f80,0x06042620, 0x02a01f00, 0xfe044260, 0x00a59f80, 0x06042620,
0x92bb353d,0x6f1283bb,0x04a81f00,0x0204620f, 0x92bb353d, 0x6f1283bb, 0x04a81f00, 0x0204620f,
0x04ac1f00,0x0200662f,0x04a41f00,0x0208624f, 0x04ac1f00, 0x0200662f, 0x04a41f00, 0x0208624f,
0x04a01f00,0x020c626f,0x00a19f80,0x06004600, 0x04a01f00, 0x020c626f, 0x00a19f80, 0x06004600,
0xc4139f3d,0x6f12833b,0x00a41f00,0xfe08620f, 0xc4139f3d, 0x6f12833b, 0x00a41f00, 0xfe08620f,
0x00a01f00,0xfe0c622f,0x00ac1f00,0xfe04624f, 0x00a01f00, 0xfe0c622f, 0x00ac1f00, 0xfe04624f,
0x00a81f00,0xfe00626f,0x00a59f80,0x06044620, 0x00a81f00, 0xfe00626f, 0x00a59f80, 0x06044620,
0xb950ed3d,0x6f12833b,0x01a41f00,0xfe00620f, 0xb950ed3d, 0x6f12833b, 0x01a41f00, 0xfe00620f,
0x01a01f00,0xfe04622f,0x01ac1f00,0xfe08624f, 0x01a01f00, 0xfe04622f, 0x01ac1f00, 0xfe08624f,
0x01a81f00,0xfe0c626f,0x00a19f80,0x06002600, 0x01a81f00, 0xfe0c626f, 0x00a19f80, 0x06002600,
0xecd7163e,0x6f12033c,0x03a41f00,0xfe000200, 0xecd7163e, 0x6f12033c, 0x03a41f00, 0xfe000200,
0x03a01f00,0xfe040220,0x03ac1f00,0xfe082240, 0x03a01f00, 0xfe040220, 0x03ac1f00, 0xfe082240,
0x03a81f00,0xfe0c2260,0x00a59f80,0x06042620, 0x03a81f00, 0xfe0c2260, 0x00a59f80, 0x06042620,
0x2168233e,0x6f12033c,0x00a11f00,0x06006200, 0x2168233e, 0x6f12033c, 0x00a11f00, 0x06006200,
0x00a51f00,0x06046220,0x00a19f00,0x06006240, 0x00a51f00, 0x06046220, 0x00a19f00, 0x06006240,
0x00a59f00,0x06046260,0x00a11f81,0x0600e600, 0x00a59f00, 0x06046260, 0x00a11f81, 0x0600e600,
0xa69b443c,0x6f12833c,0x0ad7a33c,0x00000000, 0xa69b443c, 0x6f12833c, 0x0ad7a33c, 0x00000000,
0x02ac1f00,0x0108620f,0x02a81f00,0x010c622f, 0x02ac1f00, 0x0108620f, 0x02a81f00, 0x010c622f,
0x02a41f00,0x0000624f,0x02a01f00,0x0004666f, 0x02a41f00, 0x0000624f, 0x02a01f00, 0x0004666f,
0x00a59f80,0x0604e620,0xecd7163e,0x0ad7a33c, 0x00a59f80, 0x0604e620, 0xecd7163e, 0x0ad7a33c,
0x04a81f00,0xfe04620f,0x04ac1f00,0xfe00622f, 0x04a81f00, 0xfe04620f, 0x04ac1f00, 0xfe00622f,
0x04a41f00,0xfe08624f,0x04a01f00,0xfe0c626f, 0x04a41f00, 0xfe08624f, 0x04a01f00, 0xfe0c626f,
0x00a19f80,0x06008600,0xb950ed3d,0xa69bc43c, 0x00a19f80, 0x06008600, 0xb950ed3d, 0xa69bc43c,
0x05a41f00,0xfe08620f,0x05a01f00,0xfe0c622f, 0x05a41f00, 0xfe08620f, 0x05a01f00, 0xfe0c622f,
0x05ac1f00,0xfe04624f,0x05a81f00,0xfe00626f, 0x05ac1f00, 0xfe04624f, 0x05a81f00, 0xfe00626f,
0x00a59f80,0x06048620,0xc4139f3d,0xa69bc43c, 0x00a59f80, 0x06048620, 0xc4139f3d, 0xa69bc43c,
0x03a41f00,0xfe00a200,0x03a01f00,0xfe04a220, 0x03a41f00, 0xfe00a200, 0x03a01f00, 0xfe04a220,
0x03ac1f00,0xfe086240,0x03a81f00,0xfe0c6260, 0x03ac1f00, 0xfe086240, 0x03a81f00, 0xfe0c6260,
0x00a19f80,0x06006600,0x92bb353d,0x4260e53c, 0x00a19f80, 0x06006600, 0x92bb353d, 0x4260e53c,
0x00a51f80,0x06046220,0x4260e53c,0x00000000, 0x00a51f80, 0x06046220, 0x4260e53c, 0x00000000,
0x07ac1f00,0x0308620f,0x07a81f00,0x030c622f, 0x07ac1f00, 0x0308620f, 0x07a81f00, 0x030c622f,
0x07a41f00,0x0500624f,0x07a01f80,0x0504626f, 0x07a41f00, 0x0500624f, 0x07a01f80, 0x0504626f,
0xe8eab03c,0x00000000,0x04a81f00,0xfe04620f, 0xe8eab03c, 0x00000000, 0x04a81f00, 0xfe04620f,
0x04ac1f00,0xfe00622f,0x04a41f00,0xfe08624f, 0x04ac1f00, 0xfe00622f, 0x04a41f00, 0xfe08624f,
0x04a01f80,0xfe0c626f,0xcac3123c,0x00000000, 0x04a01f80, 0xfe0c626f, 0xcac3123c, 0x00000000,
0x06a41f00,0xfe08620f,0x06a01f00,0xfe0c622f, 0x06a41f00, 0xfe08620f, 0x06a01f00, 0xfe0c622f,
0x06ac1f00,0xfe04624f,0x06a81f80,0xfe00626f, 0x06ac1f00, 0xfe04624f, 0x06a81f80, 0xfe00626f,
0xcc28913b,0x00000000,0xfe20a000,0x9000e00f, 0xcc28913b, 0x00000000, 0xfe20a000, 0x9000e00f,
0xfe242000,0x9000e02f,0xfe28a001,0x9000e04f, 0xfe242000, 0x9000e02f, 0xfe28a001, 0x9000e04f,
0xfe2c2081,0x9000e06f,0xfe28a081,0x80060020, 0xfe2c2081, 0x9000e06f, 0xfe28a081, 0x80060020,
0xfee48f00,0x7f842300,0xfee40f00,0x7f802320, 0xfee48f00, 0x7f842300, 0xfee40f00, 0x7f802320,
0xfee48f01,0x7f8c2340,0xfee40f81,0x08842b60, 0xfee48f01, 0x7f8c2340, 0xfee40f81, 0x08842b60,
0x00202000,0x90002000,0x0024a000,0x90002020, 0x00202000, 0x90002000, 0x0024a000, 0x90002020,
0x00282001,0x90002040,0x002ca081,0x90002060, 0x00282001, 0x90002040, 0x002ca081, 0x90002060,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x10000000,0x03100df0,0x00008010,0xecdfea0d, 0x10000000, 0x03100df0, 0x00008010, 0xecdfea0d,
0x10000000,0x00100df0,0x0000a051,0xecdfea0d, 0x10000000, 0x00100df0, 0x0000a051, 0xecdfea0d,
0x10000100,0x01100df0,0x00008010,0xecdfea0d, 0x10000100, 0x01100df0, 0x00008010, 0xecdfea0d,
0x10000200,0x02100df0,0x00000011,0xecdfea0d, 0x10000200, 0x02100df0, 0x00000011, 0xecdfea0d,
0x10000400,0x04100df0,0x0000b070,0xecdfea0d, 0x10000400, 0x04100df0, 0x0000b070, 0xecdfea0d,
0x10000000,0x00100df0,0x00008010,0xecdfea0d, 0x10000000, 0x00100df0, 0x00008010, 0xecdfea0d,
0x10000100,0x01100df0,0x00008010,0xecdfea0d, 0x10000100, 0x01100df0, 0x00008010, 0xecdfea0d,
0x10000600,0x03100df0,0x00008010,0xecdfea0d, 0x10000600, 0x03100df0, 0x00008010, 0xecdfea0d,
0x10000200,0x02100df0,0x00008010,0xecdfea0d, 0x10000200, 0x02100df0, 0x00008010, 0xecdfea0d,
0x10000100,0x04100df0,0x00008010,0xecdfea0d, 0x10000100, 0x04100df0, 0x00008010, 0xecdfea0d,
0x10000300,0x05100df0,0x00008010,0xecdfea0d, 0x10000300, 0x05100df0, 0x00008010, 0xecdfea0d,
0x10000300,0x03100df0,0x0000a051,0xecdfea0d, 0x10000300, 0x03100df0, 0x0000a051, 0xecdfea0d,
0x10000700,0x07100df0,0x00008010,0xecdfea0d, 0x10000700, 0x07100df0, 0x00008010, 0xecdfea0d,
0x10000400,0x04100df0,0x00008010,0xecdfea0d, 0x10000400, 0x04100df0, 0x00008010, 0xecdfea0d,
0x10000300,0x06100df0,0x00008010,0xecdfea0d, 0x10000300, 0x06100df0, 0x00008010, 0xecdfea0d,
0x10000000,0x00100df0,0x00008010,0xecdfea0d, 0x10000000, 0x00100df0, 0x00008010, 0xecdfea0d,
0xc8581837,0x22740275,0x281eddcc,0xfa8b9b65 0xc8581837, 0x22740275, 0x281eddcc, 0xfa8b9b65
}; };
static const uint32_t cPixelShaderRegs[] = { static const uint32_t cPixelShaderRegs[] = {
0x00000109,0x00000002,0x14000001,0x00000000, 0x00000109, 0x00000002, 0x14000001, 0x00000000,
0x00000001,0x00000100,0x00000000,0x00000000, 0x00000001, 0x00000100, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000,0x0000000f,0x00000001,0x00000010, 0x00000000, 0x0000000f, 0x00000001, 0x00000010,
0x00000000 0x00000000
}; };
Texture2DShader * Texture2DShader::shaderInstance = NULL; Texture2DShader *Texture2DShader::shaderInstance = NULL;
Texture2DShader::Texture2DShader() Texture2DShader::Texture2DShader()
: vertexShader(cuAttributeCount) { : vertexShader(cuAttributeCount) {
//! create pixel shader //! create pixel shader
pixelShader.setProgram(cPixelShaderProgram, sizeof(cPixelShaderProgram), cPixelShaderRegs, sizeof(cPixelShaderRegs)); pixelShader.setProgram(cPixelShaderProgram, sizeof(cPixelShaderProgram), cPixelShaderRegs, sizeof(cPixelShaderRegs));
blurLocation = 0; blurLocation = 0;
colorIntensityLocation = 4; colorIntensityLocation = 4;
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_blur_texture_direction", GX2_SHADER_VAR_TYPE_FLOAT3, 1, blurLocation, -1 "unf_blur_texture_direction", GX2_SHADER_VAR_TYPE_FLOAT3, 1, blurLocation, -1
}); });
pixelShader.addUniformVar((GX2UniformVar) { pixelShader.addUniformVar((GX2UniformVar) {
"unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1
}); });
samplerLocation = 0; samplerLocation = 0;
pixelShader.addSamplerVar((GX2SamplerVar) { pixelShader.addSamplerVar((GX2SamplerVar) {
"sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation
}); });
//! create vertex shader //! create vertex shader
@ -220,22 +220,22 @@ Texture2DShader::Texture2DShader()
offsetLocation = 4; offsetLocation = 4;
scaleLocation = 8; scaleLocation = 8;
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1 "unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1
}); });
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1 "unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1
}); });
vertexShader.addUniformVar((GX2UniformVar) { vertexShader.addUniformVar((GX2UniformVar) {
"unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1 "unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1
}); });
positionLocation = 0; positionLocation = 0;
texCoordLocation = 1; texCoordLocation = 1;
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation
}); });
vertexShader.addAttribVar((GX2AttribVar) { vertexShader.addAttribVar((GX2AttribVar) {
"attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation
}); });
//! setup attribute streams //! setup attribute streams
@ -246,8 +246,8 @@ Texture2DShader::Texture2DShader()
fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount());
//! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000 //! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000
posVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize); posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize);
texCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize); texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize);
//! defaults for normal square //! defaults for normal square
//! position vertex structure and texture coordinate vertex structure //! position vertex structure and texture coordinate vertex structure
@ -255,14 +255,14 @@ Texture2DShader::Texture2DShader()
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f;
posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f;
posVtxs[i++] = 0.0f; posVtxs[i++] = 0.0f;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize);
@ -279,11 +279,11 @@ Texture2DShader::Texture2DShader()
} }
Texture2DShader::~Texture2DShader() { Texture2DShader::~Texture2DShader() {
if(posVtxs) { if (posVtxs) {
free(posVtxs); free(posVtxs);
posVtxs = NULL; posVtxs = NULL;
} }
if(texCoords) { if (texCoords) {
free(texCoords); free(texCoords);
texCoords = NULL; texCoords = NULL;
} }