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 void contentSaveDo(const fsStr& pPath, std::function<void(fsBool)> pDone) override;
65
66 void recolourDo(fsSColour4B const& pOld, fsSColour4B const& pNew) override;
67 void paintWithSpriteBrushDo(fsPoint const& pPos) override;
68 void paintDo(std::vector<fsPoint> const& pPos, fsSColour4B const& pColour) override;
69
70 void renderDo() override;
71 void matrixApplyDo(fsAffineMtx2d const& pTransform) override;
72
73private:
74
75 struct fsSMutableTexture
76 {
77 ~fsSMutableTexture();
78 fsSMutableTexture(fsIImage* pCanvas);
79
80 void paint(fsS32 x, fsS32 y)
81 {
82 mPixels[y * stride() + x * bytesPerPixel() + 0] = mPaintColour.mR;
83 mPixels[y * stride() + x * bytesPerPixel() + 1] = mPaintColour.mG;
84 mPixels[y * stride() + x * bytesPerPixel() + 2] = mPaintColour.mB;
85 mPixels[y * stride() + x * bytesPerPixel() + 3] = mPaintColour.mA;
86 }
87
88 fsSColour4B get(fsS32 x, fsS32 y) const
89 {
90 return fsSColour4B(
91 mPixels[y * stride() + x * bytesPerPixel() + 0],
92 mPixels[y * stride() + x * bytesPerPixel() + 1],
93 mPixels[y * stride() + x * bytesPerPixel() + 2],
94 mPixels[y * stride() + x * bytesPerPixel() + 3]);
95 }
96
97 fsU32 bytesPerPixel() const { return mBpp / 8; }
98 fsS32 stride() const { return mWidth * bytesPerPixel(); }
99 fsS32 len() const { return stride() * mHeight; }
100 fsS32 mWidth;
101 fsS32 mHeight;
102 fsU32 mBpp;
103 fsU8* mPixels;
104 fsSColour4B mPaintColour;
105 };
106
107 ax::Node* implGet() const override;
108
109 void updateDynamicTexturePixels() const;
110 fsCAxmolRenderTexture* screenshotTargetGet() const;
111 void screenTextureDestroy();
112 void dynamicTextureDestroy();
113
114 enum class eScreenEffect
115 {
116 eNONE,
117 eMAGNIFY,
118 eTORCH
119 };
120
121 fsCResourceName mSaveFilename;
122 fsStr mFragmentShader;
123 eScreenEffect mScreenEffect;
124 fsPoint mScreenEffectFocusPos;
125 fsF32 mScreenEffectRadius;
126 fsBool mScreenEffectFocusOverrideActive;
127
128 ax::Mat4 mCanvasMatrix;
129 ax::Mat4 mBrushMatrix;
130
131 fsCAxmolRenderTexture* mDynamicScreenTexture;
132 ax::Sprite* mDynamicScreenSprite;
133 fsCAxmolRenderTexture* mDynamicTexture;
134 ax::Sprite* mDynamicTextureSprite;
135
136 ax::Sprite* mBrush;
137
138 std::unique_ptr<fsSMutableTexture> mMutableTexture;
139 // Paints only set this; renderDo() uploads once per frame.
140 fsBool mPixelsDirty = false;
141};
142
143#endif
Definition fsAffineMtx2d.h:27
Definition fsCNativeRenderTexture.h:31
void initialiseScreenDo(fsPoint pDimensions)
void contentSaveDo(const fsStr &pPath, std::function< void(fsBool)> pDone) override
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
~fsCNativeRenderTexture() override
void recolourDo(fsSColour4B const &pOld, fsSColour4B const &pNew) override
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:39
void paint(std::vector< fsPoint > const &pPos, fsSColour4B const &pColour)
Definition fsIRenderableTexture.cpp:102
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