1 //**************************************************************************
2 //**
3 //** ## ## ## ## ## #### #### ### ###
4 //** ## ## ## ## ## ## ## ## ## ## #### ####
5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ##
6 //** ## ## ######## ## ## ## ## ## ## ## ### ##
7 //** ### ## ## ### ## ## ## ## ## ##
8 //** # ## ## # #### #### ## ##
9 //**
10 //** $Id: r_tex_camera.cpp 4297 2010-06-03 22:49:00Z firebrand_kh $
11 //**
12 //** Copyright (C) 1999-2006 Jānis Legzdiņš
13 //**
14 //** This program is free software; you can redistribute it and/or
15 //** modify it under the terms of the GNU General Public License
16 //** as published by the Free Software Foundation; either version 2
17 //** of the License, or (at your option) any later version.
18 //**
19 //** This program is distributed in the hope that it will be useful,
20 //** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 //** GNU General Public License for more details.
23 //**
24 //**************************************************************************
25
26 // HEADER FILES ------------------------------------------------------------
27
28 #include "gamedefs.h"
29 #include "r_tex.h"
30
31 // MACROS ------------------------------------------------------------------
32
33 // TYPES -------------------------------------------------------------------
34
35 // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
36
37 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
38
39 // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
40
41 // EXTERNAL DATA DECLARATIONS ----------------------------------------------
42
43 // PUBLIC DATA DEFINITIONS -------------------------------------------------
44
45 // PRIVATE DATA DEFINITIONS ------------------------------------------------
46
47 // CODE --------------------------------------------------------------------
48
49 //==========================================================================
50 //
51 // VCameraTexture::VCameraTexture
52 //
53 //==========================================================================
54
VCameraTexture(VName AName,int AWidth,int AHeight)55 VCameraTexture::VCameraTexture(VName AName, int AWidth, int AHeight)
56 : Pixels(0)
57 , bNeedsUpdate(true)
58 , bUpdated(false)
59 {
60 Name = AName;
61 Type = TEXTYPE_Wall;
62 Format = TEXFMT_RGBA;
63 Width = AWidth;
64 Height = AHeight;
65 bIsCameraTexture = true;
66 }
67
68 //==========================================================================
69 //
70 // VCameraTexture::~VCameraTexture
71 //
72 //==========================================================================
73
~VCameraTexture()74 VCameraTexture::~VCameraTexture()
75 {
76 guard(VCameraTexture::~VCameraTexture);
77 if (Pixels)
78 {
79 delete[] Pixels;
80 Pixels = NULL;
81 }
82 unguard;
83 }
84
85 //==========================================================================
86 //
87 // VCameraTexture::CheckModified
88 //
89 //==========================================================================
90
CheckModified()91 bool VCameraTexture::CheckModified()
92 {
93 guard(VCameraTexture::CheckModified);
94 if (bUpdated)
95 {
96 bUpdated = false;
97 return true;
98 }
99 return false;
100 unguard;
101 }
102
103 //==========================================================================
104 //
105 // VCameraTexture::GetPixels
106 //
107 //==========================================================================
108
GetPixels()109 vuint8* VCameraTexture::GetPixels()
110 {
111 guard(VCameraTexture::GetPixels);
112 bNeedsUpdate = true;
113 // If already got pixels, then just return them.
114 if (Pixels)
115 {
116 return Pixels;
117 }
118
119 // Allocate image data.
120 Pixels = new vuint8[Width * Height * 4];
121
122 rgba_t* pDst = (rgba_t*)Pixels;
123 for (int i = 0; i < Height; i++)
124 {
125 for (int j = 0; j < Width; j++)
126 {
127 if (j < Width / 2)
128 {
129 pDst->r = 0;
130 pDst->g = 0;
131 pDst->b = 0;
132 pDst->a = 255;
133 }
134 else
135 {
136 pDst->r = 255;
137 pDst->g = 255;
138 pDst->b = 255;
139 pDst->a = 255;
140 }
141 pDst++;
142 }
143 }
144
145 return Pixels;
146 unguard;
147 }
148
149 //==========================================================================
150 //
151 // VCameraTexture::Unload
152 //
153 //==========================================================================
154
Unload()155 void VCameraTexture::Unload()
156 {
157 guard(VCameraTexture::Unload);
158 if (Pixels)
159 {
160 delete[] Pixels;
161 Pixels = NULL;
162 }
163 unguard;
164 }
165
166 //==========================================================================
167 //
168 // VCameraTexture::CopyImage
169 //
170 //==========================================================================
171
172 #ifdef CLIENT
CopyImage()173 void VCameraTexture::CopyImage()
174 {
175 guard(VCameraTexture::CopyImage);
176 if (!Pixels)
177 {
178 Pixels = new vuint8[Width * Height * 4];
179 }
180
181 Drawer->ReadBackScreen(Width, Height, (rgba_t*)Pixels);
182 bNeedsUpdate = false;
183 bUpdated = true;
184 Pixels8BitValid = false;
185 unguard;
186 }
187 #endif
188
189 //==========================================================================
190 //
191 // VCameraTexture::GetHighResolutionTexture
192 //
193 //==========================================================================
194
GetHighResolutionTexture()195 VTexture* VCameraTexture::GetHighResolutionTexture()
196 {
197 return NULL;
198 }
199