16 #ifndef DXGRAPHICSSTATEGUARDIAN9_H 17 #define DXGRAPHICSSTATEGUARDIAN9_H 19 #include "dxgsg9base.h" 20 #include "dxTextureContext9.h" 21 #include "config_dxgsg9.h" 23 #include "graphicsStateGuardian.h" 25 #include "samplerState.h" 26 #include "displayRegion.h" 28 #include "depthTestAttrib.h" 29 #include "cullFaceAttrib.h" 30 #include "renderModeAttrib.h" 31 #include "colorBlendAttrib.h" 33 #include "pointerToArray.h" 35 #include "vertexElementArray.h" 36 #include "dxShaderContext9.h" 49 class DXVertexBufferContext9;
65 calc_fb_properties(DWORD cformat, DWORD dformat,
66 DWORD multisampletype, DWORD multisamplequality);
102 virtual CPT(TransformState) calc_projection_mat(
const Lens *lens);
134 bool do_framebuffer_copy_to_ram(
Texture *tex,
int view,
int z,
139 void reset_render_states (
void);
140 virtual void reset();
142 virtual void apply_fog(
Fog *fog);
151 static D3DFORMAT get_index_type(Geom::NumericType numeric_type);
152 INLINE
static DWORD LColor_to_D3DCOLOR(
const LColor &cLColor);
155 const TransformState *transform);
157 bool check_dx_allocation (HRESULT result,
int allocation_size,
int attempts);
159 INLINE HRESULT set_render_state (D3DRENDERSTATETYPE state, DWORD value);
160 INLINE HRESULT set_texture_stage_state (DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
161 INLINE HRESULT set_sampler_state (DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value);
163 INLINE
bool get_supports_render_texture()
const;
165 static bool get_gamma_table(
void);
166 static bool static_set_gamma(
bool restore, PN_stdfloat gamma);
169 static void atexit_function(
void);
171 static void set_cg_device(LPDIRECT3DDEVICE9 cg_device);
176 void do_issue_transform();
177 void do_issue_alpha_test();
178 void do_issue_shader();
179 void do_issue_render_mode();
180 void do_issue_rescale_normal();
181 void do_issue_color_write();
182 void do_issue_depth_test();
183 void do_issue_depth_write();
184 void do_issue_cull_face();
186 void do_issue_depth_offset();
187 void do_issue_tex_gen();
188 void do_issue_shade_model();
189 void do_issue_material();
190 void do_issue_texture();
191 void do_issue_blending();
192 void do_issue_stencil();
193 void do_issue_scissor();
195 virtual void reissue_transforms();
197 virtual void enable_lighting(
bool enable);
198 virtual void set_ambient_light(
const LColor &
color);
199 virtual void enable_light(
int light_id,
bool enable);
201 virtual void enable_clip_plane(
int plane_id,
bool enable);
202 virtual void bind_clip_plane(
const NodePath &plane,
int plane_id);
204 virtual void close_gsg();
205 void free_nondx_resources();
206 void free_d3d_device();
211 void do_auto_rescale_normal();
213 void disable_standard_vertex_arrays();
214 bool update_standard_vertex_arrays(
bool force);
215 void disable_standard_texture_bindings();
216 void update_standard_texture_bindings();
219 INLINE
static D3DTEXTUREADDRESS get_texture_wrap_mode(SamplerState::WrapMode wm);
220 INLINE
static D3DFOGMODE get_fog_mode_type(Fog::Mode m);
221 const D3DCOLORVALUE &get_light_color(
Light *light)
const;
222 INLINE
static D3DTRANSFORMSTATETYPE get_tex_mat_sym(
int stage_index);
224 static D3DBLEND get_blend_func(ColorBlendAttrib::Operand operand);
225 void report_texmgr_stats();
228 void set_render_target();
230 void set_texture_blend_mode(
int i,
const TextureStage *stage);
233 HRESULT reset_d3d_device(D3DPRESENT_PARAMETERS *p_presentation_params,
236 bool check_cooperative_level();
244 static D3DTEXTUREFILTERTYPE get_d3d_min_type(SamplerState::FilterType filter_type);
245 static D3DTEXTUREFILTERTYPE get_d3d_mip_type(SamplerState::FilterType filter_type);
246 static D3DTEXTUREOP get_texture_operation(TextureStage::CombineMode mode,
int scale);
247 DWORD get_texture_argument(TextureStage::CombineSource source,
248 TextureStage::CombineOperand operand)
const;
249 static DWORD get_texture_argument_modifier(TextureStage::CombineOperand operand);
251 void draw_primitive_up(D3DPRIMITIVETYPE primitive_type,
252 unsigned int primitive_count,
253 unsigned int first_vertex,
254 unsigned int num_vertices,
255 const unsigned char *buffer,
size_t stride);
256 void draw_indexed_primitive_up(D3DPRIMITIVETYPE primitive_type,
257 unsigned int min_index,
unsigned int max_index,
258 unsigned int num_primitives,
259 const unsigned char *index_data,
260 D3DFORMAT index_type,
261 const unsigned char *buffer,
size_t stride);
263 INLINE
static unsigned char *get_safe_buffer_start();
269 LPDIRECT3DDEVICE9 _d3d_device;
270 IDirect3DSwapChain9 *_swap_chain;
271 D3DPRESENT_PARAMETERS _presentation_reset;
274 HRESULT _last_testcooplevel_result;
276 bool _vertex_blending_enabled;
277 bool _supports_render_texture;
279 RenderBuffer::Type _cur_read_pixel_buffer;
280 bool _auto_rescale_normal;
282 PN_stdfloat _material_ambient;
283 PN_stdfloat _material_diffuse;
284 PN_stdfloat _material_specular;
285 PN_stdfloat _material_shininess;
286 PN_stdfloat _material_emission;
290 PerVertexFog=D3DRS_FOGVERTEXMODE,
291 PerPixelFog=D3DRS_FOGTABLEMODE
293 DxgsgFogType _do_fog_type;
295 D3DVIEWPORT9 _current_viewport;
296 bool _supports_depth_bias;
298 DWORD _clip_plane_bits;
299 CullFaceAttrib::Mode _cull_face_mode;
300 RenderModeAttrib::Mode _current_fill_mode;
302 PT(
Shader) _current_shader;
304 PT(
Shader) _vertex_array_shader;
306 PT(
Shader) _texture_binding_shader;
311 bool _overlay_windows_supported;
312 bool _tex_stats_retrieval_impossible;
313 bool _supports_texture_constant_color;
314 DWORD _constant_color_operand;
316 static D3DMATRIX _d3d_ident_mat;
318 static unsigned char *_temp_buffer;
319 static unsigned char *_safe_buffer_start;
321 int _gsg_managed_textures;
322 int _gsg_managed_vertex_buffers;
323 int _gsg_managed_index_buffers;
324 UINT _available_texture_memory;
327 int _num_bound_streams;
333 DirectionalLights _dlights;
335 #define MAXIMUM_TEXTURES 16 339 #define MAXIMUM_RENDER_STATES 256 342 #define MAXIMUM_TEXTURE_STAGE_STATES 40 344 DWORD state_array [MAXIMUM_TEXTURE_STAGE_STATES];
349 #define MAXIMUM_TEXTURE_RENDER_STATES 16 351 DWORD state_array [MAXIMUM_TEXTURE_RENDER_STATES];
356 DWORD _render_state_array [MAXIMUM_RENDER_STATES];
357 TextureStageStates _texture_stage_states_array [D3D_MAXTEXTURESTAGES];
358 TextureRenderStates _texture_render_states_array [MAXIMUM_TEXTURES];
360 int _num_active_texture_stages;
362 int _vertex_shader_version_major;
363 int _vertex_shader_version_minor;
364 int _pixel_shader_version_major;
365 int _pixel_shader_version_minor;
367 char *_vertex_shader_profile;
368 char *_pixel_shader_profile;
370 int _vertex_shader_maximum_constants;
372 bool _supports_stream_offset;
374 list <wdxGraphicsBuffer9 **> _graphics_buffer_list;
376 int _supports_gamma_calibration;
379 CGcontext _cg_context;
380 static LPDIRECT3DDEVICE9 _cg_device;
385 return get_class_type();
387 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
394 static void init_type() {
395 GraphicsStateGuardian::init_type();
396 register_type(_type_handle,
"DXGraphicsStateGuardian9",
397 GraphicsStateGuardian::get_class_type());
405 friend class wdxGraphicsWindowGroup9;
408 friend class DXVertexBufferContext9;
413 #include "dxGraphicsStateGuardian9.I" A GraphicsStateGuardian for rendering into DirectX9 contexts.
A light shining from infinitely far away in a particular direction, like sunlight.
The abstract interface to all kinds of lights.
virtual bool draw_points(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of disconnected points.
virtual bool framebuffer_copy_to_ram(Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)
Copy the pixels within the indicated display region from the framebuffer into system memory...
virtual void end_frame(Thread *current_thread)
Called after each frame is rendered, to allow the GSG a chance to do any internal cleanup after rende...
Encapsulates the data from a DisplayRegion, pre-fetched for one stage of the pipeline.
virtual void release_shader(ShaderContext *sc)
Releases the resources allocated by prepare_shader.
virtual TextureContext * prepare_texture(Texture *tex)
Creates whatever structures the GSG requires to represent the texture internally, and returns a newly...
This is a base class for GraphicsWindow (actually, GraphicsOutput) and DisplayRegion, both of which are conceptually rectangular regions into which drawing commands may be issued.
virtual void release_index_buffer(IndexBufferContext *ibc)
Frees the resources previously allocated via a call to prepare_data(), including deleting the IndexBu...
virtual void clear(DrawableRegion *clearable)
Clears the framebuffer within the current DisplayRegion, according to the flags indicated by the give...
A base class for any number of different kinds of lenses, linear and otherwise.
virtual bool update_texture(TextureContext *tc, bool force)
Ensures that the current Texture data is refreshed onto the GSG.
virtual void prepare_display_region(DisplayRegionPipelineReader *dr)
Makes the specified DisplayRegion current.
virtual void end_draw_primitives()
Called after a sequence of draw_primitive() functions are called, this should do whatever cleanup is ...
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
This is a special class object that holds all the information returned by a particular GSG to indicat...
virtual bool set_gamma(PN_stdfloat gamma)
Set gamma.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
This is a special class object that holds all the information returned by a particular GSG to indicat...
virtual void restore_gamma()
Restore original gamma setting.
Caches a GeomPrimitive in the DirectX device as an index buffer.
virtual void release_vertex_buffer(VertexBufferContext *vbc)
Frees the resources previously allocated via a call to prepare_data(), including deleting the VertexB...
This data object is returned by GeomVertexArrayData::get_handle() or modify_handle().
Encapsulates the data from a Geom, pre-fetched for one stage of the pipeline.
The ShaderContext is meant to contain the compiled version of a shader string.
virtual bool draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of triangle strips.
virtual void set_state_and_transform(const RenderState *state, const TransformState *transform)
Simultaneously resets the render state and the transform state.
An offscreen render buffer.
Specifies how atmospheric fog effects are applied to geometry.
An object to create GraphicsOutputs that share a particular 3-D API.
virtual bool draw_triangles(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of disconnected triangles.
virtual void begin_occlusion_query()
Begins a new occlusion query.
virtual void release_texture(TextureContext *tc)
Frees the resources previously allocated via a call to prepare_texture(), including deleting the Text...
virtual bool draw_lines(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of disconnected line segments.
A light originating from a single point in space, and shining in a particular direction, with a cone-shaped falloff.
virtual ShaderContext * prepare_shader(Shader *shader)
Compile a vertex/fragment shader body.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Represents a set of settings that indicate how a texture is sampled.
A single graphics window for rendering DirectX under Microsoft Windows.
This is the base class for all three-component vectors and points.
virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader, const GeomMunger *munger, const GeomVertexDataPipelineReader *data_reader, bool force)
Called before a sequence of draw_primitive() functions are called, this should prepare the vertex dat...
virtual bool draw_trifans(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of triangle fans.
A thread; that is, a lightweight process.
This is a special class object that holds all the information returned by a particular GSG to indicat...
Encapsulates all the communication with a particular instance of a given rendering backend...
virtual void end_scene()
Called between begin_frame() and end_frame() to mark the end of drawing commands for a "scene" (usual...
virtual bool draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of line strips.
virtual VertexBufferContext * prepare_vertex_buffer(GeomVertexArrayData *data)
Prepares the indicated buffer for retained-mode rendering.
A rectangular subregion within a window for rendering into.
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
This graphics pipe represents the interface for creating DirectX9 graphics windows.
Returned from a GSG in response to begin_occlusion_query() .
This class is the main interface to controlling the render process.
virtual void reset()
Resets all internal state as if the gsg were newly created.
virtual bool framebuffer_copy_to_texture(Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)
Copy the pixels within the indicated display region from the framebuffer into texture memory...
virtual bool begin_frame(Thread *current_thread)
Called before each frame is rendered, to allow the GSG a chance to do any internal cleanup before beg...
TypeHandle is the identifier used to differentiate C++ class types.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
virtual IndexBufferContext * prepare_index_buffer(GeomPrimitive *data)
Prepares the indicated buffer for retained-mode rendering.
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
virtual bool prepare_lens()
Makes the current lens (whichever lens was most recently specified with set_scene()) active...
Defines the properties of a named stage of the multitexture pipeline.
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer, etc.) of a drawing region.
virtual bool extract_texture_data(Texture *tex)
This method should only be called by the GraphicsEngine.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
A light originating from a single point in space, and shining in all directions.
This is the data for one array of a GeomVertexData structure.
virtual bool begin_scene()
Called between begin_frame() and end_frame() to mark the beginning of drawing commands for a "scene" ...
virtual bool get_supports_cg_profile(const string &name) const
Returns true if this particular GSG supports the specified Cg Shader Profile.
virtual void bind_light(PointLight *light_obj, const NodePath &light, int light_id)
Called the first time a particular light has been bound to a given id within a frame, this should set up the associated hardware light with the light's properties.