TDME2 1.9.121
FrameBufferRenderShader.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
9
12
21
22FrameBufferRenderShader::FrameBufferRenderShader(Renderer* renderer)
23{
24 this->renderer = renderer;
25 initialized = false;
26 isRunning = false;
27}
28
30{
31 Engine::getInstance()->getVBOManager()->removeVBO("framebuffer_render_shader.vbos");
32}
33
35{
36 return initialized;
37}
38
40{
41 auto shaderVersion = renderer->getShaderVersion();
44 "shader/" + shaderVersion + "/framebuffer",
45 "render_vertexshader.vert"
46 );
47 if (vertexShaderId == 0) return;
48
51 "shader/" + shaderVersion + "/framebuffer",
52 "render_fragmentshader.frag"
53 );
54 if (fragmentShaderId == 0) return;
55
62 }
63 if (renderer->linkProgram(programId) == false) return;
64
65 // uniforms
67 if (uniformColorBufferTextureUnit == -1) return;
68
70
71 //
72 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
73
74 // create vbos
75 auto created = false;
76 auto vboManaged = Engine::getInstance()->getVBOManager()->addVBO("framebuffer_render_shader.vbos", 2, true, false, created);
77 vboVertices = (*vboManaged->getVBOIds())[0];
78 vboTextureCoordinates = (*vboManaged->getVBOIds())[1];
79
80 // vertices
81 {
82 auto fbVertices = ObjectBuffer::getByteBuffer(contextIdx, 6 * 3 * sizeof(float))->asFloatBuffer();
83
84 fbVertices.put(-1.0f); fbVertices.put(+1.0f); fbVertices.put(0.0f);
85 fbVertices.put(+1.0f); fbVertices.put(+1.0f); fbVertices.put(0.0f);
86 fbVertices.put(+1.0f); fbVertices.put(-1.0f); fbVertices.put(0.0f);
87
88 fbVertices.put(+1.0f); fbVertices.put(-1.0f); fbVertices.put(0.0f);
89 fbVertices.put(-1.0f); fbVertices.put(-1.0f); fbVertices.put(0.0f);
90 fbVertices.put(-1.0f); fbVertices.put(+1.0f); fbVertices.put(0.0f);
91
92 renderer->uploadBufferObject(contextIdx, vboVertices, fbVertices.getPosition() * sizeof(float), &fbVertices);
93 }
94
95 // texture coordinates
96 {
97 auto fbTextureCoordinates = ObjectBuffer::getByteBuffer(contextIdx, 6 * 2 * sizeof(float))->asFloatBuffer();
98
99 if (renderer->getRendererType() == Renderer::RENDERERTYPE_VULKAN) {
100 fbTextureCoordinates.put(+0.0f); fbTextureCoordinates.put(0.0f);
101 fbTextureCoordinates.put(+1.0f); fbTextureCoordinates.put(0.0f);
102 fbTextureCoordinates.put(+1.0f); fbTextureCoordinates.put(1.0f);
103
104 fbTextureCoordinates.put(+1.0f); fbTextureCoordinates.put(1.0f);
105 fbTextureCoordinates.put(+0.0f); fbTextureCoordinates.put(1.0f);
106 fbTextureCoordinates.put(+0.0f); fbTextureCoordinates.put(0.0f);
107 } else {
108 fbTextureCoordinates.put(+0.0f); fbTextureCoordinates.put(+1.0f);
109 fbTextureCoordinates.put(+1.0f); fbTextureCoordinates.put(+1.0f);
110 fbTextureCoordinates.put(+1.0f); fbTextureCoordinates.put(0.0f);
111
112 fbTextureCoordinates.put(+1.0f); fbTextureCoordinates.put(0.0f);
113 fbTextureCoordinates.put(+0.0f); fbTextureCoordinates.put(0.0f);
114 fbTextureCoordinates.put(+0.0f); fbTextureCoordinates.put(+1.0f);
115 }
116
117 renderer->uploadBufferObject(contextIdx, vboTextureCoordinates, fbTextureCoordinates.getPosition() * sizeof(float), &fbTextureCoordinates);
118 }
119
120 //
121 initialized = true;
122}
123
125{
126 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
127 renderer->useProgram(contextIdx, programId);
131 isRunning = true;
132}
133
135{
136 isRunning = false;
137}
Engine main class.
Definition: Engine.h:122
static Engine * getInstance()
Returns engine instance.
Definition: Engine.h:554
static VBOManager * getVBOManager()
Definition: Engine.h:572
VBOManager_VBOManaged * addVBO(const string &vboId, int32_t ids, bool useGPUMemory, bool shared, bool &created)
Adds a VBO to manager or retrieve VBO if existing.
Definition: VBOManager.cpp:31
void removeVBO(const string &vboId)
Removes a VBO from manager.
Definition: VBOManager.cpp:73
virtual int32_t loadShader(int32_t type, const string &pathName, const string &fileName, const string &definitions=string(), const string &functions=string())=0
Loads a shader.
virtual int32_t createProgram(int type)=0
Creates a shader program.
virtual void setProgramAttributeLocation(int32_t programId, int32_t location, const string &name)=0
Bind attribute to a input location.
virtual void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)=0
Set up a integer uniform value.
virtual bool linkProgram(int32_t programId)=0
Links attached shaders to a program.
void setLighting(int contextIdx, int32_t lighting)
Set current lighting model.
Definition: Renderer.h:503
virtual void attachShaderToProgram(int32_t programId, int32_t shaderId)=0
Attaches a shader to a program.
virtual int32_t getProgramUniformLocation(int32_t programId, const string &name)=0
Returns location of given uniform variable.
virtual void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data)=0
Uploads buffer data to buffer object.
virtual void useProgram(int contextIdx, int32_t programId)=0
Use shader program.
Buffers used to transfer data between main memory to graphics board memory.
Definition: ObjectBuffer.h:23
Byte buffer class.
Definition: ByteBuffer.h:24
Float buffer class.
Definition: FloatBuffer.h:18