MCPcopy Create free account
hub / github.com/axmolengine/axmol / initBuffers

Method initBuffers

core/3d/Skybox.cpp:101–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101void Skybox::initBuffers()
102{
103
104 // The skybox is rendered using a purpose-built shader which makes use of
105 // the shader language's inherent support for cubemaps. Hence there is no
106 // need to build a cube mesh. All that is needed is a single quad that
107 // covers the entire screen. The vertex shader will draw the appropriate
108 // view of the cubemap onto that quad.
109 //
110 // The vertex shader does not apply either the model/view matrix or the
111 // projection matrix, so the appropriate quad is one with unit coordinates
112 // in the x and y dimensions. Such a quad will exactly cover the screen.
113 // To ensure that the skybox is rendered behind all other objects, z needs
114 // to be 1.0, but the vertex shader overwrites z to 1.0, so - for the sake
115 // of z-buffering - it is unimportant what we set it to for the vertices
116 // of the quad.
117 //
118 // The quad vertex positions are also used in deriving a direction
119 // vector for the cubemap lookup. We choose z = -1 which matches the
120 // negative-z pointing direction of the camera and gives a field of
121 // view of 90deg in both x and y, if not otherwise adjusted. That fov
122 // is then adjusted to exactly match the camera by applying a prescaling
123 // to the camera's world transformation before sending it to the shader.
124
125 // init vertex buffer object
126 Vec3 vexBuf[] = {Vec3(1, -1, -1), Vec3(1, 1, -1), Vec3(-1, 1, -1), Vec3(-1, -1, -1)};
127
128 uint16_t idxBuf[] = {0, 1, 2, 0, 2, 3};
129
130 _customCommand.createVertexBuffer(sizeof(Vec3), sizeof(vexBuf), CustomCommand::BufferUsage::STATIC);
131 _customCommand.createIndexBuffer(CustomCommand::IndexFormat::U_SHORT, 6, CustomCommand::BufferUsage::STATIC);
132
133 _customCommand.updateVertexBuffer(&vexBuf[0], sizeof(vexBuf));
134 _customCommand.updateIndexBuffer(&idxBuf[0], sizeof(idxBuf));
135}
136
137void Skybox::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
138{

Callers

nothing calls this directly

Calls 5

createVertexBufferMethod · 0.80
createIndexBufferMethod · 0.80
Vec3Function · 0.50
updateVertexBufferMethod · 0.45
updateIndexBufferMethod · 0.45

Tested by

no test coverage detected