void raster_rgba_vline_fade(pb_rgba *pb, int y1, uint32_t color1, int y2, uint32_t color2, int x) { int ydiff = y2 - y1; if (ydiff == 0) return; int c1rd = GET_R(color1); int c1gr = GET_G(color1); int c1bl = GET_B(color1); int c2rd = GET_R(color2); int c2gr = GET_G(color2); int c2bl = GET_B(color2); int rdx = c2rd - c1rd; int gdx = c2gr - c1gr; int bdx = c2bl - c1bl; float factor = 0.0f; float factorStep = 1.0f / (float)ydiff; // draw each pixel in the span for (int y = y1; y < y2; y++) { int rd = c1rd + (int)(rdx*factor); int gr = c1gr + (int)(gdx*factor); int bl = c1bl + (int)(bdx*factor); int fg = RGBA(rd, gr, bl, 255); pb_rgba_set_pixel(pb, x, y, fg); factor += factorStep; } }
int function::call(state *E) { exo::instruction *pc = &i_store[0]; while (true) { exo::instruction I = *pc; exo::opcodes::opcode OP = GET_OP(I); std::cout << I << " (" << OP << ")" << std::endl; switch (OP) { case opcodes::NOOP: break; case opcodes::RTN: return GET_A(I); case opcodes::JMP: pc += GET_Bx(I); break; case opcodes::LOADK: E->set(GET_A(I), k_store[GET_B(I)]); break; case opcodes::MOVE: E->set(GET_B(I), E->get(GET_A(I))); break; } pc++; } }
adns_status adns__findlabel_next(findlabel_state *fls, int *lablen_r, int *labstart_r) { int lablen, jumpto; const char *dgram; dgram= fls->dgram; for (;;) { if (fls->cbyte >= fls->dglen) goto x_truncated; if (fls->cbyte >= fls->max) goto x_badresponse; GET_B(fls->cbyte,lablen); if (!(lablen & 0x0c0)) break; if ((lablen & 0x0c0) != 0x0c0) return adns_s_unknownformat; if (fls->cbyte >= fls->dglen) goto x_truncated; if (fls->cbyte >= fls->max) goto x_badresponse; GET_B(fls->cbyte,jumpto); jumpto |= (lablen&0x3f)<<8; if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte; fls->cbyte= jumpto; fls->dmend_r= 0; fls->max= fls->dglen+1; } if (labstart_r) *labstart_r= fls->cbyte; if (lablen) { if (fls->namelen) fls->namelen++; fls->namelen+= lablen; if (fls->namelen > DNS_MAXDOMAIN) return adns_s_answerdomaintoolong; fls->cbyte+= lablen; if (fls->cbyte > fls->dglen) goto x_truncated; if (fls->cbyte > fls->max) goto x_badresponse; } else { if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte; } *lablen_r= lablen; return adns_s_ok; x_truncated: *lablen_r= -1; return adns_s_ok; x_badresponse: adns__diag(fls->ads,fls->serv,fls->qu,"label in domain runs beyond end of domain"); return adns_s_invalidresponse; }
int set_pixel_rgb(struct pixmap *p, int x, int y, unsigned char r, unsigned char g, unsigned char b) { int result = 0; if (p) { if (x >= 0 && x < p->width) { if (y >= 0 && y < p->height) { if (p->components == 1) { GET_R(p, x, y) = RED * r + GREEN * g + BLUE * b; } else { GET_R(p, x, y) = r; GET_G(p, x, y) = g; GET_B(p, x, y) = b; } } else { if (!quiet) fprintf(stderr, "%s: set_pixel_rgb: error: y out of range\n", __progname); result = -1; } } else { if (!quiet) fprintf(stderr, "%s: set_pixel_rgb: error: x out of range\n", __progname); result = -1; } } return result; }
void raster_rgba_blend_alphamap(pb_rgba *pb, const int x, const int y, const unsigned char *bitmap, const int w, const int h, const uint32_t color) { int xpos = x; int ypos = y; uint32_t *dstPtr = (uint32_t *)pb->data; uint8_t *srcPtr = (uint8_t *)bitmap; dstPtr += y*pb->pixelpitch + x; uint32_t *dstRowPtr = dstPtr; int srcrow = 0; for (srcrow = 0; srcrow < h; srcrow++) { xpos = x; for (int srccol = 0; srccol < w; srccol++) { if (*srcPtr > 0) { int dstColor = RGBA(GET_R(color), GET_G(color), GET_B(color), *srcPtr); pb_rgba_cover_pixel(pb, xpos, ypos, dstColor); } xpos++; srcPtr += 1; } ypos++; } }
void CGUITextureGL::Begin(UTILS::Color color) { CBaseTexture* texture = m_texture.m_textures[m_currentFrame]; texture->LoadToGPU(); if (m_diffuse.size()) m_diffuse.m_textures[0]->LoadToGPU(); texture->BindToUnit(0); // Setup Colors m_col[0] = (GLubyte)GET_R(color); m_col[1] = (GLubyte)GET_G(color); m_col[2] = (GLubyte)GET_B(color); m_col[3] = (GLubyte)GET_A(color); bool hasAlpha = m_texture.m_textures[m_currentFrame]->HasAlpha() || m_col[3] < 255; if (m_diffuse.size()) { if (m_col[0] == 255 && m_col[1] == 255 && m_col[2] == 255 && m_col[3] == 255 ) { m_renderSystem->EnableShader(SM_MULTI); } else { m_renderSystem->EnableShader(SM_MULTI_BLENDCOLOR); } hasAlpha |= m_diffuse.m_textures[0]->HasAlpha(); m_diffuse.m_textures[0]->BindToUnit(1); } else { if (m_col[0] == 255 && m_col[1] == 255 && m_col[2] == 255 && m_col[3] == 255) { m_renderSystem->EnableShader(SM_TEXTURE_NOBLEND); } else { m_renderSystem->EnableShader(SM_TEXTURE); } } if (hasAlpha) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE); glEnable(GL_BLEND); } else { glDisable(GL_BLEND); } m_packedVertices.clear(); m_idx.clear(); }
void test_bitmap_color_transform_macro_c(short* buffer) { short* p = buffer; int n; for (n = 0; n < IMAGE_HEIGHT * IMAGE_WIDTH; ++n, ++p) { int r = GET_R(*p); int g = GET_G(*p); int b = GET_B(*p); *p = (short)TO_RGB(g, b, r); } }
void pb_rgba_cover_pixel(pb_rgba *pb, const unsigned int x, const unsigned int y, const uint32_t value) { // Quick reject if the foreground pixel has both 0 opacity // and 0 for color component values if (0 == value) { return; } if (0 == GET_A(value)) { // Combine the colors, but don't // change the alpha of the background } else if (255 == GET_A(value)) { // The foreground opacity is full, so set // the color // and set the background alpha to full as well pb_rgba_set_pixel(pb, x, y, value); } else { // All other cases where doing a cover of something // other than full opacity uint8_t alpha = GET_A(value); int32_t dstPixel = pb_rgba_get_pixel(pb, x, y); int dstColor = RGBA( lerp255(GET_R(dstPixel), GET_R(value), alpha), lerp255(GET_G(dstPixel), GET_G(value), alpha), lerp255(GET_B(dstPixel), GET_B(value), alpha), lerp255(GET_A(dstPixel), GET_A(value), alpha) ); pb_rgba_set_pixel(pb, x, y, dstColor); /* pix_rgba * B = (pix_rgba *)&pb->data[(y*(pb)->pixelpitch) + x]; B->r = lerp255(B->r, GET_R(value), alpha); B->g = lerp255(B->g, GET_R(value), alpha); B->b = lerp255(B->b, GET_R(value), alpha); B->a = lerp255(B->a, GET_R(value), alpha); */ } }
void CGUITextureGL::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords) { if (texture) { glActiveTextureARB(GL_TEXTURE0_ARB); texture->LoadToGPU(); glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject()); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); } else glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // diffuse coloring glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); VerifyGLState(); glBegin(GL_QUADS); glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f); glTexCoord2f(coords.x1, coords.y1); glVertex3f(rect.x1, rect.y1, 0); glTexCoord2f(coords.x2, coords.y1); glVertex3f(rect.x2, rect.y1, 0); glTexCoord2f(coords.x2, coords.y2); glVertex3f(rect.x2, rect.y2, 0); glTexCoord2f(coords.x1, coords.y2); glVertex3f(rect.x1, rect.y2, 0); glEnd(); if (texture) glDisable(GL_TEXTURE_2D); }
void CGUITextureGL::Begin(color_t color) { m_col[0] = (GLubyte)GET_R(color); m_col[1] = (GLubyte)GET_G(color); m_col[2] = (GLubyte)GET_B(color); m_col[3] = (GLubyte)GET_A(color); CBaseTexture* texture = m_texture.m_textures[m_currentFrame]; glActiveTextureARB(GL_TEXTURE0_ARB); texture->LoadToGPU(); if (m_diffuse.size()) m_diffuse.m_textures[0]->LoadToGPU(); glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject()); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // diffuse coloring glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); VerifyGLState(); if (m_diffuse.size()) { glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D, m_diffuse.m_textures[0]->GetTextureObject()); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); VerifyGLState(); } //glDisable(GL_TEXTURE_2D); // uncomment these 2 lines to switch to wireframe rendering //glBegin(GL_LINE_LOOP); glBegin(GL_QUADS); }
bool CRenderSystemGLES::ClearBuffers(color_t color) { if (!m_bRenderCreated) return false; float r = GET_R(color) / 255.0f; float g = GET_G(color) / 255.0f; float b = GET_B(color) / 255.0f; float a = GET_A(color) / 255.0f; glClearColor(r, g, b, a); GLbitfield flags = GL_COLOR_BUFFER_BIT; glClear(flags); return true; }
bool CRenderSystemGL::ClearBuffers(color_t color) { if (!m_bRenderCreated) return false; /* clear is not affected by stipple pattern, so we can only clear on first frame */ if(m_stereoMode == RENDER_STEREO_MODE_INTERLACED && m_stereoView == RENDER_STEREO_VIEW_RIGHT) return true; float r = GET_R(color) / 255.0f; float g = GET_G(color) / 255.0f; float b = GET_B(color) / 255.0f; float a = GET_A(color) / 255.0f; glClearColor(r, g, b, a); GLbitfield flags = GL_COLOR_BUFFER_BIT; glClear(flags); return true; }
void adns__procdgram(adns_state ads, const byte * dgram, int dglen, int serv, int viatcp, struct timeval now) { int cbyte, rrstart, wantedrrs, rri, foundsoa, foundns, cname_here; int id, f1, f2, qdcount, ancount, nscount, arcount; int flg_ra, flg_rd, flg_tc, flg_qr, opcode; int rrtype, rrclass, rdlength, rdstart; int anstart, nsstart, arstart; int ownermatched, l, nrrs; unsigned long ttl, soattl; const typeinfo *typei; adns_query qu, nqu; dns_rcode rcode; adns_status st; vbuf tempvb; byte *newquery, *rrsdata; parseinfo pai; if (dglen < DNS_HDRSIZE) { adns__diag(ads, serv, 0, "received datagram too short for message header (%d)", dglen); return; } cbyte = 0; GET_W(cbyte, id); GET_B(cbyte, f1); GET_B(cbyte, f2); GET_W(cbyte, qdcount); GET_W(cbyte, ancount); GET_W(cbyte, nscount); GET_W(cbyte, arcount); assert(cbyte == DNS_HDRSIZE); flg_qr = f1 & 0x80; opcode = (f1 & 0x78) >> 3; flg_tc = f1 & 0x02; flg_rd = f1 & 0x01; flg_ra = f2 & 0x80; rcode = (f2 & 0x0f); cname_here = 0; if (!flg_qr) { adns__diag(ads, serv, 0, "server sent us a query, not a response"); return; } if (opcode) { adns__diag(ads, serv, 0, "server sent us unknown opcode %d (wanted 0=QUERY)", opcode); return; } qu = 0; /* See if we can find the relevant query, or leave qu=0 otherwise ... */ if (qdcount == 1) { for (qu = viatcp ? ads->tcpw.head : ads->udpw.head; qu; qu = nqu) { nqu = qu->next; if (qu->id != id) continue; if (dglen < qu->query_dglen) continue; if (memcmp(qu->query_dgram + DNS_HDRSIZE, dgram + DNS_HDRSIZE, qu->query_dglen - DNS_HDRSIZE)) continue; if (viatcp) { assert(qu->state == query_tcpw); } else { assert(qu->state == query_tosend); if (!(qu->udpsent & (1 << serv))) continue; } break; } if (qu) { /* We're definitely going to do something with this query now */ if (viatcp) ALIST_UNLINK(ads->tcpw, qu); else ALIST_UNLINK(ads->udpw, qu); } } /* If we're going to ignore the packet, we return as soon as we have * failed the query (if any) and printed the warning message (if * any). */ switch (rcode) { case rcode_noerror: case rcode_nxdomain: break; case rcode_formaterror: adns__warn(ads, serv, qu, "server cannot understand our query (Format Error)"); if (qu) adns__query_fail(qu, adns_s_rcodeformaterror); return; case rcode_servfail: if (qu) adns__query_fail(qu, adns_s_rcodeservfail); else adns__debug(ads, serv, qu, "server failure on unidentifiable query"); return; case rcode_notimp: adns__warn(ads, serv, qu, "server claims not to implement our query"); if (qu) adns__query_fail(qu, adns_s_rcodenotimplemented); return; case rcode_refused: adns__debug(ads, serv, qu, "server refused our query"); if (qu) adns__query_fail(qu, adns_s_rcoderefused); return; default: adns__warn(ads, serv, qu, "server gave unknown response code %d", rcode); if (qu) adns__query_fail(qu, adns_s_rcodeunknown); return; } if (!qu) { if (!qdcount) { adns__diag(ads, serv, 0, "server sent reply without quoting our question"); } else if (qdcount > 1) { adns__diag(ads, serv, 0, "server claimed to answer %d questions with one message", qdcount); } else if (ads->iflags & adns_if_debug) { adns__vbuf_init(&tempvb); adns__debug(ads, serv, 0, "reply not found, id %02x, query owner %s", id, adns__diag_domain(ads, serv, 0, &tempvb, dgram, dglen, DNS_HDRSIZE)); adns__vbuf_free(&tempvb); } return; } /* We're definitely going to do something with this packet and this query now. */ anstart = qu->query_dglen; arstart = -1; /* Now, take a look at the answer section, and see if it is complete. * If it has any CNAMEs we stuff them in the answer. */ wantedrrs = 0; cbyte = anstart; for (rri = 0; rri < ancount; rri++) { rrstart = cbyte; st = adns__findrr(qu, serv, dgram, dglen, &cbyte, &rrtype, &rrclass, &ttl, &rdlength, &rdstart, &ownermatched); if (st) { adns__query_fail(qu, st); return; } if (rrtype == -1) goto x_truncated; if (rrclass != DNS_CLASS_IN) { adns__diag(ads, serv, qu, "ignoring answer RR with wrong class %d (expected IN=%d)", rrclass, DNS_CLASS_IN); continue; } if (!ownermatched) { if (ads->iflags & adns_if_debug) { adns__debug(ads, serv, qu, "ignoring RR with an unexpected owner %s", adns__diag_domain(ads, serv, qu, &qu->vb, dgram, dglen, rrstart)); } continue; } if (rrtype == adns_r_cname && (qu->typei->type & adns__rrt_typemask) != adns_r_cname) { if (qu->flags & adns_qf_cname_forbid) { adns__query_fail(qu, adns_s_prohibitedcname); return; } else if (qu->cname_dgram) { /* Ignore second and subsequent CNAME(s) */ adns__debug(ads, serv, qu, "allegedly canonical name %s is actually alias for %s", qu->answer->cname, adns__diag_domain(ads, serv, qu, &qu->vb, dgram, dglen, rdstart)); adns__query_fail(qu, adns_s_prohibitedcname); return; } else if (wantedrrs) { /* Ignore CNAME(s) after RR(s). */ adns__debug(ads, serv, qu, "ignoring CNAME (to %s) coexisting with RR", adns__diag_domain(ads, serv, qu, &qu->vb, dgram, dglen, rdstart)); } else { qu->cname_begin = rdstart; qu->cname_dglen = dglen; st = adns__parse_domain(ads, serv, qu, &qu->vb, qu-> flags & adns_qf_quotefail_cname ? 0 : pdf_quoteok, dgram, dglen, &rdstart, rdstart + rdlength); if (!qu->vb.used) goto x_truncated; if (st) { adns__query_fail(qu, st); return; } l = strlen((char *)qu->vb.buf) + 1; qu->answer->cname = adns__alloc_preserved(qu, l); if (!qu->answer->cname) { adns__query_fail(qu, adns_s_nomemory); return; } qu->cname_dgram = adns__alloc_mine(qu, dglen); os_memcpy(qu->cname_dgram, dgram, dglen); os_memcpy(qu->answer->cname, qu->vb.buf, l); cname_here = 1; adns__update_expires(qu, ttl, now); /* If we find the answer section truncated after this point we restart * the query at the CNAME; if beforehand then we obviously have to use * TCP. If there is no truncation we can use the whole answer if * it contains the relevant info. */ } } else if (rrtype == (qu->typei->type & adns__rrt_typemask)) { wantedrrs++; } else { adns__debug(ads, serv, qu, "ignoring answer RR with irrelevant type %d", rrtype); } } /* We defer handling truncated responses here, in case there was a CNAME * which we could use. */ if (flg_tc) goto x_truncated; nsstart = cbyte; if (!wantedrrs) { /* Oops, NODATA or NXDOMAIN or perhaps a referral (which would be a problem) */ /* RFC2308: NODATA has _either_ a SOA _or_ _no_ NS records in authority section */ foundsoa = 0; soattl = 0; foundns = 0; for (rri = 0; rri < nscount; rri++) { rrstart = cbyte; st = adns__findrr(qu, serv, dgram, dglen, &cbyte, &rrtype, &rrclass, &ttl, &rdlength, &rdstart, 0); if (st) { adns__query_fail(qu, st); return; } if (rrtype == -1) goto x_truncated; if (rrclass != DNS_CLASS_IN) { adns__diag(ads, serv, qu, "ignoring authority RR with wrong class %d (expected IN=%d)", rrclass, DNS_CLASS_IN); continue; } if (rrtype == adns_r_soa_raw) { foundsoa = 1; soattl = ttl; break; } else if (rrtype == adns_r_ns_raw) { foundns = 1; } } if (rcode == rcode_nxdomain) { /* We still wanted to look for the SOA so we could find the TTL. */ adns__update_expires(qu, soattl, now); if (qu->flags & adns_qf_search) { adns__search_next(ads, qu, now); } else { adns__query_fail(qu, adns_s_nxdomain); } return; } if (foundsoa || !foundns) { /* Aha ! A NODATA response, good. */ adns__update_expires(qu, soattl, now); adns__query_fail(qu, adns_s_nodata); return; } /* Now what ? No relevant answers, no SOA, and at least some NS's. * Looks like a referral. Just one last chance ... if we came across * a CNAME in this datagram then we should probably do our own CNAME * lookup now in the hope that we won't get a referral again. */ if (cname_here) goto x_restartquery; /* Bloody hell, I thought we asked for recursion ? */ if (!flg_ra) { adns__diag(ads, serv, qu, "server is not willing to do recursive lookups for us"); adns__query_fail(qu, adns_s_norecurse); } else { if (!flg_rd) adns__diag(ads, serv, qu, "server thinks we didn't ask for recursive lookup"); else adns__debug(ads, serv, qu, "server claims to do recursion, but gave us a referral"); adns__query_fail(qu, adns_s_invalidresponse); } return; } /* Now, we have some RRs which we wanted. */ qu->answer->rrs.untyped = adns__alloc_interim(qu, qu->typei->rrsz * wantedrrs); if (!qu->answer->rrs.untyped) { adns__query_fail(qu, adns_s_nomemory); return; } typei = qu->typei; cbyte = anstart; rrsdata = qu->answer->rrs.bytes; pai.ads = qu->ads; pai.qu = qu; pai.serv = serv; pai.dgram = dgram; pai.dglen = dglen; pai.nsstart = nsstart; pai.nscount = nscount; pai.arcount = arcount; pai.now = now; for (rri = 0, nrrs = 0; rri < ancount; rri++) { st = adns__findrr(qu, serv, dgram, dglen, &cbyte, &rrtype, &rrclass, &ttl, &rdlength, &rdstart, &ownermatched); assert(!st); assert(rrtype != -1); if (rrclass != DNS_CLASS_IN || rrtype != (qu->typei->type & adns__rrt_typemask) || !ownermatched) continue; adns__update_expires(qu, ttl, now); st = typei->parse(&pai, rdstart, rdstart + rdlength, rrsdata + nrrs * typei->rrsz); if (st) { adns__query_fail(qu, st); return; } if (rdstart == -1) goto x_truncated; nrrs++; } assert(nrrs == wantedrrs); qu->answer->nrrs = nrrs; /* This may have generated some child queries ... */ if (qu->children.head) { qu->state = query_childw; ALIST_LINK_TAIL(ads->childw, qu); return; } adns__query_done(qu); return; x_truncated: if (!flg_tc) { adns__diag(ads, serv, qu, "server sent datagram which points outside itself"); adns__query_fail(qu, adns_s_invalidresponse); return; } qu->flags |= adns_qf_usevc; x_restartquery: if (qu->cname_dgram) { st = adns__mkquery_frdgram(qu->ads, &qu->vb, &qu->id, qu->cname_dgram, qu->cname_dglen, qu->cname_begin, qu->typei->type, qu->flags); if (st) { adns__query_fail(qu, st); return; } newquery = ns_realloc(qu->query_dgram, qu->vb.used); if (!newquery) { adns__query_fail(qu, adns_s_nomemory); return; } qu->query_dgram = newquery; qu->query_dglen = qu->vb.used; os_memcpy(newquery, qu->vb.buf, qu->vb.used); } if (qu->state == query_tcpw) qu->state = query_tosend; qu->retries = 0; adns__reset_preserved(qu); adns__query_send(qu, now); }
void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords) { CRenderSystemGLES *renderSystem = dynamic_cast<CRenderSystemGLES*>(&CServiceBroker::GetRenderSystem()); if (texture) { texture->LoadToGPU(); texture->BindToUnit(0); } glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On VerifyGLState(); GLubyte col[4]; GLfloat ver[4][3]; GLfloat tex[4][2]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip if (texture) renderSystem->EnableGUIShader(SM_TEXTURE); else renderSystem->EnableGUIShader(SM_DEFAULT); GLint posLoc = renderSystem->GUIShaderGetPos(); GLint tex0Loc = renderSystem->GUIShaderGetCoord0(); GLint uniColLoc= renderSystem->GUIShaderGetUniCol(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); if (texture) glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); if (texture) glEnableVertexAttribArray(tex0Loc); // Setup Colors col[0] = (GLubyte)GET_R(color); col[1] = (GLubyte)GET_G(color); col[2] = (GLubyte)GET_B(color); col[3] = (GLubyte)GET_A(color); glUniform4f(uniColLoc, col[0] / 255.0f, col[1] / 255.0f, col[2] / 255.0f, col[3] / 255.0f); ver[0][0] = ver[3][0] = rect.x1; ver[0][1] = ver[1][1] = rect.y1; ver[1][0] = ver[2][0] = rect.x2; ver[2][1] = ver[3][1] = rect.y2; ver[0][2] = ver[1][2] = ver[2][2] = ver[3][2]= 0; if (texture) { // Setup texture coordinates CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f); tex[0][0] = tex[3][0] = coords.x1; tex[0][1] = tex[1][1] = coords.y1; tex[1][0] = tex[2][0] = coords.x2; tex[2][1] = tex[3][1] = coords.y2; } glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); if (texture) glDisableVertexAttribArray(tex0Loc); renderSystem->DisableGUIShader(); }
void CGUITextureGL::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords) { if (texture) { texture->LoadToGPU(); texture->BindToUnit(0); } glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On VerifyGLState(); GLubyte col[4]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of the vertices GLuint vertexVBO; GLuint indexVBO; struct PackedVertex { float x, y, z; float u1, v1; }vertex[4]; if (texture) g_Windowing.EnableShader(SM_TEXTURE); else g_Windowing.EnableShader(SM_DEFAULT); GLint posLoc = g_Windowing.ShaderGetPos(); GLint tex0Loc = g_Windowing.ShaderGetCoord0(); GLint uniColLoc = g_Windowing.ShaderGetUniCol(); // Setup Colors col[0] = (GLubyte)GET_R(color); col[1] = (GLubyte)GET_G(color); col[2] = (GLubyte)GET_B(color); col[3] = (GLubyte)GET_A(color); glUniform4f(uniColLoc, col[0] / 255.0f, col[1] / 255.0f, col[2] / 255.0f, col[3] / 255.0f); // bottom left vertex[0].x = rect.x1; vertex[0].y = rect.y1; vertex[0].z = 0; // bottom right vertex[1].x = rect.x2; vertex[1].y = rect.y1; vertex[1].z = 0; // top right vertex[2].x = rect.x2; vertex[2].y = rect.y2; vertex[2].z = 0; // top left vertex[3].x = rect.x1; vertex[3].y = rect.y2; vertex[3].z = 0; if (texture) { CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f); vertex[0].u1 = vertex[3].u1 = coords.x1; vertex[0].v1 = vertex[1].v1 = coords.y1; vertex[1].u1 = vertex[2].u1 = coords.x2; vertex[2].v1 = vertex[3].v1 = coords.y2; } glGenBuffers(1, &vertexVBO); glBindBuffer(GL_ARRAY_BUFFER, vertexVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(PackedVertex)*4, &vertex[0], GL_STATIC_DRAW); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, x))); glEnableVertexAttribArray(posLoc); if (texture) { glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, u1))); glEnableVertexAttribArray(tex0Loc); } glGenBuffers(1, &indexVBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte)*4, idx, GL_STATIC_DRAW); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, 0); glDisableVertexAttribArray(posLoc); if (texture) glDisableVertexAttribArray(tex0Loc); glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &vertexVBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDeleteBuffers(1, &indexVBO); g_Windowing.DisableShader(); }
void CEmTubeSplashViewContainer::Draw(const TRect& /*aRect*/) const { CWindowGc& gc = SystemGc(); gc.SetClippingRect( Rect() ); gc.SetBrushColor( KRgbWhite ); gc.Clear( Rect() ); TRect rect = Rect(); TInt x, y; x = (rect.Width() / 2) - (KBitmapSize / 2); y = (rect.Height() / 2) - (KBitmapSize / 2); TInt s_width = iBitmap->ScanLineLength(iBitmap->SizeInPixels().iWidth, EColor16MU ) / 4; TInt s_height = iBitmap->SizeInPixels().iHeight; TInt d_width = iTmpBitmap->ScanLineLength(iTmpBitmap->SizeInPixels().iWidth, EColor16MU ) / 4; // TInt d_height = iTmpBitmap->SizeInPixels().iHeight; iBitmap->LockHeap(ETrue); iTmpBitmap->LockHeap(ETrue); TUint32* src = (TUint32*) iBitmap->DataAddress(); TUint32* dst = (TUint32*) iTmpBitmap->DataAddress(); #define GET_R( rgb ) ((rgb >> 16) & 0xff) #define GET_G( rgb ) ((rgb >> 8) & 0xff) #define GET_B( rgb ) (rgb & 0xff) #define SET_R( r ) ((r & 0xff) << 16 ) #define SET_G( g ) ((g & 0xff) << 8 ) #define SET_B( b ) ( b & 0xff) TUint32 alpha = iAlpha * 255; TUint32 alpha1 = (KAlphaMax - iAlpha); for (TInt i = 0; i < s_height; i++) { TUint32* d = dst; TUint32* s = src; for (TInt j = 0; j < s_width; j++) { TUint32 rgb = *s++; TUint32 r = ((GET_R( rgb ) * alpha1) + alpha) >> 8; TUint32 g = ((GET_G( rgb ) * alpha1) + alpha) >> 8; TUint32 b = ((GET_B( rgb ) * alpha1) + alpha) >> 8; rgb = SET_R( r ) + SET_G( g ) + SET_B( b ); *d++ = rgb; } dst += d_width; src += s_width; } iBitmap->UnlockHeap(ETrue); iTmpBitmap->UnlockHeap(ETrue); gc.BitBlt( TPoint( x, y ), iTmpBitmap); gc.CancelClippingRect(); }
void execute_function(VM *vm) { restart: { Frame *frame = vm->current; Closure *closure = frame->closure; Chunk *chunk = closure->chunk; StackObject *registers = frame->registers; while (frame->pc < chunk->numinstructions) { int instruction = chunk->instructions[frame->pc]; OpCode o = GET_O(instruction); int a = GET_A(instruction); int b = GET_B(instruction); int c = GET_C(instruction); switch (o) { case OP_MOVE: { if (b < 256) { copy_object(®isters[a], ®isters[b]); } else { copy_constant(vm, ®isters[a], chunk->constants[b - 256]); } } break; case OP_GETUPVAR: { Upval *upval = closure->upvals[b]; if (!upval->open) { // upval is closed copy_object(®isters[a], upval->data.o); } else { // still on stack copy_object(®isters[a], &upval->data.ref.frame->registers[upval->data.ref.slot]); } } break; case OP_SETUPVAR: { Upval *upval = closure->upvals[b]; if (!upval->open) { // upval is closed copy_object(upval->data.o, ®isters[a]); } else { // still on stack copy_object(&upval->data.ref.frame->registers[upval->data.ref.slot], ®isters[a]); } } break; case OP_ADD: { // TODO - make string coercion better // TODO - make string type with special operators if (IS_STR(b) || IS_STR(c)) { char *arg1 = TO_STR(b); char *arg2 = TO_STR(c); char *arg3 = malloc((strlen(arg1) + strlen(arg2) + 1) + sizeof *arg3); strcpy(arg3, arg1); strcat(arg3, arg2); registers[a].value.o = make_string_ref(vm, arg3); registers[a].type = OBJECT_REFERENCE; // put this after free(arg1); free(arg2); } else { if (!(IS_INT(b) || IS_REAL(b)) || !(IS_INT(c) || IS_REAL(c))) { fatal("Cannot add types."); } if (IS_INT(b) && IS_INT(c)) { int arg1 = AS_INT(b); int arg2 = AS_INT(c); registers[a].type = OBJECT_INT; registers[a].value.i = arg1 + arg2; } else { double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_REAL; registers[a].value.d = arg1 + arg2; } } } break; case OP_SUB: { if (!(IS_INT(b) || IS_REAL(b)) || !(IS_INT(c) || IS_REAL(c))) { fatal("Tried to sub non-numbers."); } if (IS_INT(b) && IS_INT(c)) { int arg1 = AS_INT(b); int arg2 = AS_INT(c); registers[a].type = OBJECT_INT; registers[a].value.i = arg1 - arg2; } else { double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_REAL; registers[a].value.d = arg1 - arg2; } } break; case OP_MUL: { if (!(IS_INT(b) || IS_REAL(b)) || !(IS_INT(c) || IS_REAL(c))) { fatal("Tried to mul non-numbers."); } if (IS_INT(b) && IS_INT(c)) { int arg1 = AS_INT(b); int arg2 = AS_INT(c); registers[a].type = OBJECT_INT; registers[a].value.i = arg1 * arg2; } else { double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_REAL; registers[a].value.d = arg1 * arg2; } } break; case OP_DIV: { if (!(IS_INT(b) || IS_REAL(b)) || !(IS_INT(c) || IS_REAL(c))) { fatal("Tried to div non-numbers."); } if ((IS_INT(c) && AS_INT(c) == 0) || (IS_REAL(c) && AS_REAL(c) == 0)) { fatal("Div by 0."); } if (IS_INT(b) && IS_INT(c)) { int arg1 = AS_INT(b); int arg2 = AS_INT(c); registers[a].type = OBJECT_INT; registers[a].value.i = arg1 / arg2; } else { double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_REAL; registers[a].value.d = arg1 / arg2; } } break; case OP_MOD: { if (!(IS_INT(b) || IS_REAL(b)) || !(IS_INT(c) || IS_REAL(c))) { fatal("Tried to div non-numbers."); } if ((IS_INT(c) && AS_INT(c) == 0) || (IS_REAL(c) && AS_REAL(c) == 0)) { fatal("Mod by 0."); } if (IS_INT(b) && IS_INT(c)) { int arg1 = AS_INT(b); int arg2 = AS_INT(c); registers[a].type = OBJECT_INT; registers[a].value.i = arg1 % arg2; } else { double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_REAL; registers[a].value.i = fmod(arg1, arg2); } } break; case OP_POW: { if (!(IS_INT(b) || IS_REAL(b)) || !(IS_INT(c) || IS_REAL(c))) { fatal("Tried to div non-numbers."); } if (IS_INT(b) && IS_INT(c)) { int arg1 = AS_INT(b); int arg2 = AS_INT(c); registers[a].type = OBJECT_INT; registers[a].value.i = (int) pow(arg1, arg2); } else { double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_REAL; registers[a].value.d = pow(arg1, arg2); } } break; case OP_NEG: { if (IS_INT(b)) { registers[a].type = OBJECT_INT; registers[a].value.i = -AS_INT(b); } else if (IS_REAL(b)) { registers[a].type = OBJECT_INT; registers[a].value.i = -AS_REAL(b); } else { fatal("Tried to negate non-numeric type."); } } break; case OP_NOT: { if (registers[a].type != OBJECT_BOOL) { fatal("Expected boolean type, not %d.", registers[a].type); } registers[a].value.i = registers[a].value.i == 1 ? 0 : 1; } break; case OP_EQ: { if ((IS_INT(b) || IS_REAL(b)) && (IS_INT(c) || IS_REAL(c))) { double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_BOOL; registers[a].value.i = arg1 == arg2; } else { fatal("Comparison of reference types not yet supported."); } } break; case OP_LT: { if (!(IS_INT(b) || IS_REAL(b)) || !(IS_INT(c) || IS_REAL(c))) { fatal("Tried to compare non-numbers."); } double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_BOOL; registers[a].value.i = arg1 < arg2; } break; case OP_LE: { if (!(IS_INT(b) || IS_REAL(b)) || !(IS_INT(c) || IS_REAL(c))) { fatal("Tried to compare non-numbers."); } double arg1 = IS_INT(b) ? (double) AS_INT(b) : AS_REAL(b); double arg2 = IS_INT(c) ? (double) AS_INT(c) : AS_REAL(c); registers[a].type = OBJECT_BOOL; registers[a].value.i = arg1 <= arg2; } break; case OP_CLOSURE: { Closure *child = make_closure(chunk->children[b]); int i; for (i = 0; i < chunk->children[b]->numupvars; i++) { int inst = chunk->instructions[++frame->pc]; OpCode oc = GET_O(inst); int ac = GET_A(inst); int bc = GET_B(inst); int cc = GET_C(inst); if (oc == OP_MOVE) { // first upval for this variable child->upvals[ac] = make_upval(vm, bc); } else { // share upval child->upvals[ac] = closure->upvals[bc]; child->upvals[ac]->refcount++; } } registers[a].value.o = make_closure_ref(vm, child); registers[a].type = OBJECT_REFERENCE; // put this after } break; case OP_CALL: { if (registers[b].type != OBJECT_REFERENCE || registers[b].value.o->type != OBJECT_CLOSURE) { fatal("Tried to call non-closure."); } // TODO - safety issue (see compile.c for notes) Closure *child = registers[b].value.o->value.c; Frame *subframe = make_frame(frame, child); int i; for (i = 0; i < child->chunk->numparams; i++) { copy_object(&subframe->registers[i + 1], ®isters[c + i]); } vm->current = subframe; goto restart; } break; case OP_RETURN: { UpvalNode *head; for (head = vm->open; head != NULL; ) { Upval *u = head->upval; if (u->data.ref.frame == frame) { StackObject *o = malloc(sizeof *o); if (!o) { fatal("Out of memory."); } u->open = 0; copy_object(o, ®isters[u->data.ref.slot]); u->data.o = o; if (vm->open == head) { vm->open = head->next; } else { head->next->prev = head->prev; head->prev->next = head->next; } UpvalNode *temp = head; head = head->next; free(temp); } else { head = head->next; } } if (vm->current->parent != NULL) { Frame *p = vm->current->parent; StackObject *target = &p->registers[GET_A(p->closure->chunk->instructions[p->pc++])]; if (b < 256) { // debug char *d = obj_to_str(®isters[b]); printf("Return value: %s\n", d); free(d); copy_object(target, ®isters[b]); } else { copy_constant(vm, target, chunk->constants[b - 256]); } free_frame(frame); vm->current = p; goto restart; } else { // debug char *d = obj_to_str(®isters[b]); printf("Return value: %s\n", d); free(d); free_frame(frame); vm->current = NULL; return; } } break; case OP_JUMP: frame->pc += c ? -b : b; break; case OP_JUMP_TRUE: { if (registers[a].type != OBJECT_BOOL) { fatal("Expected boolean type, not %d.", registers[a].type); } if (registers[a].value.i == 1) { frame->pc += c ? -b : b; } } break; case OP_JUMP_FALSE: { if (registers[a].type != OBJECT_BOOL) { fatal("Expected boolean type, not %d.", registers[a].type); } if (registers[a].value.i == 0) { frame->pc += c ? -b : b; } } break; case OP_ENTER_TRY: { vm->catchframe = make_catch_frame(frame, vm->catchframe, frame->pc + b); } break; case OP_LEAVE_TRY: { CatchFrame *temp = vm->catchframe; vm->catchframe = vm->catchframe->parent; free_catch_frame(temp); } break; case OP_THROW: { // TODO - replace unwinding of stack with an exceptions // table per-chunk. It will have an instructions range, // the starting instruction of a handler, and the type of // exception that it may handle. // Exception table: // From To Target Type // 0 4 5 Class TestExc1 // 0 12 12 Class TestExc2 // TODO - implement a way to expect an exception // of a given type instead of a generic catch-all. char *s = obj_to_str(®isters[a]); printf("Exception value: %s!\n", s); free(s); // TODO - this is probably wrong. Not sure how complicated // it will be to handle upvalues and frame destruction here, // so we're just doing it a shitty way for now :D [GO LAZE]. if (!vm->catchframe) { // TODO - print a stack trace [ requires debug symbols :( ] fatal("Exception thrown outside of handler."); } while (vm->current != vm->catchframe->frame) { // TODO - destruct frame vm->current = vm->current->parent; } vm->current->pc = vm->catchframe->target; CatchFrame *temp = vm->catchframe; vm->catchframe = vm->catchframe->parent; free_catch_frame(temp); goto restart; } break; } frame->pc++; } fatal("VM left instruction-space."); } }
int32_t GLOBALDATA::get_avg_bgcolor(int32_t x1, int32_t y1, int32_t x2, int32_t y2, double xv, double yv) { // Movement int32_t mvx = ROUND(10. * xv); // eliminate slow movement int32_t mvy = ROUND(10. * yv); // eliminate slow movement bool mv_left = mvx < 0; bool mv_right = mvx > 0; bool mv_up = mvy < 0; bool mv_down = mvy > 0; // Boundaries int32_t min_x = 1; int32_t max_x = env.screenWidth - 2; int32_t min_y = env.isBoxed ? MENUHEIGHT + 1 : MENUHEIGHT; int32_t max_y = env.screenHeight - 2; // Coordinates int32_t left = std::max(std::min(x1, x2), min_x); int32_t right = std::min(std::max(x1, x2), max_x); int32_t centre = (x1 + x2) / 2; int32_t top = std::max(std::min(y1, y2), min_y); int32_t bottom = std::min(std::max(y1, y2), max_y); int32_t middle = (y1 + y2) / 2; // Colors: int32_t col_tl, col_tc, col_tr; // top row int32_t col_ml, col_mc, col_mr; // middle row int32_t col_bl, col_bc, col_br; // bottom row int32_t r = 0, g = 0, b = 0; // Get Sky or Terrain colour, whatever fits: /*--------------------- --- Left side --- ---------------------*/ if ( PINK == (col_tl = getpixel(terrain, left, top)) ) col_tl = getpixel(env.sky, left, top); if ( PINK == (col_ml = getpixel(terrain, left, middle)) ) col_ml = getpixel(env.sky, left, middle); if ( PINK == (col_bl = getpixel(terrain, left, bottom)) ) col_bl = getpixel(env.sky, left, bottom); /*--------------------- --- The Center --- ---------------------*/ if ( PINK == (col_tc = getpixel(terrain, centre, top)) ) col_tc = getpixel(env.sky, centre, top); if ( PINK == (col_mc = getpixel(terrain, centre, middle)) ) col_mc = getpixel(env.sky, centre, middle); if ( PINK == (col_bc = getpixel(terrain, centre, bottom)) ) col_bc = getpixel(env.sky, centre, bottom); /*---------------------- --- Right side --- ----------------------*/ if ( PINK == (col_tr = getpixel(terrain, right, top)) ) col_tr = getpixel(env.sky, right, top); if ( PINK == (col_mr = getpixel(terrain, right, middle)) ) col_mr = getpixel(env.sky, right, middle); if ( PINK == (col_br = getpixel(terrain, right, bottom)) ) col_br = getpixel(env.sky, right, bottom); // Fetch the rgb parts, according to movement: /* --- X-Movement --- */ if (mv_left) { // Movement to the left, weight left side colour twice r += (GET_R(col_tl) + GET_R(col_ml) + GET_R(col_bl)) * 2; g += (GET_G(col_tl) + GET_G(col_ml) + GET_G(col_bl)) * 2; b += (GET_B(col_tl) + GET_B(col_ml) + GET_B(col_bl)) * 2; // The others are counted once r += GET_R(col_tc) + GET_R(col_mc) + GET_R(col_bc) + GET_R(col_tr) + GET_R(col_mr) + GET_R(col_br); g += GET_G(col_tc) + GET_G(col_mc) + GET_G(col_bc) + GET_G(col_tr) + GET_G(col_mr) + GET_G(col_br); b += GET_B(col_tc) + GET_B(col_mc) + GET_B(col_bc) + GET_B(col_tr) + GET_B(col_mr) + GET_B(col_br); } else if (mv_right) { // Movement to the right, weight right side colour twice r += (GET_R(col_tr) + GET_R(col_mr) + GET_R(col_br)) * 2; g += (GET_G(col_tr) + GET_G(col_mr) + GET_G(col_br)) * 2; b += (GET_B(col_tr) + GET_B(col_mr) + GET_B(col_br)) * 2; // The others are counted once r += GET_R(col_tc) + GET_R(col_mc) + GET_R(col_bc) + GET_R(col_tl) + GET_R(col_ml) + GET_R(col_bl); g += GET_G(col_tc) + GET_G(col_mc) + GET_G(col_bc) + GET_G(col_tl) + GET_G(col_ml) + GET_G(col_bl); b += GET_B(col_tc) + GET_B(col_mc) + GET_B(col_bc) + GET_B(col_tl) + GET_B(col_ml) + GET_B(col_bl); } else { // No x-movement, weight centre colour twice r += (GET_R(col_tc) + GET_R(col_mc) + GET_R(col_bc)) * 2; g += (GET_G(col_tc) + GET_G(col_mc) + GET_G(col_bc)) * 2; b += (GET_B(col_tc) + GET_B(col_mc) + GET_B(col_bc)) * 2; // The others are counted once r += GET_R(col_tl) + GET_R(col_ml) + GET_R(col_bl) + GET_R(col_tr) + GET_R(col_mr) + GET_R(col_br); g += GET_G(col_tl) + GET_G(col_ml) + GET_G(col_bl) + GET_G(col_tr) + GET_G(col_mr) + GET_G(col_br); b += GET_B(col_tl) + GET_B(col_ml) + GET_B(col_bl) + GET_B(col_tr) + GET_B(col_mr) + GET_B(col_br); } /* --- Y-Movement --- */ if (mv_up) { // Movement upwards, weight top side colour twice r += (GET_R(col_tl) + GET_R(col_tc) + GET_R(col_tr)) * 2; g += (GET_G(col_tl) + GET_G(col_tc) + GET_G(col_tr)) * 2; b += (GET_B(col_tl) + GET_B(col_tc) + GET_B(col_tr)) * 2; // The others are counted once r += GET_R(col_ml) + GET_R(col_mc) + GET_R(col_mr) + GET_R(col_bl) + GET_R(col_bc) + GET_R(col_br); g += GET_G(col_ml) + GET_G(col_mc) + GET_G(col_mr) + GET_G(col_bl) + GET_G(col_bc) + GET_G(col_br); b += GET_B(col_ml) + GET_B(col_mc) + GET_B(col_mr) + GET_B(col_bl) + GET_B(col_bc) + GET_B(col_br); } else if (mv_down) { // Movement downwards, weight bottom side colour twice r += (GET_R(col_bl) + GET_R(col_bc) + GET_R(col_br)) * 2; g += (GET_G(col_bl) + GET_G(col_bc) + GET_G(col_br)) * 2; b += (GET_B(col_bl) + GET_B(col_bc) + GET_B(col_br)) * 2; // The others are counted once r += GET_R(col_ml) + GET_R(col_mc) + GET_R(col_mr) + GET_R(col_tl) + GET_R(col_tc) + GET_R(col_tr); g += GET_G(col_ml) + GET_G(col_mc) + GET_G(col_mr) + GET_G(col_tl) + GET_G(col_tc) + GET_G(col_tr); b += GET_B(col_ml) + GET_B(col_mc) + GET_B(col_mr) + GET_B(col_tl) + GET_B(col_tc) + GET_B(col_tr); } else { // No y-movement, weight middle colour twice r += (GET_R(col_ml) + GET_R(col_mc) + GET_R(col_mr)) * 2; g += (GET_G(col_ml) + GET_G(col_mc) + GET_G(col_mr)) * 2; b += (GET_B(col_ml) + GET_B(col_mc) + GET_B(col_mr)) * 2; // The others are counted once r += GET_R(col_tl) + GET_R(col_tc) + GET_R(col_tr) + GET_R(col_bl) + GET_R(col_bc) + GET_R(col_br); g += GET_G(col_tl) + GET_G(col_tc) + GET_G(col_tr) + GET_G(col_bl) + GET_G(col_bc) + GET_G(col_br); b += GET_B(col_tl) + GET_B(col_tc) + GET_B(col_tr) + GET_B(col_bl) + GET_B(col_bc) + GET_B(col_br); } /* I know this looks weird, but what we now have is some kind of summed * matrix, which is always the same: * Let's assume that xv and yv are both 0.0, so no movement is happening. * The result is: (In counted times) * 2|3|2 ( = 7) * -+-+- * 3|4|3 ( = 10) * -+-+- * 2|3|2 ( = 7) * = 24 * And it is always 24, no matter which movement combination you try */ r /= 24; g /= 24; b /= 24; return makecol(r > 0xff ? 0xff : r, g > 0xff ? 0xff : g, b > 0xff ? 0xff : b); }
void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, color_t color) { #ifdef HAS_DX static const DWORD FVF_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; Vertex vertex[5]; for (int i = 0; i < 4; i++) { vertex[i].pos = XMFLOAT3( x[i], y[i], 0); CD3DHelper::XMStoreColor(&vertex[i].color, color); vertex[i].texCoord = XMFLOAT2(0.0f, 0.0f); vertex[i].texCoord2 = XMFLOAT2(0.0f, 0.0f); } if (pTexture) { vertex[1].texCoord.x = vertex[2].texCoord.x = (float) pTexture->GetWidth() / pTexture->GetTextureWidth(); vertex[2].texCoord.y = vertex[3].texCoord.y = (float) pTexture->GetHeight() / pTexture->GetTextureHeight(); } else { vertex[1].texCoord.x = vertex[2].texCoord.x = 1.0f; vertex[2].texCoord.y = vertex[3].texCoord.y = 1.0f; } vertex[4] = vertex[0]; // Not used when pTexture != NULL CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_BLEND); // Set state to render the image if (pTexture) { pTexture->LoadToGPU(); CDXTexture* dxTexture = reinterpret_cast<CDXTexture*>(pTexture); ID3D11ShaderResourceView* shaderRes = dxTexture->GetShaderResource(); pGUIShader->SetShaderViews(1, &shaderRes); pGUIShader->DrawQuad(vertex[0], vertex[1], vertex[2], vertex[3]); } else { if (!UpdateVertexBuffer(vertex)) return; ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); unsigned stride = sizeof(Vertex); unsigned offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); pGUIShader->Draw(5, 0); pGUIShader->RestoreBuffers(); } #elif defined(HAS_GL) if (pTexture) { int unit = 0; pTexture->LoadToGPU(); pTexture->BindToUnit(unit++); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On // diffuse coloring glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); if(g_Windowing.UseLimitedColor()) { // compress range pTexture->BindToUnit(unit++); // dummy bind const GLfloat rgba1[4] = {(235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, 1.0f}; glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba1); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_MODULATE); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS); // transition pTexture->BindToUnit(unit++); // dummy bind const GLfloat rgba2[4] = {16.0f / 255.0f, 16.0f / 255.0f, 16.0f / 255.0f, 0.0f}; glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba2); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_ADD); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS); } } else glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, pTexture ? GL_FILL : GL_LINE); glBegin(GL_QUADS); float u1 = 0, u2 = 1, v1 = 0, v2 = 1; if (pTexture) { u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); } glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u1, v1); glVertex3f(x[0], y[0], 0); // Bottom-left vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u2, v1); glVertex3f(x[1], y[1], 0); // Bottom-right vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u2, v2); glVertex3f(x[2], y[2], 0); // Top-right vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u1, v2); glVertex3f(x[3], y[3], 0); glEnd(); #elif defined(HAS_GLES) if (pTexture) { pTexture->LoadToGPU(); pTexture->BindToUnit(0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On g_Windowing.EnableGUIShader(SM_TEXTURE); } else { glDisable(GL_TEXTURE_2D); g_Windowing.EnableGUIShader(SM_DEFAULT); } float u1 = 0, u2 = 1, v1 = 0, v2 = 1; if (pTexture) { u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); } GLubyte col[4]; GLfloat ver[4][3]; GLfloat tex[4][2]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip GLint posLoc = g_Windowing.GUIShaderGetPos(); GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); GLint uniColLoc= g_Windowing.GUIShaderGetUniCol(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(tex0Loc); // Setup Colour values col[0] = (GLubyte)GET_R(color); col[1] = (GLubyte)GET_G(color); col[2] = (GLubyte)GET_B(color); col[3] = (GLubyte)GET_A(color); for (int i=0; i<4; i++) { // Setup vertex position values ver[i][0] = x[i]; ver[i][1] = y[i]; ver[i][2] = 0.0f; } // Setup texture coordinates tex[0][0] = tex[3][0] = u1; tex[0][1] = tex[1][1] = v1; tex[1][0] = tex[2][0] = u2; tex[2][1] = tex[3][1] = v2; glUniform4f(uniColLoc,(col[0] / 255.0f), (col[1] / 255.0f), (col[2] / 255.0f), (col[3] / 255.0f)); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(tex0Loc); g_Windowing.DisableGUIShader(); #else // SDL render g_Windowing.BlitToScreen(m_pImage, NULL, NULL); #endif }
void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords) { if (texture) { glActiveTexture(GL_TEXTURE0); texture->LoadToGPU(); glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject()); glEnable(GL_TEXTURE_2D); } else glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On VerifyGLState(); GLfloat col[4][4]; GLfloat ver[4][3]; GLfloat tex[4][2]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip g_Windowing.EnableGUIShader(SM_TEXTURE); GLint posLoc = g_Windowing.GUIShaderGetPos(); GLint colLoc = g_Windowing.GUIShaderGetCol(); GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, col); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(tex0Loc); glEnableVertexAttribArray(colLoc); for (int i=0; i<4; i++) { // Setup Colour Values col[i][0] = (GLubyte)GET_R(color); col[i][1] = (GLubyte)GET_G(color); col[i][2] = (GLubyte)GET_B(color); col[i][3] = (GLubyte)GET_A(color); } // Setup vertex position values // ver[0][3] = ver[1][3] = ver[2][3] = ver[3][3] = 0.0f; // FIXME, ver has only 3 elements - this is not correct ver[0][0] = ver[3][0] = rect.x1; ver[0][1] = ver[1][1] = rect.y1; ver[1][0] = ver[2][0] = rect.x2; ver[2][1] = ver[3][1] = rect.y2; // Setup texture coordinates CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f); tex[0][0] = tex[3][0] = coords.x1; tex[0][1] = tex[1][1] = coords.y1; tex[1][0] = tex[2][0] = coords.x2; tex[2][1] = tex[3][1] = coords.y2; glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(colLoc); glDisableVertexAttribArray(tex0Loc); g_Windowing.DisableGUIShader(); if (texture) glDisable(GL_TEXTURE_2D); }
void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords) { if (texture) { glActiveTexture(GL_TEXTURE0); texture->LoadToGPU(); glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject()); } glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On VerifyGLState(); GLubyte col[4][4]; GLfloat ver[4][3]; GLfloat tex[4][2]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip if (texture) g_Windowing.EnableGUIShader(SM_TEXTURE); else g_Windowing.EnableGUIShader(SM_DEFAULT); GLint posLoc = g_Windowing.GUIShaderGetPos(); GLint colLoc = g_Windowing.GUIShaderGetCol(); GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); if(colLoc >= 0) glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, col); if (texture) glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); if (texture) glEnableVertexAttribArray(tex0Loc); if(colLoc >= 0) glEnableVertexAttribArray(colLoc); for (int i=0; i<4; i++) { // Setup Colour Values col[i][0] = (GLubyte)GET_R(color); col[i][1] = (GLubyte)GET_G(color); col[i][2] = (GLubyte)GET_B(color); col[i][3] = (GLubyte)GET_A(color); } // Setup vertex position values #define ROUND_TO_PIXEL(x) (float)(MathUtils::round_int(x)) ver[0][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x1, rect.y1)); ver[0][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x1, rect.y1)); ver[0][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x1, rect.y1)); ver[1][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x2, rect.y1)); ver[1][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x2, rect.y1)); ver[1][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x2, rect.y1)); ver[2][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x2, rect.y2)); ver[2][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x2, rect.y2)); ver[2][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x2, rect.y2)); ver[3][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x1, rect.y2)); ver[3][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x1, rect.y2)); ver[3][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x1, rect.y2)); if (texture) { // Setup texture coordinates CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f); tex[0][0] = tex[3][0] = coords.x1; tex[0][1] = tex[1][1] = coords.y1; tex[1][0] = tex[2][0] = coords.x2; tex[2][1] = tex[3][1] = coords.y2; } glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); if(colLoc >= 0) glDisableVertexAttribArray(colLoc); if (texture) glDisableVertexAttribArray(tex0Loc); g_Windowing.DisableGUIShader(); }
void CGUITextureD3D::Begin(color_t color) { int unit = 0; CBaseTexture* texture = m_texture.m_textures[m_currentFrame]; LPDIRECT3DDEVICE9 p3DDevice = g_Windowing.Get3DDevice(); texture->LoadToGPU(); if (m_diffuse.size()) m_diffuse.m_textures[0]->LoadToGPU(); // Set state to render the image texture->BindToUnit(unit); p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP , D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); unit++; if (m_diffuse.size()) { m_diffuse.m_textures[0]->BindToUnit(1); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_CURRENT ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_CURRENT ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP , D3DTOP_MODULATE ); unit++; } if(g_Windowing.UseLimitedColor()) { m_col = D3DCOLOR_RGBA(GET_R(color) * (235 - 16) / 255 , GET_G(color) * (235 - 16) / 255 , GET_B(color) * (235 - 16) / 255 , GET_A(color)); p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_ADD ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_CURRENT) ; p3DDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_RGBA(16,16,16, 0) ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_TFACTOR ); unit++; } else m_col = color; p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP, D3DTOP_DISABLE); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP, D3DTOP_DISABLE); p3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); p3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 ); p3DDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL ); p3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE ); p3DDevice->SetRenderState( D3DRS_FOGENABLE, FALSE ); p3DDevice->SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_NONE ); p3DDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); p3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); p3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); p3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); p3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); p3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE); p3DDevice->SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 ); }
void dis(Chunk *chunk) { int i; for (i = 0; i < chunk->numinstructions; i++) { int instruction = chunk->instructions[i]; OpCode o = GET_O(instruction); int a = GET_A(instruction); int b = GET_B(instruction); int c = GET_C(instruction); switch (o) { case OP_RETURN: case OP_LEAVE_TRY: printf("%d\t%-15s%d", i + 1, opcode_names[o], b); break; case OP_THROW: printf("%d\t%-15s%d", i + 1, opcode_names[0], a); break; case OP_MOVE: case OP_NEG: case OP_NOT: { printf("%d\t%-15s%d %d", i + 1, opcode_names[o], a, b); if (b > 255) { printf("\t; b="); print_const(chunk->constants[b - 256]); } } break; case OP_GETUPVAR: case OP_SETUPVAR: case OP_CLOSURE: printf("%d\t%-15s%d %d", i + 1, opcode_names[o], a, b); break; case OP_JUMP: case OP_JUMP_TRUE: case OP_JUMP_FALSE: { int offset = c == 1 ? -b : b; printf("%d\t%-15s%d %d\t; j=%d", i + 1, opcode_names[o], a, b, i + offset + 2); } break; case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_MOD: case OP_POW: case OP_EQ: case OP_LT: case OP_LE: { printf("%d\t%-15s%d %d %d", i + 1, opcode_names[o], a, b, c); if (a > 255) { printf("\t; a="); print_const(chunk->constants[a - 256]); } if (b > 255) { printf("\t; b="); print_const(chunk->constants[b - 256]); } } break; case OP_CALL: printf("%d\t%-15s%d %d %d", i + 1, opcode_names[o], a, b, c); break; case OP_ENTER_TRY: printf("%d\t%-15s%d\t; j=%d", i + 1, opcode_names[o], b, i + b + 1); break; } printf("\n"); } for (i = 0; i < chunk->numchildren; i++) { dis(chunk->children[i]); } }
/*********************************************************************** * plugin main ppu thread ***********************************************************************/ static void vsh_menu_thread(uint64_t arg) { #ifdef DEBUG dbg_init(); dbg_printf("programstart:\n"); #endif uint16_t oldpad = 0, curpad = 0; CellPadData pdata; // wait for XMB, feedback sys_timer_sleep(13); //vshtask_notify("sprx running..."); play_rco_sound("system_plugin", "snd_trophy"); #ifdef HAVE_STARFIELD init_once(/* stars */); #endif // custom bg_color init a = GET_A(bg_color_menu[1]); r = GET_R(bg_color_menu[1]); g = GET_G(bg_color_menu[1]); b = GET_B(bg_color_menu[1]); while(1) { // if VSH Menu is running, we get pad data over our MyPadGetData() // else, we use the vsh pad_data struct if(menu_running) MyPadGetData(0, &pdata); else VSHPadGetData(&pdata); // if pad_data and we are in XMB(vshmain_EB757101() == 0) if((pdata.len > 0) && (vshmain_EB757101() == 0) ) { curpad = (pdata.button[2] | (pdata.button[3] << 8)); if((curpad & PAD_SELECT) && (curpad != oldpad)) { switch(menu_running) { // VSH Menu not running, start VSH Menu case 0: // main view and start on first entry view = line = 0; // pause_RSX_rendering(); // create VSH Menu heap memory from memory container 1("app") create_heap(64); // 64 MB // initialize VSH Menu graphic (init drawing context, alloc buffers, blah, blah, blah...) init_graphic(); // stop vsh pad start_stop_vsh_pad(0); // set menu_running menu_running = 1; break; // VSH Menu is running, stop VSH Menu case 1: stop_VSH_Menu(); // restart vsh pad start_stop_vsh_pad(1); break; } oldpad = 0; sys_timer_usleep(300000); } // VSH Menu is running, draw menu / check pad if(menu_running) { #ifdef DEBUG dbg_printf("%p\n", pdata); #endif draw_frame(&pdata); flip_frame(); if(curpad != oldpad) { if(curpad & PAD_UP) { if(line <= 0){ line = 0; }else{ line--; play_rco_sound("system_plugin", "snd_cursor"); } } if(curpad & PAD_DOWN) { if(line >= max_menu[view]-1){ line = max_menu[view]-1; }else{ line++; play_rco_sound("system_plugin", "snd_cursor"); } } if(curpad & PAD_LEFT || curpad & PAD_RIGHT) do_leftright_action(curpad); if(curpad & PAD_CROSS) do_menu_action(); } // ... sys_timer_usleep(30); } // end VSH Menu is running oldpad = curpad; }else{ oldpad = 0; } } #ifdef DEBUG dbg_fini(); #endif sys_ppu_thread_exit(0); }
void CGUITextureGLES::Begin(color_t color) { CBaseTexture* texture = m_texture.m_textures[m_currentFrame]; glActiveTexture(GL_TEXTURE0); texture->LoadToGPU(); if (m_diffuse.size()) m_diffuse.m_textures[0]->LoadToGPU(); glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject()); // Setup Colors for (int i = 0; i < 4; i++) { m_col[i][0] = (GLubyte)GET_R(color); m_col[i][1] = (GLubyte)GET_G(color); m_col[i][2] = (GLubyte)GET_B(color); m_col[i][3] = (GLubyte)GET_A(color); } bool hasAlpha = m_texture.m_textures[m_currentFrame]->HasAlpha() || m_col[0][3] < 255; if (m_diffuse.size()) { if (m_col[0][0] == 255 && m_col[0][1] == 255 && m_col[0][2] == 255 && m_col[0][3] == 255 ) { g_Windowing.EnableGUIShader(SM_MULTI); } else { g_Windowing.EnableGUIShader(SM_MULTI_BLENDCOLOR); } hasAlpha |= m_diffuse.m_textures[0]->HasAlpha(); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_diffuse.m_textures[0]->GetTextureObject()); GLint tex1Loc = g_Windowing.GUIShaderGetCoord1(); glVertexAttribPointer(tex1Loc, 2, GL_FLOAT, 0, 0, m_tex1); glEnableVertexAttribArray(tex1Loc); hasAlpha = true; } else { if ( hasAlpha ) { g_Windowing.EnableGUIShader(SM_TEXTURE); } else { g_Windowing.EnableGUIShader(SM_TEXTURE_NOBLEND); } } GLint posLoc = g_Windowing.GUIShaderGetPos(); GLint colLoc = g_Windowing.GUIShaderGetCol(); GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, m_vert); if(colLoc >= 0) glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, m_col); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, m_tex0); glEnableVertexAttribArray(posLoc); if(colLoc >= 0) glEnableVertexAttribArray(colLoc); glEnableVertexAttribArray(tex0Loc); if ( hasAlpha ) { glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable( GL_BLEND ); } else { glDisable(GL_BLEND); } }
void CParticle::render() { // If particle isn't alive, then there is nothing to render if(isAlive() == false) return; // Can't render a particle that does not have a valid texture if(mTexture.getId() == TEXTURE_NOT_LOADED) return; // This OpenGL functions makes the Z-buffer "read only". That means OpenGL will // use current z-buffer values to determine if a particle should be rendered or not, BUT, // if it does render a particle it will NOT set any z-buffer values. Why do we do this? // Well we want the particles to blend, and not cover each other up. So now we can // render them in the same Z-depth and they will blend, but at the same time, they // won't render over top of anything with a lesser Z-depth glDepthMask(false); BYTE red, green, blue; // Set the color based on the life of the particle if(mLife < 1.0f) { // If the particle has less than a second to live, we will // decrease the R, G, and B value of it's color by multipling // by "mLife", this will in turn fade the particle to black, which // is our applications background color red = BYTE(GET_R(mColor) * mLife); green = BYTE(GET_G(mColor) * mLife); blue = BYTE(GET_B(mColor) * mLife); } else { // Just get the RGB components of the color red = GET_R(mColor); green = GET_G(mColor); blue = GET_B(mColor); } // Set the color for rendering glColor3ub(red, green, blue); // Set the texture for rendering mTexture.select(); glPushMatrix(); // Move to the world position of where to draw the particle glTranslatef(mPos.x, mPos.y, mPos.z); float halfSize = mSize * 0.5f; // Draw the particle glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-halfSize, halfSize, 0.0f); // Top left vertex glTexCoord2f(0.0f, 0.0f); glVertex3f(-halfSize, -halfSize, 0.0f); // Bottom left vertex glTexCoord2f(1.0f, 0.0f); glVertex3f(halfSize, -halfSize, 0.0f); // Bottom right vertex glTexCoord2f(1.0f, 1.0f); glVertex3f(halfSize, halfSize, 0.0f); // Top right vertex glEnd(); glPopMatrix(); glDepthMask(true); // Put the Z-buffer back into it's normal "Z-read and Z-write" state }