panda3d/panda/src/tinydisplay/tinyGraphicsStateGuardian.h
2008-05-10 21:51:22 +00:00

173 lines
6.0 KiB
C++

// Filename: tinyGraphicsStateGuardian.h
// Created by: drose (24Apr08)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef TINYGRAPHICSSTATEGUARDIAN_H
#define TINYGRAPHICSSTATEGUARDIAN_H
#include "pandabase.h"
#include "graphicsStateGuardian.h"
#include "tinySDLGraphicsPipe.h"
#include "simpleLru.h"
#include "zmath.h"
#include "zbuffer.h"
class TinyTextureContext;
struct GLContext;
struct GLVertex;
struct GLMaterial;
struct GLTexture;
////////////////////////////////////////////////////////////////////
// Class : TinyGraphicsStateGuardian
// Description : An interface to the TinyGL software rendering code
// within this module.
////////////////////////////////////////////////////////////////////
class EXPCL_TINYDISPLAY TinyGraphicsStateGuardian : public GraphicsStateGuardian {
public:
TinyGraphicsStateGuardian(GraphicsPipe *pipe,
TinyGraphicsStateGuardian *share_with);
virtual ~TinyGraphicsStateGuardian();
virtual void reset();
virtual void free_pointers();
virtual void close_gsg();
virtual bool depth_offset_decals();
virtual PT(GeomMunger) make_geom_munger(const RenderState *state,
Thread *current_thread);
virtual void clear(DrawableRegion *clearable);
virtual void prepare_display_region(DisplayRegionPipelineReader *dr,
Lens::StereoChannel stereo_channel);
virtual CPT(TransformState) calc_projection_mat(const Lens *lens);
virtual bool prepare_lens();
virtual bool begin_frame(Thread *current_thread);
virtual bool begin_scene();
virtual void end_scene();
virtual void end_frame(Thread *current_thread);
virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader,
const GeomMunger *munger,
const GeomVertexDataPipelineReader *data_reader,
bool force);
virtual bool draw_triangles(const GeomPrimitivePipelineReader *reader,
bool force);
virtual bool draw_lines(const GeomPrimitivePipelineReader *reader,
bool force);
virtual bool draw_points(const GeomPrimitivePipelineReader *reader,
bool force);
virtual void end_draw_primitives();
virtual void framebuffer_copy_to_texture
(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb);
virtual bool framebuffer_copy_to_ram
(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb);
virtual void set_state_and_transform(const RenderState *state,
const TransformState *transform);
virtual TextureContext *prepare_texture(Texture *tex);
virtual void release_texture(TextureContext *tc);
virtual void do_issue_light();
virtual void bind_light(PointLight *light_obj, const NodePath &light,
int light_id);
virtual void bind_light(DirectionalLight *light_obj, const NodePath &light,
int light_id);
virtual void bind_light(Spotlight *light_obj, const NodePath &light,
int light_id);
private:
void do_issue_transform();
void do_issue_render_mode();
void do_issue_cull_face();
void do_issue_material();
void do_issue_texture();
void apply_texture(TextureContext *tc);
bool upload_texture(TinyTextureContext *gtc);
bool setup_gltex(GLTexture *gltex, int x_size, int y_size, int num_levels);
int get_tex_shift(int orig_size);
static void copy_lum_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
static void copy_alpha_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
static void copy_one_channel_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level, int channel);
static void copy_la_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
static void copy_rgb_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
static void copy_rgba_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
void setup_material(GLMaterial *gl_material, const Material *material);
static void load_matrix(M4 *matrix, const TransformState *transform);
public:
// Filled in by the Tiny*GraphicsWindow at begin_frame().
ZBuffer *_current_frame_buffer;
private:
// Allocated by prepare_display_region when necessary for a zoomed
// display region.
ZBuffer *_aux_frame_buffer;
GLContext *_c;
enum ColorMaterialFlags {
CMF_ambient = 0x001,
CMF_diffuse = 0x002,
};
int _color_material_flags;
int _texfilter_state;
bool _texture_replace;
SimpleLru _textures_lru;
// Used during being_draw_primitives() .. end_draw_primitives().
int _min_vertex;
int _max_vertex;
GLVertex *_vertices;
int _vertices_size;
static PStatCollector _vertices_immediate_pcollector;
static PStatCollector _draw_transform_pcollector;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
GraphicsStateGuardian::init_type();
register_type(_type_handle, "TinyGraphicsStateGuardian",
GraphicsStateGuardian::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "tinyGraphicsStateGuardian.I"
#endif