Fission FSN
Loading...
Searching...
No Matches
fsCNativeRenderTexture.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: fsCRenderTexture.h
4*
5* Purpose: Cocos2d-x implementation of a render texture.
6*
7*********************************************************************/
8
9#ifndef fsCNativeRenderTextureV3hdr
10#define fsCNativeRenderTextureV3hdr
11
12#include <fsCore/fsBaseTypes.h>
13#include <math/Mat4.h>
14#include <fsCore/fsPoint.h>
15
18
19namespace ax
20{
21 class RenderTexture;
22 class Sprite;
23 class Texture2D;
24}
25
26class fsAffineMtx2d;
27class fsIImage;
28class fsRect;
29
31{
32 friend class fsITexture;
33
34public:
35
36 void initialiseScreenDo(fsPoint pDimensions);
38
41
42protected:
43
44 void resizeDo(fsPoint const& pSize) override;
45 void screenShotStartDo() override;
46 void screenShotEndDo(const fsStr& pSceneName) override;
47
49 void shaderEffectRefresh(const fsStr& pFragmentShader);
51
52 void shadersCreateDo(const fsStr& pVertex, const fsStr& pFragment) override;
53 void screenEffectParamsSetDo(fsPoint const& pFocusPos, fsF32 pRadius) override;
55
56 void targetSetDo() override;
57 void partialEndDo() override;
58 void partialStartDo() override;
59 void targetClearDo() override;
60
61 void brushSetDo(fsCResourceName const& pBrushFilename) override;
62 void saveDo(fsCResourceName const& pFilename) override;
63 void captureRegionSaveDo(const fsRect& pCaptureRect, fsPoint const& pOutputDimensions, fsCResourceName const& pFilename) override;
64
65 void recolourDo(fsSColour4B const& pOld, fsSColour4B const& pNew) override;
66 void paintWithSpriteBrushDo(fsPoint const& pPos) override;
67 void paintDo(std::vector<fsPoint> const& pPos, fsSColour4B const& pColour) override;
68
69 void renderDo() override;
70 void matrixApplyDo(fsAffineMtx2d const& pTransform) override;
71
72private:
73
74 struct fsSMutableTexture
75 {
76 ~fsSMutableTexture();
77 fsSMutableTexture(fsIImage* pCanvas);
78
79 void paint(fsS32 x, fsS32 y)
80 {
81 mPixels[y * stride() + x * bytesPerPixel() + 0] = mPaintColour.mR;
82 mPixels[y * stride() + x * bytesPerPixel() + 1] = mPaintColour.mG;
83 mPixels[y * stride() + x * bytesPerPixel() + 2] = mPaintColour.mB;
84 mPixels[y * stride() + x * bytesPerPixel() + 3] = mPaintColour.mA;
85 }
86
87 fsSColour4B get(fsS32 x, fsS32 y) const
88 {
89 return fsSColour4B(
90 mPixels[y * stride() + x * bytesPerPixel() + 0],
91 mPixels[y * stride() + x * bytesPerPixel() + 1],
92 mPixels[y * stride() + x * bytesPerPixel() + 2],
93 mPixels[y * stride() + x * bytesPerPixel() + 3]);
94 }
95
96 fsU32 bytesPerPixel() const { return mBpp / 8; }
97 fsS32 stride() const { return mWidth * bytesPerPixel(); }
98 fsS32 len() const { return stride() * mHeight; }
99 fsS32 mWidth;
100 fsS32 mHeight;
101 fsU32 mBpp;
102 fsU8* mPixels;
103 fsSColour4B mPaintColour;
104 };
105
106 ax::Node* implGet() const override;
107
108 void updateDynamicTexturePixels() const;
109 fsCAxmolRenderTexture* screenshotTargetGet() const;
110 void screenTextureDestroy();
111 void dynamicTextureDestroy();
112
113 enum class eScreenEffect
114 {
115 eNONE,
116 eMAGNIFY,
117 eTORCH
118 };
119
120 fsCResourceName mSaveFilename;
121 fsStr mFragmentShader;
122 eScreenEffect mScreenEffect;
123 fsPoint mScreenEffectFocusPos;
124 fsF32 mScreenEffectRadius;
125 fsBool mScreenEffectFocusOverrideActive;
126
127 ax::Mat4 mCanvasMatrix;
128 ax::Mat4 mBrushMatrix;
129
130 fsCAxmolRenderTexture* mDynamicScreenTexture;
131 ax::Sprite* mDynamicScreenSprite;
132 fsCAxmolRenderTexture* mDynamicTexture;
133 ax::Sprite* mDynamicTextureSprite;
134
135 ax::Sprite* mBrush;
136
137 std::unique_ptr<fsSMutableTexture> mMutableTexture;
138};
139
140#endif
Definition fsAffineMtx2d.h:27
Definition fsCNativeRenderTexture.h:31
void initialiseScreenDo(fsPoint pDimensions)
void resizeDo(fsPoint const &pSize) override
void paintWithSpriteBrushDo(fsPoint const &pPos) override
void matrixApplyDo(fsAffineMtx2d const &pTransform) override
void saveDo(fsCResourceName const &pFilename) override
fsPoint screenEffectFocusPosGet() const
void renderDo() override
void partialEndDo() override
void partialStartDo() override
void shaderEffectRefresh(const fsStr &pFragmentShader)
void paintDo(std::vector< fsPoint > const &pPos, fsSColour4B const &pColour) override
friend class fsITexture
Definition fsCNativeRenderTexture.h:32
void targetSetDo() override
void shadersCreateDo(const fsStr &pVertex, const fsStr &pFragment) override
void initialiseSolutionDo(fsIImage *pSolution)
void screenShotEndDo(const fsStr &pSceneName) override
void targetClearDo() override
void recolourDo(fsSColour4B const &pOld, fsSColour4B const &pNew) override
virtual ~fsCNativeRenderTexture()
void screenEffectParamsSetDo(fsPoint const &pFocusPos, fsF32 pRadius) override
void screenEffectParamsClearDo() override
void captureRegionSaveDo(const fsRect &pCaptureRect, fsPoint const &pOutputDimensions, fsCResourceName const &pFilename) override
void screenShotStartDo() override
void brushSetDo(fsCResourceName const &pBrushFilename) override
Definition fsCResourceName.h:32
Definition fsIImage.h:21
Definition fsIRenderableTexture.h:38
void paint(std::vector< fsPoint > const &pPos, fsSColour4B const &pColour)
Definition fsIRenderableTexture.cpp:97
Definition fsRect.h:16
Definition fsStr.h:23
unsigned int fsU32
Definition fsBaseTypes.h:21
bool fsBool
Definition fsBaseTypes.h:26
unsigned char fsU8
Definition fsBaseTypes.h:15
int fsS32
Definition fsBaseTypes.h:20
float fsF32
Definition fsBaseTypes.h:28
Definition fsC3dLight.h:19
Definition fsPoint.h:17
Definition fsSColour.h:54
fsU8 mG
Definition fsSColour.h:82
fsU8 mR
Definition fsSColour.h:81
fsU8 mB
Definition fsSColour.h:83
fsU8 mA
Definition fsSColour.h:84