root/OpenSceneGraph/trunk/src/osgPlugins/ive/TextureCubeMap.cpp @ 13041

Revision 13041, 4.5 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 *    FILE:            TextureCubeMap.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::TextureCubeMap in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerated
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 21.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Exception.h"
16#include "TextureCubeMap.h"
17#include "Texture.h"
18#include "Image.h"
19
20using namespace ive;
21
22void TextureCubeMap::write(DataOutputStream* out){
23    // Write TextureCubeMap's identification.
24    out->writeInt(IVETEXTURECUBEMAP);
25    // If the osg class is inherited by any other class we should also write this to file.
26    osg::Texture*  tex = dynamic_cast<osg::Texture*>(this);
27    if(tex){
28        ((ive::Texture*)(tex))->write(out);
29    }
30    else
31        out_THROW_EXCEPTION("TextureCubeMap::write(): Could not cast this osg::TextureCubeMap to an osg::Texture.");
32    // Write TextureCubeMap's properties.
33
34    // Write texture size
35    out->writeInt(getTextureWidth());
36    out->writeInt(getTextureHeight());
37
38    // Write number of mipmap levels
39    out->writeInt(getNumMipmapLevels());
40
41    if (out->getVersion() >= VERSION_0029)
42    {
43        out->writeImage(getImage(osg::TextureCubeMap::POSITIVE_X));
44        out->writeImage(getImage(osg::TextureCubeMap::NEGATIVE_X));
45        out->writeImage(getImage(osg::TextureCubeMap::POSITIVE_Y));
46        out->writeImage(getImage(osg::TextureCubeMap::NEGATIVE_Y));
47        out->writeImage(getImage(osg::TextureCubeMap::POSITIVE_Z));
48        out->writeImage(getImage(osg::TextureCubeMap::NEGATIVE_Z));
49    }
50    else
51    {
52        // Should we include images date in stream
53        IncludeImageMode includeImg = out->getIncludeImageMode(getImage(osg::TextureCubeMap::POSITIVE_X));
54        out->writeChar(includeImg);
55
56        out->writeImage(includeImg,getImage(osg::TextureCubeMap::POSITIVE_X));
57        out->writeImage(includeImg,getImage(osg::TextureCubeMap::NEGATIVE_X));
58        out->writeImage(includeImg,getImage(osg::TextureCubeMap::POSITIVE_Y));
59        out->writeImage(includeImg,getImage(osg::TextureCubeMap::NEGATIVE_Y));
60        out->writeImage(includeImg,getImage(osg::TextureCubeMap::POSITIVE_Z));
61        out->writeImage(includeImg,getImage(osg::TextureCubeMap::NEGATIVE_Z));
62    }
63}
64
65void TextureCubeMap::read(DataInputStream* in)
66{
67    // Peek on TextureCubeMap's identification.
68    int id = in->peekInt();
69    if(id == IVETEXTURECUBEMAP){
70        // Read TextureCubeMap's identification.
71        id = in->readInt();
72        // If the osg class is inherited by any other class we should also read this from file.
73        osg::Texture* tex = dynamic_cast<osg::Texture*>(this);
74        if(tex){
75            ((ive::Texture*)(tex))->read(in);
76        }
77        else
78            in_THROW_EXCEPTION("TextureCubeMap::read(): Could not cast this osg::TextureCubeMap to an osg::Texture.");
79        // Read TextureCubeMap's properties
80
81        // Read texture size
82        int width = in->readInt();
83        int height = in->readInt();
84        setTextureSize(width, height);
85
86        // Read number of mipmap levels
87        setNumMipmapLevels((unsigned int)in->readInt());
88
89        if (in->getVersion() >= VERSION_0029)
90        {
91            setImage(osg::TextureCubeMap::POSITIVE_X,in->readImage());
92            setImage(osg::TextureCubeMap::NEGATIVE_X,in->readImage());
93            setImage(osg::TextureCubeMap::POSITIVE_Y,in->readImage());
94            setImage(osg::TextureCubeMap::NEGATIVE_Y,in->readImage());
95            setImage(osg::TextureCubeMap::POSITIVE_Z,in->readImage());
96            setImage(osg::TextureCubeMap::NEGATIVE_Z,in->readImage());
97        }
98        else
99        {
100            // Should we read image data from stream
101            IncludeImageMode includeImg = (IncludeImageMode)in->readChar();
102
103            setImage(osg::TextureCubeMap::POSITIVE_X,in->readImage(includeImg));
104            setImage(osg::TextureCubeMap::NEGATIVE_X,in->readImage(includeImg));
105            setImage(osg::TextureCubeMap::POSITIVE_Y,in->readImage(includeImg));
106            setImage(osg::TextureCubeMap::NEGATIVE_Y,in->readImage(includeImg));
107            setImage(osg::TextureCubeMap::POSITIVE_Z,in->readImage(includeImg));
108            setImage(osg::TextureCubeMap::NEGATIVE_Z,in->readImage(includeImg));
109        }
110
111    }
112    else{
113        in_THROW_EXCEPTION("TextureCubeMap::read(): Expected TextureCubeMap identification.");
114    }
115}
Note: See TracBrowser for help on using the browser.