Main.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsApplication.h"
  4. #include "Material/BsMaterial.h"
  5. #include "CoreThread/BsCoreThread.h"
  6. #include "RenderAPI/BsRenderAPI.h"
  7. #include "RenderAPI/BsRenderWindow.h"
  8. #include "RenderAPI/BsCommandBuffer.h"
  9. #include "RenderAPI/BsGpuProgram.h"
  10. #include "RenderAPI/BsGpuPipelineState.h"
  11. #include "RenderAPI/BsBlendState.h"
  12. #include "RenderAPI/BsDepthStencilState.h"
  13. #include "RenderAPI/BsGpuParamBlockBuffer.h"
  14. #include "RenderAPI/BsIndexBuffer.h"
  15. #include "RenderAPI/BsVertexDataDesc.h"
  16. #include "Mesh/BsMeshData.h"
  17. #include "Math/BsQuaternion.h"
  18. #include "Utility/BsTime.h"
  19. #include "Renderer/BsRendererUtility.h"
  20. #include "BsEngineConfig.h"
  21. #if BS_PLATFORM == BS_PLATFORM_WIN32
  22. #include <windows.h>
  23. #endif
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. // This example uses the low-level rendering API to render a textured cube mesh. This is opposed to using scene objects
  26. // and components, in which case objects are rendered automatically based on their transform and other properties.
  27. //
  28. // Using low-level rendering API gives you full control over rendering, similar to using Vulkan, DirectX or OpenGL APIs.
  29. //
  30. // In order to use the low-level rendering system we need to override the Application class so we get notified of updates
  31. // and start-up/shut-down events. This is normally not necessary for a high level scene object based model.
  32. //
  33. // The rendering is performed on the core (i.e. rendering) thread, as opposed to the main thread, where majority of
  34. // Banshee's code executes.
  35. //
  36. // The example first sets up necessary resources, like GPU programs, pipeline state, vertex & index buffers. Then every
  37. // frame it binds the necessary rendering resources and executes the draw call.
  38. //
  39. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  40. namespace bs
  41. {
  42. UINT32 windowResWidth = 1280;
  43. UINT32 windowResHeight = 720;
  44. // Declare the methods we'll use to do work on the core thread. Note the "ct" namespace, which we use because we render
  45. // on the core thread (ct = core thread). Every object usable on the core thread lives in this namespace.
  46. namespace ct
  47. {
  48. void setup(const SPtr<RenderWindow>& renderWindow);
  49. void render();
  50. void shutdown();
  51. }
  52. // Override the default Application so we can get notified when engine starts-up, shuts-down and when it executes
  53. // every frame
  54. class MyApplication : public Application
  55. {
  56. public:
  57. // Pass along the start-up structure to the parent, we don't need to handle it
  58. MyApplication(const START_UP_DESC& desc)
  59. :Application(desc)
  60. { }
  61. private:
  62. // Called when the engine is first started up
  63. void onStartUp() override
  64. {
  65. // Ensure all parent systems are initialized first
  66. Application::onStartUp();
  67. // Get the primary window that was created during start-up. This will be the final desination for all our
  68. // rendering.
  69. SPtr<RenderWindow> renderWindow = getPrimaryWindow();
  70. // Get the version of the render window usable on the core thread, and send it along to setup()
  71. SPtr<ct::RenderWindow> renderWindowCore = renderWindow->getCore();
  72. // Initialize all the resources we need for rendering. Since we do rendering on a separate thread (the "core
  73. // thread"), we don't call the method directly, but rather queue it for execution using the CoreThread class.
  74. gCoreThread().queueCommand(std::bind(&ct::setup, renderWindowCore));
  75. }
  76. // Called when the engine is about to be shut down
  77. void onShutDown() override
  78. {
  79. gCoreThread().queueCommand(&ct::shutdown);
  80. // Shut-down engine components
  81. Application::onShutDown();
  82. }
  83. // Called every frame, before any other engine system (optionally use postUpdate())
  84. void preUpdate() override
  85. {
  86. gCoreThread().queueCommand(&ct::render);
  87. }
  88. };
  89. }
  90. using namespace bs;
  91. // Main entry point into the application
  92. #if BS_PLATFORM == BS_PLATFORM_WIN32
  93. int CALLBACK WinMain(
  94. _In_ HINSTANCE hInstance,
  95. _In_ HINSTANCE hPrevInstance,
  96. _In_ LPSTR lpCmdLine,
  97. _In_ int nCmdShow
  98. )
  99. #else
  100. int main()
  101. #endif
  102. {
  103. // Define a video mode for the resolution of the primary rendering window.
  104. VideoMode videoMode(windowResWidth, windowResHeight);
  105. // Start-up the engine using our custom MyApplication class. This will also create the primary rendering window.
  106. // We provide the initial resolution of the window, its title and fullscreen state.
  107. Application::startUp<MyApplication>(videoMode, "Banshee Example App", false);
  108. // Runs the main loop that does most of the work. This method will exit when user closes the main
  109. // window or exits in some other way.
  110. Application::instance().runMainLoop();
  111. Application::shutDown();
  112. return 0;
  113. }
  114. namespace bs { namespace ct
  115. {
  116. // Declarations for some helper methods we'll use during setup
  117. void writeBoxVertices(const AABox& box, UINT8* positions, UINT8* uvs, UINT32 stride);
  118. void writeBoxIndices(UINT32* indices);
  119. const char* getVertexProgSource();
  120. const char* getFragmentProgSource();
  121. Matrix4 createWorldViewProjectionMatrix();
  122. // Fields where we'll store the resources required during calls to render(). These are initialized in setup()
  123. // and cleaned up in shutDown()
  124. SPtr<GraphicsPipelineState> gPipelineState;
  125. SPtr<Texture> gSurfaceTex;
  126. SPtr<SamplerState> gSurfaceSampler;
  127. SPtr<GpuParams> gGpuParams;
  128. SPtr<VertexDeclaration> gVertexDecl;
  129. SPtr<VertexBuffer> gVertexBuffer;
  130. SPtr<IndexBuffer> gIndexBuffer;
  131. SPtr<RenderTexture> gRenderTarget;
  132. SPtr<RenderWindow> gRenderWindow;
  133. bool gUseHLSL = true;
  134. const UINT32 NUM_VERTICES = 24;
  135. const UINT32 NUM_INDICES = 36;
  136. // Structure that will hold uniform block variables for the GPU programs
  137. struct UniformBlock
  138. {
  139. Matrix4 gMatWVP; // World view projection matrix
  140. Color gTint; // Tint to apply on top of the texture
  141. };
  142. // Initializes any resources required for rendering
  143. void setup(const SPtr<RenderWindow>& renderWindow)
  144. {
  145. // Determine which shading language to use (depending on the RenderAPI chosen during build)
  146. gUseHLSL = strcmp(BS_RENDER_API_MODULE, "BansheeD3D11RenderAPI") == 0;
  147. // This will be the primary output for our rendering (created by the main thread on start-up)
  148. gRenderWindow = renderWindow;
  149. // Create a vertex GPU program
  150. const char* vertProgSrc = getVertexProgSource();
  151. GPU_PROGRAM_DESC vertProgDesc;
  152. vertProgDesc.type = GPT_VERTEX_PROGRAM;
  153. vertProgDesc.entryPoint = "main";
  154. vertProgDesc.language = gUseHLSL ? "hlsl" : "glsl";
  155. vertProgDesc.source = vertProgSrc;
  156. SPtr<GpuProgram> vertProg = GpuProgram::create(vertProgDesc);
  157. // Create a fragment GPU program
  158. const char* fragProgSrc = getFragmentProgSource();
  159. GPU_PROGRAM_DESC fragProgDesc;
  160. fragProgDesc.type = GPT_FRAGMENT_PROGRAM;
  161. fragProgDesc.entryPoint = "main";
  162. fragProgDesc.language = gUseHLSL ? "hlsl" : "glsl";
  163. fragProgDesc.source = fragProgSrc;
  164. SPtr<GpuProgram> fragProg = GpuProgram::create(fragProgDesc);
  165. // Create a graphics pipeline state
  166. BLEND_STATE_DESC blendDesc;
  167. blendDesc.renderTargetDesc[0].blendEnable = true;
  168. blendDesc.renderTargetDesc[0].renderTargetWriteMask = 0b0111; // RGB, don't write to alpha
  169. blendDesc.renderTargetDesc[0].blendOp = BO_ADD;
  170. blendDesc.renderTargetDesc[0].srcBlend = BF_SOURCE_ALPHA;
  171. blendDesc.renderTargetDesc[0].dstBlend = BF_INV_SOURCE_ALPHA;
  172. DEPTH_STENCIL_STATE_DESC depthStencilDesc;
  173. depthStencilDesc.depthWriteEnable = false;
  174. depthStencilDesc.depthReadEnable = false;
  175. PIPELINE_STATE_DESC pipelineDesc;
  176. pipelineDesc.blendState = BlendState::create(blendDesc);
  177. pipelineDesc.depthStencilState = DepthStencilState::create(depthStencilDesc);
  178. pipelineDesc.vertexProgram = vertProg;
  179. pipelineDesc.fragmentProgram = fragProg;
  180. gPipelineState = GraphicsPipelineState::create(pipelineDesc);
  181. // Create an object containing GPU program parameters
  182. gGpuParams = GpuParams::create(gPipelineState);
  183. // Create a vertex declaration for shader inputs
  184. SPtr<VertexDataDesc> vertexDesc = VertexDataDesc::create();
  185. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  186. vertexDesc->addVertElem(VET_FLOAT2, VES_TEXCOORD);
  187. gVertexDecl = VertexDeclaration::create(vertexDesc);
  188. // Create & fill the vertex buffer for a box mesh
  189. UINT32 vertexStride = vertexDesc->getVertexStride();
  190. VERTEX_BUFFER_DESC vbDesc;
  191. vbDesc.numVerts = NUM_VERTICES;
  192. vbDesc.vertexSize = vertexStride;
  193. gVertexBuffer = VertexBuffer::create(vbDesc);
  194. UINT8* vbData = (UINT8*)gVertexBuffer->lock(0, vertexStride * NUM_VERTICES, GBL_WRITE_ONLY_DISCARD);
  195. UINT8* positions = vbData + vertexDesc->getElementOffsetFromStream(VES_POSITION);
  196. UINT8* uvs = vbData + vertexDesc->getElementOffsetFromStream(VES_TEXCOORD);
  197. AABox box(Vector3::ONE * -10.0f, Vector3::ONE * 10.0f);
  198. writeBoxVertices(box, positions, uvs, vertexStride);
  199. gVertexBuffer->unlock();
  200. // Create & fill the index buffer for a box mesh
  201. INDEX_BUFFER_DESC ibDesc;
  202. ibDesc.numIndices = NUM_INDICES;
  203. ibDesc.indexType = IT_32BIT;
  204. gIndexBuffer = IndexBuffer::create(ibDesc);
  205. UINT32* ibData = (UINT32*)gIndexBuffer->lock(0, NUM_INDICES * sizeof(UINT32), GBL_WRITE_ONLY_DISCARD);
  206. writeBoxIndices(ibData);
  207. gIndexBuffer->unlock();
  208. // Create a simple 2x2 checkerboard texture to map to the object we're about to render
  209. SPtr<PixelData> pixelData = PixelData::create(2, 2, 1, PF_RGBA8);
  210. pixelData->setColorAt(Color::White, 0, 0);
  211. pixelData->setColorAt(Color::Black, 1, 0);
  212. pixelData->setColorAt(Color::White, 1, 1);
  213. pixelData->setColorAt(Color::Black, 0, 1);
  214. gSurfaceTex = Texture::create(pixelData);
  215. // Create a sampler state for the texture above
  216. SAMPLER_STATE_DESC samplerDesc;
  217. samplerDesc.minFilter = FO_POINT;
  218. samplerDesc.magFilter = FO_POINT;
  219. gSurfaceSampler = SamplerState::create(samplerDesc);
  220. // Create a color attachment texture for the render surface
  221. TEXTURE_DESC colorAttDesc;
  222. colorAttDesc.width = windowResWidth;
  223. colorAttDesc.height = windowResHeight;
  224. colorAttDesc.format = PF_RGBA8;
  225. colorAttDesc.usage = TU_RENDERTARGET;
  226. SPtr<Texture> colorAtt = Texture::create(colorAttDesc);
  227. // Create a depth attachment texture for the render surface
  228. TEXTURE_DESC depthAttDesc;
  229. depthAttDesc.width = windowResWidth;
  230. depthAttDesc.height = windowResHeight;
  231. depthAttDesc.format = PF_D32;
  232. depthAttDesc.usage = TU_DEPTHSTENCIL;
  233. SPtr<Texture> depthAtt = Texture::create(depthAttDesc);
  234. // Create the render surface
  235. RENDER_TEXTURE_DESC desc;
  236. desc.colorSurfaces[0].texture = colorAtt;
  237. desc.depthStencilSurface.texture = depthAtt;
  238. gRenderTarget = RenderTexture::create(desc);
  239. }
  240. // Render the box, called every frame
  241. void render()
  242. {
  243. // Fill out the uniform block variables
  244. UniformBlock uniformBlock;
  245. uniformBlock.gMatWVP = createWorldViewProjectionMatrix();
  246. uniformBlock.gTint = Color(1.0f, 1.0f, 1.0f, 0.5f);
  247. // Create a uniform block buffer for holding the uniform variables
  248. SPtr<GpuParamBlockBuffer> uniformBuffer = GpuParamBlockBuffer::create(sizeof(UniformBlock));
  249. uniformBuffer->write(0, &uniformBlock, sizeof(uniformBlock));
  250. // Assign the uniform buffer & texture
  251. gGpuParams->setParamBlockBuffer(GPT_FRAGMENT_PROGRAM, "Params", uniformBuffer);
  252. gGpuParams->setParamBlockBuffer(GPT_VERTEX_PROGRAM, "Params", uniformBuffer);
  253. gGpuParams->setTexture(GPT_FRAGMENT_PROGRAM, "gMainTexture", gSurfaceTex);
  254. // HLSL uses separate sampler states, so we need to use a different name for the sampler
  255. if(gUseHLSL)
  256. gGpuParams->setSamplerState(GPT_FRAGMENT_PROGRAM, "gMainTexSamp", gSurfaceSampler);
  257. else
  258. gGpuParams->setSamplerState(GPT_FRAGMENT_PROGRAM, "gMainTexture", gSurfaceSampler);
  259. // Create a command buffer
  260. SPtr<CommandBuffer> cmds = CommandBuffer::create(GQT_GRAPHICS);
  261. // Get the primary render API access point
  262. RenderAPI& rapi = RenderAPI::instance();
  263. // Bind render surface & clear it
  264. rapi.setRenderTarget(gRenderTarget, 0, RT_NONE, cmds);
  265. rapi.clearRenderTarget(FBT_COLOR | FBT_DEPTH, Color::Blue, 1, 0, 0xFF, cmds);
  266. // Bind the pipeline state
  267. rapi.setGraphicsPipeline(gPipelineState, cmds);
  268. // Set the vertex & index buffers, as well as vertex declaration and draw type
  269. rapi.setVertexBuffers(0, &gVertexBuffer, 1, cmds);
  270. rapi.setIndexBuffer(gIndexBuffer, cmds);
  271. rapi.setVertexDeclaration(gVertexDecl, cmds);
  272. rapi.setDrawOperation(DOT_TRIANGLE_LIST, cmds);
  273. // Bind the GPU program parameters (i.e. resource descriptors)
  274. rapi.setGpuParams(gGpuParams, cmds);
  275. // Draw
  276. rapi.drawIndexed(0, NUM_INDICES, 0, NUM_VERTICES, 1, cmds);
  277. // Submit the command buffer
  278. rapi.submitCommandBuffer(cmds);
  279. // Blit the image from the render texture, to the render window
  280. rapi.setRenderTarget(gRenderWindow);
  281. // Get the color attachment
  282. SPtr<Texture> colorTexture = gRenderTarget->getColorTexture(0);
  283. // Use the helper RendererUtility to draw a full-screen quad of the provided texture and output it to the currently
  284. // bound render target. Internally this uses the same calls we used above, just with a different pipeline and mesh.
  285. gRendererUtility().blit(colorTexture);
  286. // Present the rendered image to the user
  287. rapi.swapBuffers(gRenderWindow);
  288. }
  289. // Clean up any resources
  290. void shutdown()
  291. {
  292. gPipelineState = nullptr;
  293. gSurfaceTex = nullptr;
  294. gGpuParams = nullptr;
  295. gVertexDecl = nullptr;
  296. gVertexBuffer = nullptr;
  297. gIndexBuffer = nullptr;
  298. gRenderTarget = nullptr;
  299. gRenderWindow = nullptr;
  300. gSurfaceSampler = nullptr;
  301. }
  302. /////////////////////////////////////////////////////////////////////////////////////
  303. //////////////////////////////////HELPER METHODS/////////////////////////////////////
  304. /////////////////////////////////////////////////////////////////////////////////////
  305. void writeBoxVertices(const AABox& box, UINT8* positions, UINT8* uvs, UINT32 stride)
  306. {
  307. AABox::Corner vertOrder[] =
  308. {
  309. AABox::NEAR_LEFT_BOTTOM, AABox::NEAR_RIGHT_BOTTOM, AABox::NEAR_RIGHT_TOP, AABox::NEAR_LEFT_TOP,
  310. AABox::FAR_RIGHT_BOTTOM, AABox::FAR_LEFT_BOTTOM, AABox::FAR_LEFT_TOP, AABox::FAR_RIGHT_TOP,
  311. AABox::FAR_LEFT_BOTTOM, AABox::NEAR_LEFT_BOTTOM, AABox::NEAR_LEFT_TOP, AABox::FAR_LEFT_TOP,
  312. AABox::NEAR_RIGHT_BOTTOM, AABox::FAR_RIGHT_BOTTOM, AABox::FAR_RIGHT_TOP, AABox::NEAR_RIGHT_TOP,
  313. AABox::FAR_LEFT_TOP, AABox::NEAR_LEFT_TOP, AABox::NEAR_RIGHT_TOP, AABox::FAR_RIGHT_TOP,
  314. AABox::FAR_LEFT_BOTTOM, AABox::FAR_RIGHT_BOTTOM, AABox::NEAR_RIGHT_BOTTOM, AABox::NEAR_LEFT_BOTTOM
  315. };
  316. for (auto& entry : vertOrder)
  317. {
  318. Vector3 pos = box.getCorner(entry);
  319. memcpy(positions, &pos, sizeof(pos));
  320. positions += stride;
  321. }
  322. for (UINT32 i = 0; i < 6; i++)
  323. {
  324. Vector2 uv;
  325. uv = Vector2(0.0f, 1.0f);
  326. memcpy(uvs, &uv, sizeof(uv));
  327. uvs += stride;
  328. uv = Vector2(1.0f, 1.0f);
  329. memcpy(uvs, &uv, sizeof(uv));
  330. uvs += stride;
  331. uv = Vector2(1.0f, 0.0f);
  332. memcpy(uvs, &uv, sizeof(uv));
  333. uvs += stride;
  334. uv = Vector2(0.0f, 0.0f);
  335. memcpy(uvs, &uv, sizeof(uv));
  336. uvs += stride;
  337. }
  338. }
  339. void writeBoxIndices(UINT32* indices)
  340. {
  341. for (UINT32 face = 0; face < 6; face++)
  342. {
  343. UINT32 faceVertOffset = face * 4;
  344. indices[face * 6 + 0] = faceVertOffset + 2;
  345. indices[face * 6 + 1] = faceVertOffset + 1;
  346. indices[face * 6 + 2] = faceVertOffset + 0;
  347. indices[face * 6 + 3] = faceVertOffset + 0;
  348. indices[face * 6 + 4] = faceVertOffset + 3;
  349. indices[face * 6 + 5] = faceVertOffset + 2;
  350. }
  351. }
  352. const char* getVertexProgSource()
  353. {
  354. if(gUseHLSL)
  355. {
  356. static const char* src = R"(
  357. cbuffer Params
  358. {
  359. float4x4 gMatWVP;
  360. float4 gTint;
  361. }
  362. void main(
  363. in float3 inPos : POSITION,
  364. in float2 uv : TEXCOORD0,
  365. out float4 oPosition : SV_Position,
  366. out float2 oUv : TEXCOORD0)
  367. {
  368. oPosition = mul(gMatWVP, float4(inPos.xyz, 1));
  369. oUv = uv;
  370. }
  371. )";
  372. return src;
  373. }
  374. else
  375. {
  376. static const char* src = R"(
  377. layout (binding = 0, std140) uniform Params
  378. {
  379. mat4 gMatWVP;
  380. vec4 gTint;
  381. };
  382. layout (location = 0) in vec3 bs_position;
  383. layout (location = 1) in vec2 bs_texcoord0;
  384. layout (location = 0) out vec2 texcoord0;
  385. out gl_PerVertex
  386. {
  387. vec4 gl_Position;
  388. };
  389. void main()
  390. {
  391. gl_Position = gMatWVP * vec4(bs_position.xyz, 1);
  392. texcoord0 = bs_texcoord0;
  393. }
  394. )";
  395. return src;
  396. }
  397. }
  398. const char* getFragmentProgSource()
  399. {
  400. if (gUseHLSL)
  401. {
  402. static const char* src = R"(
  403. cbuffer Params
  404. {
  405. float4x4 gMatWVP;
  406. float4 gTint;
  407. }
  408. SamplerState gMainTexSamp : register(s0);
  409. Texture2D gMainTexture : register(t0);
  410. float4 main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target
  411. {
  412. float4 color = gMainTexture.Sample(gMainTexSamp, uv);
  413. return color * gTint;
  414. }
  415. )";
  416. return src;
  417. }
  418. else
  419. {
  420. static const char* src = R"(
  421. layout (binding = 0, std140) uniform Params
  422. {
  423. mat4 gMatWVP;
  424. vec4 gTint;
  425. };
  426. layout (binding = 1) uniform sampler2D gMainTexture;
  427. layout (location = 0) in vec2 texcoord0;
  428. layout (location = 0) out vec4 fragColor;
  429. void main()
  430. {
  431. vec4 color = texture(gMainTexture, texcoord0.st);
  432. fragColor = color * gTint;
  433. }
  434. )";
  435. return src;
  436. }
  437. }
  438. Matrix4 createWorldViewProjectionMatrix()
  439. {
  440. Matrix4 proj = Matrix4::projectionPerspective(Degree(75.0f), 16.0f / 9.0f, 0.05f, 1000.0f);
  441. bs::RenderAPI::convertProjectionMatrix(proj, proj);
  442. Vector3 cameraPos = Vector3(0.0f, -20.0f, 50.0f);
  443. Vector3 lookDir = -Vector3::normalize(cameraPos);
  444. Quaternion cameraRot(BsIdentity);
  445. cameraRot.lookRotation(lookDir);
  446. Matrix4 view = Matrix4::view(cameraPos, cameraRot);
  447. Quaternion rotation(Vector3::UNIT_Y, Degree(gTime().getTime() * 90.0f));
  448. Matrix4 world = Matrix4::TRS(Vector3::ZERO, rotation, Vector3::ONE);
  449. Matrix4 viewProj = proj * view * world;
  450. // GLSL uses column major matrices, so transpose
  451. if(!gUseHLSL)
  452. viewProj = viewProj.transpose();
  453. return viewProj;
  454. }
  455. }}