Browse Source

Setup default views in Device::render_world()

Daniele Bartolini 10 years ago
parent
commit
ab189d840d
6 changed files with 29 additions and 34 deletions
  1. 25 0
      src/device.cpp
  2. 0 9
      src/lua/lua_api.cpp
  3. 1 1
      src/world/debug_line.cpp
  4. 1 16
      src/world/render_world.cpp
  5. 1 1
      src/world/render_world.h
  6. 1 7
      src/world/world.cpp

+ 25 - 0
src/device.cpp

@@ -17,6 +17,7 @@
 #include "lua_environment.h"
 #include "map.h"
 #include "material_manager.h"
+#include "matrix4x4.h"
 #include "memory.h"
 #include "os.h"
 #include "os_event_queue.h"
@@ -341,6 +342,30 @@ void Device::update()
 
 void Device::render_world(World& world, CameraInstance camera)
 {
+	bgfx::setViewClear(0
+		, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
+		, 0x353839FF
+		, 1.0f
+		, 0
+		);
+
+	bgfx::setViewRect(0, 0, 0, _width, _height);
+	bgfx::setViewRect(1, 0, 0, _width, _height);
+	bgfx::setViewRect(2, 0, 0, _width, _height);
+
+	const f32* view = to_float_ptr(world.camera_view_matrix(camera));
+	const f32* proj = to_float_ptr(world.camera_projection_matrix(camera));
+
+	bgfx::setViewTransform(0, view, proj);
+	bgfx::setViewTransform(1, view, proj);
+	bgfx::setViewTransform(2, view, proj);
+
+	bgfx::touch(0);
+	bgfx::touch(1);
+	bgfx::touch(2);
+
+	world.set_camera_viewport_metrics(camera, 0, 0, _width, _height);
+
 	world.render(camera);
 }
 

+ 0 - 9
src/lua/lua_api.cpp

@@ -1344,14 +1344,6 @@ static int camera_set_orthographic_metrics(lua_State* L)
 	return 0;
 }
 
-static int camera_set_viewport_metrics(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.get_world(1)->set_camera_viewport_metrics(stack.get_camera(2), stack.get_int(3), stack.get_int(4),
-		stack.get_int(5), stack.get_int(6));
-	return 0;
-}
-
 static int camera_screen_to_world(lua_State* L)
 {
 	LuaStack stack(L);
@@ -2944,7 +2936,6 @@ void load_api(LuaEnvironment& env)
 	env.load_module_function("World", "camera_far_clip_distance",        camera_far_clip_distance);
 	env.load_module_function("World", "set_camera_far_clip_distance",    camera_set_far_clip_distance);
 	env.load_module_function("World", "set_camera_orthographic_metrics", camera_set_orthographic_metrics);
-	env.load_module_function("World", "set_camera_viewport_metrics",     camera_set_viewport_metrics);
 	env.load_module_function("World", "camera_screen_to_world",          camera_screen_to_world);
 	env.load_module_function("World", "camera_world_to_screen",          camera_world_to_screen);
 	env.load_module_function("World", "update_animations",               world_update_animations);

+ 1 - 1
src/world/debug_line.cpp

@@ -157,7 +157,7 @@ void DebugLine::submit()
 
 	bgfx::setVertexBuffer(&tvb, 0, _num * 2);
 	bgfx::setState(sd.state);
-	bgfx::submit(0, sd.program);
+	bgfx::submit(1, sd.program);
 }
 
 } // namespace crown

+ 1 - 16
src/world/render_world.cpp

@@ -461,23 +461,8 @@ void RenderWorld::update_transforms(const UnitId* begin, const UnitId* end, cons
 	}
 }
 
-void RenderWorld::render(const Matrix4x4& view, const Matrix4x4& projection, u16 x, u16 y, u16 width, u16 height)
+void RenderWorld::render(const Matrix4x4& view, const Matrix4x4& projection)
 {
-	bgfx::setViewClear(0
-		, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
-		, 0x353839FF
-		, 1.0f
-		, 0
-		);
-
-	// Set view and projection matrix for view 0.
-	bgfx::setViewTransform(0, to_float_ptr(view), to_float_ptr(projection));
-	bgfx::setViewRect(0, x, y, width, height);
-
-	// This dummy draw call is here to make sure that view 0 is cleared
-	// if no other draw calls are submitted to view 0.
-	bgfx::touch(0);
-
 	for (u32 ll = 0; ll < _light_data.size; ++ll)
 	{
 		const Vector4 ldir = normalize(_light_data.world[ll].z) * view;

+ 1 - 1
src/world/render_world.h

@@ -103,7 +103,7 @@ public:
 
 	void update_transforms(const UnitId* begin, const UnitId* end, const Matrix4x4* world);
 
-	void render(const Matrix4x4& view, const Matrix4x4& projection, u16 x, u16 y, u16 width, u16 height);
+	void render(const Matrix4x4& view, const Matrix4x4& projection);
 
 	/// Sets whether to @a enable debug drawing
 	void enable_debug_drawing(bool enable);

+ 1 - 7
src/world/world.cpp

@@ -291,13 +291,7 @@ void World::render(CameraInstance i)
 {
 	const Camera& camera = _camera[i.i];
 
-	_render_world->render(camera_view_matrix(i)
-		, camera.projection
-		, camera.view_x
-		, camera.view_y
-		, camera.view_width
-		, camera.view_height
-		);
+	_render_world->render(camera_view_matrix(i), camera.projection);
 
 	_physics_world->draw_debug();
 	_render_world->draw_debug(*_lines);