/*------------------------------------------------- * union_render_bounds - compute the union of two * render_bounds * -------------------------------------------------*/ public static void union_render_bounds(render_bounds dest, render_bounds src) { dest.x0 = Math.Min(dest.x0, src.x0); dest.x1 = Math.Max(dest.x1, src.x1); dest.y0 = Math.Min(dest.y0, src.y0); dest.y1 = Math.Max(dest.y1, src.y1); }
/*------------------------------------------------- * set_render_bounds_wh - cleaner way to set the * bounds * -------------------------------------------------*/ public static void set_render_bounds_wh(render_bounds bounds, float x0, float y0, float width, float height) { bounds.x0 = x0; bounds.y0 = y0; bounds.x1 = x0 + width; bounds.y1 = y0 + height; }
/*------------------------------------------------- * set_render_bounds_xy - cleaner way to set the * bounds * -------------------------------------------------*/ public static void set_render_bounds_xy(render_bounds bounds, float x0, float y0, float x1, float y1) { bounds.x0 = x0; bounds.y0 = y0; bounds.x1 = x1; bounds.y1 = y1; }
public uint32_t screen_update(screen_device screen, bitmap_rgb32 bitmap, rectangle cliprect) { uint32_t flags = PRIMFLAG_ANTIALIAS(1) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD) | PRIMFLAG_VECTOR(1); rectangle visarea = screen.visible_area(); float xscale = 1.0f / (65536 * visarea.width()); float yscale = 1.0f / (65536 * visarea.height()); float xoffs = (float)visarea.min_x; float yoffs = (float)visarea.min_y; int curpointIdx = 0; //point *curpoint; int lastx = 0; int lasty = 0; curpointIdx = 0; //curpoint = m_vector_list.get(); var curpoint = m_vector_list; screen.container().empty(); screen.container().add_rect(0.0f, 0.0f, 1.0f, 1.0f, new rgb_t(0xff, 0x00, 0x00, 0x00), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_VECTORBUF(1)); for (int i = 0; i < m_vector_index; i++) { render_bounds coords = new render_bounds(); float intensity = (float)curpoint[curpointIdx].intensity / 255.0f; //float intensity = (float)curpoint->intensity / 255.0f; float intensity_weight = normalized_sigmoid(intensity, vector_options.s_beam_intensity_weight); // check for static intensity float beam_width = m_min_intensity == m_max_intensity ? vector_options.s_beam_width_min : vector_options.s_beam_width_min + intensity_weight * (vector_options.s_beam_width_max - vector_options.s_beam_width_min); // normalize width beam_width *= 1.0f / (float)VECTOR_WIDTH_DENOM; // apply point scale for points if (lastx == curpoint[curpointIdx].x && lasty == curpoint[curpointIdx].y) //if (lastx == curpoint->x && lasty == curpoint->y) { beam_width *= vector_options.s_beam_dot_size; } coords.x0 = ((float)lastx - xoffs) * xscale; coords.y0 = ((float)lasty - yoffs) * yscale; coords.x1 = ((float)curpoint[curpointIdx].x - xoffs) * xscale; //coords.x1 = ((float)curpoint->x - xoffs) * xscale; coords.y1 = ((float)curpoint[curpointIdx].y - yoffs) * yscale; //coords.y1 = ((float)curpoint->y - yoffs) * yscale; if (curpoint[curpointIdx].intensity != 0) //if (curpoint->intensity != 0) { screen.container().add_line( coords.x0, coords.y0, coords.x1, coords.y1, beam_width, new rgb_t(((uint32_t)curpoint[curpointIdx].intensity << 24) | (curpoint[curpointIdx].col & 0xffffff)), //(curpoint->intensity << 24) | (curpoint->col & 0xffffff), flags); } lastx = curpoint[curpointIdx].x; //lastx = curpoint->x; lasty = curpoint[curpointIdx].y; //lasty = curpoint->y; curpointIdx++; //curpoint++; } return(0); }
/*------------------------------------------------- * render_clip_line - clip a line to a rectangle * -------------------------------------------------*/ public static bool render_clip_line(ref render_bounds bounds, render_bounds clip) { /* loop until we get a final result */ while (true) { u8 code0 = 0; u8 code1 = 0; u8 thiscode; float x; float y; /* compute Cohen Sutherland bits for first coordinate */ if (bounds.y0 > clip.y1) { code0 |= 1; } if (bounds.y0 < clip.y0) { code0 |= 2; } if (bounds.x0 > clip.x1) { code0 |= 4; } if (bounds.x0 < clip.x0) { code0 |= 8; } /* compute Cohen Sutherland bits for second coordinate */ if (bounds.y1 > clip.y1) { code1 |= 1; } if (bounds.y1 < clip.y0) { code1 |= 2; } if (bounds.x1 > clip.x1) { code1 |= 4; } if (bounds.x1 < clip.x0) { code1 |= 8; } /* trivial accept: just return FALSE */ if ((code0 | code1) == 0) { return(false); } /* trivial reject: just return TRUE */ if ((code0 & code1) != 0) { return(true); } /* fix one of the OOB cases */ thiscode = code0 > 0 ? code0 : code1; /* off the bottom */ if ((thiscode & 1) != 0) { x = bounds.x0 + (bounds.x1 - bounds.x0) * (clip.y1 - bounds.y0) / (bounds.y1 - bounds.y0); y = clip.y1; } /* off the top */ else if ((thiscode & 2) != 0) { x = bounds.x0 + (bounds.x1 - bounds.x0) * (clip.y0 - bounds.y0) / (bounds.y1 - bounds.y0); y = clip.y0; } /* off the right */ else if ((thiscode & 4) != 0) { y = bounds.y0 + (bounds.y1 - bounds.y0) * (clip.x1 - bounds.x0) / (bounds.x1 - bounds.x0); x = clip.x1; } /* off the left */ else { y = bounds.y0 + (bounds.y1 - bounds.y0) * (clip.x0 - bounds.x0) / (bounds.x1 - bounds.x0); x = clip.x0; } /* fix the appropriate coordinate */ if (thiscode == code0) { bounds.x0 = x; bounds.y0 = y; } else { bounds.x1 = x; bounds.y1 = y; } } }
/*------------------------------------------------- * render_clip_quad - clip a quad to a rectangle * -------------------------------------------------*/ public static bool render_clip_quad(ref render_bounds bounds, render_bounds clip, ref render_quad_texuv texcoords, bool use_texcoords) { /* ensure our assumptions about the bounds are correct */ assert(bounds.x0 <= bounds.x1); assert(bounds.y0 <= bounds.y1); /* trivial reject */ if (bounds.y1 < clip.y0) { return(true); } if (bounds.y0 > clip.y1) { return(true); } if (bounds.x1 < clip.x0) { return(true); } if (bounds.x0 > clip.x1) { return(true); } /* clip top (x0,y0)-(x1,y1) */ if (bounds.y0 < clip.y0) { float frac = (clip.y0 - bounds.y0) / (bounds.y1 - bounds.y0); bounds.y0 = clip.y0; if (use_texcoords) //if (texcoords != nullptr) { texcoords.tl.u += (texcoords.bl.u - texcoords.tl.u) * frac; texcoords.tl.v += (texcoords.bl.v - texcoords.tl.v) * frac; texcoords.tr.u += (texcoords.br.u - texcoords.tr.u) * frac; texcoords.tr.v += (texcoords.br.v - texcoords.tr.v) * frac; } } /* clip bottom (x3,y3)-(x2,y2) */ if (bounds.y1 > clip.y1) { float frac = (bounds.y1 - clip.y1) / (bounds.y1 - bounds.y0); bounds.y1 = clip.y1; if (use_texcoords) //if (texcoords != nullptr) { texcoords.bl.u -= (texcoords.bl.u - texcoords.tl.u) * frac; texcoords.bl.v -= (texcoords.bl.v - texcoords.tl.v) * frac; texcoords.br.u -= (texcoords.br.u - texcoords.tr.u) * frac; texcoords.br.v -= (texcoords.br.v - texcoords.tr.v) * frac; } } /* clip left (x0,y0)-(x3,y3) */ if (bounds.x0 < clip.x0) { float frac = (clip.x0 - bounds.x0) / (bounds.x1 - bounds.x0); bounds.x0 = clip.x0; if (use_texcoords) //if (texcoords != nullptr) { texcoords.tl.u += (texcoords.tr.u - texcoords.tl.u) * frac; texcoords.tl.v += (texcoords.tr.v - texcoords.tl.v) * frac; texcoords.bl.u += (texcoords.br.u - texcoords.bl.u) * frac; texcoords.bl.v += (texcoords.br.v - texcoords.bl.v) * frac; } } /* clip right (x1,y1)-(x2,y2) */ if (bounds.x1 > clip.x1) { float frac = (bounds.x1 - clip.x1) / (bounds.x1 - bounds.x0); bounds.x1 = clip.x1; if (use_texcoords) //if (texcoords != nullptr) { texcoords.tr.u -= (texcoords.tr.u - texcoords.tl.u) * frac; texcoords.tr.v -= (texcoords.tr.v - texcoords.tl.v) * frac; texcoords.br.u -= (texcoords.br.u - texcoords.bl.u) * frac; texcoords.br.v -= (texcoords.br.v - texcoords.bl.v) * frac; } } return(false); }
// texture/bitmap queries //------------------------------------------------- // get_char_texture_and_bounds - return the // texture for a character and compute the // bounds of the final bitmap //------------------------------------------------- public render_texture get_char_texture_and_bounds(float height, float aspect, char32_t chnum, ref render_bounds bounds) { glyph gl = get_char(chnum); // on entry, assume x0,y0 are the top,left coordinate of the cell and add // the character bounding box to that position float scale = m_scale * height; bounds.x0 += (float)gl.xoffs * scale * aspect; // compute x1,y1 from there based on the bitmap size bounds.x1 = bounds.x0 + (float)gl.bmwidth * scale * aspect; bounds.y1 = bounds.y0 + (float)m_height * scale; // return the texture return(gl.texture); }
public float y1; // bottommost Y coordinate public render_bounds(render_bounds rhs) { x0 = rhs.x0; y0 = rhs.y0; x1 = rhs.x1; y1 = rhs.y1; }