Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 14 | |
| 15 | #include "PixelProcessor.hpp" |
| 16 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame] | 17 | #include "PixelPipeline.hpp" |
| 18 | #include "PixelProgram.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 19 | #include "PixelShader.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 20 | #include "Surface.hpp" |
| 21 | #include "Primitive.hpp" |
| 22 | #include "Constants.hpp" |
| 23 | #include "Debug.hpp" |
| 24 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 25 | #include <string.h> |
| 26 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 27 | namespace sw |
| 28 | { |
| 29 | extern bool complementaryDepthBuffer; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 30 | extern TransparencyAntialiasing transparencyAntialiasing; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 31 | extern bool perspectiveCorrection; |
| 32 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 33 | bool precachePixel = false; |
| 34 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 35 | unsigned int PixelProcessor::States::computeHash() |
| 36 | { |
| 37 | unsigned int *state = (unsigned int*)this; |
| 38 | unsigned int hash = 0; |
| 39 | |
Nicolas Capens | 5d96188 | 2016-01-01 23:18:14 -0500 | [diff] [blame] | 40 | for(unsigned int i = 0; i < sizeof(States) / 4; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 41 | { |
| 42 | hash ^= state[i]; |
| 43 | } |
| 44 | |
| 45 | return hash; |
| 46 | } |
| 47 | |
| 48 | PixelProcessor::State::State() |
| 49 | { |
| 50 | memset(this, 0, sizeof(State)); |
| 51 | } |
| 52 | |
| 53 | bool PixelProcessor::State::operator==(const State &state) const |
| 54 | { |
| 55 | if(hash != state.hash) |
| 56 | { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0; |
| 61 | } |
| 62 | |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 63 | PixelProcessor::UniformBufferInfo::UniformBufferInfo() |
| 64 | { |
| 65 | buffer = nullptr; |
| 66 | offset = 0; |
| 67 | } |
| 68 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 69 | PixelProcessor::PixelProcessor(Context *context) : context(context) |
| 70 | { |
| 71 | setGlobalMipmapBias(0.0f); // Round to highest LOD [0.5, 1.0]: -0.5 |
| 72 | // Round to nearest LOD [0.7, 1.4]: 0.0 |
| 73 | // Round to lowest LOD [1.0, 2.0]: 0.5 |
| 74 | |
| 75 | routineCache = 0; |
| 76 | setRoutineCacheSize(1024); |
| 77 | } |
| 78 | |
| 79 | PixelProcessor::~PixelProcessor() |
| 80 | { |
| 81 | delete routineCache; |
| 82 | routineCache = 0; |
| 83 | } |
| 84 | |
| 85 | void PixelProcessor::setFloatConstant(unsigned int index, const float value[4]) |
| 86 | { |
Alexis Hetu | 04c967a | 2015-07-08 15:56:17 -0400 | [diff] [blame] | 87 | if(index < FRAGMENT_UNIFORM_VECTORS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 88 | { |
| 89 | c[index][0] = value[0]; |
| 90 | c[index][1] = value[1]; |
| 91 | c[index][2] = value[2]; |
| 92 | c[index][3] = value[3]; |
| 93 | } |
| 94 | else ASSERT(false); |
| 95 | |
| 96 | if(index < 8) // ps_1_x constants |
| 97 | { |
| 98 | // FIXME: Compact into generic function |
| 99 | short x = iround(4095 * clamp(value[0], -1.0f, 1.0f)); |
| 100 | short y = iround(4095 * clamp(value[1], -1.0f, 1.0f)); |
| 101 | short z = iround(4095 * clamp(value[2], -1.0f, 1.0f)); |
| 102 | short w = iround(4095 * clamp(value[3], -1.0f, 1.0f)); |
| 103 | |
| 104 | cW[index][0][0] = x; |
| 105 | cW[index][0][1] = x; |
| 106 | cW[index][0][2] = x; |
| 107 | cW[index][0][3] = x; |
| 108 | |
| 109 | cW[index][1][0] = y; |
| 110 | cW[index][1][1] = y; |
| 111 | cW[index][1][2] = y; |
| 112 | cW[index][1][3] = y; |
| 113 | |
| 114 | cW[index][2][0] = z; |
| 115 | cW[index][2][1] = z; |
| 116 | cW[index][2][2] = z; |
| 117 | cW[index][2][3] = z; |
| 118 | |
| 119 | cW[index][3][0] = w; |
| 120 | cW[index][3][1] = w; |
| 121 | cW[index][3][2] = w; |
| 122 | cW[index][3][3] = w; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void PixelProcessor::setIntegerConstant(unsigned int index, const int value[4]) |
| 127 | { |
| 128 | if(index < 16) |
| 129 | { |
| 130 | i[index][0] = value[0]; |
| 131 | i[index][1] = value[1]; |
| 132 | i[index][2] = value[2]; |
| 133 | i[index][3] = value[3]; |
| 134 | } |
| 135 | else ASSERT(false); |
| 136 | } |
| 137 | |
| 138 | void PixelProcessor::setBooleanConstant(unsigned int index, int boolean) |
| 139 | { |
| 140 | if(index < 16) |
| 141 | { |
| 142 | b[index] = boolean != 0; |
| 143 | } |
| 144 | else ASSERT(false); |
| 145 | } |
| 146 | |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 147 | void PixelProcessor::setUniformBuffer(int index, sw::Resource* buffer, int offset) |
| 148 | { |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 149 | uniformBufferInfo[index].buffer = buffer; |
| 150 | uniformBufferInfo[index].offset = offset; |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 153 | void PixelProcessor::lockUniformBuffers(byte** u, sw::Resource* uniformBuffers[]) |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 154 | { |
| 155 | for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; ++i) |
| 156 | { |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 157 | u[i] = uniformBufferInfo[i].buffer ? static_cast<byte*>(uniformBufferInfo[i].buffer->lock(PUBLIC, PRIVATE)) + uniformBufferInfo[i].offset : nullptr; |
| 158 | uniformBuffers[i] = uniformBufferInfo[i].buffer; |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 162 | void PixelProcessor::setRenderTarget(int index, Surface *renderTarget) |
| 163 | { |
| 164 | context->renderTarget[index] = renderTarget; |
| 165 | } |
| 166 | |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 167 | void PixelProcessor::setDepthBuffer(Surface *depthBuffer) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 168 | { |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 169 | context->depthBuffer = depthBuffer; |
| 170 | } |
| 171 | |
| 172 | void PixelProcessor::setStencilBuffer(Surface *stencilBuffer) |
| 173 | { |
| 174 | context->stencilBuffer = stencilBuffer; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void PixelProcessor::setTexCoordIndex(unsigned int stage, int texCoordIndex) |
| 178 | { |
| 179 | if(stage < 8) |
| 180 | { |
| 181 | context->textureStage[stage].setTexCoordIndex(texCoordIndex); |
| 182 | } |
| 183 | else ASSERT(false); |
| 184 | } |
| 185 | |
| 186 | void PixelProcessor::setStageOperation(unsigned int stage, TextureStage::StageOperation stageOperation) |
| 187 | { |
| 188 | if(stage < 8) |
| 189 | { |
| 190 | context->textureStage[stage].setStageOperation(stageOperation); |
| 191 | } |
| 192 | else ASSERT(false); |
| 193 | } |
| 194 | |
| 195 | void PixelProcessor::setFirstArgument(unsigned int stage, TextureStage::SourceArgument firstArgument) |
| 196 | { |
| 197 | if(stage < 8) |
| 198 | { |
| 199 | context->textureStage[stage].setFirstArgument(firstArgument); |
| 200 | } |
| 201 | else ASSERT(false); |
| 202 | } |
| 203 | |
| 204 | void PixelProcessor::setSecondArgument(unsigned int stage, TextureStage::SourceArgument secondArgument) |
| 205 | { |
| 206 | if(stage < 8) |
| 207 | { |
| 208 | context->textureStage[stage].setSecondArgument(secondArgument); |
| 209 | } |
| 210 | else ASSERT(false); |
| 211 | } |
| 212 | |
| 213 | void PixelProcessor::setThirdArgument(unsigned int stage, TextureStage::SourceArgument thirdArgument) |
| 214 | { |
| 215 | if(stage < 8) |
| 216 | { |
| 217 | context->textureStage[stage].setThirdArgument(thirdArgument); |
| 218 | } |
| 219 | else ASSERT(false); |
| 220 | } |
| 221 | |
| 222 | void PixelProcessor::setStageOperationAlpha(unsigned int stage, TextureStage::StageOperation stageOperationAlpha) |
| 223 | { |
| 224 | if(stage < 8) |
| 225 | { |
| 226 | context->textureStage[stage].setStageOperationAlpha(stageOperationAlpha); |
| 227 | } |
| 228 | else ASSERT(false); |
| 229 | } |
| 230 | |
| 231 | void PixelProcessor::setFirstArgumentAlpha(unsigned int stage, TextureStage::SourceArgument firstArgumentAlpha) |
| 232 | { |
| 233 | if(stage < 8) |
| 234 | { |
| 235 | context->textureStage[stage].setFirstArgumentAlpha(firstArgumentAlpha); |
| 236 | } |
| 237 | else ASSERT(false); |
| 238 | } |
| 239 | |
| 240 | void PixelProcessor::setSecondArgumentAlpha(unsigned int stage, TextureStage::SourceArgument secondArgumentAlpha) |
| 241 | { |
| 242 | if(stage < 8) |
| 243 | { |
| 244 | context->textureStage[stage].setSecondArgumentAlpha(secondArgumentAlpha); |
| 245 | } |
| 246 | else ASSERT(false); |
| 247 | } |
| 248 | |
| 249 | void PixelProcessor::setThirdArgumentAlpha(unsigned int stage, TextureStage::SourceArgument thirdArgumentAlpha) |
| 250 | { |
| 251 | if(stage < 8) |
| 252 | { |
| 253 | context->textureStage[stage].setThirdArgumentAlpha(thirdArgumentAlpha); |
| 254 | } |
| 255 | else ASSERT(false); |
| 256 | } |
| 257 | |
| 258 | void PixelProcessor::setFirstModifier(unsigned int stage, TextureStage::ArgumentModifier firstModifier) |
| 259 | { |
| 260 | if(stage < 8) |
| 261 | { |
| 262 | context->textureStage[stage].setFirstModifier(firstModifier); |
| 263 | } |
| 264 | else ASSERT(false); |
| 265 | } |
| 266 | |
| 267 | void PixelProcessor::setSecondModifier(unsigned int stage, TextureStage::ArgumentModifier secondModifier) |
| 268 | { |
| 269 | if(stage < 8) |
| 270 | { |
| 271 | context->textureStage[stage].setSecondModifier(secondModifier); |
| 272 | } |
| 273 | else ASSERT(false); |
| 274 | } |
| 275 | |
| 276 | void PixelProcessor::setThirdModifier(unsigned int stage, TextureStage::ArgumentModifier thirdModifier) |
| 277 | { |
| 278 | if(stage < 8) |
| 279 | { |
| 280 | context->textureStage[stage].setThirdModifier(thirdModifier); |
| 281 | } |
| 282 | else ASSERT(false); |
| 283 | } |
| 284 | |
| 285 | void PixelProcessor::setFirstModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier firstModifierAlpha) |
| 286 | { |
| 287 | if(stage < 8) |
| 288 | { |
| 289 | context->textureStage[stage].setFirstModifierAlpha(firstModifierAlpha); |
| 290 | } |
| 291 | else ASSERT(false); |
| 292 | } |
| 293 | |
| 294 | void PixelProcessor::setSecondModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier secondModifierAlpha) |
| 295 | { |
| 296 | if(stage < 8) |
| 297 | { |
| 298 | context->textureStage[stage].setSecondModifierAlpha(secondModifierAlpha); |
| 299 | } |
| 300 | else ASSERT(false); |
| 301 | } |
| 302 | |
| 303 | void PixelProcessor::setThirdModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier thirdModifierAlpha) |
| 304 | { |
| 305 | if(stage < 8) |
| 306 | { |
| 307 | context->textureStage[stage].setThirdModifierAlpha(thirdModifierAlpha); |
| 308 | } |
| 309 | else ASSERT(false); |
| 310 | } |
| 311 | |
| 312 | void PixelProcessor::setDestinationArgument(unsigned int stage, TextureStage::DestinationArgument destinationArgument) |
| 313 | { |
| 314 | if(stage < 8) |
| 315 | { |
| 316 | context->textureStage[stage].setDestinationArgument(destinationArgument); |
| 317 | } |
| 318 | else ASSERT(false); |
| 319 | } |
| 320 | |
| 321 | void PixelProcessor::setConstantColor(unsigned int stage, const Color<float> &constantColor) |
| 322 | { |
| 323 | if(stage < 8) |
| 324 | { |
| 325 | context->textureStage[stage].setConstantColor(constantColor); |
| 326 | } |
| 327 | else ASSERT(false); |
| 328 | } |
| 329 | |
| 330 | void PixelProcessor::setBumpmapMatrix(unsigned int stage, int element, float value) |
| 331 | { |
| 332 | if(stage < 8) |
| 333 | { |
| 334 | context->textureStage[stage].setBumpmapMatrix(element, value); |
| 335 | } |
| 336 | else ASSERT(false); |
| 337 | } |
| 338 | |
| 339 | void PixelProcessor::setLuminanceScale(unsigned int stage, float value) |
| 340 | { |
| 341 | if(stage < 8) |
| 342 | { |
| 343 | context->textureStage[stage].setLuminanceScale(value); |
| 344 | } |
| 345 | else ASSERT(false); |
| 346 | } |
| 347 | |
| 348 | void PixelProcessor::setLuminanceOffset(unsigned int stage, float value) |
| 349 | { |
| 350 | if(stage < 8) |
| 351 | { |
| 352 | context->textureStage[stage].setLuminanceOffset(value); |
| 353 | } |
| 354 | else ASSERT(false); |
| 355 | } |
| 356 | |
| 357 | void PixelProcessor::setTextureFilter(unsigned int sampler, FilterType textureFilter) |
| 358 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 359 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 360 | { |
| 361 | context->sampler[sampler].setTextureFilter(textureFilter); |
| 362 | } |
| 363 | else ASSERT(false); |
| 364 | } |
| 365 | |
| 366 | void PixelProcessor::setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter) |
| 367 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 368 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 369 | { |
| 370 | context->sampler[sampler].setMipmapFilter(mipmapFilter); |
| 371 | } |
| 372 | else ASSERT(false); |
| 373 | } |
| 374 | |
| 375 | void PixelProcessor::setGatherEnable(unsigned int sampler, bool enable) |
| 376 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 377 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 378 | { |
| 379 | context->sampler[sampler].setGatherEnable(enable); |
| 380 | } |
| 381 | else ASSERT(false); |
| 382 | } |
| 383 | |
| 384 | void PixelProcessor::setAddressingModeU(unsigned int sampler, AddressingMode addressMode) |
| 385 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 386 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 387 | { |
| 388 | context->sampler[sampler].setAddressingModeU(addressMode); |
| 389 | } |
| 390 | else ASSERT(false); |
| 391 | } |
| 392 | |
| 393 | void PixelProcessor::setAddressingModeV(unsigned int sampler, AddressingMode addressMode) |
| 394 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 395 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 396 | { |
| 397 | context->sampler[sampler].setAddressingModeV(addressMode); |
| 398 | } |
| 399 | else ASSERT(false); |
| 400 | } |
| 401 | |
| 402 | void PixelProcessor::setAddressingModeW(unsigned int sampler, AddressingMode addressMode) |
| 403 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 404 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 405 | { |
| 406 | context->sampler[sampler].setAddressingModeW(addressMode); |
| 407 | } |
| 408 | else ASSERT(false); |
| 409 | } |
| 410 | |
| 411 | void PixelProcessor::setReadSRGB(unsigned int sampler, bool sRGB) |
| 412 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 413 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 414 | { |
| 415 | context->sampler[sampler].setReadSRGB(sRGB); |
| 416 | } |
| 417 | else ASSERT(false); |
| 418 | } |
| 419 | |
| 420 | void PixelProcessor::setMipmapLOD(unsigned int sampler, float bias) |
| 421 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 422 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 423 | { |
| 424 | context->sampler[sampler].setMipmapLOD(bias); |
| 425 | } |
| 426 | else ASSERT(false); |
| 427 | } |
| 428 | |
| 429 | void PixelProcessor::setBorderColor(unsigned int sampler, const Color<float> &borderColor) |
| 430 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 431 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 432 | { |
| 433 | context->sampler[sampler].setBorderColor(borderColor); |
| 434 | } |
| 435 | else ASSERT(false); |
| 436 | } |
| 437 | |
Alexis Hetu | 617a5d5 | 2014-11-13 10:56:20 -0500 | [diff] [blame] | 438 | void PixelProcessor::setMaxAnisotropy(unsigned int sampler, float maxAnisotropy) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 439 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 440 | if(sampler < TEXTURE_IMAGE_UNITS) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 441 | { |
| 442 | context->sampler[sampler].setMaxAnisotropy(maxAnisotropy); |
| 443 | } |
| 444 | else ASSERT(false); |
| 445 | } |
| 446 | |
Alexis Hetu | 1d01aa3 | 2015-09-29 11:50:05 -0400 | [diff] [blame] | 447 | void PixelProcessor::setSwizzleR(unsigned int sampler, SwizzleType swizzleR) |
| 448 | { |
| 449 | if(sampler < TEXTURE_IMAGE_UNITS) |
| 450 | { |
| 451 | context->sampler[sampler].setSwizzleR(swizzleR); |
| 452 | } |
| 453 | else ASSERT(false); |
| 454 | } |
| 455 | |
| 456 | void PixelProcessor::setSwizzleG(unsigned int sampler, SwizzleType swizzleG) |
| 457 | { |
| 458 | if(sampler < TEXTURE_IMAGE_UNITS) |
| 459 | { |
| 460 | context->sampler[sampler].setSwizzleG(swizzleG); |
| 461 | } |
| 462 | else ASSERT(false); |
| 463 | } |
| 464 | |
| 465 | void PixelProcessor::setSwizzleB(unsigned int sampler, SwizzleType swizzleB) |
| 466 | { |
| 467 | if(sampler < TEXTURE_IMAGE_UNITS) |
| 468 | { |
| 469 | context->sampler[sampler].setSwizzleB(swizzleB); |
| 470 | } |
| 471 | else ASSERT(false); |
| 472 | } |
| 473 | |
| 474 | void PixelProcessor::setSwizzleA(unsigned int sampler, SwizzleType swizzleA) |
| 475 | { |
| 476 | if(sampler < TEXTURE_IMAGE_UNITS) |
| 477 | { |
| 478 | context->sampler[sampler].setSwizzleA(swizzleA); |
| 479 | } |
| 480 | else ASSERT(false); |
| 481 | } |
| 482 | |
Alexis Hetu | 95ac187 | 2016-06-06 13:26:52 -0400 | [diff] [blame] | 483 | void PixelProcessor::setBaseLevel(unsigned int sampler, int baseLevel) |
| 484 | { |
| 485 | if(sampler < TEXTURE_IMAGE_UNITS) |
| 486 | { |
| 487 | context->sampler[sampler].setBaseLevel(baseLevel); |
| 488 | } |
| 489 | else ASSERT(false); |
| 490 | } |
| 491 | |
| 492 | void PixelProcessor::setMaxLevel(unsigned int sampler, int maxLevel) |
| 493 | { |
| 494 | if(sampler < TEXTURE_IMAGE_UNITS) |
| 495 | { |
| 496 | context->sampler[sampler].setMaxLevel(maxLevel); |
| 497 | } |
| 498 | else ASSERT(false); |
| 499 | } |
| 500 | |
Alexis Hetu | 112d81f | 2016-06-07 12:36:35 -0400 | [diff] [blame] | 501 | void PixelProcessor::setMinLod(unsigned int sampler, float minLod) |
| 502 | { |
| 503 | if(sampler < TEXTURE_IMAGE_UNITS) |
| 504 | { |
| 505 | context->sampler[sampler].setMinLod(minLod); |
| 506 | } |
| 507 | else ASSERT(false); |
| 508 | } |
| 509 | |
| 510 | void PixelProcessor::setMaxLod(unsigned int sampler, float maxLod) |
| 511 | { |
| 512 | if(sampler < TEXTURE_IMAGE_UNITS) |
| 513 | { |
| 514 | context->sampler[sampler].setMaxLod(maxLod); |
| 515 | } |
| 516 | else ASSERT(false); |
| 517 | } |
| 518 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 519 | void PixelProcessor::setWriteSRGB(bool sRGB) |
| 520 | { |
| 521 | context->setWriteSRGB(sRGB); |
| 522 | } |
| 523 | |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 524 | void PixelProcessor::setColorLogicOpEnabled(bool colorLogicOpEnabled) |
| 525 | { |
| 526 | context->setColorLogicOpEnabled(colorLogicOpEnabled); |
| 527 | } |
| 528 | |
| 529 | void PixelProcessor::setLogicalOperation(LogicalOperation logicalOperation) |
| 530 | { |
| 531 | context->setLogicalOperation(logicalOperation); |
| 532 | } |
| 533 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 534 | void PixelProcessor::setDepthBufferEnable(bool depthBufferEnable) |
| 535 | { |
| 536 | context->setDepthBufferEnable(depthBufferEnable); |
| 537 | } |
| 538 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 539 | void PixelProcessor::setDepthCompare(DepthCompareMode depthCompareMode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 540 | { |
| 541 | context->depthCompareMode = depthCompareMode; |
| 542 | } |
| 543 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 544 | void PixelProcessor::setAlphaCompare(AlphaCompareMode alphaCompareMode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 545 | { |
| 546 | context->alphaCompareMode = alphaCompareMode; |
| 547 | } |
| 548 | |
| 549 | void PixelProcessor::setDepthWriteEnable(bool depthWriteEnable) |
| 550 | { |
| 551 | context->depthWriteEnable = depthWriteEnable; |
| 552 | } |
| 553 | |
| 554 | void PixelProcessor::setAlphaTestEnable(bool alphaTestEnable) |
| 555 | { |
| 556 | context->alphaTestEnable = alphaTestEnable; |
| 557 | } |
| 558 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 559 | void PixelProcessor::setCullMode(CullMode cullMode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 560 | { |
| 561 | context->cullMode = cullMode; |
| 562 | } |
| 563 | |
| 564 | void PixelProcessor::setColorWriteMask(int index, int rgbaMask) |
| 565 | { |
| 566 | context->setColorWriteMask(index, rgbaMask); |
| 567 | } |
| 568 | |
| 569 | void PixelProcessor::setStencilEnable(bool stencilEnable) |
| 570 | { |
| 571 | context->stencilEnable = stencilEnable; |
| 572 | } |
| 573 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 574 | void PixelProcessor::setStencilCompare(StencilCompareMode stencilCompareMode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 575 | { |
| 576 | context->stencilCompareMode = stencilCompareMode; |
| 577 | } |
| 578 | |
| 579 | void PixelProcessor::setStencilReference(int stencilReference) |
| 580 | { |
| 581 | context->stencilReference = stencilReference; |
| 582 | stencil.set(stencilReference, context->stencilMask, context->stencilWriteMask); |
| 583 | } |
| 584 | |
| 585 | void PixelProcessor::setStencilReferenceCCW(int stencilReferenceCCW) |
| 586 | { |
| 587 | context->stencilReferenceCCW = stencilReferenceCCW; |
| 588 | stencilCCW.set(stencilReferenceCCW, context->stencilMaskCCW, context->stencilWriteMaskCCW); |
| 589 | } |
| 590 | |
| 591 | void PixelProcessor::setStencilMask(int stencilMask) |
| 592 | { |
| 593 | context->stencilMask = stencilMask; |
| 594 | stencil.set(context->stencilReference, stencilMask, context->stencilWriteMask); |
| 595 | } |
| 596 | |
| 597 | void PixelProcessor::setStencilMaskCCW(int stencilMaskCCW) |
| 598 | { |
| 599 | context->stencilMaskCCW = stencilMaskCCW; |
| 600 | stencilCCW.set(context->stencilReferenceCCW, stencilMaskCCW, context->stencilWriteMaskCCW); |
| 601 | } |
| 602 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 603 | void PixelProcessor::setStencilFailOperation(StencilOperation stencilFailOperation) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 604 | { |
| 605 | context->stencilFailOperation = stencilFailOperation; |
| 606 | } |
| 607 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 608 | void PixelProcessor::setStencilPassOperation(StencilOperation stencilPassOperation) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 609 | { |
| 610 | context->stencilPassOperation = stencilPassOperation; |
| 611 | } |
| 612 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 613 | void PixelProcessor::setStencilZFailOperation(StencilOperation stencilZFailOperation) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 614 | { |
| 615 | context->stencilZFailOperation = stencilZFailOperation; |
| 616 | } |
| 617 | |
| 618 | void PixelProcessor::setStencilWriteMask(int stencilWriteMask) |
| 619 | { |
| 620 | context->stencilWriteMask = stencilWriteMask; |
| 621 | stencil.set(context->stencilReference, context->stencilMask, stencilWriteMask); |
| 622 | } |
| 623 | |
| 624 | void PixelProcessor::setStencilWriteMaskCCW(int stencilWriteMaskCCW) |
| 625 | { |
| 626 | context->stencilWriteMaskCCW = stencilWriteMaskCCW; |
| 627 | stencilCCW.set(context->stencilReferenceCCW, context->stencilMaskCCW, stencilWriteMaskCCW); |
| 628 | } |
| 629 | |
| 630 | void PixelProcessor::setTwoSidedStencil(bool enable) |
| 631 | { |
| 632 | context->twoSidedStencil = enable; |
| 633 | } |
| 634 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 635 | void PixelProcessor::setStencilCompareCCW(StencilCompareMode stencilCompareMode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 636 | { |
| 637 | context->stencilCompareModeCCW = stencilCompareMode; |
| 638 | } |
| 639 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 640 | void PixelProcessor::setStencilFailOperationCCW(StencilOperation stencilFailOperation) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 641 | { |
| 642 | context->stencilFailOperationCCW = stencilFailOperation; |
| 643 | } |
| 644 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 645 | void PixelProcessor::setStencilPassOperationCCW(StencilOperation stencilPassOperation) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 646 | { |
| 647 | context->stencilPassOperationCCW = stencilPassOperation; |
| 648 | } |
| 649 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 650 | void PixelProcessor::setStencilZFailOperationCCW(StencilOperation stencilZFailOperation) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 651 | { |
| 652 | context->stencilZFailOperationCCW = stencilZFailOperation; |
| 653 | } |
| 654 | |
| 655 | void PixelProcessor::setTextureFactor(const Color<float> &textureFactor) |
| 656 | { |
| 657 | // FIXME: Compact into generic function // FIXME: Clamp |
| 658 | short textureFactorR = iround(4095 * textureFactor.r); |
| 659 | short textureFactorG = iround(4095 * textureFactor.g); |
| 660 | short textureFactorB = iround(4095 * textureFactor.b); |
| 661 | short textureFactorA = iround(4095 * textureFactor.a); |
| 662 | |
| 663 | factor.textureFactor4[0][0] = textureFactorR; |
| 664 | factor.textureFactor4[0][1] = textureFactorR; |
| 665 | factor.textureFactor4[0][2] = textureFactorR; |
| 666 | factor.textureFactor4[0][3] = textureFactorR; |
| 667 | |
| 668 | factor.textureFactor4[1][0] = textureFactorG; |
| 669 | factor.textureFactor4[1][1] = textureFactorG; |
| 670 | factor.textureFactor4[1][2] = textureFactorG; |
| 671 | factor.textureFactor4[1][3] = textureFactorG; |
| 672 | |
| 673 | factor.textureFactor4[2][0] = textureFactorB; |
| 674 | factor.textureFactor4[2][1] = textureFactorB; |
| 675 | factor.textureFactor4[2][2] = textureFactorB; |
| 676 | factor.textureFactor4[2][3] = textureFactorB; |
| 677 | |
| 678 | factor.textureFactor4[3][0] = textureFactorA; |
| 679 | factor.textureFactor4[3][1] = textureFactorA; |
| 680 | factor.textureFactor4[3][2] = textureFactorA; |
| 681 | factor.textureFactor4[3][3] = textureFactorA; |
| 682 | } |
| 683 | |
| 684 | void PixelProcessor::setBlendConstant(const Color<float> &blendConstant) |
| 685 | { |
| 686 | // FIXME: Compact into generic function // FIXME: Clamp |
| 687 | short blendConstantR = iround(65535 * blendConstant.r); |
| 688 | short blendConstantG = iround(65535 * blendConstant.g); |
| 689 | short blendConstantB = iround(65535 * blendConstant.b); |
| 690 | short blendConstantA = iround(65535 * blendConstant.a); |
| 691 | |
| 692 | factor.blendConstant4W[0][0] = blendConstantR; |
| 693 | factor.blendConstant4W[0][1] = blendConstantR; |
| 694 | factor.blendConstant4W[0][2] = blendConstantR; |
| 695 | factor.blendConstant4W[0][3] = blendConstantR; |
| 696 | |
| 697 | factor.blendConstant4W[1][0] = blendConstantG; |
| 698 | factor.blendConstant4W[1][1] = blendConstantG; |
| 699 | factor.blendConstant4W[1][2] = blendConstantG; |
| 700 | factor.blendConstant4W[1][3] = blendConstantG; |
| 701 | |
| 702 | factor.blendConstant4W[2][0] = blendConstantB; |
| 703 | factor.blendConstant4W[2][1] = blendConstantB; |
| 704 | factor.blendConstant4W[2][2] = blendConstantB; |
| 705 | factor.blendConstant4W[2][3] = blendConstantB; |
| 706 | |
| 707 | factor.blendConstant4W[3][0] = blendConstantA; |
| 708 | factor.blendConstant4W[3][1] = blendConstantA; |
| 709 | factor.blendConstant4W[3][2] = blendConstantA; |
| 710 | factor.blendConstant4W[3][3] = blendConstantA; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 711 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 712 | // FIXME: Compact into generic function // FIXME: Clamp |
| 713 | short invBlendConstantR = iround(65535 * (1 - blendConstant.r)); |
| 714 | short invBlendConstantG = iround(65535 * (1 - blendConstant.g)); |
| 715 | short invBlendConstantB = iround(65535 * (1 - blendConstant.b)); |
| 716 | short invBlendConstantA = iround(65535 * (1 - blendConstant.a)); |
| 717 | |
| 718 | factor.invBlendConstant4W[0][0] = invBlendConstantR; |
| 719 | factor.invBlendConstant4W[0][1] = invBlendConstantR; |
| 720 | factor.invBlendConstant4W[0][2] = invBlendConstantR; |
| 721 | factor.invBlendConstant4W[0][3] = invBlendConstantR; |
| 722 | |
| 723 | factor.invBlendConstant4W[1][0] = invBlendConstantG; |
| 724 | factor.invBlendConstant4W[1][1] = invBlendConstantG; |
| 725 | factor.invBlendConstant4W[1][2] = invBlendConstantG; |
| 726 | factor.invBlendConstant4W[1][3] = invBlendConstantG; |
| 727 | |
| 728 | factor.invBlendConstant4W[2][0] = invBlendConstantB; |
| 729 | factor.invBlendConstant4W[2][1] = invBlendConstantB; |
| 730 | factor.invBlendConstant4W[2][2] = invBlendConstantB; |
| 731 | factor.invBlendConstant4W[2][3] = invBlendConstantB; |
| 732 | |
| 733 | factor.invBlendConstant4W[3][0] = invBlendConstantA; |
| 734 | factor.invBlendConstant4W[3][1] = invBlendConstantA; |
| 735 | factor.invBlendConstant4W[3][2] = invBlendConstantA; |
| 736 | factor.invBlendConstant4W[3][3] = invBlendConstantA; |
| 737 | |
| 738 | factor.blendConstant4F[0][0] = blendConstant.r; |
| 739 | factor.blendConstant4F[0][1] = blendConstant.r; |
| 740 | factor.blendConstant4F[0][2] = blendConstant.r; |
| 741 | factor.blendConstant4F[0][3] = blendConstant.r; |
| 742 | |
| 743 | factor.blendConstant4F[1][0] = blendConstant.g; |
| 744 | factor.blendConstant4F[1][1] = blendConstant.g; |
| 745 | factor.blendConstant4F[1][2] = blendConstant.g; |
| 746 | factor.blendConstant4F[1][3] = blendConstant.g; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 747 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 748 | factor.blendConstant4F[2][0] = blendConstant.b; |
| 749 | factor.blendConstant4F[2][1] = blendConstant.b; |
| 750 | factor.blendConstant4F[2][2] = blendConstant.b; |
| 751 | factor.blendConstant4F[2][3] = blendConstant.b; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 752 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 753 | factor.blendConstant4F[3][0] = blendConstant.a; |
| 754 | factor.blendConstant4F[3][1] = blendConstant.a; |
| 755 | factor.blendConstant4F[3][2] = blendConstant.a; |
| 756 | factor.blendConstant4F[3][3] = blendConstant.a; |
| 757 | |
| 758 | factor.invBlendConstant4F[0][0] = 1 - blendConstant.r; |
| 759 | factor.invBlendConstant4F[0][1] = 1 - blendConstant.r; |
| 760 | factor.invBlendConstant4F[0][2] = 1 - blendConstant.r; |
| 761 | factor.invBlendConstant4F[0][3] = 1 - blendConstant.r; |
| 762 | |
| 763 | factor.invBlendConstant4F[1][0] = 1 - blendConstant.g; |
| 764 | factor.invBlendConstant4F[1][1] = 1 - blendConstant.g; |
| 765 | factor.invBlendConstant4F[1][2] = 1 - blendConstant.g; |
| 766 | factor.invBlendConstant4F[1][3] = 1 - blendConstant.g; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 767 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 768 | factor.invBlendConstant4F[2][0] = 1 - blendConstant.b; |
| 769 | factor.invBlendConstant4F[2][1] = 1 - blendConstant.b; |
| 770 | factor.invBlendConstant4F[2][2] = 1 - blendConstant.b; |
| 771 | factor.invBlendConstant4F[2][3] = 1 - blendConstant.b; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 772 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 773 | factor.invBlendConstant4F[3][0] = 1 - blendConstant.a; |
| 774 | factor.invBlendConstant4F[3][1] = 1 - blendConstant.a; |
| 775 | factor.invBlendConstant4F[3][2] = 1 - blendConstant.a; |
| 776 | factor.invBlendConstant4F[3][3] = 1 - blendConstant.a; |
| 777 | } |
| 778 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 779 | void PixelProcessor::setFillMode(FillMode fillMode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 780 | { |
| 781 | context->fillMode = fillMode; |
| 782 | } |
| 783 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 784 | void PixelProcessor::setShadingMode(ShadingMode shadingMode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 785 | { |
| 786 | context->shadingMode = shadingMode; |
| 787 | } |
| 788 | |
| 789 | void PixelProcessor::setAlphaBlendEnable(bool alphaBlendEnable) |
| 790 | { |
| 791 | context->setAlphaBlendEnable(alphaBlendEnable); |
| 792 | } |
| 793 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 794 | void PixelProcessor::setSourceBlendFactor(BlendFactor sourceBlendFactor) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 795 | { |
| 796 | context->setSourceBlendFactor(sourceBlendFactor); |
| 797 | } |
| 798 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 799 | void PixelProcessor::setDestBlendFactor(BlendFactor destBlendFactor) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 800 | { |
| 801 | context->setDestBlendFactor(destBlendFactor); |
| 802 | } |
| 803 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 804 | void PixelProcessor::setBlendOperation(BlendOperation blendOperation) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 805 | { |
| 806 | context->setBlendOperation(blendOperation); |
| 807 | } |
| 808 | |
| 809 | void PixelProcessor::setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable) |
| 810 | { |
| 811 | context->setSeparateAlphaBlendEnable(separateAlphaBlendEnable); |
| 812 | } |
| 813 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 814 | void PixelProcessor::setSourceBlendFactorAlpha(BlendFactor sourceBlendFactorAlpha) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 815 | { |
| 816 | context->setSourceBlendFactorAlpha(sourceBlendFactorAlpha); |
| 817 | } |
| 818 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 819 | void PixelProcessor::setDestBlendFactorAlpha(BlendFactor destBlendFactorAlpha) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 820 | { |
| 821 | context->setDestBlendFactorAlpha(destBlendFactorAlpha); |
| 822 | } |
| 823 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 824 | void PixelProcessor::setBlendOperationAlpha(BlendOperation blendOperationAlpha) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 825 | { |
| 826 | context->setBlendOperationAlpha(blendOperationAlpha); |
| 827 | } |
| 828 | |
Alexis Hetu | a818c45 | 2015-06-11 13:06:58 -0400 | [diff] [blame] | 829 | void PixelProcessor::setAlphaReference(float alphaReference) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 830 | { |
| 831 | context->alphaReference = alphaReference; |
| 832 | |
Alexis Hetu | a818c45 | 2015-06-11 13:06:58 -0400 | [diff] [blame] | 833 | factor.alphaReference4[0] = (word)iround(alphaReference * 0x1000 / 0xFF); |
| 834 | factor.alphaReference4[1] = (word)iround(alphaReference * 0x1000 / 0xFF); |
| 835 | factor.alphaReference4[2] = (word)iround(alphaReference * 0x1000 / 0xFF); |
| 836 | factor.alphaReference4[3] = (word)iround(alphaReference * 0x1000 / 0xFF); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | void PixelProcessor::setGlobalMipmapBias(float bias) |
| 840 | { |
| 841 | context->setGlobalMipmapBias(bias); |
| 842 | } |
| 843 | |
| 844 | void PixelProcessor::setFogStart(float start) |
| 845 | { |
| 846 | setFogRanges(start, context->fogEnd); |
| 847 | } |
| 848 | |
| 849 | void PixelProcessor::setFogEnd(float end) |
| 850 | { |
| 851 | setFogRanges(context->fogStart, end); |
| 852 | } |
| 853 | |
| 854 | void PixelProcessor::setFogColor(Color<float> fogColor) |
| 855 | { |
| 856 | // TODO: Compact into generic function |
| 857 | word fogR = (unsigned short)(65535 * fogColor.r); |
| 858 | word fogG = (unsigned short)(65535 * fogColor.g); |
| 859 | word fogB = (unsigned short)(65535 * fogColor.b); |
| 860 | |
| 861 | fog.color4[0][0] = fogR; |
| 862 | fog.color4[0][1] = fogR; |
| 863 | fog.color4[0][2] = fogR; |
| 864 | fog.color4[0][3] = fogR; |
| 865 | |
| 866 | fog.color4[1][0] = fogG; |
| 867 | fog.color4[1][1] = fogG; |
| 868 | fog.color4[1][2] = fogG; |
| 869 | fog.color4[1][3] = fogG; |
| 870 | |
| 871 | fog.color4[2][0] = fogB; |
| 872 | fog.color4[2][1] = fogB; |
| 873 | fog.color4[2][2] = fogB; |
| 874 | fog.color4[2][3] = fogB; |
| 875 | |
| 876 | fog.colorF[0] = replicate(fogColor.r); |
| 877 | fog.colorF[1] = replicate(fogColor.g); |
| 878 | fog.colorF[2] = replicate(fogColor.b); |
| 879 | } |
| 880 | |
| 881 | void PixelProcessor::setFogDensity(float fogDensity) |
| 882 | { |
| 883 | fog.densityE = replicate(-fogDensity * 1.442695f); // 1/e^x = 2^(-x*1.44) |
Nicolas Capens | a36f3f9 | 2015-08-04 15:34:26 -0400 | [diff] [blame] | 884 | fog.density2E = replicate(-fogDensity * fogDensity * 1.442695f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 885 | } |
| 886 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 887 | void PixelProcessor::setPixelFogMode(FogMode fogMode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 888 | { |
| 889 | context->pixelFogMode = fogMode; |
| 890 | } |
| 891 | |
| 892 | void PixelProcessor::setPerspectiveCorrection(bool perspectiveEnable) |
| 893 | { |
| 894 | perspectiveCorrection = perspectiveEnable; |
| 895 | } |
| 896 | |
| 897 | void PixelProcessor::setOcclusionEnabled(bool enable) |
| 898 | { |
| 899 | context->occlusionEnabled = enable; |
| 900 | } |
| 901 | |
| 902 | void PixelProcessor::setRoutineCacheSize(int cacheSize) |
| 903 | { |
| 904 | delete routineCache; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 905 | routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536), precachePixel ? "sw-pixel" : 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | void PixelProcessor::setFogRanges(float start, float end) |
| 909 | { |
| 910 | context->fogStart = start; |
| 911 | context->fogEnd = end; |
| 912 | |
| 913 | if(start == end) |
| 914 | { |
| 915 | end += 0.001f; // Hack: ensure there is a small range |
| 916 | } |
| 917 | |
| 918 | float fogScale = -1.0f / (end - start); |
| 919 | float fogOffset = end * -fogScale; |
| 920 | |
| 921 | fog.scale = replicate(fogScale); |
| 922 | fog.offset = replicate(fogOffset); |
| 923 | } |
| 924 | |
| 925 | const PixelProcessor::State PixelProcessor::update() const |
| 926 | { |
| 927 | State state; |
| 928 | |
| 929 | if(context->pixelShader) |
| 930 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 931 | state.shaderID = context->pixelShader->getSerialID(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 932 | } |
| 933 | else |
| 934 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 935 | state.shaderID = 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | state.depthOverride = context->pixelShader && context->pixelShader->depthOverride(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 939 | state.shaderContainsKill = context->pixelShader ? context->pixelShader->containsKill() : false; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 940 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 941 | if(context->alphaTestActive()) |
| 942 | { |
| 943 | state.alphaCompareMode = context->alphaCompareMode; |
| 944 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 945 | state.transparencyAntialiasing = context->getMultiSampleCount() > 1 ? transparencyAntialiasing : TRANSPARENCY_NONE; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | state.depthWriteEnable = context->depthWriteActive(); |
| 949 | |
| 950 | if(context->stencilActive()) |
| 951 | { |
| 952 | state.stencilActive = true; |
| 953 | state.stencilCompareMode = context->stencilCompareMode; |
| 954 | state.stencilFailOperation = context->stencilFailOperation; |
| 955 | state.stencilPassOperation = context->stencilPassOperation; |
| 956 | state.stencilZFailOperation = context->stencilZFailOperation; |
| 957 | state.noStencilMask = (context->stencilMask == 0xFF); |
| 958 | state.noStencilWriteMask = (context->stencilWriteMask == 0xFF); |
| 959 | state.stencilWriteMasked = (context->stencilWriteMask == 0x00); |
| 960 | |
| 961 | state.twoSidedStencil = context->twoSidedStencil; |
| 962 | state.stencilCompareModeCCW = context->twoSidedStencil ? context->stencilCompareModeCCW : state.stencilCompareMode; |
| 963 | state.stencilFailOperationCCW = context->twoSidedStencil ? context->stencilFailOperationCCW : state.stencilFailOperation; |
| 964 | state.stencilPassOperationCCW = context->twoSidedStencil ? context->stencilPassOperationCCW : state.stencilPassOperation; |
| 965 | state.stencilZFailOperationCCW = context->twoSidedStencil ? context->stencilZFailOperationCCW : state.stencilZFailOperation; |
| 966 | state.noStencilMaskCCW = context->twoSidedStencil ? (context->stencilMaskCCW == 0xFF) : state.noStencilMask; |
| 967 | state.noStencilWriteMaskCCW = context->twoSidedStencil ? (context->stencilWriteMaskCCW == 0xFF) : state.noStencilWriteMask; |
| 968 | state.stencilWriteMaskedCCW = context->twoSidedStencil ? (context->stencilWriteMaskCCW == 0x00) : state.stencilWriteMasked; |
| 969 | } |
| 970 | |
| 971 | if(context->depthBufferActive()) |
| 972 | { |
| 973 | state.depthTestActive = true; |
| 974 | state.depthCompareMode = context->depthCompareMode; |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 975 | state.quadLayoutDepthBuffer = context->depthBuffer->getInternalFormat() != FORMAT_D32F_LOCKABLE && |
| 976 | context->depthBuffer->getInternalFormat() != FORMAT_D32FS8_TEXTURE && |
| 977 | context->depthBuffer->getInternalFormat() != FORMAT_D32FS8_SHADOW; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | state.occlusionEnabled = context->occlusionEnabled; |
| 981 | |
| 982 | state.fogActive = context->fogActive(); |
| 983 | state.pixelFogMode = context->pixelFogActive(); |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 984 | state.wBasedFog = context->wBasedFog && context->pixelFogActive() != FOG_NONE; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 985 | state.perspective = context->perspectiveActive(); |
| 986 | |
| 987 | if(context->alphaBlendActive()) |
| 988 | { |
| 989 | state.alphaBlendActive = true; |
| 990 | state.sourceBlendFactor = context->sourceBlendFactor(); |
| 991 | state.destBlendFactor = context->destBlendFactor(); |
| 992 | state.blendOperation = context->blendOperation(); |
| 993 | state.sourceBlendFactorAlpha = context->sourceBlendFactorAlpha(); |
| 994 | state.destBlendFactorAlpha = context->destBlendFactorAlpha(); |
| 995 | state.blendOperationAlpha = context->blendOperationAlpha(); |
| 996 | } |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 997 | |
| 998 | state.logicalOperation = context->colorLogicOp(); |
| 999 | |
Alexis Hetu | 1edcd8b | 2015-11-05 11:12:41 -0500 | [diff] [blame] | 1000 | for(int i = 0; i < RENDERTARGETS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1001 | { |
Nicolas Capens | c98186a | 2016-04-18 12:07:22 -0400 | [diff] [blame] | 1002 | state.colorWriteMask |= context->colorWriteActive(i) << (4 * i); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1003 | state.targetFormat[i] = context->renderTargetInternalFormat(i); |
| 1004 | } |
| 1005 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1006 | state.writeSRGB = context->writeSRGB && context->renderTarget[0] && Surface::isSRGBwritable(context->renderTarget[0]->getExternalFormat()); |
| 1007 | state.multiSample = context->getMultiSampleCount(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1008 | state.multiSampleMask = context->multiSampleMask; |
| 1009 | |
| 1010 | if(state.multiSample > 1 && context->pixelShader) |
| 1011 | { |
| 1012 | state.centroid = context->pixelShader->containsCentroid(); |
| 1013 | } |
| 1014 | |
| 1015 | if(!context->pixelShader) |
| 1016 | { |
| 1017 | for(unsigned int i = 0; i < 8; i++) |
| 1018 | { |
| 1019 | state.textureStage[i] = context->textureStage[i].textureStageState(); |
| 1020 | } |
| 1021 | |
| 1022 | state.specularAdd = context->specularActive() && context->specularEnable; |
| 1023 | } |
| 1024 | |
| 1025 | for(unsigned int i = 0; i < 16; i++) |
| 1026 | { |
| 1027 | if(context->pixelShader) |
| 1028 | { |
| 1029 | if(context->pixelShader->usesSampler(i)) |
| 1030 | { |
| 1031 | state.sampler[i] = context->sampler[i].samplerState(); |
| 1032 | } |
| 1033 | } |
| 1034 | else |
| 1035 | { |
| 1036 | if(i < 8 && state.textureStage[i].stageOperation != TextureStage::STAGE_DISABLE) |
| 1037 | { |
| 1038 | state.sampler[i] = context->sampler[i].samplerState(); |
| 1039 | } |
| 1040 | else break; |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | const bool point = context->isDrawPoint(true); |
| 1045 | const bool sprite = context->pointSpriteActive(); |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1046 | const bool flatShading = (context->shadingMode == SHADING_FLAT) || point; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1047 | |
| 1048 | if(context->pixelShaderVersion() < 0x0300) |
| 1049 | { |
| 1050 | for(int coordinate = 0; coordinate < 8; coordinate++) |
| 1051 | { |
| 1052 | for(int component = 0; component < 4; component++) |
| 1053 | { |
| 1054 | if(context->textureActive(coordinate, component)) |
| 1055 | { |
| 1056 | state.texture[coordinate].component |= 1 << component; |
| 1057 | |
| 1058 | if(point && !sprite) |
| 1059 | { |
| 1060 | state.texture[coordinate].flat |= 1 << component; |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | if(context->textureTransformProject[coordinate] && context->pixelShaderVersion() <= 0x0103) |
| 1066 | { |
| 1067 | if(context->textureTransformCount[coordinate] == 2) |
| 1068 | { |
| 1069 | state.texture[coordinate].project = 1; |
| 1070 | } |
| 1071 | else if(context->textureTransformCount[coordinate] == 3) |
| 1072 | { |
| 1073 | state.texture[coordinate].project = 2; |
| 1074 | } |
| 1075 | else if(context->textureTransformCount[coordinate] == 4 || context->textureTransformCount[coordinate] == 0) |
| 1076 | { |
| 1077 | state.texture[coordinate].project = 3; |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | for(int color = 0; color < 2; color++) |
| 1083 | { |
| 1084 | for(int component = 0; component < 4; component++) |
| 1085 | { |
| 1086 | if(context->colorActive(color, component)) |
| 1087 | { |
| 1088 | state.color[color].component |= 1 << component; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 1089 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1090 | if(point || flatShading) |
| 1091 | { |
| 1092 | state.color[color].flat |= 1 << component; |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | if(context->fogActive()) |
| 1099 | { |
| 1100 | state.fog.component = true; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 1101 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1102 | if(point) |
| 1103 | { |
| 1104 | state.fog.flat = true; |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | else |
| 1109 | { |
Nicolas Capens | 3b4c93f | 2016-05-18 12:51:37 -0400 | [diff] [blame] | 1110 | for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1111 | { |
| 1112 | for(int component = 0; component < 4; component++) |
| 1113 | { |
Alexis Hetu | 12b0050 | 2016-05-20 13:01:11 -0400 | [diff] [blame] | 1114 | const Shader::Semantic &semantic = context->pixelShader->semantic[interpolant][component]; |
| 1115 | |
| 1116 | if(semantic.active()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1117 | { |
| 1118 | bool flat = point; |
| 1119 | |
Alexis Hetu | 12b0050 | 2016-05-20 13:01:11 -0400 | [diff] [blame] | 1120 | switch(semantic.usage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1121 | { |
Alexis Hetu | 12b0050 | 2016-05-20 13:01:11 -0400 | [diff] [blame] | 1122 | case Shader::USAGE_TEXCOORD: flat = point && !sprite; break; |
| 1123 | case Shader::USAGE_COLOR: flat = semantic.flat || flatShading; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | state.interpolant[interpolant].component |= 1 << component; |
| 1127 | |
| 1128 | if(flat) |
| 1129 | { |
| 1130 | state.interpolant[interpolant].flat |= 1 << component; |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | if(state.centroid) |
| 1138 | { |
Nicolas Capens | 3b4c93f | 2016-05-18 12:51:37 -0400 | [diff] [blame] | 1139 | for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1140 | { |
| 1141 | for(int component = 0; component < 4; component++) |
| 1142 | { |
| 1143 | state.interpolant[interpolant].centroid = context->pixelShader->semantic[interpolant][0].centroid; |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | state.hash = state.computeHash(); |
| 1149 | |
| 1150 | return state; |
| 1151 | } |
| 1152 | |
| 1153 | Routine *PixelProcessor::routine(const State &state) |
| 1154 | { |
| 1155 | Routine *routine = routineCache->query(state); |
| 1156 | |
| 1157 | if(!routine) |
| 1158 | { |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame] | 1159 | const bool integerPipeline = (context->pixelShaderVersion() <= 0x0104); |
Nicolas Capens | ba53fbf | 2016-01-14 13:43:42 -0500 | [diff] [blame] | 1160 | QuadRasterizer *generator = nullptr; |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 1161 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame] | 1162 | if(integerPipeline) |
| 1163 | { |
| 1164 | generator = new PixelPipeline(state, context->pixelShader); |
| 1165 | } |
| 1166 | else |
| 1167 | { |
| 1168 | generator = new PixelProgram(state, context->pixelShader); |
| 1169 | } |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 1170 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1171 | generator->generate(); |
Nicolas Capens | 4f172c7 | 2016-01-13 08:34:30 -0500 | [diff] [blame] | 1172 | routine = (*generator)(L"PixelRoutine_%0.8X", state.shaderID); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1173 | delete generator; |
| 1174 | |
| 1175 | routineCache->add(state, routine); |
| 1176 | } |
| 1177 | |
| 1178 | return routine; |
| 1179 | } |
| 1180 | } |