RGBA RGBA::operator*=(float factor) { r = GLubyte(round(factor* float(r))); g = GLubyte(round(factor* float(g))); b = GLubyte(round(factor* float(b))); return *this; }
Doom3TextureManager::ImageID Doom3TextureManager::computeMakeAlpha(const Doom3TextureManager::ImageID& source) { /* Get a reference to the source image: */ const Images::RGBAImage& sourceImage=imageTree.getLeafValue(source).image; /* Store a new image structure in the image tree: */ ImageID resultId=imageTree.insertLeaf(Misc::stringPrintf("/_computedTextures/tex%06d",numTextures).c_str(),Image()); Image& result=imageTree.getLeafValue(resultId); Images::RGBAImage& resultImage=result.image; result.textureIndex=numTextures; ++numTextures; /* Compute the result image's pixels: */ resultImage=Images::RGBAImage(sourceImage.getWidth(),sourceImage.getHeight()); for(unsigned int y=0;y<resultImage.getHeight();++y) { const Images::RGBAImage::Color* sourceRow=sourceImage.getPixelRow(y); Images::RGBAImage::Color* destRow=resultImage.modifyPixelRow(y); for(unsigned int x=0;x<resultImage.getWidth();++x) { unsigned int sum=0U; for(int i=0;i<3;++i) { sum+=sourceRow[x][i]; destRow[x][i]=GLubyte(255); } destRow[x][3]=GLubyte((sum+2U)/3U); } } /* Return the result image ID: */ return resultId; }
static void _apply_gradient( Combine combine, const std::vector<Vector<T, N>>& grad0, const std::vector<Vector<T, N>>& grad1, const std::vector<Vector<T, N>>& grad2, GLubyte* dp, GLubyte* de ) { auto gb0 = grad0.begin(), ge0 = grad0.end(); auto gb1 = grad1.begin(), ge1 = grad1.end(); auto gb2 = grad2.begin(), ge2 = grad2.end(); for(auto gp0=gb0; gp0!=ge0; ++gp0) for(auto gp1=gb1; gp1!=ge1; ++gp1) for(auto gp2=gb2; gp2!=ge2; ++gp2) { Vector<T, N> color = combine(*gp0, *gp1, *gp2); for(std::size_t c=0; c!=N; ++c) { assert(dp != de); *dp++ = GLubyte(_clamp(color.At(c))*_cc_max()); } } OGLPLUS_FAKE_USE(de); assert(dp == de); }
/// Creates a cloud image of given @p width, @p height and @p depth Cloud( GLsizei width, GLsizei height, GLsizei depth, const Vec3f& origin = Vec3f(0.0f, -0.3f, 0.0f), GLfloat init_radius = 0.7f, GLfloat sub_scale = 0.333f, GLfloat sub_variance = 0.5f, GLfloat min_radius = 0.04f ): Image(width, height, depth, 1, (GLubyte*)0) , _sub_scale(sub_scale) , _sub_variance(sub_variance) , _min_radius(min_radius) { auto p = this->_begin_ub(), e = this->_end_ub(); for(GLsizei k=0; k!=depth; ++k) for(GLsizei j=0; j!=height; ++j) for(GLsizei i=0; i!=width; ++i) { assert(p != e); *p = GLubyte(0); ++p; } OGLPLUS_FAKE_USE(e); assert(p == e); _make_spheres(origin, init_radius); }
/* Smooth-shaded, RGBA line with Z interpolation/testing */ static void smooth_rgba_z_line( GLcontext *ctx, GLuint vert0, GLuint vert1, GLuint pvert ) { GLint count = ctx->PB->count; GLint *pbx = ctx->PB->x; GLint *pby = ctx->PB->y; GLdepth *pbz = ctx->PB->z; GLubyte (*pbrgba)[4] = ctx->PB->rgba; (void) pvert; #define INTERP_XY 1 #define INTERP_Z 1 #define INTERP_RGB 1 #define INTERP_ALPHA 1 #define PLOT(X,Y) \ pbx[count] = X; \ pby[count] = Y; \ pbz[count] = Z; \ pbrgba[count][RCOMP] = FixedToInt(r0); \ pbrgba[count][GCOMP] = FixedToInt(g0); \ pbrgba[count][BCOMP] = FixedToInt(b0); \ pbrgba[count][ACOMP] = FixedToInt(a0); \ count++; #include "linetemp.h" ctx->PB->count = count; gl_flush_pb(ctx); }
void operator()(cubic_to_t, point_t const& pt1, point_t const& pt2, point_t const& pt3) { commands.push_back(GLubyte(GL_CUBIC_CURVE_TO_NV)); points.push_back(pt1); points.push_back(pt2); points.push_back(pt3); }
bool _apply_sphere(const Vec3f& center, GLfloat radius) { assert(radius > 0.0f); bool something_updated = false; Vec3f c = center*0.5f + Vec3f(0.5f, 0.5f, 0.5f); GLfloat r = radius*0.5f; GLsizei w = Width(), h = Height(), d = Depth(); GLubyte* data = _begin_ub(); for(GLsizei k=(c.z()-r)*d, ke=(c.z()+r)*d; k!=ke; ++k) for(GLsizei j=(c.y()-r)*h, je=(c.y()+r)*h; j!=je; ++j) for(GLsizei i=(c.x()-r)*w, ie=(c.x()+r)*w; i!=ie; ++i) { assert(k >= 0 && k < d); assert(j >= 0 && j < h); assert(i >= 0 && i < w); GLsizei n = k*w*h + j*w + i; GLubyte b = data[n]; if(b != 0xFF) { GLfloat cd = GLfloat(b)/GLfloat(0xFF); Vec3f p(GLfloat(i)/w, GLfloat(j)/h, GLfloat(k)/d); GLfloat nd = (r - Distance(c, p))/r; if(nd < 0.0f) nd = 0.0f; nd = std::sqrt(nd); nd += cd; if(nd > 1.0f) nd = 1.0f; data[n] = GLubyte(0xFF * nd); something_updated = true; } } return something_updated; }
/** * Apply antialiasing coverage value to alpha values. */ static inline void apply_aa_coverage(SWspan *span) { const GLfloat *coverage = span->array->coverage; GLuint i; if (span->array->ChanType == GL_UNSIGNED_BYTE) { GLubyte (*rgba)[4] = span->array->rgba8; for (i = 0; i < span->end; i++) { const GLfloat a = rgba[i][ACOMP] * coverage[i]; rgba[i][ACOMP] = (GLubyte) CLAMP(a, 0.0, 255.0); ASSERT(coverage[i] >= 0.0); ASSERT(coverage[i] <= 1.0); } } else if (span->array->ChanType == GL_UNSIGNED_SHORT) { GLushort (*rgba)[4] = span->array->rgba16; for (i = 0; i < span->end; i++) { const GLfloat a = rgba[i][ACOMP] * coverage[i]; rgba[i][ACOMP] = (GLushort) CLAMP(a, 0.0, 65535.0); } } else { GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL]; for (i = 0; i < span->end; i++) { rgba[i][ACOMP] = rgba[i][ACOMP] * coverage[i]; /* clamp later */ } } }
void PizzaSpeedLevel::showInstructions() { Size visibleSize = Director::getInstance()->getVisibleSize(); Label* label1 = Label::createWithTTF("2Antes de poder ser rey, \nel príncipe Tonthor\ndebe conocer a sus súbditos\ny poder ayudarlos\na resolver sus problemas.", font, 60); Label* label2 = Label::createWithTTF("En medio del espacio,\nel repartidor de pizza \nse mueve a velocidad constante. \nDesde la pizzería hasta su destino \nse mueve en una perfecta línea recta.", font, 60); Label* label3 = Label::createWithTTF("Si la pizza llega a su destino \nen más de 5 segundos \nestará demasiado fría para comer, \npero si tarda menos de 3, \nestará demasiado caliente. \nEl tiempo perfecto son 4 segundos.", font, 60); Label* label4 = Label::createWithTTF("si la distancia entre la pizzería \ny el sitio de la entrega son 4km \n¿a qué velocidad debe viajar \nel repartidor de pizza para que \nla pizza llega lo mejor posible?" , font, 60); Label* labels [4] = {label1, label2, label3, label4}; auto intro = FadeIn::create(_defaultActionTime); auto delay = DelayTime::create(_defaultActionTime); auto outro = FadeOut::create(_defaultActionTime); for(int i = 0; i<4 ; i++) { labels[i]->setPosition(visibleSize.width/2,visibleSize.height/2); labels[i]->setOpacity(GLubyte(0)); labels[i]->runAction(Sequence::create(DelayTime::create(i*3*_defaultActionTime) ,intro,delay,outro,nullptr)); this->addChild(labels[i]); } }
void HpGrayOut::update(float time) { HpLightProtocol *pLightProtocol = dynamic_cast<HpLightProtocol*>(getTarget()); if (pLightProtocol) { pLightProtocol->setGray(GLubyte(255 * (1 - time))); } }
void CCFadeOut::update(cocos2d::ccTime time) { CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); if (pRGBAProtocol) { pRGBAProtocol->setOpacity(GLubyte(255 * (1 - time))); } /*m_pTarget->setOpacity(GLubyte(255 * (1 - time)));*/ }
void CCFadeOut::update(ccTime time) { CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(m_pTarget); if (pRGBAProtocol) { pRGBAProtocol->setOpacity(GLubyte(255 * (1 - time))); } /*m_pTarget->setOpacity(GLubyte(255 * (1 - time)));*/ }
void FadeOut::update(float time) { RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(_target); if (pRGBAProtocol) { pRGBAProtocol->setOpacity(GLubyte(255 * (1 - time))); } /*_target->setOpacity(GLubyte(255 * (1 - time)));*/ }
void PizzaSpeedLevel::addSpaceShip(std::string file) { _spaceShip = Sprite::create(file); _spaceShip->setPosition(_startPoint); _spaceShip->setOpacity(GLubyte(0)); _spaceShip->runAction(Sequence::create(DelayTime::create(_defaultActionTime*12),FadeIn::create(_defaultActionTime),nullptr)); this->addChild(_spaceShip); }
void CCTintTo::update(ccTime time) { CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(m_pTarget); if (pRGBAProtocol) { pRGBAProtocol->setColor(ccc3(GLubyte(m_from.r + (m_to.r - m_from.r) * time), (GLbyte)(m_from.g + (m_to.g - m_from.g) * time), (GLbyte)(m_from.b + (m_to.b - m_from.b) * time))); } }
void TintTo::update(float time) { RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(_target); if (pRGBAProtocol) { pRGBAProtocol->setColor(Color3B(GLubyte(_from.r + (_to.r - _from.r) * time), (GLubyte)(_from.g + (_to.g - _from.g) * time), (GLubyte)(_from.b + (_to.b - _from.b) * time))); } }
void CCTintTo::update(cocos2d::ccTime time) { CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); if (pRGBAProtocol) { pRGBAProtocol->setColor(ccc3(GLubyte(m_from.r + (m_to.r - m_from.r) * time), (GLbyte)(m_from.g + (m_to.g - m_from.g) * time), (GLbyte)(m_from.b + (m_to.b - m_from.b) * time))); } }
void HpShineTo::update(float time) { HpLightProtocol *lightProtocol = dynamic_cast<HpLightProtocol*>(getTarget()); if (lightProtocol) { lightProtocol->setLight(Color3B(GLubyte(m_from.r + (m_to.r - m_from.r) * time), (GLbyte)(m_from.g + (m_to.g - m_from.g) * time), (GLbyte)(m_from.b + (m_to.b - m_from.b) * time))); } }
void PizzaSpeedLevel::addBackground(std::string file) { Size visibleSize = Director::getInstance()->getVisibleSize(); Sprite* background = Sprite::create(file); background->setPosition( visibleSize.width/2 , visibleSize.height/2); background->setOpacity(GLubyte(0)); background->runAction(Sequence::create(DelayTime::create(_defaultActionTime*12),FadeIn::create(_defaultActionTime), nullptr)); this->addChild(background); }
Doom3TextureManager::ImageID Doom3TextureManager::computeAdd(const Doom3TextureManager::ImageID& source1,const Doom3TextureManager::ImageID& source2) { /* Get a reference to the source images: */ const Images::RGBAImage& source1Image=imageTree.getLeafValue(source1).image; Images::RGBAImage source2Image=imageTree.getLeafValue(source2).image; if(source1Image.getWidth()!=source2Image.getWidth()||source1Image.getHeight()!=source2Image.getHeight()) { /* Resample the second image to match the first image's size: */ source2Image.resize(source1Image.getWidth(),source1Image.getHeight()); } /* Store a new image structure in the image tree: */ ImageID resultId=imageTree.insertLeaf(Misc::stringPrintf("/_computedTextures/tex%06d",numTextures).c_str(),Image()); Image& result=imageTree.getLeafValue(resultId); Images::RGBAImage& resultImage=result.image; result.textureIndex=numTextures; ++numTextures; /* Compute the result image's pixels: */ resultImage=Images::RGBAImage(source1Image.getWidth(),source1Image.getHeight()); for(unsigned int y=0;y<resultImage.getHeight();++y) { const Images::RGBAImage::Color* source1Row=source1Image.getPixelRow(y); const Images::RGBAImage::Color* source2Row=source2Image.getPixelRow(y); Images::RGBAImage::Color* destRow=resultImage.modifyPixelRow(y); for(unsigned int x=0;x<resultImage.getWidth();++x) { for(int i=0;i<3;++i) { unsigned int sum=(unsigned int)(source1Row[x][i])+(unsigned int)(source2Row[x][i]); if(sum>=255) destRow[x][i]=GLubyte(255); else destRow[x][i]=GLubyte(sum); } } } /* Return the result image ID: */ return resultId; }
Color SFColor::parse(VRMLParser& parser) { Color result(0,0,0,255); for(int i=0;i<3;++i) { /* Parse the current token: */ double val=atof(parser.getToken()); if(val<0.0) result[i]=GLubyte(0); else if(val>1.0) result[i]=GLubyte(255); else result[i]=GLubyte(Math::floor(val*255.0+0.5)); /* Go to the next token: */ parser.getNextToken(); } return result; }
/** * Bilinear interpolation of two source rows. * GLubyte pixels. */ static void resample_linear_row_ub(GLint srcWidth, GLint dstWidth, const GLvoid *srcBuffer0, const GLvoid *srcBuffer1, GLvoid *dstBuffer, GLboolean flip, GLfloat rowWeight) { const GLubyte (*srcColor0)[4] = (const GLubyte (*)[4]) srcBuffer0; const GLubyte (*srcColor1)[4] = (const GLubyte (*)[4]) srcBuffer1; GLubyte (*dstColor)[4] = (GLubyte (*)[4]) dstBuffer; const GLfloat dstWidthF = (GLfloat) dstWidth; GLint dstCol; for (dstCol = 0; dstCol < dstWidth; dstCol++) { const GLfloat srcCol = (dstCol * srcWidth) / dstWidthF; GLint srcCol0 = IFLOOR(srcCol); GLint srcCol1 = srcCol0 + 1; GLfloat colWeight = srcCol - srcCol0; /* fractional part of srcCol */ GLfloat red, green, blue, alpha; ASSERT(srcCol0 >= 0); ASSERT(srcCol0 < srcWidth); ASSERT(srcCol1 <= srcWidth); if (srcCol1 == srcWidth) { /* last column fudge */ srcCol1--; colWeight = 0.0; } if (flip) { srcCol0 = srcWidth - 1 - srcCol0; srcCol1 = srcWidth - 1 - srcCol1; } red = lerp_2d(colWeight, rowWeight, srcColor0[srcCol0][RCOMP], srcColor0[srcCol1][RCOMP], srcColor1[srcCol0][RCOMP], srcColor1[srcCol1][RCOMP]); green = lerp_2d(colWeight, rowWeight, srcColor0[srcCol0][GCOMP], srcColor0[srcCol1][GCOMP], srcColor1[srcCol0][GCOMP], srcColor1[srcCol1][GCOMP]); blue = lerp_2d(colWeight, rowWeight, srcColor0[srcCol0][BCOMP], srcColor0[srcCol1][BCOMP], srcColor1[srcCol0][BCOMP], srcColor1[srcCol1][BCOMP]); alpha = lerp_2d(colWeight, rowWeight, srcColor0[srcCol0][ACOMP], srcColor0[srcCol1][ACOMP], srcColor1[srcCol0][ACOMP], srcColor1[srcCol1][ACOMP]); dstColor[dstCol][RCOMP] = IFLOOR(red); dstColor[dstCol][GCOMP] = IFLOOR(green); dstColor[dstCol][BCOMP] = IFLOOR(blue); dstColor[dstCol][ACOMP] = IFLOOR(alpha); } }
Doom3TextureManager::ImageID Doom3TextureManager::computeScale(const Doom3TextureManager::ImageID& source,const float factors[4]) { /* Get a reference to the source image: */ const Images::RGBAImage& sourceImage=imageTree.getLeafValue(source).image; /* Store a new image structure in the image tree: */ ImageID resultId=imageTree.insertLeaf(Misc::stringPrintf("/_computedTextures/tex%06d",numTextures).c_str(),Image()); Image& result=imageTree.getLeafValue(resultId); Images::RGBAImage& resultImage=result.image; result.textureIndex=numTextures; ++numTextures; /* Compute the result image's pixels: */ resultImage=Images::RGBAImage(sourceImage.getWidth(),sourceImage.getHeight()); for(unsigned int y=0;y<resultImage.getHeight();++y) { const Images::RGBAImage::Color* sourceRow=sourceImage.getPixelRow(y); Images::RGBAImage::Color* destRow=resultImage.modifyPixelRow(y); for(unsigned int x=0;x<resultImage.getWidth();++x) { for(int i=0;i<4;++i) { float val=float(sourceRow[x][i])*factors[i]; if(val<0.5f) destRow[x][i]=GLubyte(0); else if(val>=254.5f) destRow[x][i]=GLubyte(255); else destRow[x][i]=GLubyte(Math::floor(val+0.5f)); } } } /* Return the result image ID: */ return resultId; }
static void downsample(GLsizei W, GLsizei H, GLsizei C, std::vector<GLubyte>& P) { const GLsizei w = W / 2; const GLsizei h = H / 2; for (GLsizei i = 0; i < h; i++) for (GLsizei j = 0; j < w; j++) for (GLsizei k = 0; k < C; k++) { GLuint b = GLuint(P[((2 * i + 0) * W + (2 * j + 0)) * C + k]) + GLuint(P[((2 * i + 0) * W + (2 * j + 1)) * C + k]) + GLuint(P[((2 * i + 1) * W + (2 * j + 0)) * C + k]) + GLuint(P[((2 * i + 1) * W + (2 * j + 1)) * C + k]); P[(i * w + j) * C + k] = GLubyte(b / 4); } }
Cloud2D(const Cloud& cloud) : Image(cloud.Width(), cloud.Height(), 1, 3, (GLubyte*)0) { auto p = this->_begin_ub(); auto e = this->_end_ub(); GLsizei w = Width(), h = Height(), d = cloud.Depth(); for(GLsizei j=0; j!=h; ++j) for(GLsizei i=0; i!=w; ++i) { GLubyte depth_near = 0; GLubyte depth_far = 0; GLuint total_density = 0; for(GLsizei k=0; k!=d; ++k) { GLubyte c = cloud.ComponentAs<GLubyte>(i, j, k, 0); if(depth_near == 0) { if(c != 0) { depth_near = (256*k)/d; depth_far = depth_near; } } else if(depth_far == depth_near) { if(c == 0) depth_far = (256*k)/d; } total_density += c; } assert(depth_far >= depth_near); GLuint avg_density = ((depth_far-depth_near) > 0)? total_density/(depth_far-depth_near):0; assert(p != e); *p = depth_near; ++p; assert(p != e); *p = depth_far; ++p; assert(p != e); *p = GLubyte(avg_density); ++p; } OGLPLUS_FAKE_USE(e); assert(p == e); }
static void _apply_gradient( const std::vector<Vector<T, N>>& grad0, GLubyte* dp, GLubyte* de ) { auto gb0 = grad0.begin(), ge0 = grad0.end(); for(auto gp0=gb0; gp0!=ge0; ++gp0) { Vector<T, N> color = *gp0; for(std::size_t c=0; c!=N; ++c) { assert(dp != de); *dp++ = GLubyte(_clamp(color.At(c))*_cc_max()); } } OGLPLUS_FAKE_USE(de); assert(dp == de); }
void distanceField(FT_Bitmap bitmap, int ratio, int border, GLubyte* buffer) { // Convert a font bitmap to a scaled-down int const width = bitmap.width / ratio; int const height = bitmap.rows / ratio; int const borderedWidth = width + 2*border; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { int const bx = x * ratio; int const by = y * ratio; int const distance = distanceForTexel(bitmap, bx, by); assert(distance <= std::numeric_limits<GLubyte>::max()); buffer[(x+border)+borderedWidth*(y+border)] = GLubyte(distance); //buffer[x+width*y] = bitmap.buffer[bx+bitmap.width*by]; } } }
/** * Apply fog to a span of RGBA pixels. * The fog value are either in the span->array->fog array or interpolated from * the fog/fogStep values. * They fog values are either fog coordinates (Z) or fog blend factors. * _PreferPixelFog should be in sync with that state! */ void _swrast_fog_rgba_span( const GLcontext *ctx, SWspan *span ) { const SWcontext *swrast = CONST_SWRAST_CONTEXT(ctx); GLfloat rFog, gFog, bFog; ASSERT(swrast->_FogEnabled); ASSERT(span->arrayMask & SPAN_RGBA); /* compute (scaled) fog color */ if (span->array->ChanType == GL_UNSIGNED_BYTE) { rFog = ctx->Fog.Color[RCOMP] * 255.0F; gFog = ctx->Fog.Color[GCOMP] * 255.0F; bFog = ctx->Fog.Color[BCOMP] * 255.0F; } else if (span->array->ChanType == GL_UNSIGNED_SHORT) { rFog = ctx->Fog.Color[RCOMP] * 65535.0F; gFog = ctx->Fog.Color[GCOMP] * 65535.0F; bFog = ctx->Fog.Color[BCOMP] * 65535.0F; } else { rFog = ctx->Fog.Color[RCOMP]; gFog = ctx->Fog.Color[GCOMP]; bFog = ctx->Fog.Color[BCOMP]; } if (swrast->_PreferPixelFog) { /* The span's fog values are fog coordinates, now compute blend factors * and blend the fragment colors with the fog color. */ switch (swrast->_FogMode) { case GL_LINEAR: { const GLfloat fogEnd = ctx->Fog.End; const GLfloat fogScale = (ctx->Fog.Start == ctx->Fog.End) ? 1.0F : 1.0F / (ctx->Fog.End - ctx->Fog.Start); if (span->array->ChanType == GL_UNSIGNED_BYTE) { GLubyte (*rgba)[4] = span->array->rgba8; FOG_LOOP(GLubyte, LINEAR_FOG); } else if (span->array->ChanType == GL_UNSIGNED_SHORT) { GLushort (*rgba)[4] = span->array->rgba16; FOG_LOOP(GLushort, LINEAR_FOG); } else { GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0]; ASSERT(span->array->ChanType == GL_FLOAT); FOG_LOOP(GLfloat, LINEAR_FOG); } } break; case GL_EXP: { const GLfloat density = -ctx->Fog.Density; if (span->array->ChanType == GL_UNSIGNED_BYTE) { GLubyte (*rgba)[4] = span->array->rgba8; FOG_LOOP(GLubyte, EXP_FOG); } else if (span->array->ChanType == GL_UNSIGNED_SHORT) { GLushort (*rgba)[4] = span->array->rgba16; FOG_LOOP(GLushort, EXP_FOG); } else { GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0]; ASSERT(span->array->ChanType == GL_FLOAT); FOG_LOOP(GLfloat, EXP_FOG); } } break; case GL_EXP2: { const GLfloat negDensitySquared = -ctx->Fog.Density * ctx->Fog.Density; if (span->array->ChanType == GL_UNSIGNED_BYTE) { GLubyte (*rgba)[4] = span->array->rgba8; FOG_LOOP(GLubyte, EXP2_FOG); } else if (span->array->ChanType == GL_UNSIGNED_SHORT) { GLushort (*rgba)[4] = span->array->rgba16; FOG_LOOP(GLushort, EXP2_FOG); } else { GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0]; ASSERT(span->array->ChanType == GL_FLOAT); FOG_LOOP(GLfloat, EXP2_FOG); } } break; default: _mesa_problem(ctx, "Bad fog mode in _swrast_fog_rgba_span"); return; } } else { /* The span's fog start/step/array values are blend factors in [0,1]. * They were previously computed per-vertex. */ if (span->array->ChanType == GL_UNSIGNED_BYTE) { GLubyte (*rgba)[4] = span->array->rgba8; FOG_LOOP(GLubyte, BLEND_FOG); } else if (span->array->ChanType == GL_UNSIGNED_SHORT) { GLushort (*rgba)[4] = span->array->rgba16; FOG_LOOP(GLushort, BLEND_FOG); } else { GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0]; ASSERT(span->array->ChanType == GL_FLOAT); FOG_LOOP(GLfloat, BLEND_FOG); } } }
/* Read the pixel value: */ unsigned char pixel[4]; dataSource.template read<unsigned char>(pixel,pixelByteSize); unsigned int pixelBits=0x0U; for(int i=0;i<pixelByteSize;++i) pixelBits=(pixelBits<<8)|(unsigned int)pixel[i]; if(ColorParam::numComponents==3) { /* Skip the pixel alpha value: */ pixelBits>>=alphaSize; } else if(alphaSize>0) { /* Read the pixel alpha value: */ dest[3]=GLubyte(((pixelBits&alphaMask)*255U)/alphaMask); pixelBits>>=alphaSize; } else dest[3]=GLubyte(255); /* Read the pixel color values: */ for(int i=0;i<3;++i) { dest[i]=GLubyte(((pixelBits&colorFieldMask)*255U)/colorFieldMask); pixelBits>>=colorFieldSize; } }; /* Constructors and destructors: */ public:
/** * Interpolate primary colors to fill in the span->array->rgba8 (or rgb16) * color array. */ static inline void interpolate_int_colors(struct gl_context *ctx, SWspan *span) { #if CHAN_BITS != 32 const GLuint n = span->end; GLuint i; ASSERT(!(span->arrayMask & SPAN_RGBA)); #endif switch (span->array->ChanType) { #if CHAN_BITS != 32 case GL_UNSIGNED_BYTE: { GLubyte (*rgba)[4] = span->array->rgba8; if (span->interpMask & SPAN_FLAT) { GLubyte color[4]; color[RCOMP] = FixedToInt(span->red); color[GCOMP] = FixedToInt(span->green); color[BCOMP] = FixedToInt(span->blue); color[ACOMP] = FixedToInt(span->alpha); for (i = 0; i < n; i++) { COPY_4UBV(rgba[i], color); } } else { GLfixed r = span->red; GLfixed g = span->green; GLfixed b = span->blue; GLfixed a = span->alpha; GLint dr = span->redStep; GLint dg = span->greenStep; GLint db = span->blueStep; GLint da = span->alphaStep; for (i = 0; i < n; i++) { rgba[i][RCOMP] = FixedToChan(r); rgba[i][GCOMP] = FixedToChan(g); rgba[i][BCOMP] = FixedToChan(b); rgba[i][ACOMP] = FixedToChan(a); r += dr; g += dg; b += db; a += da; } } } break; case GL_UNSIGNED_SHORT: { GLushort (*rgba)[4] = span->array->rgba16; if (span->interpMask & SPAN_FLAT) { GLushort color[4]; color[RCOMP] = FixedToInt(span->red); color[GCOMP] = FixedToInt(span->green); color[BCOMP] = FixedToInt(span->blue); color[ACOMP] = FixedToInt(span->alpha); for (i = 0; i < n; i++) { COPY_4V(rgba[i], color); } } else { GLushort (*rgba)[4] = span->array->rgba16; GLfixed r, g, b, a; GLint dr, dg, db, da; r = span->red; g = span->green; b = span->blue; a = span->alpha; dr = span->redStep; dg = span->greenStep; db = span->blueStep; da = span->alphaStep; for (i = 0; i < n; i++) { rgba[i][RCOMP] = FixedToChan(r); rgba[i][GCOMP] = FixedToChan(g); rgba[i][BCOMP] = FixedToChan(b); rgba[i][ACOMP] = FixedToChan(a); r += dr; g += dg; b += db; a += da; } } } break; #endif case GL_FLOAT: interpolate_active_attribs(ctx, span, FRAG_BIT_COL); break; default: _mesa_problem(ctx, "bad datatype 0x%x in interpolate_int_colors", span->array->ChanType); } span->arrayMask |= SPAN_RGBA; }