X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frenderer.h;h=157282a5398f6a18a23f0f80684a9765a16e7a3e;hb=f632bf388a58b036e265f3789c797beff5ab063a;hp=1be1a4549211828d8b3dedfeea7898a4c0a526b3;hpb=db2fd517dcd215e9d16345287d413f2a64f5ba03;p=libs%2Fgl.git diff --git a/source/renderer.h b/source/renderer.h index 1be1a454..157282a5 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -13,6 +13,7 @@ namespace GL { class Batch; class Buffer; class Camera; +class Clipping; class Material; class Mesh; class Lighting; @@ -63,12 +64,15 @@ public: private: struct State { + Matrix modelview_matrix; const Texture *texture; const Texturing *texturing; unsigned lowest_effect_texunit; const Material *material; const Lighting *lighting; Matrix lighting_matrix; + const Clipping *clipping; + Matrix clipping_matrix; const Program *shprog; unsigned shdata_count; const Mesh *mesh; @@ -78,34 +82,45 @@ private: State(); }; - class MtxStack: public MatrixStack + enum ChangeMask { - private: - Renderer &renderer; - - public: - MtxStack(Renderer &); - private: - virtual void update(); + LEGACY_MATRIX = 1, + MODERN_MATRIX = 2, + MATRIX = LEGACY_MATRIX|MODERN_MATRIX, + LEGACY_LIGHTING = 4, + LEGACY_CLIPPING = 8, + SHADER_DATA = 16, + MATERIAL_SHDATA = 32, + STANDARD_SHDATA = 64 }; - MtxStack mtx_stack; - bool mtx_changed; + unsigned char changed; + bool matrices_loaded; + unsigned shdata_applied; const Camera *camera; std::vector state_stack; State *state; - bool lighting_changed; ProgramData standard_shdata; std::vector shdata_stack; - bool shdata_changed; - const Buffer *element_buffer; std::set excluded; public: Renderer(const Camera *); ~Renderer(); - MatrixStack &matrix_stack() { return mtx_stack; } + /** Resets all internal state and restarts rendering. There must be no + unpopped state in the stack. It is permissible to call begin() multiple + times without an intervening end(). */ + void begin(const Camera *); + + /** Replaces the Renderer's modelview matrix. */ + void set_matrix(const Matrix &); + + /** Applies a transform to the Renderer's modelview matrix. */ + void transform(const Matrix &); + + /** Returns the current modelview matrix. */ + const Matrix &get_matrix() const { return state->modelview_matrix; } const Camera *get_camera() const { return camera; } @@ -115,6 +130,7 @@ public: void set_material(const Material *); void set_lighting(const Lighting *); + void set_clipping(const Clipping *); /** Sets the shader program to use. An initial set of data can be set as well, with the same semantics as add_shader_data. */ @@ -126,7 +142,6 @@ public: void add_shader_data(const ProgramData &data); void set_mesh(const Mesh *); - void set_element_buffer(const Buffer *); void set_winding_test(const WindingTest *); void set_reverse_winding(bool); @@ -139,9 +154,14 @@ public: /** Prepares for temporarily bypassing the Renderer by synchronizing the current state with GL. No additional call is necessary to resume using the - Renderer. */ + Renderer. DEPRECATED. */ void escape(); + /** Unbinds all objects and resets related state. There must be no unpopped + state in the stack. Rendering with the same camera can be restarted without + an explicit begin() call. */ + void end(); + void exclude(const Renderable &); void include(const Renderable &); @@ -150,6 +170,7 @@ public: private: void apply_state(); + void reset_state(); }; } // namespace GL