unify Texture, ImageBuffer, and PixelBuffer; add 3-d and cube map textures
This commit is contained in:
parent
58584c4bb2
commit
001abb0edd
|
|
@ -17,7 +17,6 @@
|
|||
displayRegionStack.I \
|
||||
displayRegionStack.h \
|
||||
frameBufferProperties.I frameBufferProperties.h \
|
||||
frameBufferStack.I frameBufferStack.h \
|
||||
graphicsEngine.I graphicsEngine.h \
|
||||
graphicsOutput.I graphicsOutput.h \
|
||||
graphicsBuffer.I graphicsBuffer.h \
|
||||
|
|
@ -59,7 +58,6 @@
|
|||
displayRegion.I displayRegion.h displayRegionStack.I \
|
||||
displayRegionStack.h \
|
||||
frameBufferProperties.I frameBufferProperties.h \
|
||||
frameBufferStack.I frameBufferStack.h \
|
||||
graphicsEngine.I graphicsEngine.h \
|
||||
graphicsOutput.I graphicsOutput.h \
|
||||
graphicsBuffer.I graphicsBuffer.h \
|
||||
|
|
|
|||
|
|
@ -19,10 +19,11 @@
|
|||
#include "displayRegion.h"
|
||||
#include "graphicsOutput.h"
|
||||
#include "config_display.h"
|
||||
#include "pixelBuffer.h"
|
||||
#include "texture.h"
|
||||
#include "camera.h"
|
||||
#include "dcast.h"
|
||||
#include "mutexHolder.h"
|
||||
#include "pnmImage.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -519,29 +520,26 @@ get_screenshot(PNMImage &image) {
|
|||
|
||||
GraphicsStateGuardian *gsg = window->get_gsg();
|
||||
nassertr(gsg != (GraphicsStateGuardian *)NULL, false);
|
||||
|
||||
int x_size = get_pixel_width();
|
||||
int y_size = get_pixel_height();
|
||||
|
||||
window->make_current();
|
||||
|
||||
int components = 3;
|
||||
PixelBuffer::Format format = PixelBuffer::F_rgb;
|
||||
Texture::Format format = Texture::F_rgb;
|
||||
|
||||
if ((gsg->get_properties().get_frame_buffer_mode() & FrameBufferProperties::FM_alpha) != 0) {
|
||||
components = 4;
|
||||
format = PixelBuffer::F_rgba;
|
||||
format = Texture::F_rgba;
|
||||
}
|
||||
|
||||
PixelBuffer p(x_size, y_size, components, 1, PixelBuffer::T_unsigned_byte,
|
||||
format);
|
||||
// Create a temporary texture to receive the framebuffer image.
|
||||
PT(Texture) tex = new Texture;
|
||||
|
||||
RenderBuffer buffer = gsg->get_render_buffer(get_screenshot_buffer_type());
|
||||
if (!gsg->copy_pixel_buffer(&p, this, buffer)) {
|
||||
if (!gsg->framebuffer_copy_to_ram(tex, this, buffer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!p.store(image)) {
|
||||
if (!tex->store(image)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
// Filename: frameBufferStack.I
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FrameBufferStack::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FrameBufferStack::
|
||||
FrameBufferStack() {
|
||||
_stack_level = -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FrameBufferStack::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FrameBufferStack::
|
||||
~FrameBufferStack() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FrameBufferStack::Copy Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FrameBufferStack::
|
||||
FrameBufferStack(const FrameBufferStack ©) :
|
||||
_frame_buffer(copy._frame_buffer),
|
||||
_stack_level(copy._stack_level)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FrameBufferStack::Copy Operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void FrameBufferStack::
|
||||
operator =(const FrameBufferStack ©) {
|
||||
_frame_buffer = copy._frame_buffer;
|
||||
_stack_level = copy._stack_level;
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
// Filename: frameBufferStack.h
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 FRAMEBUFFERSTACK_H
|
||||
#define FRAMEBUFFERSTACK_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "savedFrameBuffer.h"
|
||||
|
||||
class GraphicsStateGuardian;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : FrameBufferStack
|
||||
// Description : An instance of this kind of object is returned by
|
||||
// GraphicsStateGuardian::push_frame_buffer(). It
|
||||
// holds the information needed to restore the previous
|
||||
// frame buffer contents in the subsequent matching call
|
||||
// to pop_frame_buffer().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA FrameBufferStack {
|
||||
public:
|
||||
INLINE FrameBufferStack();
|
||||
INLINE ~FrameBufferStack();
|
||||
INLINE FrameBufferStack(const FrameBufferStack ©);
|
||||
INLINE void operator =(const FrameBufferStack ©);
|
||||
|
||||
private:
|
||||
PT(SavedFrameBuffer) _frame_buffer;
|
||||
int _stack_level;
|
||||
friend class GraphicsStateGuardian;
|
||||
};
|
||||
|
||||
#include "frameBufferStack.I"
|
||||
|
||||
#endif
|
||||
|
|
@ -200,17 +200,16 @@ setup_render_texture() {
|
|||
_gsg->framebuffer_release_texture(this, get_texture());
|
||||
}
|
||||
|
||||
_texture = new Texture(true);
|
||||
_texture->set_name(get_name());
|
||||
_texture->set_wrapu(Texture::WM_clamp);
|
||||
_texture->set_wrapv(Texture::WM_clamp);
|
||||
_texture = new Texture(get_name());
|
||||
_texture->set_match_framebuffer_format(true);
|
||||
_texture->set_wrap_u(Texture::WM_clamp);
|
||||
_texture->set_wrap_v(Texture::WM_clamp);
|
||||
|
||||
// Go ahead and tell the texture our anticipated size, even if it
|
||||
// might be inaccurate (particularly if this is a GraphicsWindow,
|
||||
// which has system-imposed restrictions on size).
|
||||
PixelBuffer *pb = _texture->_pbuffer;
|
||||
pb->set_xsize(get_x_size());
|
||||
pb->set_ysize(get_y_size());
|
||||
_texture->set_x_size(get_x_size());
|
||||
_texture->set_y_size(get_y_size());
|
||||
|
||||
_copy_texture = true;
|
||||
_render_texture = false;
|
||||
|
|
@ -606,7 +605,7 @@ begin_frame() {
|
|||
make_current();
|
||||
|
||||
if (_render_texture) {
|
||||
// Release the texture so we can render into the pbuffer.
|
||||
// Release the texture so we can render into the frame buffer.
|
||||
_gsg->framebuffer_release_texture(this, get_texture());
|
||||
}
|
||||
|
||||
|
|
@ -686,7 +685,7 @@ end_frame() {
|
|||
<< "Copying texture for " << get_name() << " at frame end.\n";
|
||||
}
|
||||
RenderBuffer buffer = _gsg->get_render_buffer(get_draw_buffer_type());
|
||||
_gsg->copy_texture(get_texture(), _default_display_region, buffer);
|
||||
_gsg->framebuffer_copy_to_texture(get_texture(), _default_display_region, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -439,40 +439,6 @@ pop_display_region(DisplayRegionStack &node) {
|
|||
node._stack_level = -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GraphicsStateGuardian::push_frame_buffer
|
||||
// Access: Public
|
||||
// Description: Saves the contents of the frame buffer (within the
|
||||
// indicated display region only) so that rendering may
|
||||
// be performed (for instance, to render a partial in a
|
||||
// multipass algorithm) and the frame buffer later
|
||||
// restored via a matching call to pop_frame_buffer().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE FrameBufferStack GraphicsStateGuardian::
|
||||
push_frame_buffer(const RenderBuffer &buffer,
|
||||
const DisplayRegion *dr) {
|
||||
FrameBufferStack old;
|
||||
old._frame_buffer = save_frame_buffer(buffer, dr);
|
||||
old._stack_level = _frame_buffer_stack_level;
|
||||
_frame_buffer_stack_level++;
|
||||
return old;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GraphicsStateGuardian::pop_frame_buffer
|
||||
// Access: Public
|
||||
// Description: Restores the contents of the frame buffer as saved by
|
||||
// a previous call to push_frame_buffer().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void GraphicsStateGuardian::
|
||||
pop_frame_buffer(FrameBufferStack &node) {
|
||||
nassertv(_frame_buffer_stack_level > 0);
|
||||
_frame_buffer_stack_level--;
|
||||
nassertv(node._stack_level == _frame_buffer_stack_level);
|
||||
restore_frame_buffer(node._frame_buffer);
|
||||
node._stack_level = -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GraphicsStateGuardian::get_coordinate_system
|
||||
// Access: Public
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#include "pandabase.h"
|
||||
|
||||
#include "savedFrameBuffer.h"
|
||||
#include "frameBufferStack.h"
|
||||
#include "frameBufferProperties.h"
|
||||
#include "displayRegionStack.h"
|
||||
#include "lensStack.h"
|
||||
|
|
@ -153,9 +152,6 @@ public:
|
|||
|
||||
INLINE DisplayRegionStack push_display_region(const DisplayRegion *dr);
|
||||
INLINE void pop_display_region(DisplayRegionStack &node);
|
||||
INLINE FrameBufferStack push_frame_buffer(const RenderBuffer &buffer,
|
||||
const DisplayRegion *dr);
|
||||
INLINE void pop_frame_buffer(FrameBufferStack &node);
|
||||
|
||||
void set_coordinate_system(CoordinateSystem cs);
|
||||
INLINE CoordinateSystem get_coordinate_system() const;
|
||||
|
|
@ -199,10 +195,6 @@ protected:
|
|||
|
||||
virtual void set_blend_mode();
|
||||
|
||||
virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr)=0;
|
||||
virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer)=0;
|
||||
|
||||
virtual void finish_modify_state();
|
||||
|
||||
virtual void free_pointers();
|
||||
|
|
|
|||
|
|
@ -284,6 +284,7 @@ appear before they are referenced.
|
|||
WORLD_POSITION
|
||||
OBJECT_POSITION
|
||||
EYE_POSITION
|
||||
OBJECT_NORMAL
|
||||
|
||||
<Scalar> stage-name { name }
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
// build dxGraphicsStateGuardian separately since its so big
|
||||
|
||||
#define SOURCES \
|
||||
dxGraphicsStateGuardian7.cxx dxSavedFrameBuffer7.I dxSavedFrameBuffer7.h \
|
||||
dxGraphicsStateGuardian7.cxx \
|
||||
wdxGraphicsPipe7.I wdxGraphicsPipe7.h \
|
||||
wdxGraphicsWindow7.I wdxGraphicsWindow7.h \
|
||||
$[INSTALL_HEADERS]
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
#define INCLUDED_SOURCES \
|
||||
config_dxgsg7.cxx \
|
||||
dxgsg7base.cxx \
|
||||
dxSavedFrameBuffer7.cxx dxTextureContext7.cxx \
|
||||
dxTextureContext7.cxx \
|
||||
wdxGraphicsPipe7.cxx wdxGraphicsWindow7.cxx
|
||||
|
||||
#end lib_target
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "config_dxgsg7.h"
|
||||
#include "dxGraphicsStateGuardian7.h"
|
||||
#include "dxSavedFrameBuffer7.h"
|
||||
#include "dxTextureContext7.h"
|
||||
#include "wdxGraphicsPipe7.h"
|
||||
#include "wdxGraphicsWindow7.h"
|
||||
|
|
@ -118,7 +117,6 @@ init_libdxgsg7() {
|
|||
initialized = true;
|
||||
|
||||
DXGraphicsStateGuardian7::init_type();
|
||||
DXSavedFrameBuffer7::init_type();
|
||||
DXTextureContext7::init_type();
|
||||
|
||||
wdxGraphicsPipe7::init_type();
|
||||
|
|
|
|||
|
|
@ -1752,8 +1752,8 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) {
|
|||
modify_state(RenderState::make
|
||||
(TextureAttrib::make(tex),
|
||||
TextureApplyAttrib::make(TextureApplyAttrib::M_modulate)));
|
||||
tex_xsize = tex->_pbuffer->get_xsize();
|
||||
tex_ysize = tex->_pbuffer->get_ysize();
|
||||
tex_xsize = tex->get_x_size();
|
||||
tex_ysize = tex->get_y_size();
|
||||
}
|
||||
|
||||
// save the modelview matrix
|
||||
|
|
@ -3375,8 +3375,8 @@ apply_texture(TextureContext *tc) {
|
|||
|
||||
Texture *tex = tc->_texture;
|
||||
Texture::WrapMode wrapU,wrapV;
|
||||
wrapU=tex->get_wrapu();
|
||||
wrapV=tex->get_wrapv();
|
||||
wrapU=tex->get_wrap_u();
|
||||
wrapV=tex->get_wrap_v();
|
||||
|
||||
if (wrapU!=_CurTexWrapModeU) {
|
||||
_pScrn->pD3DDevice->SetTextureStageState(0,D3DTSS_ADDRESSU,get_texture_wrap_mode(wrapU));
|
||||
|
|
@ -3482,88 +3482,42 @@ release_texture(TextureContext *tc) {
|
|||
delete gtc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian7::framebuffer_copy_to_texture
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian7::
|
||||
copy_texture(Texture *tex, const DisplayRegion *dr) {
|
||||
framebuffer_copy_to_texture(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||
dxgsg7_cat.error() << "DX copy_texture unimplemented!!!";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian7::copy_texture
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian7::
|
||||
copy_texture(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||
dxgsg7_cat.error() << "DX copy_texture unimplemented!!!";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian7::texture_to_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian7::
|
||||
texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb) {
|
||||
dxgsg7_cat.error()
|
||||
<< "texture_to_pixel_buffer unimplemented!\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian7::texture_to_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian7::
|
||||
texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
|
||||
const DisplayRegion *dr) {
|
||||
dxgsg7_cat.error()
|
||||
<< "texture_to_pixel_buffer unimplemented!\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian7::copy_pixel_buffer
|
||||
// Function: DXGraphicsStateGuardian7::framebuffer_copy_to_ram
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool DXGraphicsStateGuardian7::
|
||||
copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) {
|
||||
framebuffer_copy_to_ram(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
|
||||
extern HRESULT ConvertDDSurftoPixBuf(Texture *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf);
|
||||
|
||||
nassertr(tex != NULL && dr != NULL, false);
|
||||
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
|
||||
// only handled simple case
|
||||
nassertr(xo == 0 && yo==0, false);
|
||||
|
||||
extern HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf);
|
||||
|
||||
nassertr(pb != NULL && dr != NULL, false);
|
||||
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
|
||||
// only handled simple case
|
||||
nassertr(xo == 0 && yo==0 && w == pb->get_xsize() && h == pb->get_ysize(), false);
|
||||
|
||||
/*
|
||||
set_pack_alignment(1);
|
||||
glReadPixels( pb->get_xorg() + xo, pb->get_yorg() + yo,
|
||||
pb->get_xsize(), pb->get_ysize(),
|
||||
get_external_image_format(pb->get_format()),
|
||||
get_image_type(pb->get_image_type()),
|
||||
pb->_image.p() );
|
||||
*/
|
||||
|
||||
|
||||
(void) ConvertDDSurftoPixBuf(pb,((_cur_read_pixel_buffer & RenderBuffer::T_back) ? _pScrn->pddsBack : _pScrn->pddsPrimary));
|
||||
|
||||
nassertr(!pb->_image.empty(), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian7::copy_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool DXGraphicsStateGuardian7::
|
||||
copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
return copy_pixel_buffer(pb, dr);
|
||||
tex->setup_2d_texture(w, h, Texture::T_unsigned_byte, Texture::F_rgb);
|
||||
|
||||
(void) ConvertDDSurftoPixBuf(tex,((_cur_read_pixel_buffer & RenderBuffer::T_back) ? _pScrn->pddsBack : _pScrn->pddsPrimary));
|
||||
|
||||
nassertr(tex->has_ram_image(), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -4637,55 +4591,6 @@ free_pointers() {
|
|||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian7::save_frame_buffer
|
||||
// Access: Public
|
||||
// Description: Saves the indicated planes of the frame buffer
|
||||
// (within the indicated display region) and returns it
|
||||
// in some meaningful form that can be restored later
|
||||
// via restore_frame_buffer(). This is a helper
|
||||
// function for push_frame_buffer() and
|
||||
// pop_frame_buffer().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(SavedFrameBuffer) DXGraphicsStateGuardian7::
|
||||
save_frame_buffer(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr) {
|
||||
|
||||
dxgsg7_cat.error() << "save_frame_buffer unimplemented!!\n";
|
||||
return NULL;
|
||||
|
||||
#if 0
|
||||
DXSavedFrameBuffer7 *sfb = new DXSavedFrameBuffer7(buffer, dr);
|
||||
|
||||
if (buffer._buffer_type & RenderBuffer::T_depth) {
|
||||
// Save the depth buffer.
|
||||
sfb->_depth =
|
||||
new PixelBuffer(PixelBuffer::depth_buffer(dr->get_pixel_width(),
|
||||
dr->get_pixel_height()));
|
||||
copy_pixel_buffer(sfb->_depth, dr, buffer);
|
||||
}
|
||||
|
||||
if (buffer._buffer_type & RenderBuffer::T_back) {
|
||||
// Save the color buffer.
|
||||
sfb->_back_rgba = new Texture;
|
||||
copy_texture(sfb->_back_rgba->prepare(this), dr, buffer);
|
||||
}
|
||||
|
||||
return sfb;
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian7::restore_frame_buffer
|
||||
// Access: Public
|
||||
// Description: Restores the frame buffer that was previously saved.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian7::
|
||||
restore_frame_buffer(SavedFrameBuffer *frame_buffer) {
|
||||
dxgsg7_cat.error() << "restore_frame_buffer unimplemented!!\n";
|
||||
return;
|
||||
}
|
||||
|
||||
TypeHandle DXGraphicsStateGuardian7::get_type(void) const {
|
||||
return get_class_type();
|
||||
}
|
||||
|
|
@ -5244,62 +5149,6 @@ void DXGraphicsStateGuardian7::adjust_view_rect(int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GLGraphicsStateGuardian::save_mipmap_images
|
||||
// Access: Protected
|
||||
// Description: Saves out each mipmap level of the indicated texture
|
||||
// (which must also be the currently active texture in
|
||||
// the GL state) as a separate image file to disk.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian7::read_mipmap_images(Texture *tex) {
|
||||
Filename filename = tex->get_name();
|
||||
string name;
|
||||
if (filename.empty()) {
|
||||
static index = 0;
|
||||
name = "texture" + format_string(index);
|
||||
index++;
|
||||
} else {
|
||||
name = filename.get_basename_wo_extension();
|
||||
}
|
||||
|
||||
PixelBuffer *pb = tex->get_ram_image();
|
||||
nassertv(pb != (PixelBuffer *)NULL);
|
||||
|
||||
GLenum external_format = get_external_image_format(pb->get_format());
|
||||
GLenum type = get_image_type(pb->get_image_type());
|
||||
|
||||
int xsize = pb->get_xsize();
|
||||
int ysize = pb->get_ysize();
|
||||
|
||||
// Specify byte-alignment for the pixels on output.
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
|
||||
int mipmap_level = 0;
|
||||
do {
|
||||
xsize = max(xsize, 1);
|
||||
ysize = max(ysize, 1);
|
||||
|
||||
PT(PixelBuffer) mpb =
|
||||
new PixelBuffer(xsize, ysize, pb->get_num_components(),
|
||||
pb->get_component_width(), pb->get_image_type(),
|
||||
pb->get_format());
|
||||
glGetTexImage(GL_TEXTURE_2D, mipmap_level, external_format,
|
||||
type, mpb->_image);
|
||||
Filename mipmap_filename = name + "_" + format_string(mipmap_level) + ".pnm";
|
||||
nout << "Writing mipmap level " << mipmap_level
|
||||
<< " (" << xsize << " by " << ysize << ") "
|
||||
<< mipmap_filename << "\n";
|
||||
mpb->write(mipmap_filename);
|
||||
|
||||
xsize >>= 1;
|
||||
ysize >>= 1;
|
||||
mipmap_level++;
|
||||
} while (xsize > 0 && ysize > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "graphicsStateGuardian.h"
|
||||
#include "geomprimitives.h"
|
||||
#include "texture.h"
|
||||
#include "pixelBuffer.h"
|
||||
#include "displayRegion.h"
|
||||
#include "material.h"
|
||||
#include "depthTestAttrib.h"
|
||||
|
|
@ -92,17 +91,11 @@ public:
|
|||
virtual void apply_texture(TextureContext *tc);
|
||||
virtual void release_texture(TextureContext *tc);
|
||||
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr);
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
virtual void framebuffer_copy_to_texture(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb);
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
|
||||
const DisplayRegion *dr);
|
||||
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr);
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
virtual bool framebuffer_copy_to_ram(Texture *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
|
||||
virtual void apply_material(const Material *material);
|
||||
virtual void apply_fog(Fog *fog);
|
||||
|
|
@ -158,9 +151,6 @@ protected:
|
|||
|
||||
void free_pointers(); // free local internal buffers
|
||||
void free_dxgsg_objects(void); // free the DirectX objects we create
|
||||
virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr);
|
||||
virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer);
|
||||
|
||||
void set_draw_buffer(const RenderBuffer &rb);
|
||||
void set_read_buffer(const RenderBuffer &rb);
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer7.I
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXSavedFrameBuffer7::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE DXSavedFrameBuffer7::
|
||||
DXSavedFrameBuffer7(const RenderBuffer &buffer, CPT(DisplayRegion) dr) :
|
||||
SavedFrameBuffer(buffer, dr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXSavedFrameBuffer7::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE DXSavedFrameBuffer7::
|
||||
~DXSavedFrameBuffer7() {
|
||||
}
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer7.cxx
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "dxSavedFrameBuffer7.h"
|
||||
|
||||
TypeHandle DXSavedFrameBuffer7::_type_handle;
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer7.h
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 DXSAVEDFRAMEBUFFER7_H
|
||||
#define DXSAVEDFRAMEBUFFER7_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "savedFrameBuffer.h"
|
||||
#include "texture.h"
|
||||
#include "textureContext.h"
|
||||
#include "pixelBuffer.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : DXSavedFrameBuffer7
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDADX DXSavedFrameBuffer7 : public SavedFrameBuffer {
|
||||
public:
|
||||
INLINE DXSavedFrameBuffer7(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr);
|
||||
INLINE ~DXSavedFrameBuffer7();
|
||||
|
||||
PT(Texture) _back_rgba;
|
||||
PT(PixelBuffer) _depth;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
SavedFrameBuffer::init_type();
|
||||
register_type(_type_handle, "DXSavedFrameBuffer7",
|
||||
SavedFrameBuffer::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 "dxSavedFrameBuffer7.I"
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ static const DWORD g_LowByteMask = 0x000000FF;
|
|||
|
||||
#ifdef PANDA_BGRA_ORDER
|
||||
// assume Panda uses byte-order BGRA/LA to store pixels, which when read into little-endian word is ARGB/AL
|
||||
// these macros GET from PixelBuffer, (wont work from DDSurface)
|
||||
// these macros GET from Texture, (wont work from DDSurface)
|
||||
#define GET_RED_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD >> 16) & g_LowByteMask))
|
||||
#define GET_BLUE_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD) & g_LowByteMask))
|
||||
#else
|
||||
|
|
@ -150,54 +150,54 @@ enum Format {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXTextureContext7::get_bits_per_pixel
|
||||
// Access: Protected
|
||||
// Description: Maps from the PixelBuffer's Format symbols
|
||||
// Description: Maps from the Texture's Format symbols
|
||||
// to bpp. returns # of alpha bits
|
||||
// Note: PixelBuffer's format indicates REQUESTED final format,
|
||||
// Note: Texture's format indicates REQUESTED final format,
|
||||
// not the stored format, which is indicated by pixelbuffer type
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned int DXTextureContext7::
|
||||
get_bits_per_pixel(PixelBuffer::Format format, int *alphbits) {
|
||||
get_bits_per_pixel(Texture::Format format, int *alphbits) {
|
||||
*alphbits = 0; // assume no alpha bits
|
||||
switch(format) {
|
||||
case PixelBuffer::F_alpha:
|
||||
case Texture::F_alpha:
|
||||
*alphbits = 8;
|
||||
return 8;
|
||||
case PixelBuffer::F_color_index:
|
||||
case PixelBuffer::F_red:
|
||||
case PixelBuffer::F_green:
|
||||
case PixelBuffer::F_blue:
|
||||
case PixelBuffer::F_rgb332:
|
||||
case PixelBuffer::F_luminance_alphamask:
|
||||
case Texture::F_color_index:
|
||||
case Texture::F_red:
|
||||
case Texture::F_green:
|
||||
case Texture::F_blue:
|
||||
case Texture::F_rgb332:
|
||||
case Texture::F_luminance_alphamask:
|
||||
*alphbits = 1;
|
||||
return 16;
|
||||
case PixelBuffer::F_luminance_alpha:
|
||||
case Texture::F_luminance_alpha:
|
||||
*alphbits = 8;
|
||||
return 16;
|
||||
case PixelBuffer::F_luminance:
|
||||
case Texture::F_luminance:
|
||||
return 8;
|
||||
case PixelBuffer::F_rgba4:
|
||||
case Texture::F_rgba4:
|
||||
*alphbits = 4;
|
||||
return 16;
|
||||
case PixelBuffer::F_rgba5:
|
||||
case Texture::F_rgba5:
|
||||
*alphbits = 1;
|
||||
return 16;
|
||||
case PixelBuffer::F_depth_component:
|
||||
case PixelBuffer::F_rgb5:
|
||||
case Texture::F_depth_component:
|
||||
case Texture::F_rgb5:
|
||||
return 16;
|
||||
case PixelBuffer::F_rgb8:
|
||||
case PixelBuffer::F_rgb:
|
||||
case Texture::F_rgb8:
|
||||
case Texture::F_rgb:
|
||||
return 24;
|
||||
case PixelBuffer::F_rgba8:
|
||||
case PixelBuffer::F_rgba:
|
||||
case Texture::F_rgba8:
|
||||
case Texture::F_rgba:
|
||||
*alphbits = 8;
|
||||
return 32;
|
||||
case PixelBuffer::F_rgbm:
|
||||
case Texture::F_rgbm:
|
||||
*alphbits = 1;
|
||||
return 32;
|
||||
case PixelBuffer::F_rgb12:
|
||||
case Texture::F_rgb12:
|
||||
return 36;
|
||||
case PixelBuffer::F_rgba12:
|
||||
case Texture::F_rgba12:
|
||||
*alphbits = 12;
|
||||
return 48;
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||
return hr;
|
||||
}
|
||||
|
||||
//pbuf contains raw ARGB in PixelBuffer byteorder
|
||||
//pbuf contains raw ARGB in Texture byteorder
|
||||
|
||||
DWORD lPitch = ddsd.lPitch;
|
||||
BYTE* pDDSurfBytes = (BYTE*)ddsd.lpSurface;
|
||||
|
|
@ -672,7 +672,7 @@ HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWS
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf) {
|
||||
HRESULT ConvertDDSurftoPixBuf(Texture *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf) {
|
||||
|
||||
HRESULT hr;
|
||||
DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd);
|
||||
|
|
@ -681,7 +681,7 @@ HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf)
|
|||
|
||||
assert((dwNumComponents==3) || (dwNumComponents==4)); // cant handle anything else now
|
||||
|
||||
BYTE *pbuf=pixbuf->_image.p();
|
||||
BYTE *pbuf=pixbuf->modify_ram_image().p();
|
||||
|
||||
if(IsBadWritePtr(pDDSurf,sizeof(DWORD))) {
|
||||
dxgsg7_cat.error() << "ConvertDDSurftoPixBuf failed: bad pDDSurf ptr value (" << ((void*)pDDSurf) << ")\n";
|
||||
|
|
@ -732,7 +732,7 @@ HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf)
|
|||
//make sure there's enough space in the pixbuf, its size must match (especially xsize)
|
||||
// or scanlines will be too long
|
||||
|
||||
if(!((dwCopyWidth==pixbuf->get_xsize()) && (dwCopyHeight<=(DWORD)pixbuf->get_ysize()))) {
|
||||
if(!((dwCopyWidth==pixbuf->get_x_size()) && (dwCopyHeight<=(DWORD)pixbuf->get_y_size()))) {
|
||||
pDDSurf->Unlock(NULL);
|
||||
assert(0);
|
||||
dxgsg7_cat.error() << "ConvertDDSurftoPixBuf, PixBuf incorrect size to hold display surface!\n";
|
||||
|
|
@ -742,7 +742,7 @@ HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf)
|
|||
// others not handled yet
|
||||
assert((ddsd.ddpfPixelFormat.dwRGBBitCount==32)||(ddsd.ddpfPixelFormat.dwRGBBitCount==16)||(ddsd.ddpfPixelFormat.dwRGBBitCount==24));
|
||||
|
||||
//pbuf contains raw ARGB in PixelBuffer byteorder
|
||||
//pbuf contains raw ARGB in Texture byteorder
|
||||
|
||||
DWORD lPitch = ddsd.lPitch;
|
||||
BYTE* pDDSurfBytes = (BYTE*)ddsd.lpSurface;
|
||||
|
|
@ -751,7 +751,7 @@ HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf)
|
|||
|
||||
if(dxgsg7_cat.is_debug())
|
||||
dxgsg7_cat.debug() << "ConvertDDSurftoPixBuf converting " << ddsd.ddpfPixelFormat.dwRGBBitCount << "bpp DDSurf to "
|
||||
<< dwNumComponents << "-channel panda PixelBuffer\n";
|
||||
<< dwNumComponents << "-channel panda Texture\n";
|
||||
|
||||
|
||||
if(dwNumComponents==4) {
|
||||
|
|
@ -1017,8 +1017,6 @@ LPDIRECTDRAWSURFACE7 DXTextureContext7::CreateTexture(LPDIRECT3DDEVICE7 pd3dDevi
|
|||
|
||||
assert(_texture!=NULL);
|
||||
|
||||
PixelBuffer *pbuf = _texture->_pbuffer;
|
||||
|
||||
#ifdef USE_TEXFMTVEC
|
||||
int cNumTexPixFmts=TexturePixelFormats.size();
|
||||
#endif
|
||||
|
|
@ -1035,12 +1033,12 @@ LPDIRECTDRAWSURFACE7 DXTextureContext7::CreateTexture(LPDIRECT3DDEVICE7 pd3dDevi
|
|||
#endif
|
||||
|
||||
// bpp indicates requested fmt, not pixbuf fmt
|
||||
DWORD bpp = get_bits_per_pixel(pbuf->get_format(), &cNumAlphaBits);
|
||||
PixelBuffer::Type pixbuf_type = pbuf->get_image_type();
|
||||
DWORD cNumColorChannels = pbuf->get_num_components();
|
||||
DWORD bpp = get_bits_per_pixel(_texture->get_format(), &cNumAlphaBits);
|
||||
Texture::ComponentType pixbuf_type = _texture->get_component_type();
|
||||
DWORD cNumColorChannels = _texture->get_num_components();
|
||||
|
||||
DWORD dwOrigWidth = (DWORD)pbuf->get_xsize();
|
||||
DWORD dwOrigHeight = (DWORD)pbuf->get_ysize();
|
||||
DWORD dwOrigWidth = (DWORD)_texture->get_x_size();
|
||||
DWORD dwOrigHeight = (DWORD)_texture->get_y_size();
|
||||
|
||||
// Use the device caps so we can check if the device has any constraints
|
||||
// when using textures.
|
||||
|
|
@ -1061,9 +1059,9 @@ LPDIRECTDRAWSURFACE7 DXTextureContext7::CreateTexture(LPDIRECT3DDEVICE7 pd3dDevi
|
|||
|
||||
ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
||||
|
||||
if((pbuf->get_format() == PixelBuffer::F_luminance_alpha)||
|
||||
(pbuf->get_format() == PixelBuffer::F_luminance_alphamask) ||
|
||||
(pbuf->get_format() == PixelBuffer::F_luminance)) {
|
||||
if((_texture->get_format() == Texture::F_luminance_alpha)||
|
||||
(_texture->get_format() == Texture::F_luminance_alphamask) ||
|
||||
(_texture->get_format() == Texture::F_luminance)) {
|
||||
ddsd.ddpfPixelFormat.dwFlags = DDPF_LUMINANCE;
|
||||
}
|
||||
|
||||
|
|
@ -1132,13 +1130,13 @@ LPDIRECTDRAWSURFACE7 DXTextureContext7::CreateTexture(LPDIRECT3DDEVICE7 pd3dDevi
|
|||
// need 2 add checks for errors
|
||||
PNMImage pnmi_src;
|
||||
PNMImage *pnmi = new PNMImage(ddsd.dwWidth, ddsd.dwHeight, cNumColorChannels);
|
||||
pbuf->store(pnmi_src);
|
||||
_texture->store(pnmi_src);
|
||||
pnmi->quick_filter_from(pnmi_src,0,0);
|
||||
|
||||
pbuf->load(*pnmi); // violates device independence of pixbufs
|
||||
_texture->load(*pnmi); // violates device independence of pixbufs
|
||||
|
||||
dwOrigWidth = (DWORD)pbuf->get_xsize();
|
||||
dwOrigHeight = (DWORD)pbuf->get_ysize();
|
||||
dwOrigWidth = (DWORD)_texture->get_x_size();
|
||||
dwOrigHeight = (DWORD)_texture->get_y_size();
|
||||
delete pnmi;
|
||||
}
|
||||
|
||||
|
|
@ -1661,18 +1659,18 @@ downsample_image(uchar *source, int num_pixels, int component_width) {
|
|||
HRESULT DXTextureContext7::
|
||||
FillDDSurfTexturePixels(void) {
|
||||
|
||||
PixelBuffer *pbuf = _texture->get_ram_image();
|
||||
if (pbuf == (PixelBuffer *)NULL) {
|
||||
CPTA_uchar orig_image = _texture->get_ram_image();
|
||||
if (orig_image.empty()) {
|
||||
dxgsg7_cat.fatal() << "CreateTexture: get_ram_image() failed\n";
|
||||
// The texture doesn't have an image to load.
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
PTA_uchar image = pbuf->_image;
|
||||
if (pbuf->get_component_width() != 1) {
|
||||
PTA_uchar image = (PTA_uchar &)orig_image;
|
||||
if (_texture->get_component_width() != 1) {
|
||||
image = downsample_image(image,
|
||||
pbuf->get_xsize() * pbuf->get_ysize() * pbuf->get_num_components(),
|
||||
pbuf->get_component_width());
|
||||
_texture->get_x_size() * _texture->get_y_size() * _texture->get_num_components(),
|
||||
_texture->get_component_width());
|
||||
}
|
||||
|
||||
HRESULT hr = ConvertPixBuftoDDSurf((ConversionType)_PixBufConversionType,image.p(),_surface);
|
||||
|
|
@ -1688,7 +1686,7 @@ FillDDSurfTexturePixels(void) {
|
|||
DWORD i,oldcurxsize,oldcurysize,curxsize,curysize,cMipMapCount=ddsd.dwMipMapCount;
|
||||
assert(ddsd.dwMipMapCount<20);
|
||||
|
||||
DWORD cNumColorChannels = pbuf->get_num_components();
|
||||
DWORD cNumColorChannels = _texture->get_num_components();
|
||||
|
||||
curxsize=ddsd.dwWidth; curysize=ddsd.dwHeight;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public:
|
|||
HRESULT FillDDSurfTexturePixels(void);
|
||||
|
||||
protected:
|
||||
unsigned int get_bits_per_pixel(PixelBuffer::Format format, int *alphbits);
|
||||
unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "dxgsg7base.h"
|
||||
#include "dxgsg7base.cxx"
|
||||
#include "config_dxgsg7.cxx"
|
||||
#include "dxSavedFrameBuffer7.cxx"
|
||||
#include "dxTextureContext7.cxx"
|
||||
#include "wdxGraphicsPipe7.cxx"
|
||||
#include "wdxGraphicsWindow7.cxx"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
// build dxGraphicsStateGuardian separately since its so big
|
||||
|
||||
#define SOURCES \
|
||||
dxGraphicsStateGuardian8.cxx dxSavedFrameBuffer8.I dxSavedFrameBuffer8.h \
|
||||
dxGraphicsStateGuardian8.cxx \
|
||||
dxGraphicsDevice8.h \
|
||||
wdxGraphicsPipe8.I wdxGraphicsPipe8.h \
|
||||
wdxGraphicsWindow8.I wdxGraphicsWindow8.h \
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#define INCLUDED_SOURCES \
|
||||
config_dxgsg8.cxx \
|
||||
dxSavedFrameBuffer8.cxx dxTextureContext8.cxx \
|
||||
dxTextureContext8.cxx \
|
||||
d3dfont8.cxx \
|
||||
dxGraphicsDevice8.cxx \
|
||||
wdxGraphicsPipe8.cxx wdxGraphicsWindow8.cxx
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "config_dxgsg8.h"
|
||||
#include "dxGraphicsStateGuardian8.h"
|
||||
#include "dxSavedFrameBuffer8.h"
|
||||
#include "dxTextureContext8.h"
|
||||
#include "graphicsPipeSelection.h"
|
||||
#include "wdxGraphicsWindow8.h"
|
||||
|
|
@ -143,7 +142,6 @@ init_libdxgsg8() {
|
|||
initialized = true;
|
||||
|
||||
DXGraphicsStateGuardian8::init_type();
|
||||
DXSavedFrameBuffer8::init_type();
|
||||
DXTextureContext8::init_type();
|
||||
|
||||
wdxGraphicsPipe8::init_type();
|
||||
|
|
|
|||
|
|
@ -1549,8 +1549,8 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) {
|
|||
modify_state(RenderState::make
|
||||
(TextureAttrib::make(tex),
|
||||
TextureApplyAttrib::make(TextureApplyAttrib::M_modulate)));
|
||||
tex_xsize = tex->_pbuffer->get_xsize();
|
||||
tex_ysize = tex->_pbuffer->get_ysize();
|
||||
tex_xsize = tex->get_x_size();
|
||||
tex_ysize = tex->get_y_size();
|
||||
}
|
||||
|
||||
// save the modelview matrix
|
||||
|
|
@ -2657,8 +2657,8 @@ apply_texture(TextureContext *tc) {
|
|||
|
||||
Texture *tex = tc->_texture;
|
||||
Texture::WrapMode wrapU,wrapV;
|
||||
wrapU=tex->get_wrapu();
|
||||
wrapV=tex->get_wrapv();
|
||||
wrapU=tex->get_wrap_u();
|
||||
wrapV=tex->get_wrap_v();
|
||||
|
||||
if (wrapU!=_CurTexWrapModeU) {
|
||||
_pD3DDevice->SetTextureStageState(0,D3DTSS_ADDRESSU,get_texture_wrap_mode(wrapU));
|
||||
|
|
@ -2783,15 +2783,15 @@ release_texture(TextureContext *tc) {
|
|||
// copies current display region in framebuffer to the texture
|
||||
// usually its more efficient to do SetRenderTgt
|
||||
void DXGraphicsStateGuardian8::
|
||||
copy_texture(Texture *tex, const DisplayRegion *dr) {
|
||||
framebuffer_copy_to_texture(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
|
||||
HRESULT hr;
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
|
||||
PixelBuffer *pb = tex->_pbuffer;
|
||||
pb->set_xsize(w);
|
||||
pb->set_ysize(h);
|
||||
tex->set_x_size(w);
|
||||
tex->set_y_size(h);
|
||||
|
||||
TextureContext *tc = tex->prepare_now(get_prepared_objects(), this);
|
||||
if (tc == (TextureContext *)NULL) {
|
||||
|
|
@ -2833,151 +2833,93 @@ copy_texture(Texture *tex, const DisplayRegion *dr) {
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian8::copy_texture
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian8::
|
||||
copy_texture(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
copy_texture(tex, dr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian8::texture_to_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian8::
|
||||
texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb) {
|
||||
// This code is now invalidated by the new design; perhaps the
|
||||
// interface is not needed anyway.
|
||||
dxgsg8_cat.error() << "texture_to_pixel_buffer unimplemented for DX!\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian8::texture_to_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian8::
|
||||
texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
|
||||
const DisplayRegion *dr) {
|
||||
dxgsg8_cat.error()
|
||||
<< "texture_to_pixel_buffer unimplemented!\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian8::copy_pixel_buffer
|
||||
// Function: DXGraphicsStateGuardian9::framebuffer_copy_to_ram
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool DXGraphicsStateGuardian8::
|
||||
copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) {
|
||||
framebuffer_copy_to_ram(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
|
||||
RECT SrcCopyRect;
|
||||
nassertr(pb != NULL && dr != NULL, false);
|
||||
RECT SrcCopyRect;
|
||||
nassertr(tex != NULL && dr != NULL, false);
|
||||
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
tex->setup_2d_texture(w, h, Texture::T_unsigned_byte, Texture::F_rgb);
|
||||
|
||||
// only handled simple case
|
||||
nassertr(xo == 0 && yo==0 && w == pb->get_xsize() && h == pb->get_ysize(), false);
|
||||
SrcCopyRect.top = yo;
|
||||
SrcCopyRect.left = xo;
|
||||
SrcCopyRect.right = xo + w;
|
||||
SrcCopyRect.bottom = yo + h;
|
||||
|
||||
IDirect3DSurface8 *pD3DSurf;
|
||||
HRESULT hr;
|
||||
|
||||
if(_cur_read_pixel_buffer & RenderBuffer::T_back) {
|
||||
hr=_pD3DDevice->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&pD3DSurf);
|
||||
|
||||
if(FAILED(hr)) {
|
||||
dxgsg8_cat.error() << "GetBackBuffer failed" << D3DERRORSTRING(hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
// note if you try to grab the backbuffer and full-screen anti-aliasing is on,
|
||||
// the backbuffer might be larger than the window size. for screenshots its safer to get the front buffer.
|
||||
|
||||
} else if(_cur_read_pixel_buffer & RenderBuffer::T_front) {
|
||||
// must create a A8R8G8B8 sysmem surface for GetFrontBuffer to copy to
|
||||
|
||||
DWORD TmpSurfXsize,TmpSurfYsize;
|
||||
|
||||
if(_pScrn->PresParams.Windowed) {
|
||||
// GetFrontBuffer retrieves the entire desktop for a monitor, so
|
||||
// need space for that
|
||||
|
||||
MONITORINFO minfo;
|
||||
minfo.cbSize = sizeof(MONITORINFO);
|
||||
GetMonitorInfo(_pScrn->hMon, &minfo); // have to use GetMonitorInfo, since this gsg may not be for primary monitor
|
||||
|
||||
TmpSurfXsize = RECT_XSIZE(minfo.rcMonitor);
|
||||
TmpSurfYsize = RECT_YSIZE(minfo.rcMonitor);
|
||||
|
||||
IDirect3DSurface8 *pD3DSurf;
|
||||
HRESULT hr;
|
||||
// set SrcCopyRect to client area of window in scrn coords
|
||||
ClientToScreen( _pScrn->hWnd, (POINT*)&SrcCopyRect.left );
|
||||
ClientToScreen( _pScrn->hWnd, (POINT*)&SrcCopyRect.right );
|
||||
|
||||
RECT WindRect;
|
||||
GetWindowRect(_pScrn->hWnd,&WindRect);
|
||||
|
||||
// just handling front and backbuf for now, not textures yet
|
||||
if(_cur_read_pixel_buffer & RenderBuffer::T_back) {
|
||||
hr=_pD3DDevice->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&pD3DSurf);
|
||||
|
||||
if(FAILED(hr)) {
|
||||
dxgsg8_cat.error() << "GetBackBuffer failed" << D3DERRORSTRING(hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
D3DSURFACE_DESC SurfDesc;
|
||||
hr = pD3DSurf->GetDesc(&SurfDesc);
|
||||
|
||||
SrcCopyRect.top=SrcCopyRect.left=0;
|
||||
SrcCopyRect.right=SurfDesc.Width;
|
||||
SrcCopyRect.bottom=SurfDesc.Height;
|
||||
|
||||
// note if you try to grab the backbuffer and full-screen anti-aliasing is on,
|
||||
// the backbuffer might be larger than the window size. for screenshots its safer to get the front buffer.
|
||||
|
||||
} else if(_cur_read_pixel_buffer & RenderBuffer::T_front) {
|
||||
// must create a A8R8G8B8 sysmem surface for GetFrontBuffer to copy to
|
||||
|
||||
DWORD TmpSurfXsize,TmpSurfYsize;
|
||||
|
||||
if(_pScrn->PresParams.Windowed) {
|
||||
// GetFrontBuffer retrieves the entire desktop for a monitor, so need space for that
|
||||
|
||||
MONITORINFO minfo;
|
||||
minfo.cbSize = sizeof(MONITORINFO);
|
||||
GetMonitorInfo(_pScrn->hMon, &minfo); // have to use GetMonitorInfo, since this gsg may not be for primary monitor
|
||||
|
||||
TmpSurfXsize=RECT_XSIZE(minfo.rcMonitor);
|
||||
TmpSurfYsize=RECT_YSIZE(minfo.rcMonitor);
|
||||
|
||||
// set SrcCopyRect to client area of window in scrn coords
|
||||
GetClientRect( _pScrn->hWnd, &SrcCopyRect);
|
||||
ClientToScreen( _pScrn->hWnd, (POINT*)&SrcCopyRect.left );
|
||||
ClientToScreen( _pScrn->hWnd, (POINT*)&SrcCopyRect.right );
|
||||
} else {
|
||||
TmpSurfXsize=RECT_XSIZE(WindRect);
|
||||
TmpSurfYsize=RECT_YSIZE(WindRect);
|
||||
|
||||
SrcCopyRect.top=SrcCopyRect.left=0;
|
||||
SrcCopyRect.right=TmpSurfXsize;
|
||||
SrcCopyRect.bottom=TmpSurfYsize;
|
||||
}
|
||||
|
||||
hr=_pD3DDevice->CreateImageSurface(TmpSurfXsize,TmpSurfYsize,D3DFMT_A8R8G8B8,&pD3DSurf);
|
||||
if(FAILED(hr)) {
|
||||
dxgsg8_cat.error() << "CreateImageSurface failed in copy_pixel_buffer()" << D3DERRORSTRING(hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr=_pD3DDevice->GetFrontBuffer(pD3DSurf);
|
||||
|
||||
if(hr==D3DERR_DEVICELOST) {
|
||||
pD3DSurf->Release();
|
||||
dxgsg8_cat.error() << "copy_pixel_buffer failed: device lost\n";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
dxgsg8_cat.error() << "copy_pixel_buffer: unhandled current_read_pixel_buffer type\n";
|
||||
return false;
|
||||
RECT WindRect;
|
||||
GetWindowRect(_pScrn->hWnd,&WindRect);
|
||||
TmpSurfXsize = RECT_XSIZE(WindRect);
|
||||
TmpSurfYsize = RECT_YSIZE(WindRect);
|
||||
}
|
||||
|
||||
hr=_pD3DDevice->CreateImageSurface(TmpSurfXsize,TmpSurfYsize,D3DFMT_A8R8G8B8,&pD3DSurf);
|
||||
if(FAILED(hr)) {
|
||||
dxgsg8_cat.error() << "CreateImageSurface failed in copy_pixel_buffer()" << D3DERRORSTRING(hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr=_pD3DDevice->GetFrontBuffer(pD3DSurf);
|
||||
|
||||
if(hr==D3DERR_DEVICELOST) {
|
||||
pD3DSurf->Release();
|
||||
dxgsg8_cat.error() << "copy_pixel_buffer failed: device lost\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if((RECT_XSIZE(SrcCopyRect)>w) || (RECT_YSIZE(SrcCopyRect)>h)) {
|
||||
dxgsg8_cat.error() << "copy_pixel_buffer: pixel buffer size does not match selected screen RenderBuffer size!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
(void) ConvertD3DSurftoPixBuf(SrcCopyRect,pD3DSurf,pb);
|
||||
|
||||
RELEASE(pD3DSurf,dxgsg8,"pD3DSurf",RELEASE_ONCE);
|
||||
|
||||
nassertr(!pb->_image.empty(), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian8::copy_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool DXGraphicsStateGuardian8::
|
||||
copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
return copy_pixel_buffer(pb, dr);
|
||||
} else {
|
||||
dxgsg8_cat.error() << "copy_pixel_buffer: unhandled current_read_pixel_buffer type\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
(void) ConvertD3DSurftoPixBuf(SrcCopyRect,pD3DSurf,tex);
|
||||
|
||||
RELEASE(pD3DSurf,dxgsg8,"pD3DSurf",RELEASE_ONCE);
|
||||
|
||||
nassertr(tex->has_ram_image(), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -3997,55 +3939,6 @@ set_blend_mode() {
|
|||
enable_blend(false);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian8::save_frame_buffer
|
||||
// Access: Public
|
||||
// Description: Saves the indicated planes of the frame buffer
|
||||
// (within the indicated display region) and returns it
|
||||
// in some meaningful form that can be restored later
|
||||
// via restore_frame_buffer(). This is a helper
|
||||
// function for push_frame_buffer() and
|
||||
// pop_frame_buffer().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(SavedFrameBuffer) DXGraphicsStateGuardian8::
|
||||
save_frame_buffer(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr) {
|
||||
|
||||
dxgsg8_cat.error() << "save_frame_buffer unimplemented!!\n";
|
||||
return NULL;
|
||||
|
||||
#if 0
|
||||
DXSavedFrameBuffer *sfb = new DXSavedFrameBuffer(buffer, dr);
|
||||
|
||||
if (buffer._buffer_type & RenderBuffer::T_depth) {
|
||||
// Save the depth buffer.
|
||||
sfb->_depth =
|
||||
new PixelBuffer(PixelBuffer::depth_buffer(dr->get_pixel_width(),
|
||||
dr->get_pixel_height()));
|
||||
copy_pixel_buffer(sfb->_depth, dr, buffer);
|
||||
}
|
||||
|
||||
if (buffer._buffer_type & RenderBuffer::T_back) {
|
||||
// Save the color buffer.
|
||||
sfb->_back_rgba = new Texture;
|
||||
copy_texture(sfb->_back_rgba, dr, buffer);
|
||||
}
|
||||
|
||||
return sfb;
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian8::restore_frame_buffer
|
||||
// Access: Public
|
||||
// Description: Restores the frame buffer that was previously saved.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian8::
|
||||
restore_frame_buffer(SavedFrameBuffer *frame_buffer) {
|
||||
dxgsg8_cat.error() << "restore_frame_buffer unimplemented!!\n";
|
||||
return;
|
||||
}
|
||||
|
||||
TypeHandle DXGraphicsStateGuardian8::get_type(void) const {
|
||||
return get_class_type();
|
||||
}
|
||||
|
|
@ -4655,4 +4548,3 @@ POS_TEX_VERTEX junk11;
|
|||
POS_COLOR_TEX_VERTEX junk22;
|
||||
POS_NORM_COLOR_TEX_VERTEX junk33;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
#include "graphicsStateGuardian.h"
|
||||
#include "geomprimitives.h"
|
||||
#include "texture.h"
|
||||
#include "pixelBuffer.h"
|
||||
#include "displayRegion.h"
|
||||
#include "material.h"
|
||||
#include "depthTestAttrib.h"
|
||||
|
|
@ -94,17 +93,10 @@ public:
|
|||
virtual void apply_texture(TextureContext *tc);
|
||||
virtual void release_texture(TextureContext *tc);
|
||||
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr);
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb);
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
|
||||
const DisplayRegion *dr);
|
||||
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr);
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
virtual void framebuffer_copy_to_texture(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
virtual bool framebuffer_copy_to_ram(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
|
||||
virtual void apply_material(const Material *material);
|
||||
virtual void apply_fog(Fog *fog);
|
||||
|
|
@ -159,9 +151,6 @@ protected:
|
|||
|
||||
void free_nondx_resources(); // free local internal buffers
|
||||
void free_d3d_device(void);
|
||||
virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr);
|
||||
virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer);
|
||||
|
||||
void set_draw_buffer(const RenderBuffer &rb);
|
||||
void set_read_buffer(const RenderBuffer &rb);
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer8.I
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXSavedFrameBuffer8::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE DXSavedFrameBuffer8::
|
||||
DXSavedFrameBuffer8(const RenderBuffer &buffer, CPT(DisplayRegion) dr) :
|
||||
SavedFrameBuffer(buffer, dr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXSavedFrameBuffer8::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE DXSavedFrameBuffer8::
|
||||
~DXSavedFrameBuffer8() {
|
||||
}
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer8.cxx
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "dxSavedFrameBuffer8.h"
|
||||
|
||||
TypeHandle DXSavedFrameBuffer8::_type_handle;
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer8.h
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 DXSAVEDFRAMEBUFFER8_H
|
||||
#define DXSAVEDFRAMEBUFFER8_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "savedFrameBuffer.h"
|
||||
#include "texture.h"
|
||||
#include "textureContext.h"
|
||||
#include "pixelBuffer.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : DXSavedFrameBuffer8
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDADX DXSavedFrameBuffer8 : public SavedFrameBuffer {
|
||||
public:
|
||||
INLINE DXSavedFrameBuffer8(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr);
|
||||
INLINE ~DXSavedFrameBuffer8();
|
||||
|
||||
PT(Texture) _back_rgba;
|
||||
PT(PixelBuffer) _depth;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
SavedFrameBuffer::init_type();
|
||||
register_type(_type_handle, "DXSavedFrameBuffer8",
|
||||
SavedFrameBuffer::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 "DXSavedFrameBuffer8.I"
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ static const DWORD g_LowByteMask = 0x000000FF;
|
|||
|
||||
#ifdef PANDA_BGRA_ORDER
|
||||
// assume Panda uses byte-order BGRA/LA to store pixels, which when read into little-endian word is ARGB/AL
|
||||
// these macros GET from PixelBuffer, (wont work from DDSurface)
|
||||
// these macros GET from Texture, (wont work from DDSurface)
|
||||
#define GET_RED_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD >> 16) & g_LowByteMask))
|
||||
#define GET_BLUE_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD) & g_LowByteMask))
|
||||
#else
|
||||
|
|
@ -135,54 +135,54 @@ enum Format {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXTextureContext8::get_bits_per_pixel
|
||||
// Access: Protected
|
||||
// Description: Maps from the PixelBuffer's Format symbols
|
||||
// Description: Maps from the Texture's Format symbols
|
||||
// to bpp. returns # of alpha bits
|
||||
// Note: PixelBuffer's format indicates REQUESTED final format,
|
||||
// Note: Texture's format indicates REQUESTED final format,
|
||||
// not the stored format, which is indicated by pixelbuffer type
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned int DXTextureContext8::
|
||||
get_bits_per_pixel(PixelBuffer::Format format, int *alphbits) {
|
||||
get_bits_per_pixel(Texture::Format format, int *alphbits) {
|
||||
*alphbits = 0; // assume no alpha bits
|
||||
switch(format) {
|
||||
case PixelBuffer::F_alpha:
|
||||
case Texture::F_alpha:
|
||||
*alphbits = 8;
|
||||
case PixelBuffer::F_color_index:
|
||||
case PixelBuffer::F_red:
|
||||
case PixelBuffer::F_green:
|
||||
case PixelBuffer::F_blue:
|
||||
case PixelBuffer::F_rgb332:
|
||||
case Texture::F_color_index:
|
||||
case Texture::F_red:
|
||||
case Texture::F_green:
|
||||
case Texture::F_blue:
|
||||
case Texture::F_rgb332:
|
||||
return 8;
|
||||
case PixelBuffer::F_luminance_alphamask:
|
||||
case Texture::F_luminance_alphamask:
|
||||
*alphbits = 1;
|
||||
return 16;
|
||||
case PixelBuffer::F_luminance_alpha:
|
||||
case Texture::F_luminance_alpha:
|
||||
*alphbits = 8;
|
||||
return 16;
|
||||
case PixelBuffer::F_luminance:
|
||||
case Texture::F_luminance:
|
||||
return 8;
|
||||
case PixelBuffer::F_rgba4:
|
||||
case Texture::F_rgba4:
|
||||
*alphbits = 4;
|
||||
return 16;
|
||||
case PixelBuffer::F_rgba5:
|
||||
case Texture::F_rgba5:
|
||||
*alphbits = 1;
|
||||
return 16;
|
||||
case PixelBuffer::F_depth_component:
|
||||
case PixelBuffer::F_rgb5:
|
||||
case Texture::F_depth_component:
|
||||
case Texture::F_rgb5:
|
||||
return 16;
|
||||
case PixelBuffer::F_rgb8:
|
||||
case PixelBuffer::F_rgb:
|
||||
case Texture::F_rgb8:
|
||||
case Texture::F_rgb:
|
||||
return 24;
|
||||
case PixelBuffer::F_rgba8:
|
||||
case PixelBuffer::F_rgba:
|
||||
case PixelBuffer::F_rgbm:
|
||||
if(format==PixelBuffer::F_rgbm) // does this make any sense?
|
||||
case Texture::F_rgba8:
|
||||
case Texture::F_rgba:
|
||||
case Texture::F_rgbm:
|
||||
if(format==Texture::F_rgbm) // does this make any sense?
|
||||
*alphbits = 1;
|
||||
else *alphbits = 8;
|
||||
return 32;
|
||||
case PixelBuffer::F_rgb12:
|
||||
case Texture::F_rgb12:
|
||||
return 36;
|
||||
case PixelBuffer::F_rgba12:
|
||||
case Texture::F_rgba12:
|
||||
*alphbits = 12;
|
||||
return 48;
|
||||
}
|
||||
|
|
@ -190,20 +190,20 @@ get_bits_per_pixel(PixelBuffer::Format format, int *alphbits) {
|
|||
}
|
||||
|
||||
// still need custom conversion since d3d/d3dx has no way to convert arbitrary fmt to ARGB in-memory user buffer
|
||||
HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelBuffer *pixbuf) {
|
||||
// copies SrcRect in pD3DSurf to upper left of pixbuf
|
||||
HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,Texture *texture) {
|
||||
// copies SrcRect in pD3DSurf to upper left of texture
|
||||
HRESULT hr;
|
||||
DWORD dwNumComponents=pixbuf->get_num_components();
|
||||
DWORD dwNumComponents=texture->get_num_components();
|
||||
|
||||
assert(pixbuf->get_component_width()==sizeof(BYTE)); // cant handle anything else now
|
||||
assert(pixbuf->get_image_type()==PixelBuffer::T_unsigned_byte); // cant handle anything else now
|
||||
assert(texture->get_component_width()==sizeof(BYTE)); // cant handle anything else now
|
||||
assert(texture->get_component_type()==Texture::T_unsigned_byte); // cant handle anything else now
|
||||
assert((dwNumComponents==3) || (dwNumComponents==4)); // cant handle anything else now
|
||||
assert(IS_VALID_PTR(pD3DSurf8));
|
||||
|
||||
BYTE *pbuf=pixbuf->_image.p();
|
||||
BYTE *pbuf=texture->modify_ram_image().p();
|
||||
|
||||
if(IsBadWritePtr(pD3DSurf8,sizeof(DWORD))) {
|
||||
dxgsg8_cat.error() << "ConvertDDSurftoPixBuf failed: bad pD3DSurf ptr value (" << ((void*)pD3DSurf8) << ")\n";
|
||||
dxgsg8_cat.error() << "ConvertDDSurftoTexture failed: bad pD3DSurf ptr value (" << ((void*)pD3DSurf8) << ")\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -219,11 +219,11 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelB
|
|||
dwCopyWidth=RECT_XSIZE(SrcRect);
|
||||
dwCopyHeight=RECT_YSIZE(SrcRect);
|
||||
|
||||
//make sure there's enough space in the pixbuf, its size must match (especially xsize)
|
||||
//make sure there's enough space in the texture, its size must match (especially xsize)
|
||||
// or scanlines will be too long
|
||||
|
||||
if(!((dwCopyWidth==pixbuf->get_xsize()) && (dwCopyHeight<=(DWORD)pixbuf->get_ysize()))) {
|
||||
dxgsg8_cat.error() << "ConvertDDSurftoPixBuf, PixBuf size too small to hold display surface!\n";
|
||||
if(!((dwCopyWidth==texture->get_x_size()) && (dwCopyHeight<=(DWORD)texture->get_y_size()))) {
|
||||
dxgsg8_cat.error() << "ConvertDDSurftoPixBuf, Texture size too small to hold display surface!\n";
|
||||
assert(0);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
|
@ -239,7 +239,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelB
|
|||
(SurfDesc.Format==D3DFMT_R5G6B5)||(SurfDesc.Format==D3DFMT_X1R5G5B5)||(SurfDesc.Format==D3DFMT_A1R5G5B5)||
|
||||
(SurfDesc.Format==D3DFMT_A4R4G4B4));
|
||||
|
||||
//pbuf contains raw ARGB in PixelBuffer byteorder
|
||||
//pbuf contains raw ARGB in Texture byteorder
|
||||
|
||||
DWORD BytePitch = LockedRect.Pitch;
|
||||
BYTE* pSurfBytes = (BYTE*)LockedRect.pBits;
|
||||
|
|
@ -249,7 +249,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelB
|
|||
if(dxgsg8_cat.is_debug()) {
|
||||
dxgsg8_cat.debug()
|
||||
<< "ConvertD3DSurftoPixBuf converting " << D3DFormatStr(SurfDesc.Format) << "bpp DDSurf to "
|
||||
<< dwNumComponents << "-channel panda PixelBuffer\n";
|
||||
<< dwNumComponents << "-channel panda Texture\n";
|
||||
}
|
||||
|
||||
DWORD *pDstWord = (DWORD *) pbuf;
|
||||
|
|
@ -285,7 +285,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelB
|
|||
#endif
|
||||
}
|
||||
} else {
|
||||
// 24bpp pixbuf case (numComponents==3)
|
||||
// 24bpp texture case (numComponents==3)
|
||||
DWORD *pSrcWord;
|
||||
pSurfBytes+=BytePitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||
for(DWORD y=0; y<dwCopyHeight; y++,pSurfBytes-=BytePitch) {
|
||||
|
|
@ -336,7 +336,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelB
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// 24bpp pixbuf case (numComponents==3)
|
||||
// 24bpp texture case (numComponents==3)
|
||||
for(DWORD y=0; y<dwCopyHeight; y++,pSurfBytes-=BytePitch) {
|
||||
pSrcByte = pSurfBytes+dwXWindowOffset*3*sizeof(BYTE);
|
||||
#ifdef PANDA_BGRA_ORDER
|
||||
|
|
@ -398,7 +398,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelB
|
|||
|
||||
pSurfBytes+=BytePitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||
if(dwNumComponents==4) {
|
||||
// Note: these 16bpp loops ignore input alpha completely (alpha is set to fully opaque in pixbuf!)
|
||||
// Note: these 16bpp loops ignore input alpha completely (alpha is set to fully opaque in texture!)
|
||||
// if we need to capture alpha, probably need to make separate loops for diff 16bpp fmts
|
||||
// for best speed
|
||||
|
||||
|
|
@ -422,7 +422,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelB
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// 24bpp pixbuf case (numComponents==3)
|
||||
// 24bpp texture case (numComponents==3)
|
||||
for(DWORD y=0; y<dwCopyHeight; y++,pSurfBytes-=BytePitch) {
|
||||
pSrcWord = ((WORD*)pSurfBytes)+dwXWindowOffset;
|
||||
for(DWORD x=0; x<dwCopyWidth; x++,pSrcWord++) {
|
||||
|
|
@ -470,20 +470,18 @@ IDirect3DTexture8 *DXTextureContext8::CreateTexture(DXScreenData &scrn) {
|
|||
|
||||
assert(IS_VALID_PTR(_texture));
|
||||
|
||||
PixelBuffer *pbuf = _texture->_pbuffer;
|
||||
// bpp indicates requested fmt, not pixbuf fmt
|
||||
DWORD target_bpp = get_bits_per_pixel(pbuf->get_format(), &cNumAlphaBits);
|
||||
PixelBuffer::Type pixbuf_type = pbuf->get_image_type();
|
||||
DWORD cNumColorChannels = pbuf->get_num_components();
|
||||
// bpp indicates requested fmt, not texture fmt
|
||||
DWORD target_bpp = get_bits_per_pixel(_texture->get_format(), &cNumAlphaBits);
|
||||
DWORD cNumColorChannels = _texture->get_num_components();
|
||||
|
||||
//PRINT_REFCNT(dxgsg8,scrn.pD3D8);
|
||||
|
||||
DWORD dwOrigWidth = (DWORD)pbuf->get_xsize();
|
||||
DWORD dwOrigHeight = (DWORD)pbuf->get_ysize();
|
||||
DWORD dwOrigWidth = (DWORD)_texture->get_x_size();
|
||||
DWORD dwOrigHeight = (DWORD)_texture->get_y_size();
|
||||
|
||||
if((pbuf->get_format() == PixelBuffer::F_luminance_alpha)||
|
||||
(pbuf->get_format() == PixelBuffer::F_luminance_alphamask) ||
|
||||
(pbuf->get_format() == PixelBuffer::F_luminance)) {
|
||||
if((_texture->get_format() == Texture::F_luminance_alpha)||
|
||||
(_texture->get_format() == Texture::F_luminance_alphamask) ||
|
||||
(_texture->get_format() == Texture::F_luminance)) {
|
||||
bNeedLuminance = true;
|
||||
}
|
||||
|
||||
|
|
@ -496,7 +494,7 @@ IDirect3DTexture8 *DXTextureContext8::CreateTexture(DXScreenData &scrn) {
|
|||
|
||||
_PixBufD3DFmt=D3DFMT_UNKNOWN;
|
||||
|
||||
// figure out what 'D3DFMT' the PixelBuffer is in, so D3DXLoadSurfFromMem knows how to perform copy
|
||||
// figure out what 'D3DFMT' the Texture is in, so D3DXLoadSurfFromMem knows how to perform copy
|
||||
|
||||
switch(cNumColorChannels) {
|
||||
case 1:
|
||||
|
|
@ -567,13 +565,13 @@ IDirect3DTexture8 *DXTextureContext8::CreateTexture(DXScreenData &scrn) {
|
|||
// need 2 add checks for errors
|
||||
PNMImage pnmi_src;
|
||||
PNMImage *pnmi = new PNMImage(TargetWidth, TargetHeight, cNumColorChannels);
|
||||
pbuf->store(pnmi_src);
|
||||
_texture->store(pnmi_src);
|
||||
pnmi->quick_filter_from(pnmi_src,0,0);
|
||||
|
||||
pbuf->load(*pnmi); // violates device independence of pixbufs
|
||||
_texture->load(*pnmi); // violates device independence of pixbufs
|
||||
|
||||
dwOrigWidth = (DWORD)pbuf->get_xsize();
|
||||
dwOrigHeight = (DWORD)pbuf->get_ysize();
|
||||
dwOrigWidth = (DWORD)_texture->get_x_size();
|
||||
dwOrigHeight = (DWORD)_texture->get_y_size();
|
||||
delete pnmi;
|
||||
}
|
||||
*/
|
||||
|
|
@ -601,7 +599,7 @@ IDirect3DTexture8 *DXTextureContext8::CreateTexture(DXScreenData &scrn) {
|
|||
switch(target_bpp) {
|
||||
|
||||
// IMPORTANT NOTE:
|
||||
// target_bpp is REQUESTED bpp, not what exists in the pixbuf array (the pixbuf array contains cNumColorChannels*8bits)
|
||||
// target_bpp is REQUESTED bpp, not what exists in the texture array (the texture array contains cNumColorChannels*8bits)
|
||||
|
||||
case 32:
|
||||
if(!((cNumColorChannels==3) || (cNumColorChannels==4)))
|
||||
|
|
@ -772,7 +770,7 @@ IDirect3DTexture8 *DXTextureContext8::CreateTexture(DXScreenData &scrn) {
|
|||
///////////////////////////////////////////////////////////
|
||||
|
||||
found_matching_format:
|
||||
// We found a suitable format that matches the pbuffer's format.
|
||||
// We found a suitable format that matches the texture's format.
|
||||
|
||||
if (_texture->get_match_framebuffer_format()) {
|
||||
// Instead of creating a texture with the found format, we will
|
||||
|
|
@ -936,8 +934,8 @@ FillDDSurfTexturePixels(void) {
|
|||
HRESULT hr=E_FAIL;
|
||||
assert(IS_VALID_PTR(_texture));
|
||||
|
||||
PixelBuffer *pbuf = _texture->get_ram_image();
|
||||
if (pbuf == (PixelBuffer *)NULL) {
|
||||
CPTA_uchar image = _texture->get_ram_image();
|
||||
if (image.is_null()) {
|
||||
// The texture doesn't have an image to load. That's ok; it
|
||||
// might be a texture we've rendered to by frame buffer
|
||||
// operations or something.
|
||||
|
|
@ -946,12 +944,12 @@ FillDDSurfTexturePixels(void) {
|
|||
|
||||
assert(IS_VALID_PTR(_pD3DTexture8));
|
||||
|
||||
DWORD OrigWidth = (DWORD) pbuf->get_xsize();
|
||||
DWORD OrigHeight = (DWORD) pbuf->get_ysize();
|
||||
DWORD cNumColorChannels = pbuf->get_num_components();
|
||||
DWORD OrigWidth = (DWORD) _texture->get_x_size();
|
||||
DWORD OrigHeight = (DWORD) _texture->get_y_size();
|
||||
DWORD cNumColorChannels = _texture->get_num_components();
|
||||
D3DFORMAT SrcFormat=_PixBufD3DFmt;
|
||||
BYTE *pPixels=(BYTE*)pbuf->_image.p();
|
||||
int component_width = pbuf->get_component_width();
|
||||
BYTE *pPixels=(BYTE*)image.p();
|
||||
int component_width = _texture->get_component_width();
|
||||
|
||||
assert(IS_VALID_PTR(pPixels));
|
||||
|
||||
|
|
@ -1009,7 +1007,7 @@ FillDDSurfTexturePixels(void) {
|
|||
// original image, but dx8 doesn't support high-precision images
|
||||
// anyway.
|
||||
|
||||
int num_components = pbuf->get_num_components();
|
||||
int num_components = _texture->get_num_components();
|
||||
int num_pixels = OrigWidth * OrigHeight * num_components;
|
||||
BYTE *pTempPixBuf = new BYTE[num_pixels];
|
||||
if(!IS_VALID_PTR(pTempPixBuf)) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public:
|
|||
Texture *_tex; // ptr to parent, primarily for access to namestr
|
||||
IDirect3DTexture8 *CreateTexture(DXScreenData &scrn);
|
||||
|
||||
D3DFORMAT _PixBufD3DFmt; // the 'D3DFORMAT' the Panda PixelBuffer fmt corresponds to
|
||||
D3DFORMAT _PixBufD3DFmt; // the 'D3DFORMAT' the Panda TextureBuffer fmt corresponds to
|
||||
|
||||
bool _bHasMipMaps;
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ public:
|
|||
HRESULT FillDDSurfTexturePixels(void);
|
||||
|
||||
protected:
|
||||
unsigned int get_bits_per_pixel(PixelBuffer::Format format, int *alphbits);
|
||||
unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
|
@ -74,7 +74,7 @@ private:
|
|||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
extern HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,PixelBuffer *pixbuf);
|
||||
extern HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface8 *pD3DSurf8,Texture *pixbuf);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include "dxgsg8base.h"
|
||||
#include "config_dxgsg8.cxx"
|
||||
#include "dxSavedFrameBuffer8.cxx"
|
||||
#include "dxTextureContext8.cxx"
|
||||
#include "d3dfont8.cxx"
|
||||
#include "wdxGraphicsPipe8.cxx"
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
// build dxGraphicsStateGuardian separately since its so big
|
||||
|
||||
#define SOURCES \
|
||||
dxGraphicsStateGuardian9.cxx dxSavedFrameBuffer9.I dxSavedFrameBuffer9.h \
|
||||
dxGraphicsStateGuardian9.cxx \
|
||||
dxGraphicsDevice9.h \
|
||||
wdxGraphicsPipe9.I wdxGraphicsPipe9.h \
|
||||
wdxGraphicsWindow9.I wdxGraphicsWindow9.h \
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#define INCLUDED_SOURCES \
|
||||
config_dxgsg9.cxx \
|
||||
dxSavedFrameBuffer9.cxx dxTextureContext9.cxx \
|
||||
dxTextureContext9.cxx \
|
||||
d3dfont9.cxx \
|
||||
dxGraphicsDevice9.cxx \
|
||||
wdxGraphicsPipe9.cxx wdxGraphicsWindow9.cxx
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "config_dxgsg9.h"
|
||||
#include "dxGraphicsStateGuardian9.h"
|
||||
#include "dxSavedFrameBuffer9.h"
|
||||
#include "dxTextureContext9.h"
|
||||
#include "graphicsPipeSelection.h"
|
||||
#include "wdxGraphicsWindow9.h"
|
||||
|
|
@ -143,7 +142,6 @@ init_libdxgsg9() {
|
|||
initialized = true;
|
||||
|
||||
DXGraphicsStateGuardian9::init_type();
|
||||
DXSavedFrameBuffer9::init_type();
|
||||
DXTextureContext9::init_type();
|
||||
|
||||
wdxGraphicsPipe9::init_type();
|
||||
|
|
|
|||
|
|
@ -1530,8 +1530,8 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) {
|
|||
modify_state(RenderState::make
|
||||
(TextureAttrib::make(tex),
|
||||
TextureApplyAttrib::make(TextureApplyAttrib::M_modulate)));
|
||||
tex_xsize = tex->_pbuffer->get_xsize();
|
||||
tex_ysize = tex->_pbuffer->get_ysize();
|
||||
tex_xsize = tex->get_x_size();
|
||||
tex_ysize = tex->get_y_size();
|
||||
}
|
||||
|
||||
// save the modelview matrix
|
||||
|
|
@ -2640,8 +2640,8 @@ apply_texture(TextureContext *tc) {
|
|||
|
||||
Texture *tex = tc->_texture;
|
||||
Texture::WrapMode wrapU,wrapV;
|
||||
wrapU=tex->get_wrapu();
|
||||
wrapV=tex->get_wrapv();
|
||||
wrapU=tex->get_wrap_u();
|
||||
wrapV=tex->get_wrap_v();
|
||||
|
||||
if (wrapU!=_CurTexWrapModeU) {
|
||||
_pD3DDevice->SetSamplerState(0,D3DSAMP_ADDRESSU,get_texture_wrap_mode(wrapU));
|
||||
|
|
@ -2766,15 +2766,15 @@ release_texture(TextureContext *tc) {
|
|||
// copies current display region in framebuffer to the texture
|
||||
// usually its more efficient to do SetRenderTgt
|
||||
void DXGraphicsStateGuardian9::
|
||||
copy_texture(Texture *tex, const DisplayRegion *dr) {
|
||||
framebuffer_copy_to_texture(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
|
||||
HRESULT hr;
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
|
||||
PixelBuffer *pb = tex->_pbuffer;
|
||||
pb->set_xsize(w);
|
||||
pb->set_ysize(h);
|
||||
tex->set_x_size(w);
|
||||
tex->set_y_size(h);
|
||||
|
||||
TextureContext *tc = tex->prepare_now(get_prepared_objects(), this);
|
||||
if (tc == (TextureContext *)NULL) {
|
||||
|
|
@ -2819,153 +2819,94 @@ copy_texture(Texture *tex, const DisplayRegion *dr) {
|
|||
SAFE_RELEASE(pTexSurfaceLev0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian9::copy_texture
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian9::
|
||||
copy_texture(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
copy_texture(tex, dr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian9::texture_to_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian9::
|
||||
texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb) {
|
||||
// This code is now invalidated by the new design; perhaps the
|
||||
// interface is not needed anyway.
|
||||
dxgsg9_cat.error() << "texture_to_pixel_buffer unimplemented for DX!\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian9::texture_to_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian9::
|
||||
texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
|
||||
const DisplayRegion *dr) {
|
||||
dxgsg9_cat.error()
|
||||
<< "texture_to_pixel_buffer unimplemented!\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian9::copy_pixel_buffer
|
||||
// Function: DXGraphicsStateGuardian9::framebuffer_copy_to_ram
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool DXGraphicsStateGuardian9::
|
||||
copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) {
|
||||
framebuffer_copy_to_ram(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
|
||||
RECT SrcCopyRect;
|
||||
nassertr(pb != NULL && dr != NULL, false);
|
||||
RECT SrcCopyRect;
|
||||
nassertr(tex != NULL && dr != NULL, false);
|
||||
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
tex->setup_2d_texture(w, h, Texture::T_unsigned_byte, Texture::F_rgb);
|
||||
|
||||
// only handled simple case
|
||||
nassertr(xo == 0 && yo==0 && w == pb->get_xsize() && h == pb->get_ysize(), false);
|
||||
SrcCopyRect.top = yo;
|
||||
SrcCopyRect.left = xo;
|
||||
SrcCopyRect.right = xo + w;
|
||||
SrcCopyRect.bottom = yo + h;
|
||||
|
||||
IDirect3DSurface9 *pD3DSurf;
|
||||
HRESULT hr;
|
||||
|
||||
if(_cur_read_pixel_buffer & RenderBuffer::T_back) {
|
||||
hr=_pD3DDevice->GetBackBuffer(0, 0,D3DBACKBUFFER_TYPE_MONO,&pD3DSurf);
|
||||
|
||||
if(FAILED(hr)) {
|
||||
dxgsg9_cat.error() << "GetBackBuffer failed" << D3DERRORSTRING(hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
// note if you try to grab the backbuffer and full-screen anti-aliasing is on,
|
||||
// the backbuffer might be larger than the window size. for screenshots its safer to get the front buffer.
|
||||
|
||||
} else if(_cur_read_pixel_buffer & RenderBuffer::T_front) {
|
||||
// must create a A8R8G8B8 sysmem surface for GetFrontBuffer to copy to
|
||||
|
||||
DWORD TmpSurfXsize,TmpSurfYsize;
|
||||
|
||||
if(_pScrn->PresParams.Windowed) {
|
||||
// GetFrontBuffer retrieves the entire desktop for a monitor, so
|
||||
// need space for that
|
||||
|
||||
MONITORINFO minfo;
|
||||
minfo.cbSize = sizeof(MONITORINFO);
|
||||
GetMonitorInfo(_pScrn->hMon, &minfo); // have to use GetMonitorInfo, since this gsg may not be for primary monitor
|
||||
|
||||
TmpSurfXsize = RECT_XSIZE(minfo.rcMonitor);
|
||||
TmpSurfYsize = RECT_YSIZE(minfo.rcMonitor);
|
||||
|
||||
IDirect3DSurface9 *pD3DSurf;
|
||||
HRESULT hr;
|
||||
// set SrcCopyRect to client area of window in scrn coords
|
||||
ClientToScreen( _pScrn->hWnd, (POINT*)&SrcCopyRect.left );
|
||||
ClientToScreen( _pScrn->hWnd, (POINT*)&SrcCopyRect.right );
|
||||
|
||||
RECT WindRect;
|
||||
GetWindowRect(_pScrn->hWnd,&WindRect);
|
||||
|
||||
// just handling front and backbuf for now, not textures yet
|
||||
if(_cur_read_pixel_buffer & RenderBuffer::T_back) {
|
||||
hr=_pD3DDevice->GetBackBuffer(0, 0,D3DBACKBUFFER_TYPE_MONO,&pD3DSurf);
|
||||
|
||||
if(FAILED(hr)) {
|
||||
dxgsg9_cat.error() << "GetBackBuffer failed" << D3DERRORSTRING(hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
D3DSURFACE_DESC SurfDesc;
|
||||
hr = pD3DSurf->GetDesc(&SurfDesc);
|
||||
|
||||
SrcCopyRect.top=SrcCopyRect.left=0;
|
||||
SrcCopyRect.right=SurfDesc.Width;
|
||||
SrcCopyRect.bottom=SurfDesc.Height;
|
||||
|
||||
// note if you try to grab the backbuffer and full-screen anti-aliasing is on,
|
||||
// the backbuffer might be larger than the window size. for screenshots its safer to get the front buffer.
|
||||
|
||||
} else if(_cur_read_pixel_buffer & RenderBuffer::T_front) {
|
||||
// must create a A8R8G8B8 sysmem surface for GetFrontBuffer to copy to
|
||||
|
||||
DWORD TmpSurfXsize,TmpSurfYsize;
|
||||
|
||||
if(_pScrn->PresParams.Windowed) {
|
||||
// GetFrontBuffer retrieves the entire desktop for a monitor, so need space for that
|
||||
|
||||
MONITORINFO minfo;
|
||||
minfo.cbSize = sizeof(MONITORINFO);
|
||||
GetMonitorInfo(_pScrn->hMon, &minfo); // have to use GetMonitorInfo, since this gsg may not be for primary monitor
|
||||
|
||||
TmpSurfXsize=RECT_XSIZE(minfo.rcMonitor);
|
||||
TmpSurfYsize=RECT_YSIZE(minfo.rcMonitor);
|
||||
|
||||
// set SrcCopyRect to client area of window in scrn coords
|
||||
GetClientRect( _pScrn->hWnd, &SrcCopyRect);
|
||||
ClientToScreen( _pScrn->hWnd, (POINT*)&SrcCopyRect.left );
|
||||
ClientToScreen( _pScrn->hWnd, (POINT*)&SrcCopyRect.right );
|
||||
} else {
|
||||
TmpSurfXsize=RECT_XSIZE(WindRect);
|
||||
TmpSurfYsize=RECT_YSIZE(WindRect);
|
||||
|
||||
SrcCopyRect.top=SrcCopyRect.left=0;
|
||||
SrcCopyRect.right=TmpSurfXsize;
|
||||
SrcCopyRect.bottom=TmpSurfYsize;
|
||||
}
|
||||
|
||||
hr=_pD3DDevice->CreateOffscreenPlainSurface(TmpSurfXsize,TmpSurfYsize,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM, &pD3DSurf, NULL);
|
||||
if(FAILED(hr)) {
|
||||
dxgsg9_cat.error() << "CreateImageSurface failed in copy_pixel_buffer()" << D3DERRORSTRING(hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr=_pD3DDevice->GetFrontBufferData(0, pD3DSurf);
|
||||
|
||||
if(hr==D3DERR_DEVICELOST) {
|
||||
pD3DSurf->Release();
|
||||
dxgsg9_cat.error() << "copy_pixel_buffer failed: device lost\n";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
dxgsg9_cat.error() << "copy_pixel_buffer: unhandled current_read_pixel_buffer type\n";
|
||||
return false;
|
||||
RECT WindRect;
|
||||
GetWindowRect(_pScrn->hWnd,&WindRect);
|
||||
TmpSurfXsize = RECT_XSIZE(WindRect);
|
||||
TmpSurfYsize = RECT_YSIZE(WindRect);
|
||||
}
|
||||
|
||||
hr=_pD3DDevice->CreateOffscreenPlainSurface(TmpSurfXsize,TmpSurfYsize,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM, &pD3DSurf, NULL);
|
||||
if(FAILED(hr)) {
|
||||
dxgsg9_cat.error() << "CreateImageSurface failed in copy_pixel_buffer()" << D3DERRORSTRING(hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr=_pD3DDevice->GetFrontBufferData(0, pD3DSurf);
|
||||
|
||||
if(hr==D3DERR_DEVICELOST) {
|
||||
pD3DSurf->Release();
|
||||
dxgsg9_cat.error() << "copy_pixel_buffer failed: device lost\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if((RECT_XSIZE(SrcCopyRect)>w) || (RECT_YSIZE(SrcCopyRect)>h)) {
|
||||
dxgsg9_cat.error() << "copy_pixel_buffer: pixel buffer size does not match selected screen RenderBuffer size!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
(void) ConvertD3DSurftoPixBuf(SrcCopyRect,pD3DSurf,pb);
|
||||
|
||||
RELEASE(pD3DSurf,dxgsg9,"pD3DSurf",RELEASE_ONCE);
|
||||
|
||||
nassertr(!pb->_image.empty(), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian9::copy_pixel_buffer
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool DXGraphicsStateGuardian9::
|
||||
copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb) {
|
||||
set_read_buffer(rb);
|
||||
return copy_pixel_buffer(pb, dr);
|
||||
} else {
|
||||
dxgsg9_cat.error() << "copy_pixel_buffer: unhandled current_read_pixel_buffer type\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
(void) ConvertD3DSurftoPixBuf(SrcCopyRect,pD3DSurf,tex);
|
||||
|
||||
RELEASE(pD3DSurf,dxgsg9,"pD3DSurf",RELEASE_ONCE);
|
||||
|
||||
nassertr(tex->has_ram_image(), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -3986,55 +3927,6 @@ set_blend_mode() {
|
|||
enable_blend(false);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian9::save_frame_buffer
|
||||
// Access: Public
|
||||
// Description: Saves the indicated planes of the frame buffer
|
||||
// (within the indicated display region) and returns it
|
||||
// in some meaningful form that can be restored later
|
||||
// via restore_frame_buffer(). This is a helper
|
||||
// function for push_frame_buffer() and
|
||||
// pop_frame_buffer().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(SavedFrameBuffer) DXGraphicsStateGuardian9::
|
||||
save_frame_buffer(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr) {
|
||||
|
||||
dxgsg9_cat.error() << "save_frame_buffer unimplemented!!\n";
|
||||
return NULL;
|
||||
|
||||
#if 0
|
||||
DXSavedFrameBuffer *sfb = new DXSavedFrameBuffer(buffer, dr);
|
||||
|
||||
if (buffer._buffer_type & RenderBuffer::T_depth) {
|
||||
// Save the depth buffer.
|
||||
sfb->_depth =
|
||||
new PixelBuffer(PixelBuffer::depth_buffer(dr->get_pixel_width(),
|
||||
dr->get_pixel_height()));
|
||||
copy_pixel_buffer(sfb->_depth, dr, buffer);
|
||||
}
|
||||
|
||||
if (buffer._buffer_type & RenderBuffer::T_back) {
|
||||
// Save the color buffer.
|
||||
sfb->_back_rgba = new Texture;
|
||||
copy_texture(sfb->_back_rgba, dr, buffer);
|
||||
}
|
||||
|
||||
return sfb;
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXGraphicsStateGuardian9::restore_frame_buffer
|
||||
// Access: Public
|
||||
// Description: Restores the frame buffer that was previously saved.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void DXGraphicsStateGuardian9::
|
||||
restore_frame_buffer(SavedFrameBuffer *frame_buffer) {
|
||||
dxgsg9_cat.error() << "restore_frame_buffer unimplemented!!\n";
|
||||
return;
|
||||
}
|
||||
|
||||
TypeHandle DXGraphicsStateGuardian9::get_type(void) const {
|
||||
return get_class_type();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#include "geomprimitives.h"
|
||||
#include "texture.h"
|
||||
#include "texGenAttrib.h"
|
||||
#include "pixelBuffer.h"
|
||||
#include "displayRegion.h"
|
||||
#include "material.h"
|
||||
#include "depthTestAttrib.h"
|
||||
|
|
@ -95,17 +94,10 @@ public:
|
|||
virtual void apply_texture(TextureContext *tc);
|
||||
virtual void release_texture(TextureContext *tc);
|
||||
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr);
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb);
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
|
||||
const DisplayRegion *dr);
|
||||
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr);
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
virtual void framebuffer_copy_to_texture(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
virtual bool framebuffer_copy_to_ram(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
|
||||
virtual void apply_material(const Material *material);
|
||||
virtual void apply_fog(Fog *fog);
|
||||
|
|
@ -160,9 +152,6 @@ protected:
|
|||
|
||||
void free_nondx_resources(); // free local internal buffers
|
||||
void free_d3d_device(void);
|
||||
virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr);
|
||||
virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer);
|
||||
|
||||
void set_draw_buffer(const RenderBuffer &rb);
|
||||
void set_read_buffer(const RenderBuffer &rb);
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer8.I
|
||||
// Created by: masad (02Jan04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXSavedFrameBuffer9::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE DXSavedFrameBuffer9::
|
||||
DXSavedFrameBuffer9(const RenderBuffer &buffer, CPT(DisplayRegion) dr) :
|
||||
SavedFrameBuffer(buffer, dr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXSavedFrameBuffer9::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE DXSavedFrameBuffer9::
|
||||
~DXSavedFrameBuffer9() {
|
||||
}
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer8.cxx
|
||||
// Created by: masad (02Jan04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "dxSavedFrameBuffer9.h"
|
||||
|
||||
TypeHandle DXSavedFrameBuffer9::_type_handle;
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
// Filename: dxSavedFrameBuffer8.h
|
||||
// Created by: masad (02Jan04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 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 DXSAVEDFRAMEBUFFER9_H
|
||||
#define DXSAVEDFRAMEBUFFER9_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "savedFrameBuffer.h"
|
||||
#include "texture.h"
|
||||
#include "textureContext.h"
|
||||
#include "pixelBuffer.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : DXSavedFrameBuffer9
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDADX DXSavedFrameBuffer9 : public SavedFrameBuffer {
|
||||
public:
|
||||
INLINE DXSavedFrameBuffer9(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr);
|
||||
INLINE ~DXSavedFrameBuffer9();
|
||||
|
||||
PT(Texture) _back_rgba;
|
||||
PT(PixelBuffer) _depth;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
SavedFrameBuffer::init_type();
|
||||
register_type(_type_handle, "DXSavedFrameBuffer9",
|
||||
SavedFrameBuffer::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 "DXSavedFrameBuffer9.I"
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ static const DWORD g_LowByteMask = 0x000000FF;
|
|||
|
||||
#ifdef PANDA_BGRA_ORDER
|
||||
// assume Panda uses byte-order BGRA/LA to store pixels, which when read into little-endian word is ARGB/AL
|
||||
// these macros GET from PixelBuffer, (wont work from DDSurface)
|
||||
// these macros GET from Texture, (wont work from DDSurface)
|
||||
#define GET_RED_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD >> 16) & g_LowByteMask))
|
||||
#define GET_BLUE_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD) & g_LowByteMask))
|
||||
#else
|
||||
|
|
@ -135,54 +135,54 @@ enum Format {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DXTextureContext9::get_bits_per_pixel
|
||||
// Access: Protected
|
||||
// Description: Maps from the PixelBuffer's Format symbols
|
||||
// Description: Maps from the Texture's Format symbols
|
||||
// to bpp. returns # of alpha bits
|
||||
// Note: PixelBuffer's format indicates REQUESTED final format,
|
||||
// Note: Texture's format indicates REQUESTED final format,
|
||||
// not the stored format, which is indicated by pixelbuffer type
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned int DXTextureContext9::
|
||||
get_bits_per_pixel(PixelBuffer::Format format, int *alphbits) {
|
||||
get_bits_per_pixel(Texture::Format format, int *alphbits) {
|
||||
*alphbits = 0; // assume no alpha bits
|
||||
switch(format) {
|
||||
case PixelBuffer::F_alpha:
|
||||
case Texture::F_alpha:
|
||||
*alphbits = 8;
|
||||
case PixelBuffer::F_color_index:
|
||||
case PixelBuffer::F_red:
|
||||
case PixelBuffer::F_green:
|
||||
case PixelBuffer::F_blue:
|
||||
case PixelBuffer::F_rgb332:
|
||||
case Texture::F_color_index:
|
||||
case Texture::F_red:
|
||||
case Texture::F_green:
|
||||
case Texture::F_blue:
|
||||
case Texture::F_rgb332:
|
||||
return 8;
|
||||
case PixelBuffer::F_luminance_alphamask:
|
||||
case Texture::F_luminance_alphamask:
|
||||
*alphbits = 1;
|
||||
return 16;
|
||||
case PixelBuffer::F_luminance_alpha:
|
||||
case Texture::F_luminance_alpha:
|
||||
*alphbits = 8;
|
||||
return 16;
|
||||
case PixelBuffer::F_luminance:
|
||||
case Texture::F_luminance:
|
||||
return 8;
|
||||
case PixelBuffer::F_rgba4:
|
||||
case Texture::F_rgba4:
|
||||
*alphbits = 4;
|
||||
return 16;
|
||||
case PixelBuffer::F_rgba5:
|
||||
case Texture::F_rgba5:
|
||||
*alphbits = 1;
|
||||
return 16;
|
||||
case PixelBuffer::F_depth_component:
|
||||
case PixelBuffer::F_rgb5:
|
||||
case Texture::F_depth_component:
|
||||
case Texture::F_rgb5:
|
||||
return 16;
|
||||
case PixelBuffer::F_rgb8:
|
||||
case PixelBuffer::F_rgb:
|
||||
case Texture::F_rgb8:
|
||||
case Texture::F_rgb:
|
||||
return 24;
|
||||
case PixelBuffer::F_rgba8:
|
||||
case PixelBuffer::F_rgba:
|
||||
case PixelBuffer::F_rgbm:
|
||||
if(format==PixelBuffer::F_rgbm) // does this make any sense?
|
||||
case Texture::F_rgba8:
|
||||
case Texture::F_rgba:
|
||||
case Texture::F_rgbm:
|
||||
if(format==Texture::F_rgbm) // does this make any sense?
|
||||
*alphbits = 1;
|
||||
else *alphbits = 8;
|
||||
return 32;
|
||||
case PixelBuffer::F_rgb12:
|
||||
case Texture::F_rgb12:
|
||||
return 36;
|
||||
case PixelBuffer::F_rgba12:
|
||||
case Texture::F_rgba12:
|
||||
*alphbits = 12;
|
||||
return 48;
|
||||
}
|
||||
|
|
@ -190,20 +190,20 @@ get_bits_per_pixel(PixelBuffer::Format format, int *alphbits) {
|
|||
}
|
||||
|
||||
// still need custom conversion since d3d/d3dx has no way to convert arbitrary fmt to ARGB in-memory user buffer
|
||||
HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelBuffer *pixbuf) {
|
||||
// copies SrcRect in pD3DSurf to upper left of pixbuf
|
||||
HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,Texture *texture) {
|
||||
// copies SrcRect in pD3DSurf to upper left of texture
|
||||
HRESULT hr;
|
||||
DWORD dwNumComponents=pixbuf->get_num_components();
|
||||
DWORD dwNumComponents=texture->get_num_components();
|
||||
|
||||
assert(pixbuf->get_component_width()==sizeof(BYTE)); // cant handle anything else now
|
||||
assert(pixbuf->get_image_type()==PixelBuffer::T_unsigned_byte); // cant handle anything else now
|
||||
assert(texture->get_component_width()==sizeof(BYTE)); // cant handle anything else now
|
||||
assert(texture->get_component_type()==Texture::T_unsigned_byte); // cant handle anything else now
|
||||
assert((dwNumComponents==3) || (dwNumComponents==4)); // cant handle anything else now
|
||||
assert(IS_VALID_PTR(pD3DSurf9));
|
||||
|
||||
BYTE *pbuf=pixbuf->_image.p();
|
||||
BYTE *pbuf=texture->modify_ram_image().p();
|
||||
|
||||
if(IsBadWritePtr(pD3DSurf9,sizeof(DWORD))) {
|
||||
dxgsg9_cat.error() << "ConvertDDSurftoPixBuf failed: bad pD3DSurf ptr value (" << ((void*)pD3DSurf9) << ")\n";
|
||||
dxgsg9_cat.error() << "ConvertDDSurftoTexture failed: bad pD3DSurf ptr value (" << ((void*)pD3DSurf9) << ")\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -219,11 +219,11 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelB
|
|||
dwCopyWidth=RECT_XSIZE(SrcRect);
|
||||
dwCopyHeight=RECT_YSIZE(SrcRect);
|
||||
|
||||
//make sure there's enough space in the pixbuf, its size must match (especially xsize)
|
||||
//make sure there's enough space in the texture, its size must match (especially xsize)
|
||||
// or scanlines will be too long
|
||||
|
||||
if(!((dwCopyWidth==pixbuf->get_xsize()) && (dwCopyHeight<=(DWORD)pixbuf->get_ysize()))) {
|
||||
dxgsg9_cat.error() << "ConvertDDSurftoPixBuf, PixBuf size too small to hold display surface!\n";
|
||||
if(!((dwCopyWidth==texture->get_x_size()) && (dwCopyHeight<=(DWORD)texture->get_y_size()))) {
|
||||
dxgsg9_cat.error() << "ConvertDDSurftoPixBuf, Texture size too small to hold display surface!\n";
|
||||
assert(0);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
|
@ -239,7 +239,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelB
|
|||
(SurfDesc.Format==D3DFMT_R5G6B5)||(SurfDesc.Format==D3DFMT_X1R5G5B5)||(SurfDesc.Format==D3DFMT_A1R5G5B5)||
|
||||
(SurfDesc.Format==D3DFMT_A4R4G4B4));
|
||||
|
||||
//pbuf contains raw ARGB in PixelBuffer byteorder
|
||||
//pbuf contains raw ARGB in Texture byteorder
|
||||
|
||||
DWORD BytePitch = LockedRect.Pitch;
|
||||
BYTE* pSurfBytes = (BYTE*)LockedRect.pBits;
|
||||
|
|
@ -249,7 +249,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelB
|
|||
if(dxgsg9_cat.is_debug()) {
|
||||
dxgsg9_cat.debug()
|
||||
<< "ConvertD3DSurftoPixBuf converting " << D3DFormatStr(SurfDesc.Format) << "bpp DDSurf to "
|
||||
<< dwNumComponents << "-channel panda PixelBuffer\n";
|
||||
<< dwNumComponents << "-channel panda Texture\n";
|
||||
}
|
||||
|
||||
DWORD *pDstWord = (DWORD *) pbuf;
|
||||
|
|
@ -285,7 +285,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelB
|
|||
#endif
|
||||
}
|
||||
} else {
|
||||
// 24bpp pixbuf case (numComponents==3)
|
||||
// 24bpp texture case (numComponents==3)
|
||||
DWORD *pSrcWord;
|
||||
pSurfBytes+=BytePitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||
for(DWORD y=0; y<dwCopyHeight; y++,pSurfBytes-=BytePitch) {
|
||||
|
|
@ -336,7 +336,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelB
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// 24bpp pixbuf case (numComponents==3)
|
||||
// 24bpp texture case (numComponents==3)
|
||||
for(DWORD y=0; y<dwCopyHeight; y++,pSurfBytes-=BytePitch) {
|
||||
pSrcByte = pSurfBytes+dwXWindowOffset*3*sizeof(BYTE);
|
||||
#ifdef PANDA_BGRA_ORDER
|
||||
|
|
@ -398,7 +398,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelB
|
|||
|
||||
pSurfBytes+=BytePitch*(dwYWindowOffset+dwCopyHeight-1);
|
||||
if(dwNumComponents==4) {
|
||||
// Note: these 16bpp loops ignore input alpha completely (alpha is set to fully opaque in pixbuf!)
|
||||
// Note: these 16bpp loops ignore input alpha completely (alpha is set to fully opaque in texture!)
|
||||
// if we need to capture alpha, probably need to make separate loops for diff 16bpp fmts
|
||||
// for best speed
|
||||
|
||||
|
|
@ -422,7 +422,7 @@ HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelB
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// 24bpp pixbuf case (numComponents==3)
|
||||
// 24bpp texture case (numComponents==3)
|
||||
for(DWORD y=0; y<dwCopyHeight; y++,pSurfBytes-=BytePitch) {
|
||||
pSrcWord = ((WORD*)pSurfBytes)+dwXWindowOffset;
|
||||
for(DWORD x=0; x<dwCopyWidth; x++,pSrcWord++) {
|
||||
|
|
@ -470,20 +470,18 @@ IDirect3DTexture9 *DXTextureContext9::CreateTexture(DXScreenData &scrn) {
|
|||
|
||||
assert(IS_VALID_PTR(_texture));
|
||||
|
||||
PixelBuffer *pbuf = _texture->_pbuffer;
|
||||
// bpp indicates requested fmt, not pixbuf fmt
|
||||
DWORD target_bpp = get_bits_per_pixel(pbuf->get_format(), &cNumAlphaBits);
|
||||
PixelBuffer::Type pixbuf_type = pbuf->get_image_type();
|
||||
DWORD cNumColorChannels = pbuf->get_num_components();
|
||||
// bpp indicates requested fmt, not texture fmt
|
||||
DWORD target_bpp = get_bits_per_pixel(_texture->get_format(), &cNumAlphaBits);
|
||||
DWORD cNumColorChannels = _texture->get_num_components();
|
||||
|
||||
//PRINT_REFCNT(dxgsg9,scrn.pD3D9);
|
||||
|
||||
DWORD dwOrigWidth = (DWORD)pbuf->get_xsize();
|
||||
DWORD dwOrigHeight = (DWORD)pbuf->get_ysize();
|
||||
DWORD dwOrigWidth = (DWORD)_texture->get_x_size();
|
||||
DWORD dwOrigHeight = (DWORD)_texture->get_y_size();
|
||||
|
||||
if((pbuf->get_format() == PixelBuffer::F_luminance_alpha)||
|
||||
(pbuf->get_format() == PixelBuffer::F_luminance_alphamask) ||
|
||||
(pbuf->get_format() == PixelBuffer::F_luminance)) {
|
||||
if((_texture->get_format() == Texture::F_luminance_alpha)||
|
||||
(_texture->get_format() == Texture::F_luminance_alphamask) ||
|
||||
(_texture->get_format() == Texture::F_luminance)) {
|
||||
bNeedLuminance = true;
|
||||
}
|
||||
|
||||
|
|
@ -496,7 +494,7 @@ IDirect3DTexture9 *DXTextureContext9::CreateTexture(DXScreenData &scrn) {
|
|||
|
||||
_PixBufD3DFmt=D3DFMT_UNKNOWN;
|
||||
|
||||
// figure out what 'D3DFMT' the PixelBuffer is in, so D3DXLoadSurfFromMem knows how to perform copy
|
||||
// figure out what 'D3DFMT' the Texture is in, so D3DXLoadSurfFromMem knows how to perform copy
|
||||
|
||||
switch(cNumColorChannels) {
|
||||
case 1:
|
||||
|
|
@ -567,13 +565,13 @@ IDirect3DTexture9 *DXTextureContext9::CreateTexture(DXScreenData &scrn) {
|
|||
// need 2 add checks for errors
|
||||
PNMImage pnmi_src;
|
||||
PNMImage *pnmi = new PNMImage(TargetWidth, TargetHeight, cNumColorChannels);
|
||||
pbuf->store(pnmi_src);
|
||||
_texture->store(pnmi_src);
|
||||
pnmi->quick_filter_from(pnmi_src,0,0);
|
||||
|
||||
pbuf->load(*pnmi); // violates device independence of pixbufs
|
||||
_texture->load(*pnmi); // violates device independence of pixbufs
|
||||
|
||||
dwOrigWidth = (DWORD)pbuf->get_xsize();
|
||||
dwOrigHeight = (DWORD)pbuf->get_ysize();
|
||||
dwOrigWidth = (DWORD)_texture->get_x_size();
|
||||
dwOrigHeight = (DWORD)_texture->get_y_size();
|
||||
delete pnmi;
|
||||
}
|
||||
*/
|
||||
|
|
@ -601,7 +599,7 @@ IDirect3DTexture9 *DXTextureContext9::CreateTexture(DXScreenData &scrn) {
|
|||
switch(target_bpp) {
|
||||
|
||||
// IMPORTANT NOTE:
|
||||
// target_bpp is REQUESTED bpp, not what exists in the pixbuf array (the pixbuf array contains cNumColorChannels*8bits)
|
||||
// target_bpp is REQUESTED bpp, not what exists in the texture array (the texture array contains cNumColorChannels*8bits)
|
||||
|
||||
case 32:
|
||||
if(!((cNumColorChannels==3) || (cNumColorChannels==4)))
|
||||
|
|
@ -772,7 +770,7 @@ IDirect3DTexture9 *DXTextureContext9::CreateTexture(DXScreenData &scrn) {
|
|||
///////////////////////////////////////////////////////////
|
||||
|
||||
found_matching_format:
|
||||
// We found a suitable format that matches the pbuffer's format.
|
||||
// We found a suitable format that matches the texture's format.
|
||||
|
||||
if (_texture->get_match_framebuffer_format()) {
|
||||
// Instead of creating a texture with the found format, we will
|
||||
|
|
@ -936,8 +934,8 @@ FillDDSurfTexturePixels(void) {
|
|||
HRESULT hr=E_FAIL;
|
||||
assert(IS_VALID_PTR(_texture));
|
||||
|
||||
PixelBuffer *pbuf = _texture->get_ram_image();
|
||||
if (pbuf == (PixelBuffer *)NULL) {
|
||||
CPTA_uchar image = _texture->get_ram_image();
|
||||
if (image.is_null()) {
|
||||
// The texture doesn't have an image to load. That's ok; it
|
||||
// might be a texture we've rendered to by frame buffer
|
||||
// operations or something.
|
||||
|
|
@ -946,12 +944,12 @@ FillDDSurfTexturePixels(void) {
|
|||
|
||||
assert(IS_VALID_PTR(_pD3DTexture9));
|
||||
|
||||
DWORD OrigWidth = (DWORD) pbuf->get_xsize();
|
||||
DWORD OrigHeight = (DWORD) pbuf->get_ysize();
|
||||
DWORD cNumColorChannels = pbuf->get_num_components();
|
||||
DWORD OrigWidth = (DWORD) _texture->get_x_size();
|
||||
DWORD OrigHeight = (DWORD) _texture->get_y_size();
|
||||
DWORD cNumColorChannels = _texture->get_num_components();
|
||||
D3DFORMAT SrcFormat=_PixBufD3DFmt;
|
||||
BYTE *pPixels=(BYTE*)pbuf->_image.p();
|
||||
int component_width = pbuf->get_component_width();
|
||||
BYTE *pPixels=(BYTE*)image.p();
|
||||
int component_width = _texture->get_component_width();
|
||||
|
||||
assert(IS_VALID_PTR(pPixels));
|
||||
|
||||
|
|
@ -1009,7 +1007,7 @@ FillDDSurfTexturePixels(void) {
|
|||
// original image. dx9 does support some of these
|
||||
// high-precision formats, but we don't right now.
|
||||
|
||||
int num_components = pbuf->get_num_components();
|
||||
int num_components = _texture->get_num_components();
|
||||
int num_pixels = OrigWidth * OrigHeight * num_components;
|
||||
BYTE *pTempPixBuf = new BYTE[num_pixels];
|
||||
if(!IS_VALID_PTR(pTempPixBuf)) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public:
|
|||
Texture *_tex; // ptr to parent, primarily for access to namestr
|
||||
IDirect3DTexture9 *CreateTexture(DXScreenData &scrn);
|
||||
|
||||
D3DFORMAT _PixBufD3DFmt; // the 'D3DFORMAT' the Panda PixelBuffer fmt corresponds to
|
||||
D3DFORMAT _PixBufD3DFmt; // the 'D3DFORMAT' the Panda TextureBuffer fmt corresponds to
|
||||
|
||||
bool _bHasMipMaps;
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ public:
|
|||
HRESULT FillDDSurfTexturePixels(void);
|
||||
|
||||
protected:
|
||||
unsigned int get_bits_per_pixel(PixelBuffer::Format format, int *alphbits);
|
||||
unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
|
@ -74,7 +74,7 @@ private:
|
|||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
extern HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,PixelBuffer *pixbuf);
|
||||
extern HRESULT ConvertD3DSurftoPixBuf(RECT &SrcRect,IDirect3DSurface9 *pD3DSurf9,Texture *pixbuf);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include "dxgsg9base.h"
|
||||
#include "config_dxgsg9.cxx"
|
||||
#include "dxSavedFrameBuffer9.cxx"
|
||||
#include "dxTextureContext9.cxx"
|
||||
#include "d3dfont9.cxx"
|
||||
#include "wdxGraphicsPipe9.cxx"
|
||||
|
|
|
|||
|
|
@ -816,6 +816,9 @@ string_tex_gen(const string &string) {
|
|||
} else if (cmp_nocase_uh(string, "eye_position") == 0) {
|
||||
return TG_eye_position;
|
||||
|
||||
} else if (cmp_nocase_uh(string, "object_normal") == 0) {
|
||||
return TG_object_normal;
|
||||
|
||||
} else {
|
||||
return TG_unspecified;
|
||||
}
|
||||
|
|
@ -1125,6 +1128,9 @@ operator << (ostream &out, EggTexture::TexGen tex_gen) {
|
|||
|
||||
case EggTexture::TG_eye_position:
|
||||
return out << "eye_position";
|
||||
|
||||
case EggTexture::TG_object_normal:
|
||||
return out << "object_normal";
|
||||
}
|
||||
|
||||
return out << "**invalid TexGen(" << (int)tex_gen << ")**";
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ PUBLISHED:
|
|||
TG_world_position,
|
||||
TG_object_position,
|
||||
TG_eye_position,
|
||||
TG_object_normal,
|
||||
};
|
||||
|
||||
INLINE void set_format(Format format);
|
||||
|
|
|
|||
|
|
@ -860,16 +860,16 @@ void EggLoader::
|
|||
apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
|
||||
switch (egg_tex->determine_wrap_u()) {
|
||||
case EggTexture::WM_repeat:
|
||||
tex->set_wrapu(Texture::WM_repeat);
|
||||
tex->set_wrap_u(Texture::WM_repeat);
|
||||
break;
|
||||
|
||||
case EggTexture::WM_clamp:
|
||||
if (egg_ignore_clamp) {
|
||||
egg2pg_cat.warning()
|
||||
<< "Ignoring clamp request\n";
|
||||
tex->set_wrapu(Texture::WM_repeat);
|
||||
tex->set_wrap_u(Texture::WM_repeat);
|
||||
} else {
|
||||
tex->set_wrapu(Texture::WM_clamp);
|
||||
tex->set_wrap_u(Texture::WM_clamp);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -884,16 +884,16 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
|
|||
|
||||
switch (egg_tex->determine_wrap_v()) {
|
||||
case EggTexture::WM_repeat:
|
||||
tex->set_wrapv(Texture::WM_repeat);
|
||||
tex->set_wrap_v(Texture::WM_repeat);
|
||||
break;
|
||||
|
||||
case EggTexture::WM_clamp:
|
||||
if (egg_ignore_clamp) {
|
||||
egg2pg_cat.warning()
|
||||
<< "Ignoring clamp request\n";
|
||||
tex->set_wrapv(Texture::WM_repeat);
|
||||
tex->set_wrap_v(Texture::WM_repeat);
|
||||
} else {
|
||||
tex->set_wrapv(Texture::WM_clamp);
|
||||
tex->set_wrap_v(Texture::WM_clamp);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -1018,22 +1018,22 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
|
|||
tex->set_anisotropic_degree(egg_tex->get_anisotropic_degree());
|
||||
}
|
||||
|
||||
if (tex->_pbuffer->get_num_components() == 1) {
|
||||
if (tex->get_num_components() == 1) {
|
||||
switch (egg_tex->get_format()) {
|
||||
case EggTexture::F_red:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_red);
|
||||
tex->set_format(Texture::F_red);
|
||||
break;
|
||||
case EggTexture::F_green:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_green);
|
||||
tex->set_format(Texture::F_green);
|
||||
break;
|
||||
case EggTexture::F_blue:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_blue);
|
||||
tex->set_format(Texture::F_blue);
|
||||
break;
|
||||
case EggTexture::F_alpha:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_alpha);
|
||||
tex->set_format(Texture::F_alpha);
|
||||
break;
|
||||
case EggTexture::F_luminance:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_luminance);
|
||||
tex->set_format(Texture::F_luminance);
|
||||
break;
|
||||
|
||||
case EggTexture::F_unspecified:
|
||||
|
|
@ -1045,14 +1045,14 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
|
|||
<< " for 1-component texture " << egg_tex->get_name() << "\n";
|
||||
}
|
||||
|
||||
} else if (tex->_pbuffer->get_num_components() == 2) {
|
||||
} else if (tex->get_num_components() == 2) {
|
||||
switch (egg_tex->get_format()) {
|
||||
case EggTexture::F_luminance_alpha:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_luminance_alpha);
|
||||
tex->set_format(Texture::F_luminance_alpha);
|
||||
break;
|
||||
|
||||
case EggTexture::F_luminance_alphamask:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_luminance_alphamask);
|
||||
tex->set_format(Texture::F_luminance_alphamask);
|
||||
break;
|
||||
|
||||
case EggTexture::F_unspecified:
|
||||
|
|
@ -1064,15 +1064,15 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
|
|||
<< " for 2-component texture " << egg_tex->get_name() << "\n";
|
||||
}
|
||||
|
||||
} else if (tex->_pbuffer->get_num_components() == 3) {
|
||||
} else if (tex->get_num_components() == 3) {
|
||||
switch (egg_tex->get_format()) {
|
||||
case EggTexture::F_rgb:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgb);
|
||||
tex->set_format(Texture::F_rgb);
|
||||
break;
|
||||
case EggTexture::F_rgb12:
|
||||
if (tex->_pbuffer->get_component_width() >= 2) {
|
||||
if (tex->get_component_width() >= 2) {
|
||||
// Only do this if the component width supports it.
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgb12);
|
||||
tex->set_format(Texture::F_rgb12);
|
||||
} else {
|
||||
egg2pg_cat.warning()
|
||||
<< "Ignoring inappropriate format " << egg_tex->get_format()
|
||||
|
|
@ -1084,13 +1084,13 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
|
|||
// We'll quietly accept RGBA8 for a 3-component texture, since
|
||||
// flt2egg generates these for 3-component as well as for
|
||||
// 4-component textures.
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgb8);
|
||||
tex->set_format(Texture::F_rgb8);
|
||||
break;
|
||||
case EggTexture::F_rgb5:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgb5);
|
||||
tex->set_format(Texture::F_rgb5);
|
||||
break;
|
||||
case EggTexture::F_rgb332:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgb332);
|
||||
tex->set_format(Texture::F_rgb332);
|
||||
break;
|
||||
|
||||
case EggTexture::F_unspecified:
|
||||
|
|
@ -1102,18 +1102,18 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
|
|||
<< " for 3-component texture " << egg_tex->get_name() << "\n";
|
||||
}
|
||||
|
||||
} else if (tex->_pbuffer->get_num_components() == 4) {
|
||||
} else if (tex->get_num_components() == 4) {
|
||||
switch (egg_tex->get_format()) {
|
||||
case EggTexture::F_rgba:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgba);
|
||||
tex->set_format(Texture::F_rgba);
|
||||
break;
|
||||
case EggTexture::F_rgbm:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgbm);
|
||||
tex->set_format(Texture::F_rgbm);
|
||||
break;
|
||||
case EggTexture::F_rgba12:
|
||||
if (tex->_pbuffer->get_component_width() >= 2) {
|
||||
if (tex->get_component_width() >= 2) {
|
||||
// Only do this if the component width supports it.
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgba12);
|
||||
tex->set_format(Texture::F_rgba12);
|
||||
} else {
|
||||
egg2pg_cat.warning()
|
||||
<< "Ignoring inappropriate format " << egg_tex->get_format()
|
||||
|
|
@ -1121,13 +1121,13 @@ apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) {
|
|||
}
|
||||
break;
|
||||
case EggTexture::F_rgba8:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgba8);
|
||||
tex->set_format(Texture::F_rgba8);
|
||||
break;
|
||||
case EggTexture::F_rgba4:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgba4);
|
||||
tex->set_format(Texture::F_rgba4);
|
||||
break;
|
||||
case EggTexture::F_rgba5:
|
||||
tex->_pbuffer->set_format(PixelBuffer::F_rgba5);
|
||||
tex->set_format(Texture::F_rgba5);
|
||||
break;
|
||||
|
||||
case EggTexture::F_unspecified:
|
||||
|
|
@ -1451,7 +1451,7 @@ setup_bucket(BuilderBucket &bucket, EggLoader::BakeInUVs &bake_in_uvs,
|
|||
const TextureAttrib *tex_attrib = DCAST(TextureAttrib, def._texture);
|
||||
Texture *tex = tex_attrib->get_texture();
|
||||
nassertv(tex != (Texture *)NULL);
|
||||
int num_components = tex->_pbuffer->get_num_components();
|
||||
int num_components = tex->get_num_components();
|
||||
if (egg_tex->has_alpha_channel(num_components)) {
|
||||
switch (egg_tex->get_env_type()) {
|
||||
case EggTexture::ET_decal:
|
||||
|
|
@ -3129,6 +3129,9 @@ get_tex_gen(const EggTexture *egg_tex) {
|
|||
|
||||
case EggTexture::TG_eye_position:
|
||||
return TexGenAttrib::M_eye_position;
|
||||
|
||||
case EggTexture::TG_object_normal:
|
||||
return TexGenAttrib::M_object_normal;
|
||||
};
|
||||
|
||||
return TexGenAttrib::M_off;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,6 @@
|
|||
glGraphicsStateGuardian_src.cxx \
|
||||
glGraphicsStateGuardian_src.I \
|
||||
glGraphicsStateGuardian_src.h \
|
||||
glSavedFrameBuffer_src.cxx \
|
||||
glSavedFrameBuffer_src.I \
|
||||
glSavedFrameBuffer_src.h \
|
||||
glTextureContext_src.cxx \
|
||||
glTextureContext_src.I \
|
||||
glTextureContext_src.h \
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -21,7 +21,6 @@
|
|||
#include "graphicsStateGuardian.h"
|
||||
#include "geomprimitives.h"
|
||||
#include "texture.h"
|
||||
#include "pixelBuffer.h"
|
||||
#include "displayRegion.h"
|
||||
#include "material.h"
|
||||
#include "depthTestAttrib.h"
|
||||
|
|
@ -95,17 +94,10 @@ public:
|
|||
virtual GeomContext *prepare_geom(Geom *geom);
|
||||
virtual void release_geom(GeomContext *gc);
|
||||
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr);
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb);
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
|
||||
const DisplayRegion *dr);
|
||||
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr);
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
virtual void framebuffer_copy_to_texture
|
||||
(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb);
|
||||
virtual bool framebuffer_copy_to_ram
|
||||
(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb);
|
||||
|
||||
virtual void apply_material(const Material *material);
|
||||
void apply_fog(Fog *fog);
|
||||
|
|
@ -182,9 +174,6 @@ protected:
|
|||
virtual void finish_modify_state();
|
||||
|
||||
virtual void free_pointers();
|
||||
virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr);
|
||||
virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer);
|
||||
|
||||
INLINE void enable_multisample_antialias(bool val);
|
||||
INLINE void enable_multisample_alpha_one(bool val);
|
||||
|
|
@ -215,19 +204,18 @@ protected:
|
|||
void bind_texture(TextureContext *tc);
|
||||
void specify_texture(Texture *tex);
|
||||
bool apply_texture_immediate(CLP(TextureContext) *gtc, Texture *tex);
|
||||
bool upload_texture_image(CLP(TextureContext) *gtc, bool uses_mipmaps,
|
||||
GLenum target, GLint internal_format,
|
||||
int width, int height, int depth,
|
||||
GLint external_format, GLenum component_type,
|
||||
const unsigned char *image);
|
||||
|
||||
void draw_texture(TextureContext *tc, const DisplayRegion *dr);
|
||||
void draw_texture(TextureContext *tc, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr);
|
||||
void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb);
|
||||
|
||||
GLenum get_texture_wrap_mode(Texture::WrapMode wm) const;
|
||||
static GLenum get_texture_target(Texture::TextureType texture_type);
|
||||
GLenum get_texture_wrap_mode(Texture::WrapMode wm);
|
||||
static GLenum get_texture_filter_type(Texture::FilterType ft, bool ignore_mipmaps);
|
||||
static GLenum get_image_type(PixelBuffer::Type type);
|
||||
GLint get_external_image_format(PixelBuffer::Format format) const;
|
||||
static GLint get_internal_image_format(PixelBuffer::Format format);
|
||||
static GLenum get_component_type(Texture::ComponentType component_type);
|
||||
GLint get_external_image_format(Texture::Format format) const;
|
||||
static GLint get_internal_image_format(Texture::Format format);
|
||||
static GLint get_texture_apply_mode_type(TextureStage::Mode am);
|
||||
static GLint get_texture_combine_type(TextureStage::CombineMode cm);
|
||||
static GLint get_texture_src_type(TextureStage::CombineSource cs);
|
||||
|
|
@ -243,7 +231,7 @@ protected:
|
|||
|
||||
#ifndef NDEBUG
|
||||
void build_phony_mipmaps(Texture *tex);
|
||||
void build_phony_mipmap_level(int level, int xsize, int ysize);
|
||||
void build_phony_mipmap_level(int level, int x_size, int y_size);
|
||||
void save_mipmap_images(Texture *tex);
|
||||
#endif
|
||||
|
||||
|
|
@ -305,6 +293,10 @@ protected:
|
|||
pset<string> _extensions;
|
||||
|
||||
public:
|
||||
GLint _max_texture_size;
|
||||
GLint _max_3d_texture_size;
|
||||
GLint _max_cube_map_size;
|
||||
|
||||
bool _supports_bgr;
|
||||
bool _supports_rescale_normal;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
// Filename: glSavedFrameBuffer_src.I
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(SavedFrameBuffer)::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE CLP(SavedFrameBuffer)::
|
||||
CLP(SavedFrameBuffer)(const RenderBuffer &buffer, CPT(DisplayRegion) dr) :
|
||||
SavedFrameBuffer(buffer, dr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(SavedFrameBuffer)::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE CLP(SavedFrameBuffer)::
|
||||
~CLP(SavedFrameBuffer)() {
|
||||
}
|
||||
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// Filename: glSavedFrameBuffer.cxx
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
TypeHandle CLP(SavedFrameBuffer)::_type_handle;
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// Filename: glSavedFrameBuffer_src.h
|
||||
// Created by: drose (06Oct99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "savedFrameBuffer.h"
|
||||
#include "texture.h"
|
||||
#include "pixelBuffer.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : GLSavedFrameBuffer
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_GL CLP(SavedFrameBuffer) : public SavedFrameBuffer {
|
||||
public:
|
||||
INLINE CLP(SavedFrameBuffer)(const RenderBuffer &buffer,
|
||||
CPT(DisplayRegion) dr);
|
||||
INLINE ~CLP(SavedFrameBuffer)();
|
||||
|
||||
PT(Texture) _back_rgba;
|
||||
PT(PixelBuffer) _depth;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
SavedFrameBuffer::init_type();
|
||||
register_type(_type_handle, CLASSPREFIX_QUOTED "SavedFrameBuffer",
|
||||
SavedFrameBuffer::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 "glSavedFrameBuffer_src.I"
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ public:
|
|||
GLint _internal_format;
|
||||
GLsizei _width;
|
||||
GLsizei _height;
|
||||
GLint _border_width;
|
||||
GLsizei _depth;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ ConfigVariableBool CLP(color_mask)
|
|||
|
||||
void CLP(init_classes)() {
|
||||
CLP(GraphicsStateGuardian)::init_type();
|
||||
CLP(SavedFrameBuffer)::init_type();
|
||||
CLP(TextureContext)::init_type();
|
||||
CLP(GeomContext)::init_type();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include "glmisc_src.cxx"
|
||||
#include "glTextureContext_src.cxx"
|
||||
#include "glGeomContext_src.cxx"
|
||||
#include "glSavedFrameBuffer_src.cxx"
|
||||
#include "glCgShaderContext_src.cxx"
|
||||
#include "glGraphicsStateGuardian_src.cxx"
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@
|
|||
#include "glmisc_src.h"
|
||||
#include "glTextureContext_src.h"
|
||||
#include "glGeomContext_src.h"
|
||||
#include "glSavedFrameBuffer_src.h"
|
||||
#include "glCgShaderContext_src.h"
|
||||
#include "glGraphicsStateGuardian_src.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,11 @@
|
|||
geomContext.I geomContext.h \
|
||||
geomLine.h geomLinestrip.h geomPoint.h geomPolygon.h \
|
||||
geomQuad.h geomSphere.h geomSprite.I geomSprite.h geomTri.h \
|
||||
geomTrifan.h geomTristrip.h imageBuffer.I imageBuffer.h \
|
||||
geomTrifan.h geomTristrip.h \
|
||||
material.I material.h materialPool.I materialPool.h \
|
||||
matrixLens.I matrixLens.h \
|
||||
orthographicLens.I orthographicLens.h perspectiveLens.I \
|
||||
perspectiveLens.h pixelBuffer.I \
|
||||
pixelBuffer.h \
|
||||
perspectiveLens.h \
|
||||
preparedGraphicsObjects.I preparedGraphicsObjects.h \
|
||||
lens.h lens.I \
|
||||
savedContext.I savedContext.h \
|
||||
|
|
@ -37,9 +36,9 @@
|
|||
geomContext.cxx \
|
||||
geomLine.cxx geomLinestrip.cxx geomPoint.cxx geomPolygon.cxx \
|
||||
geomQuad.cxx geomSphere.cxx geomSprite.cxx geomTri.cxx \
|
||||
geomTrifan.cxx geomTristrip.cxx imageBuffer.cxx material.cxx \
|
||||
geomTrifan.cxx geomTristrip.cxx material.cxx \
|
||||
materialPool.cxx matrixLens.cxx orthographicLens.cxx \
|
||||
perspectiveLens.cxx pixelBuffer.cxx \
|
||||
perspectiveLens.cxx \
|
||||
preparedGraphicsObjects.cxx \
|
||||
lens.cxx \
|
||||
savedContext.cxx texture.cxx textureContext.cxx texturePool.cxx \
|
||||
|
|
@ -53,10 +52,10 @@
|
|||
geomLine.h \
|
||||
geomLinestrip.h geomPoint.h geomPolygon.h geomQuad.h geomSphere.h \
|
||||
geomSprite.I geomSprite.h geomTri.h geomTrifan.h geomTristrip.h \
|
||||
geomprimitives.h imageBuffer.I imageBuffer.h material.I material.h \
|
||||
geomprimitives.h material.I material.h \
|
||||
materialPool.I materialPool.h matrixLens.I matrixLens.h \
|
||||
orthographicLens.I orthographicLens.h perspectiveLens.I \
|
||||
perspectiveLens.h pixelBuffer.I pixelBuffer.h \
|
||||
perspectiveLens.h \
|
||||
preparedGraphicsObjects.I preparedGraphicsObjects.h \
|
||||
lens.h lens.I \
|
||||
savedContext.I savedContext.h \
|
||||
|
|
|
|||
|
|
@ -22,12 +22,10 @@
|
|||
#include "drawable.h"
|
||||
#include "geom.h"
|
||||
#include "geomprimitives.h"
|
||||
#include "imageBuffer.h"
|
||||
#include "material.h"
|
||||
#include "orthographicLens.h"
|
||||
#include "matrixLens.h"
|
||||
#include "perspectiveLens.h"
|
||||
#include "pixelBuffer.h"
|
||||
#include "lens.h"
|
||||
#include "texture.h"
|
||||
#include "textureStage.h"
|
||||
|
|
@ -52,7 +50,7 @@ ConfigVariableBool keep_texture_ram
|
|||
("keep-texture-ram", false,
|
||||
PRC_DESC("Set this to true to retain the ram image for each texture after it "
|
||||
"has been prepared with the GSG. This will allow the texture to be "
|
||||
"prepared with multiple GSG, or to be re-prepared later after it is "
|
||||
"prepared with multiple GSG's, or to be re-prepared later after it is "
|
||||
"explicitly released from the GSG, without having to reread the "
|
||||
"texture image from disk; but it will consume memory somewhat "
|
||||
"wastefully."));
|
||||
|
|
@ -135,12 +133,10 @@ ConfigureFn(config_gobj) {
|
|||
GeomTri::init_type();
|
||||
GeomTrifan::init_type();
|
||||
GeomTristrip::init_type();
|
||||
ImageBuffer::init_type();
|
||||
Material::init_type();
|
||||
OrthographicLens::init_type();
|
||||
MatrixLens::init_type();
|
||||
PerspectiveLens::init_type();
|
||||
PixelBuffer::init_type();
|
||||
Lens::init_type();
|
||||
Texture::init_type();
|
||||
dDrawable::init_type();
|
||||
|
|
|
|||
|
|
@ -2,13 +2,11 @@
|
|||
#include "config_gobj.cxx"
|
||||
#include "drawable.cxx"
|
||||
#include "geomContext.cxx"
|
||||
#include "imageBuffer.cxx"
|
||||
#include "material.cxx"
|
||||
#include "materialPool.cxx"
|
||||
#include "orthographicLens.cxx"
|
||||
#include "matrixLens.cxx"
|
||||
#include "perspectiveLens.cxx"
|
||||
#include "pixelBuffer.cxx"
|
||||
#include "preparedGraphicsObjects.cxx"
|
||||
#include "lens.cxx"
|
||||
#include "savedContext.cxx"
|
||||
|
|
|
|||
|
|
@ -1,224 +0,0 @@
|
|||
// Filename: imageBuffer.I
|
||||
// Created by: drose (21Nov00)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::has_filename
|
||||
// Access: Published
|
||||
// Description: Returns true if the filename has been set and
|
||||
// is available. See set_filename().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool ImageBuffer::
|
||||
has_filename() const {
|
||||
return !_filename.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::get_filename
|
||||
// Access: Published
|
||||
// Description: Returns the filename that has been set. This is the
|
||||
// name of the file as it was requested. Also see
|
||||
// get_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &ImageBuffer::
|
||||
get_filename() const {
|
||||
return _filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::has_alpha_filename
|
||||
// Access: Published
|
||||
// Description: Returns true if the alpha_filename has been set and
|
||||
// is available. See set_alpha_filename().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool ImageBuffer::
|
||||
has_alpha_filename() const {
|
||||
return !_alpha_filename.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::get_alpha_filename
|
||||
// Access: Published
|
||||
// Description: Returns the alpha_filename that has been set. If
|
||||
// this is set, it represents the name of the alpha
|
||||
// component, which is stored in a separate file. See
|
||||
// also get_filename(), and get_alpha_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &ImageBuffer::
|
||||
get_alpha_filename() const {
|
||||
return _alpha_filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::has_fullpath
|
||||
// Access: Published
|
||||
// Description: Returns true if the fullpath has been set and
|
||||
// is available. See set_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool ImageBuffer::
|
||||
has_fullpath() const {
|
||||
return !_fullpath.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::get_fullpath
|
||||
// Access: Published
|
||||
// Description: Returns the fullpath that has been set. This is the
|
||||
// full path to the file as it was found along the
|
||||
// texture search path.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &ImageBuffer::
|
||||
get_fullpath() const {
|
||||
return _fullpath;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::has_alpha_fullpath
|
||||
// Access: Published
|
||||
// Description: Returns true if the alpha_fullpath has been set and
|
||||
// is available. See set_alpha_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool ImageBuffer::
|
||||
has_alpha_fullpath() const {
|
||||
return !_alpha_fullpath.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::get_alpha_fullpath
|
||||
// Access: Published
|
||||
// Description:
|
||||
// Returns the alpha_fullpath that has been set. This
|
||||
// is the full path to the alpha part of the image file
|
||||
// as it was found along the texture search path.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &ImageBuffer::
|
||||
get_alpha_fullpath() const {
|
||||
return _alpha_fullpath;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::set_filename
|
||||
// Access: Public
|
||||
// Description: Sets the name of the file that contains the image's
|
||||
// contents. Normally, this is set automatically when
|
||||
// the image is loaded, for instance via
|
||||
// Texture::read().
|
||||
//
|
||||
// The ImageBuffer's get_name() function used to return
|
||||
// the filename, but now returns just the basename
|
||||
// (without the extension), which is a more useful name
|
||||
// for identifying an image in show code.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void ImageBuffer::
|
||||
set_filename(const Filename &filename) {
|
||||
_filename = filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::clear_filename
|
||||
// Access: Public
|
||||
// Description: Removes the alpha filename, if it was previously set.
|
||||
// See set_filename().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void ImageBuffer::
|
||||
clear_filename() {
|
||||
_filename = Filename();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::set_alpha_filename
|
||||
// Access: Public
|
||||
// Description: Sets the name of the file that contains the image's
|
||||
// alpha channel contents. Normally, this is set
|
||||
// automatically when the image is loaded, for instance
|
||||
// via Texture::read().
|
||||
//
|
||||
// The ImageBuffer's get_filename() function returns the
|
||||
// name of the image file that was loaded into the
|
||||
// buffer. In the case where a texture specified two
|
||||
// separate files to load, a 1- or 3-channel color image
|
||||
// and a 1-channel alpha image, this Filename is update
|
||||
// to contain the name of the image file that was loaded
|
||||
// into the buffer's alpha channel.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void ImageBuffer::
|
||||
set_alpha_filename(const Filename &alpha_filename) {
|
||||
_alpha_filename = alpha_filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::clear_alpha_filename
|
||||
// Access: Public
|
||||
// Description: Removes the alpha filename, if it was previously set.
|
||||
// See set_alpha_filename().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void ImageBuffer::
|
||||
clear_alpha_filename() {
|
||||
_alpha_filename = Filename();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::set_fullpath
|
||||
// Access: Public
|
||||
// Description: Sets the full pathname to the file that contains the
|
||||
// image's contents, as found along the search path.
|
||||
// Normally, this is set automatically when the image is
|
||||
// loaded, for instance via Texture::read().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void ImageBuffer::
|
||||
set_fullpath(const Filename &fullpath) {
|
||||
_fullpath = fullpath;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::clear_fullpath
|
||||
// Access: Public
|
||||
// Description: Removes the alpha fullpath, if it was previously set.
|
||||
// See set_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void ImageBuffer::
|
||||
clear_fullpath() {
|
||||
_fullpath = Filename();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::set_alpha_fullpath
|
||||
// Access: Public
|
||||
// Description: Sets the full pathname to the file that contains the
|
||||
// image's alpha channel contents, as found along the
|
||||
// search path. Normally, this is set automatically
|
||||
// when the image is loaded, for instance via
|
||||
// Texture::read().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void ImageBuffer::
|
||||
set_alpha_fullpath(const Filename &alpha_fullpath) {
|
||||
_alpha_fullpath = alpha_fullpath;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::clear_alpha_fullpath
|
||||
// Access: Public
|
||||
// Description: Removes the alpha fullpath, if it was previously set.
|
||||
// See set_alpha_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void ImageBuffer::
|
||||
clear_alpha_fullpath() {
|
||||
_alpha_fullpath = Filename();
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
// Filename: imageBuffer.cxx
|
||||
// Created by: mike (09Jan97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "imageBuffer.h"
|
||||
#include "config_gobj.h"
|
||||
#include "config_util.h"
|
||||
|
||||
#include "datagram.h"
|
||||
#include "datagramIterator.h"
|
||||
#include "bamReader.h"
|
||||
|
||||
TypeHandle ImageBuffer::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ImageBuffer::
|
||||
ImageBuffer() {
|
||||
_primary_file_num_channels = 0;
|
||||
_alpha_file_channel = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::Destructor
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ImageBuffer::
|
||||
~ImageBuffer() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::write_datagram
|
||||
// Access: Public
|
||||
// Description: Function to write the important information in
|
||||
// the particular object to a Datagram
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ImageBuffer::
|
||||
write_datagram(BamWriter *, Datagram &me)
|
||||
{
|
||||
Filename filename = get_filename();
|
||||
Filename alpha_filename = get_alpha_filename();
|
||||
|
||||
switch (bam_texture_mode) {
|
||||
case BTM_unchanged:
|
||||
case BTM_rawdata:
|
||||
break;
|
||||
|
||||
case BTM_fullpath:
|
||||
filename = get_fullpath();
|
||||
alpha_filename = get_alpha_fullpath();
|
||||
break;
|
||||
|
||||
case BTM_relative:
|
||||
filename = get_fullpath();
|
||||
alpha_filename = get_alpha_fullpath();
|
||||
filename.find_on_searchpath(get_texture_path()) ||
|
||||
filename.find_on_searchpath(get_model_path());
|
||||
if (gobj_cat.is_debug()) {
|
||||
gobj_cat.debug()
|
||||
<< "Texture file " << get_filename() << " found as " << filename << "\n";
|
||||
}
|
||||
alpha_filename.find_on_searchpath(get_texture_path()) ||
|
||||
alpha_filename.find_on_searchpath(get_model_path());
|
||||
if (gobj_cat.is_debug()) {
|
||||
gobj_cat.debug()
|
||||
<< "Alpha image " << get_alpha_filename() << " found as " << alpha_filename << "\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case BTM_basename:
|
||||
filename = filename.get_basename();
|
||||
alpha_filename = alpha_filename.get_basename();
|
||||
break;
|
||||
|
||||
default:
|
||||
gobj_cat.error()
|
||||
<< "Unsupported bam-texture-mode: " << (int)bam_texture_mode << "\n";
|
||||
}
|
||||
|
||||
me.add_string(get_name());
|
||||
me.add_string(filename);
|
||||
me.add_string(alpha_filename);
|
||||
me.add_uint8(_primary_file_num_channels);
|
||||
me.add_uint8(_alpha_file_channel);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ImageBuffer::fillin
|
||||
// Access: Protected
|
||||
// Description: Function that reads out of the datagram (or asks
|
||||
// manager to read) all of the data that is needed to
|
||||
// re-create this object and stores it in the appropiate
|
||||
// place
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ImageBuffer::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
set_name(scan.get_string());
|
||||
set_filename(scan.get_string());
|
||||
set_alpha_filename(scan.get_string());
|
||||
|
||||
if (manager->get_file_minor_ver() < 3) {
|
||||
_primary_file_num_channels = 0;
|
||||
_alpha_file_channel = 0;
|
||||
} else {
|
||||
_primary_file_num_channels = scan.get_uint8();
|
||||
_alpha_file_channel = scan.get_uint8();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
// Filename: imageBuffer.h
|
||||
// Created by: mike (09Jan97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 IMAGEBUFFER_H
|
||||
#define IMAGEBUFFER_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "drawable.h"
|
||||
#include "pointerToArray.h"
|
||||
#include "typedef.h"
|
||||
#include "filename.h"
|
||||
#include "namable.h"
|
||||
|
||||
class RenderBuffer;
|
||||
class DisplayRegion;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : ImageBuffer
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA ImageBuffer : public ReferenceCount,
|
||||
public WritableConfigurable, public Namable {
|
||||
PUBLISHED:
|
||||
ImageBuffer();
|
||||
virtual ~ImageBuffer();
|
||||
|
||||
public:
|
||||
virtual void config( void ) { WritableConfigurable::config(); }
|
||||
|
||||
PUBLISHED:
|
||||
INLINE bool has_filename() const;
|
||||
INLINE const Filename &get_filename() const;
|
||||
INLINE bool has_alpha_filename() const;
|
||||
INLINE const Filename &get_alpha_filename() const;
|
||||
|
||||
INLINE bool has_fullpath() const;
|
||||
INLINE const Filename &get_fullpath() const;
|
||||
INLINE bool has_alpha_fullpath() const;
|
||||
INLINE const Filename &get_alpha_fullpath() const;
|
||||
|
||||
public:
|
||||
INLINE void set_filename(const Filename &filename);
|
||||
INLINE void clear_filename();
|
||||
INLINE void set_alpha_filename(const Filename &alpha_filename);
|
||||
INLINE void clear_alpha_filename();
|
||||
|
||||
INLINE void set_fullpath(const Filename &fullpath);
|
||||
INLINE void clear_fullpath();
|
||||
INLINE void set_alpha_fullpath(const Filename &alpha_fullpath);
|
||||
INLINE void clear_alpha_fullpath();
|
||||
|
||||
private:
|
||||
Filename _filename;
|
||||
Filename _alpha_filename;
|
||||
Filename _fullpath;
|
||||
Filename _alpha_fullpath;
|
||||
|
||||
protected:
|
||||
// These are set by (and read by) the derived Texture class.
|
||||
|
||||
// The number of channels of the primary file we use. 1, 2, 3, or 4.
|
||||
int _primary_file_num_channels;
|
||||
|
||||
// If we have a separate alpha file, this designates which channel
|
||||
// in the alpha file provides the alpha channel. 0 indicates the
|
||||
// combined grayscale value of rgb; otherwise, 1, 2, 3, or 4 are
|
||||
// valid.
|
||||
int _alpha_file_channel;
|
||||
|
||||
public:
|
||||
// Abstract class, so no factory methods for Reading and Writing
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &me);
|
||||
|
||||
protected:
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
ReferenceCount::init_type();
|
||||
WritableConfigurable::init_type();
|
||||
Namable::init_type();
|
||||
register_type(_type_handle, "ImageBuffer",
|
||||
ReferenceCount::get_class_type(),
|
||||
WritableConfigurable::get_class_type(),
|
||||
Namable::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 "imageBuffer.I"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -1,331 +0,0 @@
|
|||
// Filename: pixelBuffer.I
|
||||
// Created by: drose (05Feb99)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: rgb_buffer
|
||||
// Access: Public
|
||||
// Description: Constructs a PixelBuffer suitable for RGB
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PixelBuffer PixelBuffer::
|
||||
rgb_buffer(int xsize, int ysize) {
|
||||
return PixelBuffer(xsize, ysize, 3, sizeof(uchar), T_unsigned_byte,
|
||||
F_rgb);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: rgba_buffer
|
||||
// Access: Public
|
||||
// Description: Constructs a PixelBuffer suitable for RGBA
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PixelBuffer PixelBuffer::
|
||||
rgba_buffer(int xsize, int ysize) {
|
||||
return PixelBuffer(xsize, ysize, 4, sizeof(uchar), T_unsigned_byte,
|
||||
F_rgba);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: depth_buffer
|
||||
// Access: Public
|
||||
// Description: Constructs a PixelBuffer suitable for depth maps
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PixelBuffer PixelBuffer::
|
||||
depth_buffer(int xsize, int ysize) {
|
||||
return PixelBuffer(xsize, ysize, 1, sizeof(float), T_float,
|
||||
F_depth_component);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: stencil_buffer
|
||||
// Access: Public
|
||||
// Description: Constructs a PixelBuffer suitable for stencil buffers
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PixelBuffer PixelBuffer::
|
||||
stencil_buffer(int xsize, int ysize) {
|
||||
return PixelBuffer(xsize, ysize, 1, sizeof(uchar), T_unsigned_byte,
|
||||
F_stencil_index);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PixelBuffer::
|
||||
~PixelBuffer(void) {
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::set_xsize
|
||||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::set_xsize(int size)
|
||||
{
|
||||
if (_xsize != size) {
|
||||
_xsize = size;
|
||||
make_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::set_ysize
|
||||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::set_ysize(int size)
|
||||
{
|
||||
if (_ysize != size) {
|
||||
_ysize = size;
|
||||
make_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::set_num_components
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
set_num_components(int num_components) {
|
||||
if (_num_components != num_components) {
|
||||
_num_components = num_components;
|
||||
make_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::set_component_width
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
set_component_width(int component_width) {
|
||||
if (_component_width != component_width) {
|
||||
_component_width = component_width;
|
||||
make_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::set_format
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
set_format(PixelBuffer::Format format) {
|
||||
if (_format != format) {
|
||||
_format = format;
|
||||
make_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::set_image_type
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
set_image_type(PixelBuffer::Type type) {
|
||||
if (_type != type) {
|
||||
_type = type;
|
||||
make_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::set_loaded
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
set_loaded() {
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::get_xsize
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int PixelBuffer::
|
||||
get_xsize() const {
|
||||
return _xsize;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::get_ysize
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int PixelBuffer::
|
||||
get_ysize() const {
|
||||
return _ysize;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::get_num_components
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int PixelBuffer::
|
||||
get_num_components() const {
|
||||
return _num_components;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::get_component_width
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int PixelBuffer::
|
||||
get_component_width() const {
|
||||
return _component_width;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::get_format
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PixelBuffer::Format PixelBuffer::
|
||||
get_format() const {
|
||||
return _format;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::get_image_type
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PixelBuffer::Type PixelBuffer::
|
||||
get_image_type() const {
|
||||
return _type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::set_uchar_rgb_texel
|
||||
// Access: Public
|
||||
// Description: This is only valid when the PixelBuffer is an RGB
|
||||
// buffer with uchar components.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
set_uchar_rgb_texel(const uchar color[3], int x, int y, int width)
|
||||
{
|
||||
int i = y * 3 * width + x * 3;
|
||||
_image[i] = color[0];
|
||||
_image[i+1] = color[1];
|
||||
_image[i+2] = color[2];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::store_unscaled_byte
|
||||
// Access: Private
|
||||
// Description: This is used by load() to store the next consecutive
|
||||
// component value into the indicated element of the
|
||||
// array, which is taken to be an array of unsigned
|
||||
// bytes. The value is assumed to be in the range
|
||||
// 0-255.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
store_unscaled_byte(int &index, int value) {
|
||||
_image[index++] = (uchar)value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::store_unscaled_short
|
||||
// Access: Private
|
||||
// Description: This is used by load() to store the next consecutive
|
||||
// component value into the indicated element of the
|
||||
// array, which is taken to be an array of unsigned
|
||||
// shorts. The value is assumed to be in the range
|
||||
// 0-65535.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
store_unscaled_short(int &index, int value) {
|
||||
union {
|
||||
ushort us;
|
||||
uchar uc[2];
|
||||
} v;
|
||||
v.us = (ushort)value;
|
||||
_image[index++] = v.uc[0];
|
||||
_image[index++] = v.uc[1];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::store_scaled_byte
|
||||
// Access: Private
|
||||
// Description: This is used by load() to store the next consecutive
|
||||
// component value into the indicated element of the
|
||||
// array, which is taken to be an array of unsigned
|
||||
// bytes. The value will be scaled by the indicated
|
||||
// factor before storing it.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
store_scaled_byte(int &index, int value, double scale) {
|
||||
store_unscaled_byte(index, (int)(value * scale));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::store_scaled_short
|
||||
// Access: Private
|
||||
// Description: This is used by load() to store the next consecutive
|
||||
// component value into the indicated element of the
|
||||
// array, which is taken to be an array of unsigned
|
||||
// shorts. The value will be scaled by the indicated
|
||||
// factor before storing it.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PixelBuffer::
|
||||
store_scaled_short(int &index, int value, double scale) {
|
||||
store_unscaled_short(index, (int)(value * scale));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::get_unsigned_byte
|
||||
// Access: Private
|
||||
// Description: This is used by store() to retieve the next
|
||||
// consecutive component value from the indicated
|
||||
// element of the array, which is taken to be an array
|
||||
// of unsigned bytes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE double PixelBuffer::
|
||||
get_unsigned_byte(int &index) const {
|
||||
nassertr(index >= 0 && index < (int)_image.size(), 0.0);
|
||||
return (double)_image[index++] / 255.0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::get_unsigned_short
|
||||
// Access: Private
|
||||
// Description: This is used by store() to retieve the next
|
||||
// consecutive component value from the indicated
|
||||
// element of the array, which is taken to be an array
|
||||
// of unsigned shorts.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE double PixelBuffer::
|
||||
get_unsigned_short(int &index) const {
|
||||
nassertr(index >= 0 && index+1 < (int)_image.size(), 0.0);
|
||||
union {
|
||||
ushort us;
|
||||
uchar uc[2];
|
||||
} v;
|
||||
v.uc[0] = _image[index++];
|
||||
v.uc[1] = _image[index++];
|
||||
return (double)v.us / 65535.0;
|
||||
}
|
||||
|
|
@ -1,390 +0,0 @@
|
|||
// Filename: pixelBuffer.cxx
|
||||
// Created by: mike (09Jan97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pixelBuffer.h"
|
||||
#include "config_gobj.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Static variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
TypeHandle PixelBuffer::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PixelBuffer::
|
||||
PixelBuffer() {
|
||||
_xsize = 0;
|
||||
_ysize = 0;
|
||||
_format = F_rgb;
|
||||
_type = T_unsigned_byte;
|
||||
_num_components = 3;
|
||||
_component_width = 1;
|
||||
_image = PTA_uchar();
|
||||
|
||||
_loaded = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PixelBuffer::
|
||||
PixelBuffer(int xsize, int ysize, int components, int component_width,
|
||||
Type type, Format format, bool allocate_ram) {
|
||||
_xsize = xsize;
|
||||
_ysize = ysize;
|
||||
_num_components = components;
|
||||
_component_width = component_width;
|
||||
_type = type;
|
||||
_format = format;
|
||||
|
||||
if (allocate_ram) {
|
||||
int num_pixels = _xsize * _ysize * _num_components * _component_width;
|
||||
_image = PTA_uchar::empty_array((size_t)num_pixels);
|
||||
}
|
||||
_loaded = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::Copy Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PixelBuffer::
|
||||
PixelBuffer(const PixelBuffer ©) :
|
||||
_xsize(copy._xsize),
|
||||
_ysize(copy._ysize),
|
||||
_num_components(copy._num_components),
|
||||
_component_width(copy._component_width),
|
||||
_format(copy._format),
|
||||
_type(copy._type),
|
||||
_loaded(copy._loaded),
|
||||
_image(copy._image)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PixelBuffer::Copy Assignment Operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PixelBuffer::
|
||||
operator = (const PixelBuffer ©) {
|
||||
_xsize = copy._xsize;
|
||||
_ysize = copy._ysize;
|
||||
_num_components = copy._num_components;
|
||||
_component_width = copy._component_width;
|
||||
_format = copy._format;
|
||||
_type = copy._type;
|
||||
_loaded = copy._loaded;
|
||||
_image = copy._image;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: config
|
||||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PixelBuffer::config(void)
|
||||
{
|
||||
ImageBuffer::config();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: read
|
||||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PixelBuffer::
|
||||
read(const Filename &name) {
|
||||
PNMImage pnmimage;
|
||||
|
||||
if (!pnmimage.read(name)) {
|
||||
gobj_cat.error()
|
||||
<< "PixelBuffer::read() - couldn't read: " << name << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
set_name(name.get_basename_wo_extension());
|
||||
set_filename(name);
|
||||
clear_alpha_filename();
|
||||
return load(pnmimage);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: write
|
||||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PixelBuffer::
|
||||
write(const Filename &name) const {
|
||||
PNMImage pnmimage;
|
||||
if (!store(pnmimage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Filename tname;
|
||||
if (name.empty()) {
|
||||
tname = get_filename();
|
||||
} else {
|
||||
tname = name;
|
||||
}
|
||||
|
||||
if (!pnmimage.write(tname)) {
|
||||
gobj_cat.error()
|
||||
<< "PixelBuffer::write() - couldn't write: " << name << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: load
|
||||
// Access: Public
|
||||
// Description: Extracts the image data from the given PNMImage and
|
||||
// stores it in the _image member, as an unadorned array
|
||||
// of pixel values. Note that we now store pixel
|
||||
// components in the order B, G, R, A.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PixelBuffer::load(const PNMImage& pnmimage)
|
||||
{
|
||||
int num_components = pnmimage.get_num_channels();
|
||||
|
||||
if (!_loaded || num_components != _num_components) {
|
||||
// Come up with a default format based on the number of channels.
|
||||
// But only do this the first time the file is loaded, or if the
|
||||
// number of channels in the image changes on subsequent loads.
|
||||
|
||||
switch (pnmimage.get_color_type()) {
|
||||
case PNMImage::CT_grayscale:
|
||||
_format = F_luminance;
|
||||
break;
|
||||
|
||||
case PNMImage::CT_two_channel:
|
||||
_format = F_luminance_alpha;
|
||||
break;
|
||||
|
||||
case PNMImage::CT_color:
|
||||
_format = F_rgb;
|
||||
break;
|
||||
|
||||
case PNMImage::CT_four_channel:
|
||||
_format = F_rgba;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Eh?
|
||||
nassertr(false, false);
|
||||
_format = F_rgb;
|
||||
};
|
||||
}
|
||||
|
||||
_xsize = pnmimage.get_x_size();
|
||||
_ysize = pnmimage.get_y_size();
|
||||
_num_components = num_components;
|
||||
_component_width = 1;
|
||||
_loaded = true;
|
||||
|
||||
// Now copy the pixel data from the PNMImage into our internal
|
||||
// _image component.
|
||||
bool has_alpha = pnmimage.has_alpha();
|
||||
bool is_grayscale = pnmimage.is_grayscale();
|
||||
xelval maxval = pnmimage.get_maxval();
|
||||
|
||||
if (maxval == 255) {
|
||||
// Most common case: one byte per pixel, and the source image
|
||||
// shows a maxval of 255. No scaling is necessary.
|
||||
_type = T_unsigned_byte;
|
||||
_image = PTA_uchar::empty_array((int)(_xsize * _ysize * _num_components));
|
||||
int idx = 0;
|
||||
|
||||
for (int j = _ysize-1; j >= 0; j--) {
|
||||
for (int i = 0; i < _xsize; i++) {
|
||||
if (is_grayscale) {
|
||||
store_unscaled_byte(idx, pnmimage.get_gray_val(i, j));
|
||||
} else {
|
||||
store_unscaled_byte(idx, pnmimage.get_blue_val(i, j));
|
||||
store_unscaled_byte(idx, pnmimage.get_green_val(i, j));
|
||||
store_unscaled_byte(idx, pnmimage.get_red_val(i, j));
|
||||
}
|
||||
if (has_alpha) {
|
||||
store_unscaled_byte(idx, pnmimage.get_alpha_val(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (maxval == 65535) {
|
||||
// Another possible case: two bytes per pixel, and the source
|
||||
// image shows a maxval of 65535. Again, no scaling is necessary.
|
||||
_type = T_unsigned_short;
|
||||
_image = PTA_uchar::empty_array(_xsize * _ysize * _num_components * 2);
|
||||
_component_width = 2;
|
||||
int idx = 0;
|
||||
|
||||
for (int j = _ysize-1; j >= 0; j--) {
|
||||
for (int i = 0; i < _xsize; i++) {
|
||||
if (is_grayscale) {
|
||||
store_unscaled_short(idx, pnmimage.get_gray_val(i, j));
|
||||
} else {
|
||||
store_unscaled_short(idx, pnmimage.get_blue_val(i, j));
|
||||
store_unscaled_short(idx, pnmimage.get_green_val(i, j));
|
||||
store_unscaled_short(idx, pnmimage.get_red_val(i, j));
|
||||
}
|
||||
if (has_alpha) {
|
||||
store_unscaled_short(idx, pnmimage.get_alpha_val(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (maxval <= 255) {
|
||||
// A less common case: one byte per pixel, but the maxval is
|
||||
// something other than 255. In this case, we should scale the
|
||||
// pixel values up to the appropriate amount.
|
||||
_type = T_unsigned_byte;
|
||||
_image = PTA_uchar::empty_array(_xsize * _ysize * _num_components);
|
||||
int idx = 0;
|
||||
double scale = 255.0 / (double)maxval;
|
||||
|
||||
for (int j = _ysize-1; j >= 0; j--) {
|
||||
for (int i = 0; i < _xsize; i++) {
|
||||
if (is_grayscale) {
|
||||
store_scaled_byte(idx, pnmimage.get_gray_val(i, j), scale);
|
||||
} else {
|
||||
store_scaled_byte(idx, pnmimage.get_blue_val(i, j), scale);
|
||||
store_scaled_byte(idx, pnmimage.get_green_val(i, j), scale);
|
||||
store_scaled_byte(idx, pnmimage.get_red_val(i, j), scale);
|
||||
}
|
||||
if (has_alpha) {
|
||||
store_scaled_byte(idx, pnmimage.get_alpha_val(i, j), scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Another uncommon case: two bytes per pixel, and the maxval is
|
||||
// something other than 65535. Again, we must scale the pixel
|
||||
// values.
|
||||
_type = T_unsigned_short;
|
||||
_image = PTA_uchar::empty_array(_xsize * _ysize * _num_components * 2);
|
||||
_component_width = 2;
|
||||
int idx = 0;
|
||||
double scale = 65535.0 / (double)maxval;
|
||||
|
||||
for (int j = _ysize-1; j >= 0; j--) {
|
||||
for (int i = 0; i < _xsize; i++) {
|
||||
if (is_grayscale) {
|
||||
store_scaled_short(idx, pnmimage.get_gray_val(i, j), scale);
|
||||
} else {
|
||||
store_scaled_short(idx, pnmimage.get_blue_val(i, j), scale);
|
||||
store_scaled_short(idx, pnmimage.get_green_val(i, j), scale);
|
||||
store_scaled_short(idx, pnmimage.get_red_val(i, j), scale);
|
||||
}
|
||||
if (has_alpha) {
|
||||
store_scaled_short(idx, pnmimage.get_alpha_val(i, j), scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: store
|
||||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PixelBuffer::
|
||||
store(PNMImage &pnmimage) const {
|
||||
if (_type == T_unsigned_byte) {
|
||||
pnmimage.clear(_xsize, _ysize, _num_components);
|
||||
bool has_alpha = pnmimage.has_alpha();
|
||||
bool is_grayscale = pnmimage.is_grayscale();
|
||||
|
||||
int idx = 0;
|
||||
for (int j = _ysize-1; j >= 0; j--) {
|
||||
for (int i = 0; i < _xsize; i++) {
|
||||
if (is_grayscale) {
|
||||
pnmimage.set_gray(i, j, get_unsigned_byte(idx));
|
||||
} else {
|
||||
pnmimage.set_blue(i, j, get_unsigned_byte(idx));
|
||||
pnmimage.set_green(i, j, get_unsigned_byte(idx));
|
||||
pnmimage.set_red(i, j, get_unsigned_byte(idx));
|
||||
}
|
||||
if (has_alpha)
|
||||
pnmimage.set_alpha(i, j, get_unsigned_byte(idx));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (_type == T_unsigned_short) {
|
||||
pnmimage.clear(_xsize, _ysize, _num_components, 65535);
|
||||
bool has_alpha = pnmimage.has_alpha();
|
||||
bool is_grayscale = pnmimage.is_grayscale();
|
||||
|
||||
int idx = 0;
|
||||
for (int j = _ysize-1; j >= 0; j--) {
|
||||
for (int i = 0; i < _xsize; i++) {
|
||||
if (is_grayscale) {
|
||||
pnmimage.set_gray(i, j, get_unsigned_short(idx));
|
||||
} else {
|
||||
pnmimage.set_blue(i, j, get_unsigned_short(idx));
|
||||
pnmimage.set_green(i, j, get_unsigned_short(idx));
|
||||
pnmimage.set_red(i, j, get_unsigned_short(idx));
|
||||
}
|
||||
if (has_alpha)
|
||||
pnmimage.set_alpha(i, j, get_unsigned_short(idx));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
gobj_cat.error()
|
||||
<< "Couldn't write image for " << get_name()
|
||||
<< "; inappropriate type " << (int)_type << ".\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: copy
|
||||
// Access:
|
||||
// Description: Deep copy of pixel buffer
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PixelBuffer::
|
||||
copy(const PixelBuffer *pb) {
|
||||
nassertv(pb != NULL);
|
||||
_xsize = pb->_xsize;
|
||||
_ysize = pb->_ysize;
|
||||
_num_components = pb->_num_components;
|
||||
_component_width = pb->_component_width;
|
||||
_format = pb->_format;
|
||||
|
||||
if (!pb->_image.is_null()) {
|
||||
_image = PTA_uchar::empty_array(0);
|
||||
_image.v() = pb->_image.v();
|
||||
} else {
|
||||
_image = PTA_uchar();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
// Filename: pixelBuffer.h
|
||||
// Created by: mike (09Jan97)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 PIXELBUFFER_H
|
||||
#define PIXELBUFFER_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "imageBuffer.h"
|
||||
|
||||
#include "pnmImage.h"
|
||||
#include "graphicsStateGuardianBase.h"
|
||||
#include "pta_uchar.h"
|
||||
|
||||
class RenderBuffer;
|
||||
class Filename;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PixelBuffer
|
||||
// Description : Maintains an array of pixel data corresponding to an
|
||||
// image, e.g. copied from the frame buffer, or as part
|
||||
// of a Texture.
|
||||
//
|
||||
// Pixel data is stored in a generic, uncompressed
|
||||
// format. Each row of pixels is laid out horizontally,
|
||||
// from the top to the bottom, with no padding between
|
||||
// rows. Each pixel consumes one or more bytes,
|
||||
// according to get_component_width(). If the Format
|
||||
// indicates multiple components are present, they are
|
||||
// stored in the order B, G, R, A.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA PixelBuffer : public ImageBuffer {
|
||||
public:
|
||||
enum Type {
|
||||
T_unsigned_byte,
|
||||
T_unsigned_short,
|
||||
T_unsigned_byte_332,
|
||||
T_float,
|
||||
};
|
||||
|
||||
enum Format {
|
||||
F_color_index,
|
||||
F_stencil_index,
|
||||
F_depth_component,
|
||||
F_red,
|
||||
F_green,
|
||||
F_blue,
|
||||
F_alpha,
|
||||
F_rgb, // any suitable RGB mode, whatever the hardware prefers
|
||||
F_rgb5, // specifically, 5 bits per R,G,B channel.
|
||||
// this is paired with T_unsigned_byte. really T_unsigned_byte
|
||||
// should not be specified for this one, it should use
|
||||
// T_unsigned_5bits or something
|
||||
F_rgb8, // 8 bits per R,G,B channel
|
||||
F_rgb12, // 12 bits per R,G,B channel
|
||||
F_rgb332, // 3 bits per R & G, 2 bits for B
|
||||
F_rgba, // any suitable RGBA mode, whatever the hardware prefers
|
||||
F_rgbm, // as above, but only requires 1 bit for alpha (i.e. mask)
|
||||
F_rgba4, // 4 bits per R,G,B,A channel
|
||||
F_rgba5, // 5 bits per R,G,B channel, 1 bit alpha
|
||||
F_rgba8, // 8 bits per R,G,B,A channel
|
||||
F_rgba12, // 12 bits per R,G,B,A channel
|
||||
F_luminance,
|
||||
F_luminance_alpha, // 8 bits luminance, 8 bits alpha
|
||||
F_luminance_alphamask // 8 bits luminance, only needs 1 bit of alpha
|
||||
};
|
||||
|
||||
PixelBuffer(void);
|
||||
PixelBuffer(int xsize, int ysize, int components,
|
||||
int component_width, Type type, Format format,
|
||||
bool allocate_ram = true);
|
||||
PixelBuffer(const PixelBuffer ©);
|
||||
void operator = (const PixelBuffer ©);
|
||||
|
||||
// Some named constructors for common PixelBuffer types.
|
||||
INLINE static PixelBuffer rgb_buffer(int xsize, int ysize);
|
||||
INLINE static PixelBuffer rgba_buffer(int xsize, int ysize);
|
||||
INLINE static PixelBuffer depth_buffer(int xsize, int ysize);
|
||||
INLINE static PixelBuffer stencil_buffer(int xsize, int ysize);
|
||||
|
||||
INLINE ~PixelBuffer(void);
|
||||
|
||||
virtual void config( void );
|
||||
|
||||
bool read(const Filename &name);
|
||||
bool write(const Filename &name) const;
|
||||
|
||||
bool load( const PNMImage& pnmimage );
|
||||
bool store( PNMImage& pnmimage ) const;
|
||||
|
||||
void copy(const PixelBuffer *pb);
|
||||
|
||||
INLINE void set_xsize(int size);
|
||||
INLINE void set_ysize(int size);
|
||||
INLINE void set_num_components(int num_components);
|
||||
INLINE void set_component_width(int component_width);
|
||||
INLINE void set_format(Format format);
|
||||
INLINE void set_image_type(Type type);
|
||||
INLINE void set_loaded();
|
||||
|
||||
INLINE int get_xsize() const;
|
||||
INLINE int get_ysize() const;
|
||||
INLINE int get_num_components() const;
|
||||
INLINE int get_component_width() const;
|
||||
INLINE Format get_format() const;
|
||||
INLINE Type get_image_type() const;
|
||||
|
||||
INLINE void set_uchar_rgb_texel(const uchar color[3],
|
||||
int x, int y, int width);
|
||||
|
||||
private:
|
||||
INLINE void store_unscaled_byte(int &index, int value);
|
||||
INLINE void store_unscaled_short(int &index, int value);
|
||||
INLINE void store_scaled_byte(int &index, int value, double scale);
|
||||
INLINE void store_scaled_short(int &index, int value, double scale);
|
||||
INLINE double get_unsigned_byte(int &index) const;
|
||||
INLINE double get_unsigned_short(int &index) const;
|
||||
|
||||
public:
|
||||
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
ImageBuffer::init_type();
|
||||
register_type(_type_handle, "PixelBuffer",
|
||||
ImageBuffer::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;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected:
|
||||
int _xsize;
|
||||
int _ysize;
|
||||
int _num_components;
|
||||
int _component_width;
|
||||
Format _format;
|
||||
Type _type;
|
||||
|
||||
bool _loaded;
|
||||
|
||||
public:
|
||||
// This is public to allow direct manipulation of the image data.
|
||||
// Know what you are doing!
|
||||
PTA_uchar _image;
|
||||
};
|
||||
|
||||
#include "pixelBuffer.I"
|
||||
|
||||
#endif
|
||||
|
|
@ -18,29 +18,336 @@
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_wrapu
|
||||
// Function: Texture::setup_1d_texture
|
||||
// Access: Published
|
||||
// Description:
|
||||
// Description: Sets the texture as an empty 1-d texture with no
|
||||
// dimensions. Follow up with read() or load() to fill
|
||||
// the texture properties and image data.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::WrapMode Texture::
|
||||
get_wrapu() const {
|
||||
return _wrapu;
|
||||
INLINE void Texture::
|
||||
setup_1d_texture() {
|
||||
setup_1d_texture(0, T_unsigned_byte, F_rgb);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_wrapv
|
||||
// Function: Texture::setup_1d_texture
|
||||
// Access: Published
|
||||
// Description:
|
||||
// Description: Sets the texture as an empty 1-d texture with the
|
||||
// specified dimensions and properties. Follow up with
|
||||
// set_ram_image() or modify_ram_image() to fill the
|
||||
// image data.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
setup_1d_texture(int x_size, ComponentType component_type, Format format) {
|
||||
setup_texture(TT_1d_texture, x_size, 1, 1, component_type, format);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::setup_2d_texture
|
||||
// Access: Published
|
||||
// Description: Sets the texture as an empty 2-d texture with no
|
||||
// dimensions. Follow up with read() or load() to fill
|
||||
// the texture properties and image data.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
setup_2d_texture() {
|
||||
setup_2d_texture(0, 1, T_unsigned_byte, F_rgb);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::setup_2d_texture
|
||||
// Access: Published
|
||||
// Description: Sets the texture as an empty 2-d texture with the
|
||||
// specified dimensions and properties. Follow up with
|
||||
// set_ram_image() or modify_ram_image() to fill the
|
||||
// image data.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
setup_2d_texture(int x_size, int y_size, ComponentType component_type,
|
||||
Format format) {
|
||||
setup_texture(TT_2d_texture, x_size, y_size, 1, component_type, format);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::setup_3d_texture
|
||||
// Access: Published
|
||||
// Description: Sets the texture as an empty 3-d texture with no
|
||||
// dimensions (though if you know the depth ahead
|
||||
// of time, it saves a bit of reallocation later).
|
||||
// Follow up with read() or load() to fill the texture
|
||||
// properties and image data.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
setup_3d_texture(int z_size) {
|
||||
setup_3d_texture(0, 1, z_size, T_unsigned_byte, F_rgb);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::setup_3d_texture
|
||||
// Access: Published
|
||||
// Description: Sets the texture as an empty 3-d texture with the
|
||||
// specified dimensions and properties. Follow up with
|
||||
// set_ram_image() or modify_ram_image() to fill the
|
||||
// image data.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
setup_3d_texture(int x_size, int y_size, int z_size,
|
||||
ComponentType component_type, Format format) {
|
||||
setup_texture(TT_3d_texture, x_size, y_size, z_size, component_type, format);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::setup_cube_map
|
||||
// Access: Published
|
||||
// Description: Sets the texture as an empty cube map texture with no
|
||||
// dimensions. Follow up with read() or load() to fill
|
||||
// the texture properties and image data.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
setup_cube_map() {
|
||||
setup_cube_map(0, 1, T_unsigned_byte, F_rgb);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::setup_cube_map
|
||||
// Access: Published
|
||||
// Description: Sets the texture as an empty cube map texture with
|
||||
// the specified dimensions and properties. Follow up
|
||||
// with set_ram_image() or modify_ram_image() to fill
|
||||
// the image data.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
setup_cube_map(int x_size, int y_size, ComponentType component_type,
|
||||
Format format) {
|
||||
setup_texture(TT_cube_map, x_size, y_size, 6, component_type, format);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::has_filename
|
||||
// Access: Published
|
||||
// Description: Returns true if the filename has been set and
|
||||
// is available. See set_filename().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
has_filename() const {
|
||||
return !_filename.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_filename
|
||||
// Access: Published
|
||||
// Description: Returns the filename that has been set. This is the
|
||||
// name of the file as it was requested. Also see
|
||||
// get_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &Texture::
|
||||
get_filename() const {
|
||||
return _filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::has_alpha_filename
|
||||
// Access: Published
|
||||
// Description: Returns true if the alpha_filename has been set and
|
||||
// is available. See set_alpha_filename().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
has_alpha_filename() const {
|
||||
return !_alpha_filename.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_alpha_filename
|
||||
// Access: Published
|
||||
// Description: Returns the alpha_filename that has been set. If
|
||||
// this is set, it represents the name of the alpha
|
||||
// component, which is stored in a separate file. See
|
||||
// also get_filename(), and get_alpha_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &Texture::
|
||||
get_alpha_filename() const {
|
||||
return _alpha_filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::has_fullpath
|
||||
// Access: Published
|
||||
// Description: Returns true if the fullpath has been set and
|
||||
// is available. See set_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
has_fullpath() const {
|
||||
return !_fullpath.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_fullpath
|
||||
// Access: Published
|
||||
// Description: Returns the fullpath that has been set. This is the
|
||||
// full path to the file as it was found along the
|
||||
// texture search path.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &Texture::
|
||||
get_fullpath() const {
|
||||
return _fullpath;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::has_alpha_fullpath
|
||||
// Access: Published
|
||||
// Description: Returns true if the alpha_fullpath has been set and
|
||||
// is available. See set_alpha_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
has_alpha_fullpath() const {
|
||||
return !_alpha_fullpath.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_alpha_fullpath
|
||||
// Access: Published
|
||||
// Description:
|
||||
// Returns the alpha_fullpath that has been set. This
|
||||
// is the full path to the alpha part of the image file
|
||||
// as it was found along the texture search path.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &Texture::
|
||||
get_alpha_fullpath() const {
|
||||
return _alpha_fullpath;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_x_size
|
||||
// Access: Published
|
||||
// Description: Returns the width of the texture image in texels.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Texture::
|
||||
get_x_size() const {
|
||||
return _x_size;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_y_size
|
||||
// Access: Published
|
||||
// Description: Returns the height of the texture image in texels.
|
||||
// For a 1-d texture, this will be 1.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Texture::
|
||||
get_y_size() const {
|
||||
return _y_size;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_z_size
|
||||
// Access: Published
|
||||
// Description: Returns the depth of the texture image in texels.
|
||||
// For a 1-d texture or 2-d texture, this will be 1.
|
||||
// For a cube map texture, this will be 6.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Texture::
|
||||
get_z_size() const {
|
||||
return _z_size;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_num_components
|
||||
// Access: Published
|
||||
// Description: Returns the number of color components for each texel
|
||||
// of the texture image. This is 3 for an rgb texture
|
||||
// or 4 for an rgba texture; it may also be 1 or 2 for a
|
||||
// grayscale texture.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Texture::
|
||||
get_num_components() const {
|
||||
return _num_components;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_component_width
|
||||
// Access: Published
|
||||
// Description: Returns the number of bytes stored for each color
|
||||
// component of a texel. Typically this is 1, but it
|
||||
// may be 2 for 16-bit texels.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Texture::
|
||||
get_component_width() const {
|
||||
return _component_width;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_texture_type
|
||||
// Access: Published
|
||||
// Description: Returns the overall interpretation of the texture.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::TextureType Texture::
|
||||
get_texture_type() const {
|
||||
return _texture_type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_format
|
||||
// Access: Published
|
||||
// Description: Returns the format of the texture, which represents
|
||||
// both the semantic meaning of the texels and, to some
|
||||
// extent, their storage information.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::Format Texture::
|
||||
get_format() const {
|
||||
return _format;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_component_type
|
||||
// Access: Published
|
||||
// Description: Returns the numeric interpretation of each component
|
||||
// of the texture.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::ComponentType Texture::
|
||||
get_component_type() const {
|
||||
return _component_type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_wrap_u
|
||||
// Access: Published
|
||||
// Description: Returns the wrap mode of the texture in the U
|
||||
// direction.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::WrapMode Texture::
|
||||
get_wrapv() const {
|
||||
return _wrapv;
|
||||
get_wrap_u() const {
|
||||
return _wrap_u;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_wrap_v
|
||||
// Access: Published
|
||||
// Description: Returns the wrap mode of the texture in the V
|
||||
// direction.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::WrapMode Texture::
|
||||
get_wrap_v() const {
|
||||
return _wrap_v;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_wrap_w
|
||||
// Access: Published
|
||||
// Description: Returns the wrap mode of the texture in the W
|
||||
// direction. This is the depth direction of 3-d
|
||||
// textures.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::WrapMode Texture::
|
||||
get_wrap_w() const {
|
||||
return _wrap_w;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_minfilter
|
||||
// Access: Published
|
||||
// Description:
|
||||
// Description: Returns the filter mode of the texture for
|
||||
// minification. If this is one of the mipmap
|
||||
// constants, then the texture requires mipmaps.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::FilterType Texture::
|
||||
get_minfilter() const {
|
||||
|
|
@ -50,7 +357,9 @@ get_minfilter() const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_magfilter
|
||||
// Access: Published
|
||||
// Description:
|
||||
// Description: Returns the filter mode of the texture for
|
||||
// magnification. The mipmap constants are invalid
|
||||
// here.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Texture::FilterType Texture::
|
||||
get_magfilter() const {
|
||||
|
|
@ -75,28 +384,21 @@ get_anisotropic_degree() const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_border_color
|
||||
// Access: Published
|
||||
// Description:
|
||||
// Description: Returns the solid color of the texture's border.
|
||||
// Some OpenGL implementations use a border for tiling
|
||||
// textures; in Panda, it is only used for specifying
|
||||
// the clamp color.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Colorf Texture::
|
||||
get_border_color() const {
|
||||
return _border_color;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_border_width
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int Texture::
|
||||
get_border_width() const {
|
||||
return _border_width;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::uses_mipmaps
|
||||
// Access: Public
|
||||
// Description: Returns true if the minfilter settings on this
|
||||
// texture require the use of mipmapping, false
|
||||
// texture indicate the use of mipmapping, false
|
||||
// otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
|
|
@ -104,24 +406,9 @@ uses_mipmaps() const {
|
|||
return is_mipmap(get_minfilter());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_match_framebuffer_format
|
||||
// Access: Published
|
||||
// Description: Returns true if the Texture was created with a
|
||||
// special flag that indicates to the GSG that the
|
||||
// Texture's format should be chosen to exactly match
|
||||
// the framebuffer's format, presumably because the
|
||||
// application intends to copy image data from the
|
||||
// framebuffer into the Texture (or vice-versa).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
get_match_framebuffer_format() const {
|
||||
return _match_framebuffer_format;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::has_ram_image
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: Returns true if the Texture has its image contents
|
||||
// available in main RAM, false if it exists only in
|
||||
// texture memory or in the prepared GSG context.
|
||||
|
|
@ -149,12 +436,48 @@ get_match_framebuffer_format() const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
has_ram_image() const {
|
||||
return !_pbuffer->_image.empty();
|
||||
return !_image.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_ram_image_size
|
||||
// Access: Published
|
||||
// Description: Returns the number of bytes used by the in-memory
|
||||
// image, or 0 if there is no in-memory image.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE size_t Texture::
|
||||
get_ram_image_size() const {
|
||||
return _image.size();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_expected_ram_image_size
|
||||
// Access: Published
|
||||
// Description: Returns the number of bytes that *ought* to be used
|
||||
// by the in-memory image, based on the texture
|
||||
// parameters.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE size_t Texture::
|
||||
get_expected_ram_image_size() const {
|
||||
return get_expected_ram_page_size() * (size_t)_z_size;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_expected_ram_page_size
|
||||
// Access: Published
|
||||
// Description: Returns the number of bytes that should be used per
|
||||
// each Z page of the 3-d texture. For a 2-d or 1-d
|
||||
// texture, this is the same as
|
||||
// get_expected_ram_image_size().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE size_t Texture::
|
||||
get_expected_ram_page_size() const {
|
||||
return (size_t)(_x_size * _y_size * _num_components * _component_width);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::might_have_ram_image
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: Returns true if the texture's image contents are
|
||||
// currently available in main RAM, or there is reason
|
||||
// to believe it can be loaded on demand. That is, this
|
||||
|
|
@ -169,7 +492,7 @@ might_have_ram_image() const {
|
|||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_keep_ram_image
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: Sets the flag that indicates whether this Texture is
|
||||
// eligible to have its main RAM copy of the texture
|
||||
// memory dumped when the texture is prepared for
|
||||
|
|
@ -179,8 +502,8 @@ might_have_ram_image() const {
|
|||
// their images if needed by rereading the input file.
|
||||
// However, textures that were generated dynamically and
|
||||
// cannot be easily reloaded will want to set this flag
|
||||
// to true, so that the _pbuffer member will always keep
|
||||
// its image copy around.
|
||||
// to true, so that the texture will always keep its
|
||||
// image copy around.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_keep_ram_image(bool keep_ram_image) {
|
||||
|
|
@ -189,7 +512,7 @@ set_keep_ram_image(bool keep_ram_image) {
|
|||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_keep_ram_image
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: Returns the flag that indicates whether this Texture
|
||||
// is eligible to have its main RAM copy of the texture
|
||||
// memory dumped when the texture is prepared for
|
||||
|
|
@ -200,4 +523,305 @@ get_keep_ram_image() const {
|
|||
return _keep_ram_image;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_filename
|
||||
// Access: Public
|
||||
// Description: Sets the name of the file that contains the image's
|
||||
// contents. Normally, this is set automatically when
|
||||
// the image is loaded, for instance via
|
||||
// Texture::read().
|
||||
//
|
||||
// The Texture's get_name() function used to return
|
||||
// the filename, but now returns just the basename
|
||||
// (without the extension), which is a more useful name
|
||||
// for identifying an image in show code.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_filename(const Filename &filename) {
|
||||
_filename = filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::clear_filename
|
||||
// Access: Public
|
||||
// Description: Removes the alpha filename, if it was previously set.
|
||||
// See set_filename().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
clear_filename() {
|
||||
_filename = Filename();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_alpha_filename
|
||||
// Access: Public
|
||||
// Description: Sets the name of the file that contains the image's
|
||||
// alpha channel contents. Normally, this is set
|
||||
// automatically when the image is loaded, for instance
|
||||
// via Texture::read().
|
||||
//
|
||||
// The Texture's get_filename() function returns the
|
||||
// name of the image file that was loaded into the
|
||||
// buffer. In the case where a texture specified two
|
||||
// separate files to load, a 1- or 3-channel color image
|
||||
// and a 1-channel alpha image, this Filename is update
|
||||
// to contain the name of the image file that was loaded
|
||||
// into the buffer's alpha channel.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_alpha_filename(const Filename &alpha_filename) {
|
||||
_alpha_filename = alpha_filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::clear_alpha_filename
|
||||
// Access: Public
|
||||
// Description: Removes the alpha filename, if it was previously set.
|
||||
// See set_alpha_filename().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
clear_alpha_filename() {
|
||||
_alpha_filename = Filename();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_fullpath
|
||||
// Access: Public
|
||||
// Description: Sets the full pathname to the file that contains the
|
||||
// image's contents, as found along the search path.
|
||||
// Normally, this is set automatically when the image is
|
||||
// loaded, for instance via Texture::read().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_fullpath(const Filename &fullpath) {
|
||||
_fullpath = fullpath;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::clear_fullpath
|
||||
// Access: Public
|
||||
// Description: Removes the alpha fullpath, if it was previously set.
|
||||
// See set_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
clear_fullpath() {
|
||||
_fullpath = Filename();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_alpha_fullpath
|
||||
// Access: Public
|
||||
// Description: Sets the full pathname to the file that contains the
|
||||
// image's alpha channel contents, as found along the
|
||||
// search path. Normally, this is set automatically
|
||||
// when the image is loaded, for instance via
|
||||
// Texture::read().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_alpha_fullpath(const Filename &alpha_fullpath) {
|
||||
_alpha_fullpath = alpha_fullpath;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::clear_alpha_fullpath
|
||||
// Access: Public
|
||||
// Description: Removes the alpha fullpath, if it was previously set.
|
||||
// See set_alpha_fullpath().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
clear_alpha_fullpath() {
|
||||
_alpha_fullpath = Filename();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_x_size
|
||||
// Access: Public
|
||||
// Description: Changes the x size indicated for the texture. This
|
||||
// also implicitly unloads the texture if it has already
|
||||
// been loaded.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_x_size(int x_size) {
|
||||
if (_x_size != x_size) {
|
||||
_x_size = x_size;
|
||||
clear_ram_image();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_y_size
|
||||
// Access: Public
|
||||
// Description: Changes the y size indicated for the texture. This
|
||||
// also implicitly unloads the texture if it has already
|
||||
// been loaded.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_y_size(int y_size) {
|
||||
if (_y_size != y_size) {
|
||||
nassertv(_texture_type != Texture::TT_1d_texture);
|
||||
_y_size = y_size;
|
||||
clear_ram_image();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_z_size
|
||||
// Access: Public
|
||||
// Description: Changes the z size indicated for the texture. This
|
||||
// also implicitly unloads the texture if it has already
|
||||
// been loaded.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_z_size(int z_size) {
|
||||
if (_z_size != z_size) {
|
||||
nassertv(_texture_type == Texture::TT_3d_texture);
|
||||
_z_size = z_size;
|
||||
clear_ram_image();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_loaded_from_disk
|
||||
// Access: Public
|
||||
// Description: Sets the flag that indicates the texture has been
|
||||
// loaded from a disk file. You should also ensure the
|
||||
// filename has been set correctly. When this flag is
|
||||
// true, the texture may be automatically reloaded when
|
||||
// its ram image needs to be replaced.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_loaded_from_disk() {
|
||||
_loaded_from_disk = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_match_framebuffer_format
|
||||
// Access: Public
|
||||
// Description: Returns true if the special flag was set that
|
||||
// indicates to the GSG that the Texture's format should
|
||||
// be chosen to exactly match the framebuffer's format,
|
||||
// presumably because the application intends to copy
|
||||
// image data from the framebuffer into the Texture (or
|
||||
// vice-versa).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Texture::
|
||||
get_match_framebuffer_format() const {
|
||||
return _match_framebuffer_format;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::set_match_framebuffer_format
|
||||
// Access: Public
|
||||
// Description: Sets the special flag that, if true, indicates to the
|
||||
// GSG that the Texture's format should be chosen to
|
||||
// exactly match the framebuffer's format, presumably
|
||||
// because the application intends to copy image data
|
||||
// from the framebuffer into the Texture (or
|
||||
// vice-versa).
|
||||
//
|
||||
// This sets only the graphics card's idea of the
|
||||
// texture format; it is not related to the
|
||||
// system-memory format.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
set_match_framebuffer_format(bool flag) {
|
||||
_match_framebuffer_format = flag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::store_unscaled_byte
|
||||
// Access: Private
|
||||
// Description: This is used by load() to store the next consecutive
|
||||
// component value into the indicated element of the
|
||||
// array, which is taken to be an array of unsigned
|
||||
// bytes. The value is assumed to be in the range
|
||||
// 0-255.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
store_unscaled_byte(int &index, int value) {
|
||||
_image[index++] = (uchar)value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::store_unscaled_short
|
||||
// Access: Private
|
||||
// Description: This is used by load() to store the next consecutive
|
||||
// component value into the indicated element of the
|
||||
// array, which is taken to be an array of unsigned
|
||||
// shorts. The value is assumed to be in the range
|
||||
// 0-65535.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
store_unscaled_short(int &index, int value) {
|
||||
union {
|
||||
ushort us;
|
||||
uchar uc[2];
|
||||
} v;
|
||||
v.us = (ushort)value;
|
||||
_image[index++] = v.uc[0];
|
||||
_image[index++] = v.uc[1];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::store_scaled_byte
|
||||
// Access: Private
|
||||
// Description: This is used by load() to store the next consecutive
|
||||
// component value into the indicated element of the
|
||||
// array, which is taken to be an array of unsigned
|
||||
// bytes. The value will be scaled by the indicated
|
||||
// factor before storing it.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
store_scaled_byte(int &index, int value, double scale) {
|
||||
store_unscaled_byte(index, (int)(value * scale));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::store_scaled_short
|
||||
// Access: Private
|
||||
// Description: This is used by load() to store the next consecutive
|
||||
// component value into the indicated element of the
|
||||
// array, which is taken to be an array of unsigned
|
||||
// shorts. The value will be scaled by the indicated
|
||||
// factor before storing it.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Texture::
|
||||
store_scaled_short(int &index, int value, double scale) {
|
||||
store_unscaled_short(index, (int)(value * scale));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_unsigned_byte
|
||||
// Access: Private
|
||||
// Description: This is used by store() to retieve the next
|
||||
// consecutive component value from the indicated
|
||||
// element of the array, which is taken to be an array
|
||||
// of unsigned bytes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE double Texture::
|
||||
get_unsigned_byte(int &index) const {
|
||||
nassertr(index >= 0 && index < (int)_image.size(), 0.0);
|
||||
return (double)_image[index++] / 255.0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::get_unsigned_short
|
||||
// Access: Private
|
||||
// Description: This is used by store() to retieve the next
|
||||
// consecutive component value from the indicated
|
||||
// element of the array, which is taken to be an array
|
||||
// of unsigned shorts.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE double Texture::
|
||||
get_unsigned_short(int &index) const {
|
||||
nassertr(index >= 0 && index+1 < (int)_image.size(), 0.0);
|
||||
union {
|
||||
ushort us;
|
||||
uchar uc[2];
|
||||
} v;
|
||||
v.uc[0] = _image[index++];
|
||||
v.uc[1] = _image[index++];
|
||||
return (double)v.us / 65535.0;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -15,13 +15,14 @@
|
|||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "imageBuffer.h"
|
||||
#include "pixelBuffer.h"
|
||||
#include "typedWritableReferenceCount.h"
|
||||
#include "namable.h"
|
||||
#include "graphicsStateGuardianBase.h"
|
||||
#include "pmap.h"
|
||||
|
||||
|
|
@ -32,10 +33,64 @@ class PreparedGraphicsObjects;
|
|||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : Texture
|
||||
// Description : 2D texture class
|
||||
// Description : Represents a texture object, which is typically a
|
||||
// single 2-d image but may also represent a 1-d or 3-d
|
||||
// texture image, or the six 2-d faces of a cube map
|
||||
// texture.
|
||||
//
|
||||
// A texture's image data might be stored in system RAM
|
||||
// (see get_ram_image()) or its image may be represented
|
||||
// in texture memory on one or more
|
||||
// GraphicsStateGuardians (see prepare()), or both. The
|
||||
// typical usage pattern is that a texture is loaded
|
||||
// from an image file on disk, which copies its image
|
||||
// data into system RAM; then the first time the texture
|
||||
// is rendered its image data is copied to texture
|
||||
// memory (actually, to the graphics API), and the
|
||||
// system RAM image is automatically freed.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA Texture : public ImageBuffer {
|
||||
class EXPCL_PANDA Texture : public TypedWritableReferenceCount, public Namable {
|
||||
PUBLISHED:
|
||||
enum TextureType {
|
||||
TT_1d_texture,
|
||||
TT_2d_texture,
|
||||
TT_3d_texture,
|
||||
TT_cube_map,
|
||||
};
|
||||
|
||||
enum ComponentType {
|
||||
T_unsigned_byte,
|
||||
T_unsigned_short,
|
||||
T_float,
|
||||
};
|
||||
|
||||
enum Format {
|
||||
F_color_index,
|
||||
F_stencil_index,
|
||||
F_depth_component,
|
||||
F_red,
|
||||
F_green,
|
||||
F_blue,
|
||||
F_alpha,
|
||||
F_rgb, // any suitable RGB mode, whatever the hardware prefers
|
||||
F_rgb5, // specifically, 5 bits per R,G,B channel.
|
||||
// this is paired with T_unsigned_byte. really T_unsigned_byte
|
||||
// should not be specified for this one, it should use
|
||||
// T_unsigned_5bits or something
|
||||
F_rgb8, // 8 bits per R,G,B channel
|
||||
F_rgb12, // 12 bits per R,G,B channel
|
||||
F_rgb332, // 3 bits per R & G, 2 bits for B
|
||||
F_rgba, // any suitable RGBA mode, whatever the hardware prefers
|
||||
F_rgbm, // as above, but only requires 1 bit for alpha (i.e. mask)
|
||||
F_rgba4, // 4 bits per R,G,B,A channel
|
||||
F_rgba5, // 5 bits per R,G,B channel, 1 bit alpha
|
||||
F_rgba8, // 8 bits per R,G,B,A channel
|
||||
F_rgba12, // 12 bits per R,G,B,A channel
|
||||
F_luminance,
|
||||
F_luminance_alpha, // 8 bits luminance, 8 bits alpha
|
||||
F_luminance_alphamask // 8 bits luminance, only needs 1 bit of alpha
|
||||
};
|
||||
|
||||
enum FilterType {
|
||||
// Mag Filter and Min Filter
|
||||
|
||||
|
|
@ -75,54 +130,118 @@ PUBLISHED:
|
|||
};
|
||||
|
||||
PUBLISHED:
|
||||
Texture(bool match_framebuffer_format = false);
|
||||
Texture(int xsize, int ysize, int components, int component_width,
|
||||
PixelBuffer::Type type, PixelBuffer::Format format,
|
||||
bool allocate_ram);
|
||||
Texture(const string &name = string());
|
||||
~Texture();
|
||||
|
||||
bool read(const Filename &fullpath, int primary_file_num_channels = 0);
|
||||
bool read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
void setup_texture(TextureType texture_type,
|
||||
int x_size, int y_size, int z_size,
|
||||
ComponentType component_type, Format format);
|
||||
|
||||
INLINE void setup_1d_texture();
|
||||
INLINE void setup_1d_texture(int x_size,
|
||||
ComponentType component_type, Format format);
|
||||
INLINE void setup_2d_texture();
|
||||
INLINE void setup_2d_texture(int x_size, int y_size,
|
||||
ComponentType component_type, Format format);
|
||||
INLINE void setup_3d_texture(int z_size = 1);
|
||||
INLINE void setup_3d_texture(int x_size, int y_size, int z_size,
|
||||
ComponentType component_type, Format format);
|
||||
INLINE void setup_cube_map();
|
||||
INLINE void setup_cube_map(int x_size, int y_size,
|
||||
ComponentType component_type, Format format);
|
||||
|
||||
bool read(const Filename &fullpath, int z = 0,
|
||||
int primary_file_num_channels = 0);
|
||||
bool read(const Filename &fullpath, const Filename &alpha_fullpath,
|
||||
int z = 0,
|
||||
int primary_file_num_channels = 0, int alpha_file_channel = 0);
|
||||
bool write(const Filename &fullpath = "") const;
|
||||
bool write(const Filename &fullpath, int z = 0) const;
|
||||
|
||||
bool load(const PNMImage &pnmimage);
|
||||
bool store(PNMImage &pnmimage) const;
|
||||
bool load(const PNMImage &pnmimage, int z = 0);
|
||||
bool store(PNMImage &pnmimage, int z = 0) const;
|
||||
|
||||
void set_wrapu(WrapMode wrap);
|
||||
void set_wrapv(WrapMode wrap);
|
||||
INLINE bool has_filename() const;
|
||||
INLINE const Filename &get_filename() const;
|
||||
INLINE bool has_alpha_filename() const;
|
||||
INLINE const Filename &get_alpha_filename() const;
|
||||
|
||||
INLINE bool has_fullpath() const;
|
||||
INLINE const Filename &get_fullpath() const;
|
||||
INLINE bool has_alpha_fullpath() const;
|
||||
INLINE const Filename &get_alpha_fullpath() const;
|
||||
|
||||
INLINE int get_x_size() const;
|
||||
INLINE int get_y_size() const;
|
||||
INLINE int get_z_size() const;
|
||||
INLINE int get_num_components() const;
|
||||
INLINE int get_component_width() const;
|
||||
INLINE TextureType get_texture_type() const;
|
||||
INLINE Format get_format() const;
|
||||
INLINE ComponentType get_component_type() const;
|
||||
|
||||
void set_wrap_u(WrapMode wrap);
|
||||
void set_wrap_v(WrapMode wrap);
|
||||
void set_wrap_w(WrapMode wrap);
|
||||
void set_minfilter(FilterType filter);
|
||||
void set_magfilter(FilterType filter);
|
||||
void set_anisotropic_degree(int anisotropic_degree);
|
||||
void set_border_color(const Colorf &color);
|
||||
void set_border_width(int border_width);
|
||||
|
||||
INLINE WrapMode get_wrapu() const;
|
||||
INLINE WrapMode get_wrapv() const;
|
||||
INLINE WrapMode get_wrap_u() const;
|
||||
INLINE WrapMode get_wrap_v() const;
|
||||
INLINE WrapMode get_wrap_w() const;
|
||||
INLINE FilterType get_minfilter() const;
|
||||
INLINE FilterType get_magfilter() const;
|
||||
INLINE int get_anisotropic_degree() const;
|
||||
INLINE Colorf get_border_color() const;
|
||||
INLINE int get_border_width() const;
|
||||
INLINE bool uses_mipmaps() const;
|
||||
|
||||
INLINE bool get_match_framebuffer_format() const;
|
||||
INLINE bool has_ram_image() const;
|
||||
INLINE bool might_have_ram_image() const;
|
||||
INLINE size_t get_ram_image_size() const;
|
||||
INLINE size_t get_expected_ram_image_size() const;
|
||||
INLINE size_t get_expected_ram_page_size() const;
|
||||
CPTA_uchar get_ram_image();
|
||||
PTA_uchar modify_ram_image();
|
||||
PTA_uchar make_ram_image();
|
||||
void set_ram_image(PTA_uchar image);
|
||||
void clear_ram_image();
|
||||
INLINE void set_keep_ram_image(bool keep_ram_image);
|
||||
INLINE bool get_keep_ram_image() const;
|
||||
|
||||
void prepare(PreparedGraphicsObjects *prepared_objects);
|
||||
bool release(PreparedGraphicsObjects *prepared_objects);
|
||||
int release_all();
|
||||
|
||||
public:
|
||||
// These are public, but in general, you shouldn't be mucking with
|
||||
// these values; they are set automatically when a texture is
|
||||
// loaded.
|
||||
INLINE void set_filename(const Filename &filename);
|
||||
INLINE void clear_filename();
|
||||
INLINE void set_alpha_filename(const Filename &alpha_filename);
|
||||
INLINE void clear_alpha_filename();
|
||||
|
||||
INLINE void set_fullpath(const Filename &fullpath);
|
||||
INLINE void clear_fullpath();
|
||||
INLINE void set_alpha_fullpath(const Filename &alpha_fullpath);
|
||||
INLINE void clear_alpha_fullpath();
|
||||
|
||||
INLINE void set_x_size(int x_size);
|
||||
INLINE void set_y_size(int y_size);
|
||||
INLINE void set_z_size(int z_size);
|
||||
void set_format(Format format);
|
||||
void set_component_type(ComponentType component_type);
|
||||
INLINE void set_loaded_from_disk();
|
||||
|
||||
public:
|
||||
INLINE bool get_match_framebuffer_format() const;
|
||||
INLINE void set_match_framebuffer_format(bool flag);
|
||||
|
||||
static bool is_mipmap(FilterType type);
|
||||
|
||||
TextureContext *prepare_now(PreparedGraphicsObjects *prepared_objects,
|
||||
GraphicsStateGuardianBase *gsg);
|
||||
bool release(PreparedGraphicsObjects *prepared_objects);
|
||||
int release_all();
|
||||
|
||||
INLINE bool has_ram_image() const;
|
||||
INLINE bool might_have_ram_image() const;
|
||||
PixelBuffer *get_ram_image();
|
||||
INLINE void set_keep_ram_image(bool keep_ram_image);
|
||||
INLINE bool get_keep_ram_image() const;
|
||||
|
||||
// These bits are used as parameters to Texture::mark_dirty() and
|
||||
// also TextureContext::mark_dirty() (and related functions in
|
||||
|
|
@ -143,14 +262,53 @@ public:
|
|||
private:
|
||||
void clear_prepared(PreparedGraphicsObjects *prepared_objects);
|
||||
|
||||
WrapMode _wrapu;
|
||||
WrapMode _wrapv;
|
||||
static int up_to_power_2(int value);
|
||||
static int down_to_power_2(int value);
|
||||
|
||||
void consider_rescale(PNMImage &pnmimage);
|
||||
void consider_downgrade(PNMImage &pnmimage, int num_channels);
|
||||
|
||||
INLINE void store_unscaled_byte(int &index, int value);
|
||||
INLINE void store_unscaled_short(int &index, int value);
|
||||
INLINE void store_scaled_byte(int &index, int value, double scale);
|
||||
INLINE void store_scaled_short(int &index, int value, double scale);
|
||||
INLINE double get_unsigned_byte(int &index) const;
|
||||
INLINE double get_unsigned_short(int &index) const;
|
||||
|
||||
private:
|
||||
Filename _filename;
|
||||
Filename _alpha_filename;
|
||||
Filename _fullpath;
|
||||
Filename _alpha_fullpath;
|
||||
|
||||
// The number of channels of the primary file we use. 1, 2, 3, or 4.
|
||||
int _primary_file_num_channels;
|
||||
|
||||
// If we have a separate alpha file, this designates which channel
|
||||
// in the alpha file provides the alpha channel. 0 indicates the
|
||||
// combined grayscale value of rgb; otherwise, 1, 2, 3, or 4 are
|
||||
// valid.
|
||||
int _alpha_file_channel;
|
||||
|
||||
int _x_size;
|
||||
int _y_size;
|
||||
int _z_size;
|
||||
int _num_components;
|
||||
int _component_width;
|
||||
TextureType _texture_type;
|
||||
Format _format;
|
||||
ComponentType _component_type;
|
||||
|
||||
bool _loaded_from_disk;
|
||||
|
||||
WrapMode _wrap_u;
|
||||
WrapMode _wrap_v;
|
||||
WrapMode _wrap_w;
|
||||
FilterType _minfilter;
|
||||
FilterType _magfilter;
|
||||
int _anisotropic_degree;
|
||||
bool _keep_ram_image;
|
||||
Colorf _border_color;
|
||||
int _border_width;
|
||||
bool _match_framebuffer_format;
|
||||
|
||||
// A Texture keeps a list (actually, a map) of all the
|
||||
|
|
@ -166,10 +324,8 @@ private:
|
|||
// texture.
|
||||
int _all_dirty_flags;
|
||||
|
||||
public:
|
||||
// These are public to allow direct manipulation of the underlying
|
||||
// pixel buffer when needed. Know what you are doing!
|
||||
PT(PixelBuffer) _pbuffer;
|
||||
PTA_uchar _image;
|
||||
|
||||
|
||||
// Datagram stuff
|
||||
public:
|
||||
|
|
@ -186,9 +342,9 @@ public:
|
|||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
ImageBuffer::init_type();
|
||||
TypedWritableReferenceCount::init_type();
|
||||
register_type(_type_handle, "Texture",
|
||||
ImageBuffer::get_class_type());
|
||||
TypedWritableReferenceCount::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "textureContext.h"
|
||||
|
||||
#include "pixelBuffer.h"
|
||||
#include "texture.h"
|
||||
|
||||
TypeHandle TextureContext::_type_handle;
|
||||
|
|
@ -34,45 +33,43 @@ TypeHandle TextureContext::_type_handle;
|
|||
////////////////////////////////////////////////////////////////////
|
||||
size_t TextureContext::
|
||||
estimate_texture_memory() {
|
||||
PixelBuffer *pb = _texture->_pbuffer;
|
||||
|
||||
size_t pixels = pb->get_xsize() * pb->get_ysize();
|
||||
size_t pixels = _texture->get_x_size() * _texture->get_y_size();
|
||||
|
||||
size_t bpp = 4;
|
||||
|
||||
/*
|
||||
size_t bpp = 1;
|
||||
switch (pb->get_format()) {
|
||||
case PixelBuffer::F_rgb332:
|
||||
case PixelBuffer::F_alpha:
|
||||
case PixelBuffer::F_red:
|
||||
case PixelBuffer::F_green:
|
||||
case PixelBuffer::F_blue:
|
||||
case PixelBuffer::F_luminance:
|
||||
case PixelBuffer::F_luminance_alpha:
|
||||
case PixelBuffer::F_luminance_alphamask:
|
||||
case PixelBuffer::F_color_index:
|
||||
case PixelBuffer::F_stencil_index:
|
||||
case PixelBuffer::F_depth_component:
|
||||
switch (_texture->get_format()) {
|
||||
case Texture::F_rgb332:
|
||||
case Texture::F_alpha:
|
||||
case Texture::F_red:
|
||||
case Texture::F_green:
|
||||
case Texture::F_blue:
|
||||
case Texture::F_luminance:
|
||||
case Texture::F_luminance_alpha:
|
||||
case Texture::F_luminance_alphamask:
|
||||
case Texture::F_color_index:
|
||||
case Texture::F_stencil_index:
|
||||
case Texture::F_depth_component:
|
||||
bpp = 1;
|
||||
break;
|
||||
|
||||
case PixelBuffer::F_rgba:
|
||||
case PixelBuffer::F_rgba4:
|
||||
case PixelBuffer::F_rgbm:
|
||||
case PixelBuffer::F_rgb:
|
||||
case PixelBuffer::F_rgb5:
|
||||
case PixelBuffer::F_rgba5:
|
||||
case Texture::F_rgba:
|
||||
case Texture::F_rgba4:
|
||||
case Texture::F_rgbm:
|
||||
case Texture::F_rgb:
|
||||
case Texture::F_rgb5:
|
||||
case Texture::F_rgba5:
|
||||
bpp = 2;
|
||||
break;
|
||||
|
||||
case PixelBuffer::F_rgb8:
|
||||
case PixelBuffer::F_rgba8:
|
||||
case Texture::F_rgb8:
|
||||
case Texture::F_rgba8:
|
||||
bpp = 4;
|
||||
break;
|
||||
|
||||
case PixelBuffer::F_rgba12:
|
||||
case PixelBuffer::F_rgb12:
|
||||
case Texture::F_rgba12:
|
||||
case Texture::F_rgb12:
|
||||
bpp = 6;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,14 +51,9 @@ ns_has_texture(const Filename &orig_filename) {
|
|||
filename = _fake_texture_image;
|
||||
}
|
||||
|
||||
if (use_vfs) {
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(filename, get_texture_path());
|
||||
vfs->resolve_filename(filename, get_model_path());
|
||||
} else {
|
||||
filename.resolve_filename(get_texture_path());
|
||||
filename.resolve_filename(get_model_path());
|
||||
}
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(filename, get_texture_path());
|
||||
vfs->resolve_filename(filename, get_model_path());
|
||||
|
||||
Textures::const_iterator ti;
|
||||
ti = _textures.find(filename);
|
||||
|
|
@ -83,14 +78,9 @@ ns_load_texture(const Filename &orig_filename, int primary_file_num_channels) {
|
|||
filename = _fake_texture_image;
|
||||
}
|
||||
|
||||
if (use_vfs) {
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(filename, get_texture_path()) ||
|
||||
vfs->resolve_filename(filename, get_model_path());
|
||||
} else {
|
||||
filename.resolve_filename(get_texture_path()) ||
|
||||
filename.resolve_filename(get_model_path());
|
||||
}
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(filename, get_texture_path()) ||
|
||||
vfs->resolve_filename(filename, get_model_path());
|
||||
|
||||
Textures::const_iterator ti;
|
||||
ti = _textures.find(filename);
|
||||
|
|
@ -102,11 +92,10 @@ ns_load_texture(const Filename &orig_filename, int primary_file_num_channels) {
|
|||
gobj_cat.info()
|
||||
<< "Loading texture " << filename << "\n";
|
||||
PT(Texture) tex = new Texture;
|
||||
if (!tex->read(filename, primary_file_num_channels)) {
|
||||
if (!tex->read(filename, 0, primary_file_num_channels)) {
|
||||
// This texture was not found.
|
||||
gobj_cat.error()
|
||||
<< "Unable to read texture \"" << filename << "\""
|
||||
<< (use_vfs ? " (using vfs) ": "")
|
||||
<< " on texture_path " << texture_path
|
||||
<< " or model_path " << model_path <<"\n";
|
||||
return NULL;
|
||||
|
|
@ -136,21 +125,12 @@ ns_load_texture(const Filename &orig_filename,
|
|||
return ns_load_texture(_fake_texture_image, primary_file_num_channels);
|
||||
}
|
||||
|
||||
if (use_vfs) {
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(filename, get_texture_path()) ||
|
||||
vfs->resolve_filename(filename, get_model_path());
|
||||
|
||||
vfs->resolve_filename(alpha_filename, get_texture_path()) ||
|
||||
vfs->resolve_filename(alpha_filename, get_model_path());
|
||||
|
||||
} else {
|
||||
filename.resolve_filename(get_texture_path()) ||
|
||||
filename.resolve_filename(get_model_path());
|
||||
|
||||
alpha_filename.resolve_filename(get_texture_path()) ||
|
||||
alpha_filename.resolve_filename(get_model_path());
|
||||
}
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
vfs->resolve_filename(filename, get_texture_path()) ||
|
||||
vfs->resolve_filename(filename, get_model_path());
|
||||
|
||||
vfs->resolve_filename(alpha_filename, get_texture_path()) ||
|
||||
vfs->resolve_filename(alpha_filename, get_model_path());
|
||||
|
||||
Textures::const_iterator ti;
|
||||
ti = _textures.find(filename);
|
||||
|
|
@ -163,7 +143,7 @@ ns_load_texture(const Filename &orig_filename,
|
|||
<< "Loading texture " << filename << " and alpha component "
|
||||
<< alpha_filename << endl;
|
||||
PT(Texture) tex = new Texture;
|
||||
if (!tex->read(filename, alpha_filename, primary_file_num_channels,
|
||||
if (!tex->read(filename, alpha_filename, 0, primary_file_num_channels,
|
||||
alpha_file_channel)) {
|
||||
// This texture was not found.
|
||||
gobj_cat.error() << "Unable to read texture " << filename << "\n";
|
||||
|
|
@ -260,7 +240,7 @@ ns_list_contents(ostream &out) const {
|
|||
Texture *texture = (*ti).second;
|
||||
out << " " << (*ti).first
|
||||
<< " (count = " << texture->get_ref_count() << ", ram = "
|
||||
<< texture->_pbuffer->_image.size() / 1024 << " Kb)\n";
|
||||
<< texture->get_ram_image_size() / 1024 << " Kb)\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -471,10 +471,7 @@ scan_geom_node(GeomNode *node, const RenderState *state,
|
|||
for (int si = 0; si < num_stages; si++) {
|
||||
TextureStage *stage = ta->get_on_stage(si);
|
||||
Texture *tex = ta->get_on_texture(stage);
|
||||
PixelBuffer *tex_pbuffer = tex->_pbuffer;
|
||||
if (tex_pbuffer != (PixelBuffer *)NULL &&
|
||||
tex_pbuffer->get_xsize() != 0 &&
|
||||
tex_pbuffer->get_ysize() != 0) {
|
||||
if (tex->get_x_size() != 0 && tex->get_y_size() != 0) {
|
||||
stage_list.push_back(StageInfo(stage, ta, tma));
|
||||
|
||||
} else {
|
||||
|
|
@ -633,11 +630,10 @@ choose_texture_size(int &x_size, int &y_size,
|
|||
const LVecBase2f &uv_scale,
|
||||
GraphicsOutput *window) const {
|
||||
Texture *model_tex = model_stage._tex;
|
||||
PixelBuffer *model_pbuffer = model_tex->_pbuffer;
|
||||
|
||||
// Start with the same size as the model texture.
|
||||
x_size = model_pbuffer->get_xsize();
|
||||
y_size = model_pbuffer->get_ysize();
|
||||
x_size = model_tex->get_x_size();
|
||||
y_size = model_tex->get_y_size();
|
||||
|
||||
// But we might be looking at just a subset of that texture (scale <
|
||||
// 1) or a superset of the texture (scale > 1). In this case, we
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ class PreparedGraphicsObjects;
|
|||
class GraphicsOutput;
|
||||
class TextureContext;
|
||||
class Texture;
|
||||
class PixelBuffer;
|
||||
class RenderState;
|
||||
class TransformState;
|
||||
|
||||
|
|
@ -166,21 +165,14 @@ public:
|
|||
virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc)=0;
|
||||
virtual void draw_sphere(GeomSphere *geom, GeomContext *gc)=0;
|
||||
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr)=0;
|
||||
virtual void copy_texture(Texture *tex, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb)=0;
|
||||
virtual void framebuffer_copy_to_texture
|
||||
(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb)=0;
|
||||
virtual bool framebuffer_copy_to_ram
|
||||
(Texture *tex, const DisplayRegion *dr, const RenderBuffer &rb)=0;
|
||||
|
||||
virtual bool framebuffer_bind_to_texture(GraphicsOutput *win, Texture *tex)=0;
|
||||
virtual void framebuffer_release_texture(GraphicsOutput *win, Texture *tex)=0;
|
||||
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb)=0;
|
||||
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
|
||||
const DisplayRegion *dr)=0;
|
||||
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr)=0;
|
||||
virtual bool copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
|
||||
const RenderBuffer &rb)=0;
|
||||
|
||||
virtual void apply_material(const Material *material)=0;
|
||||
|
||||
virtual void issue_transform(const TransformState *) { }
|
||||
|
|
|
|||
|
|
@ -197,26 +197,9 @@ STDMETHODIMP HxSiteSupplier::SitesNeeded(UINT32 request_id, IHXValues* pProps)
|
|||
style = WS_OVERLAPPED | WS_VISIBLE | WS_CLIPCHILDREN;
|
||||
#endif
|
||||
|
||||
// Determine if there is a valid Panda buffer available
|
||||
// so that it may be sent down into the sites video
|
||||
// surface object.
|
||||
if( _texture->has_ram_image() ) {
|
||||
pSiteWindowed->SetDstBuffer(_texture->_pbuffer->_image,
|
||||
_texture->_pbuffer->get_xsize(),
|
||||
_texture->_pbuffer->get_ysize());
|
||||
}
|
||||
else {
|
||||
cout << "--- {{ HxSiteSupplier.cxx, RELOADED RAM IMAGE!!! }}---" << endl;
|
||||
PixelBuffer* fake = _texture->get_ram_image();
|
||||
if( fake ) {
|
||||
pSiteWindowed->SetDstBuffer(fake->_image,
|
||||
_texture->_pbuffer->get_xsize(),
|
||||
_texture->_pbuffer->get_ysize());
|
||||
}
|
||||
else {
|
||||
cout << "--- {{ HxSiteSupplier.cxx, NO RAM IMAGE PRESENT!!! }} ---" << endl;
|
||||
}
|
||||
}
|
||||
pSiteWindowed->SetDstBuffer(_texture->modify_ram_image(),
|
||||
_texture->get_x_size(),
|
||||
_texture->get_y_size());
|
||||
|
||||
// Create the window. Not necessary later on.
|
||||
hres = pSiteWindowed->Create(NULL, style);
|
||||
|
|
|
|||
|
|
@ -366,18 +366,15 @@ collect_statistics(Texture *texture) {
|
|||
|
||||
// Attempt to guess how many bytes of texture memory this one
|
||||
// requires.
|
||||
PixelBuffer *pb = texture->_pbuffer;
|
||||
if (pb != (PixelBuffer *)NULL) {
|
||||
int bytes =
|
||||
pb->get_xsize() * pb->get_ysize() * pb->get_num_components() *
|
||||
pb->get_component_width();
|
||||
|
||||
if (texture->uses_mipmaps()) {
|
||||
bytes *= 4/3;
|
||||
}
|
||||
|
||||
_texture_bytes += bytes;
|
||||
int bytes =
|
||||
texture->get_x_size() * texture->get_y_size() *
|
||||
texture->get_num_components() * texture->get_component_width();
|
||||
|
||||
if (texture->uses_mipmaps()) {
|
||||
bytes *= 4/3;
|
||||
}
|
||||
|
||||
_texture_bytes += bytes;
|
||||
|
||||
} else {
|
||||
// This texture has been encountered before; don't count it again.
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include "colorAttrib.h"
|
||||
#include "texture.h"
|
||||
#include "config_pgraph.h"
|
||||
#include "pnmImage.h"
|
||||
|
||||
TypeHandle Spotlight::_type_handle;
|
||||
|
||||
|
|
@ -171,26 +172,20 @@ make_image(Texture *texture, float radius) {
|
|||
<< "Spotlight::make_image() - NULL texture" << endl;
|
||||
return false;
|
||||
}
|
||||
PixelBuffer *pb = texture->_pbuffer;
|
||||
int size = pb->get_xsize();
|
||||
int size = min(texture->get_x_size(), texture->get_y_size());
|
||||
if (size == 0) {
|
||||
pgraph_cat.error()
|
||||
<< "Spotlight::make_image() - pixel buffer has size == 0" << endl;
|
||||
return false;
|
||||
size = 64;
|
||||
}
|
||||
|
||||
const Colorf &color = get_color();
|
||||
PNMImage image(size, size, 1);
|
||||
|
||||
RGBColorf scaled_color;
|
||||
scaled_color[0] = (color[0] * 255.0f);
|
||||
scaled_color[1] = (color[1] * 255.0f);
|
||||
scaled_color[2] = (color[2] * 255.0f);
|
||||
const Colorf &c4 = get_color();
|
||||
const RGBColord color(c4[0], c4[1], c4[2]);
|
||||
|
||||
int half_width = (size - 2) / 2;
|
||||
float dXY = 1 / (float)half_width;
|
||||
float Y = dXY + dXY;
|
||||
float X, YY, dist_from_center, intensity;
|
||||
uchar C[3];
|
||||
int tx, ty, tx2, ty2;
|
||||
|
||||
for (int y = 0; y < half_width; y++, Y += dXY) {
|
||||
|
|
@ -209,28 +204,23 @@ make_image(Texture *texture, float radius) {
|
|||
else
|
||||
intensity = 0;
|
||||
|
||||
C[0] = (uchar)(intensity * scaled_color[0]);
|
||||
C[1] = (uchar)(intensity * scaled_color[1]);
|
||||
C[2] = (uchar)(intensity * scaled_color[2]);
|
||||
|
||||
tx = x + half_width;
|
||||
|
||||
pb->set_uchar_rgb_texel(C, tx, ty, size);
|
||||
pb->set_uchar_rgb_texel(C, tx, size - ty - 1, size);
|
||||
pb->set_uchar_rgb_texel(C, size - tx - 1, ty, size);
|
||||
pb->set_uchar_rgb_texel(C, size - tx - 1, size - ty - 1, size);
|
||||
image.set_xel(tx, ty, color * intensity);
|
||||
image.set_xel(tx, size - ty - 1, color * intensity);
|
||||
image.set_xel(size - tx - 1, ty, color * intensity);
|
||||
image.set_xel(size - tx - 1, size - ty - 1, color * intensity);
|
||||
|
||||
tx2 = ty; ty2 = tx;
|
||||
|
||||
pb->set_uchar_rgb_texel(C, tx2, ty2, size);
|
||||
pb->set_uchar_rgb_texel(C, tx2, size - ty2 - 1, size);
|
||||
pb->set_uchar_rgb_texel(C, size - tx2 - 1, ty2, size);
|
||||
pb->set_uchar_rgb_texel(C, size - tx2 - 1, size - ty2 - 1, size);
|
||||
image.set_xel(tx2, ty2, color * intensity);
|
||||
image.set_xel(tx2, size - ty2 - 1, color * intensity);
|
||||
image.set_xel(size - tx2 - 1, ty2, color * intensity);
|
||||
image.set_xel(size - tx2 - 1, size - ty2 - 1, color * intensity);
|
||||
}
|
||||
}
|
||||
|
||||
// Force the texture to be reloaded into texture memory.
|
||||
texture->mark_dirty(Texture::DF_image);
|
||||
texture->load(image);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,6 +172,9 @@ output(ostream &out) const {
|
|||
case M_eye_position:
|
||||
out << "eye_position";
|
||||
break;
|
||||
case M_object_normal:
|
||||
out << "object_normal";
|
||||
break;
|
||||
}
|
||||
out << ")";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ PUBLISHED:
|
|||
M_world_position,
|
||||
M_object_position,
|
||||
M_eye_position,
|
||||
M_object_normal,
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ static const unsigned short _bam_minor_ver = 16;
|
|||
// Bumped to minor version 14 on 11/18/04 to differentiate old_hpr from new_hpr in compressed anim channels.
|
||||
// Bumped to minor version 15 on 1/16/05 to remove width from GeomLine, etc.
|
||||
// Bumped to minor version 16 on 2/24/05 to add TextureStage::rgb_scale, etc.
|
||||
// Bumped to minor version 17 on 3/03/05 to add 3-d textures, etc.
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ unsigned char *DynamicTextGlyph::
|
|||
get_row(int y) {
|
||||
nassertr(y >= 0 && y < _y_size - _margin * 2, (unsigned char *)NULL);
|
||||
nassertr(_page != (DynamicTextPage *)NULL, (unsigned char *)NULL);
|
||||
nassertr(_page->_pbuffer != (PixelBuffer *)NULL, (unsigned char *)NULL);
|
||||
|
||||
// First, offset y by the glyph's start.
|
||||
y += _y + _margin;
|
||||
|
|
@ -55,10 +54,10 @@ get_row(int y) {
|
|||
int x = _x + _margin;
|
||||
|
||||
// Invert y.
|
||||
y = _page->_pbuffer->get_ysize() - 1 - y;
|
||||
y = _page->get_y_size() - 1 - y;
|
||||
|
||||
int offset = (y * _page->_pbuffer->get_xsize()) + x;
|
||||
return _page->_pbuffer->_image + offset;
|
||||
int offset = (y * _page->get_x_size()) + x;
|
||||
return _page->modify_ram_image() + offset;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -69,14 +68,14 @@ get_row(int y) {
|
|||
void DynamicTextGlyph::
|
||||
erase() {
|
||||
nassertv(_page != (DynamicTextPage *)NULL);
|
||||
nassertv(_page->_pbuffer != (PixelBuffer *)NULL);
|
||||
nassertv(_page->has_ram_image());
|
||||
|
||||
int ysizetop = _page->_pbuffer->get_ysize() - 1;
|
||||
int xsize = _page->_pbuffer->get_xsize();
|
||||
unsigned char *buffer = _page->_pbuffer->_image;
|
||||
int ysizetop = _page->get_y_size() - 1;
|
||||
int width = _page->get_x_size();
|
||||
unsigned char *buffer = _page->modify_ram_image();
|
||||
|
||||
for (int y = _y; y < _y + _y_size; y++) {
|
||||
int offset = (ysizetop - y) * xsize + _x;
|
||||
int offset = (ysizetop - y) * width + _x;
|
||||
memset(buffer + offset, 0, _x_size);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,18 +36,13 @@ DynamicTextPage(DynamicTextFont *font, int page_number) :
|
|||
_x_size = _font->get_page_x_size();
|
||||
_y_size = _font->get_page_y_size();
|
||||
|
||||
setup_2d_texture(_x_size, _y_size, T_unsigned_byte, F_alpha);
|
||||
|
||||
// Assign a name to the Texture.
|
||||
ostringstream strm;
|
||||
strm << font->get_name() << "_" << page_number;
|
||||
set_name(strm.str());
|
||||
|
||||
// Initialize the Texture to an empty, black (transparent) image of
|
||||
// the appropriate size.
|
||||
_pbuffer = new PixelBuffer(_x_size, _y_size, 1, 1,
|
||||
PixelBuffer::T_unsigned_byte,
|
||||
PixelBuffer::F_alpha);
|
||||
mark_dirty(DF_image);
|
||||
|
||||
// We'd better never free this image.
|
||||
set_keep_ram_image(true);
|
||||
|
||||
|
|
@ -58,8 +53,8 @@ DynamicTextPage(DynamicTextFont *font, int page_number) :
|
|||
|
||||
// It's slightly better to let the texture clamp, rather than
|
||||
// wrapping, so we're less likely to get bleeding at the edges.
|
||||
set_wrapu(WM_clamp);
|
||||
set_wrapv(WM_clamp);
|
||||
set_wrap_u(WM_clamp);
|
||||
set_wrap_v(WM_clamp);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
Loading…
Reference in New Issue