Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Add default rendering processor #85

Merged
merged 24 commits into from Sep 10, 2016
Merged

Add default rendering processor #85

merged 24 commits into from Sep 10, 2016

Conversation

nchashch
Copy link
Member

Changes:

  • Add processors::rendering module containing RenderingProcessor type, component types such as Renderable, Light, Camera, and a RendererConfig type
  • Add examples/renderable.rs and examples/pong.rs examples
  • Add ApplicationBuilder::register method to allow registering components with the application using the following syntax:
Application::build(StateType::new(), context)
    .with::<ProcessorType>(processor, "processor_name", 0)
    .register::<ComponentType>()
    .done();
  • Add amethyst_renderer::Camera::orthographic method, which returns an orthographic projection matrix with the given parameters
  • Rename amethyst_context::Config to amethyst_context::ContextConfig
  • Add amethyst::engine::Config, which contains ContextConfig and RendererConfig

* Now Application::build() takes a Context as a paramater instead
  of Config
* Now RenderingProcessor::new() takes scene_name and context as
  parameters and calls context.renderer.add_scene()
* Add num_lights method to context::renderer::Renderer
* Add num_fragments method to context::renderer::Renderer
* Note: if you delete a Component associated Fragment or Light won't
  be deleted from the frame.
* Now Fragments and Ligts corresponding to deleted components
  are deleted from the frame
* Add RendererConfig config struct to the processors::rendering mod,
  it contains the pipeline (Forward or Deferred), the shading (Flat or
  Shaded), and the clear color.
* Now RenderingProcessor::new takes RendererConfig as a parameter
  and creates and sets a pipeline according to this config
* Add ACTIVE_SCENE_NAME and ACTIVE_CAMERA_NAME constants to
  processors::rendering mod
* Now RenderingProcessor::new doesn't take scene_name as a parameter
  instead it adds the default scene with name = ACTIVE_SCENE_NAME to
  the frame
* Add translation, rotation_axis, rotation_angle, and scale fields to
  Renderable component
* Add amethyst::engine::Config containing ContextConfig and
  RendererConfig
* Rename amethyst_context::Config to amethyst_context::ContextConfig
* Remove State::update impl from window.rs example
* Remove State::update impl from sphere.rs example
* Don't register rendering processor Components in
  ApplicationBuilder::new.
* Now amethyst::processor::Camera::new takes Projection as an argument
  instead of fov, aspect, near, and far arguments.
* Add amethyst::renderer::Camera::orthographic function, which returns
  an orthographic projection matrix.
* Add more doc comments to processors::rendering mod
use std::ops::Deref;

// Get all needed component storages and resources
let context = context.lock().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder... technically, why can't this context just be an ECS resource?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could work, but I haven't tried it yet. Probably it would make Application code less ugly, since it would allow removing all context.lock.unwrap() calls in Application impl and only &mut World would need to be passed to State methods instead of &mut Context and &mut World. Also it would simplify Processor implementation code, since you won't have to deal with Arc<Mutex<Context>> argument in Processor::run anymore.

But I think it would be better to put this change in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. What about println! calls though - would you be able to fix them in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no propper logging yet, so it is either println! or panic!. And I think logging also should be added in a separate PR.

if let Some(transform) = context.renderer.mut_fragment_transform(ACTIVE_SCENE_NAME, idx) {
*transform = renderable.transform;
} else {
println!("Error: entity with id = {0} is deleted, \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, error!

@kvark
Copy link
Member

kvark commented Aug 23, 2016

Got a few notes on the PR, plus the cgmath dependency seems to be screwed up (according to Travis).
Other than that, here is some impressive work, thanks @nchashch !
Would be great to have @csherratt and @ebkalderon eyes here as well.

@Emilgardis
Copy link
Contributor

Emilgardis commented Sep 5, 2016

hello_world.md needs to get updated to match the changes to Config. Otherwise everything looks good! Edit: Oops, no changes needed 👍

impl RenderingProcessor {
pub fn new(renderer_config: RendererConfig, context: &mut Context) -> RenderingProcessor {
let clear_color = renderer_config.clear_color;
let pipeline = match renderer_config.pipeline.as_str() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ni: this might be tidier if you use a single match.

match (renderer_config.pipeline.as_str(), renderer_config.shading.as_str()) {
    ("Forward", "Flat") => forward_flat(clear_color),
    ("Forward", "Shaded") => forward_shaded(clear_color),
    ("Deferred", "Flat") => deferred_flat(clear_color),
    ("Deferred", "Shaded") => deferred_shaded(clear_color),
    _ => panic!("Error: Can't provide rendering pipeline requested in renderer_config, \
                 renderer_config.shading field is invalid.")
}

@ghost
Copy link

ghost commented Sep 5, 2016

Some minor nits, but otherwise it LGTM

@kvark
Copy link
Member

kvark commented Sep 8, 2016

@nchashch ok, considering the logging is left out for another PR, could you please rebase the code (and may be fix a few @csherratt -noted nits) for the merge?

@ebkalderon
Copy link
Member

@nchashch This looks pretty good to me! Hopefully we can get this in a mergeable state soon.

@kvark
Copy link
Member

kvark commented Sep 10, 2016

Thanks @nchashch, merging now!

@kvark kvark merged commit e1c862b into amethyst:develop Sep 10, 2016
@nchashch nchashch deleted the renderingprocessor branch October 8, 2016 17:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants