38 nassertv(context !=
nullptr);
48 ColorBlendAttrib::O_incoming_alpha,
49 ColorBlendAttrib::O_one_minus_incoming_alpha
53 _dimensions = context->GetDimensions();
58 _net_transform =
nullptr;
65PT(
Geom) RocketRenderInterface::
66make_geom(Rocket::Core::Vertex* vertices,
67 int num_vertices,
int* indices,
int num_indices,
68 GeomEnums::UsageHint uh,
const LVecBase2 &tex_scale) {
71 vdata->unclean_set_num_rows(num_vertices);
78 for (
int i = 0; i < num_vertices; ++i) {
79 const Rocket::Core::Vertex &vertex = vertices[i];
81 vwriter.
add_data3f(LVector3f::right() * vertex.position.x + LVector3f::up() * vertex.position.y);
82 cwriter.
add_data4i(vertex.colour.red, vertex.colour.green,
83 vertex.colour.blue, vertex.colour.alpha);
84 twriter.
add_data2f(vertex.tex_coord.x * tex_scale[0],
85 (1.0f - vertex.tex_coord.y) * tex_scale[1]);
93 idata->unclean_set_num_rows(num_indices);
96 for (
int i = 0; i < num_indices; ++i) {
102 geom->add_primitive(triangles);
109void RocketRenderInterface::
110render_geom(
const Geom* geom,
const RenderState* state,
const Rocket::Core::Vector2f& translation) {
111 LVector3 offset = LVector3::right() * translation.x + LVector3::up() * translation.y;
113 if (_enable_scissor) {
114 state = state->
add_attrib(ScissorAttrib::make(_scissor));
116 <<
"Rendering geom " << geom <<
" with state "
117 << *state <<
", translation (" << offset <<
"), "
118 <<
"scissor region (" << _scissor <<
")\n";
121 <<
"Rendering geom " << geom <<
" with state "
122 << *state <<
", translation (" << offset <<
")\n";
126 _trav->get_scene()->get_cs_world_transform()->compose(
127 _net_transform->compose(TransformState::make_pos(offset)));
129 CullableObject *
object =
130 new CullableObject(geom, _net_state->compose(state),
132 _trav->get_cull_handler()->record_object(
object, _trav);
139void RocketRenderInterface::
140RenderGeometry(Rocket::Core::Vertex* vertices,
141 int num_vertices,
int* indices,
int num_indices,
142 Rocket::Core::TextureHandle thandle,
143 const Rocket::Core::Vector2f& translation) {
145 Texture *texture = (Texture *)thandle;
147 LVecBase2 tex_scale(1, 1);
148 if (texture !=
nullptr) {
152 PT(Geom) geom = make_geom(vertices, num_vertices, indices, num_indices,
153 GeomEnums::UH_stream, tex_scale);
155 CPT(RenderState) state;
156 if (texture !=
nullptr) {
159 state = RenderState::make_empty();
162 render_geom(geom, state, translation);
169Rocket::Core::CompiledGeometryHandle RocketRenderInterface::
170CompileGeometry(Rocket::Core::Vertex* vertices,
171 int num_vertices,
int* indices,
int num_indices,
172 Rocket::Core::TextureHandle thandle) {
174 Texture *texture = (Texture *)thandle;
176 CompiledGeometry *c =
new CompiledGeometry;
177 LVecBase2 tex_scale(1, 1);
179 if (texture !=
nullptr) {
181 <<
"Compiling geom " << c->_geom <<
" with texture '"
182 << texture->get_name() <<
"'\n";
186 PT(TextureStage) stage =
new TextureStage(
"");
187 stage->set_mode(TextureStage::M_modulate);
190 attr = DCAST(TextureAttrib, attr->add_on_stage(stage, (Texture *)texture));
196 <<
"Compiling geom " << c->_geom <<
" without texture\n";
198 c->_state = RenderState::make_empty();
201 c->_geom = make_geom(vertices, num_vertices, indices, num_indices,
202 GeomEnums::UH_static, tex_scale);
204 return (Rocket::Core::CompiledGeometryHandle) c;
210void RocketRenderInterface::
211RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry,
const Rocket::Core::Vector2f& translation) {
213 CompiledGeometry *c = (CompiledGeometry*) geometry;
214 render_geom(c->_geom, c->_state, translation);
220void RocketRenderInterface::
221ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry) {
222 delete (CompiledGeometry*) geometry;
228bool RocketRenderInterface::
229LoadTexture(Rocket::Core::TextureHandle& texture_handle,
230 Rocket::Core::Vector2i& texture_dimensions,
231 const Rocket::Core::String& source) {
234 LoaderOptions options;
243 if (tex ==
nullptr) {
245 texture_dimensions.x = 0;
246 texture_dimensions.y = 0;
250 tex->set_minfilter(SamplerState::FT_nearest);
251 tex->set_magfilter(SamplerState::FT_nearest);
256 int width = tex->get_orig_file_x_size();
257 int height = tex->get_orig_file_y_size();
258 if (width == 0 && height == 0) {
261 width = tex->get_x_size();
262 height = tex->get_y_size();
264 texture_dimensions.x = width;
265 texture_dimensions.y = height;
268 texture_handle = (Rocket::Core::TextureHandle) tex.p();
277bool RocketRenderInterface::
278GenerateTexture(Rocket::Core::TextureHandle& texture_handle,
279 const Rocket::Core::byte* source,
280 const Rocket::Core::Vector2i& source_dimensions) {
282 PT(Texture) tex =
new Texture;
283 tex->setup_2d_texture(source_dimensions.x, source_dimensions.y,
284 Texture::T_unsigned_byte, Texture::F_rgba);
288 tex->set_size_padded(source_dimensions.x, source_dimensions.y);
290 PTA_uchar image = tex->modify_ram_image();
293 size_t src_stride = source_dimensions.x * 4;
294 size_t dst_stride = tex->get_x_size() * 4;
295 const unsigned char *src_ptr = source + (src_stride * source_dimensions.y);
296 unsigned char *dst_ptr = &image[0];
298 for (; src_ptr > source; dst_ptr += dst_stride) {
299 src_ptr -= src_stride;
300 for (
size_t i = 0; i < src_stride; i += 4) {
301 dst_ptr[i + 0] = src_ptr[i + 2];
302 dst_ptr[i + 1] = src_ptr[i + 1];
303 dst_ptr[i + 2] = src_ptr[i];
304 dst_ptr[i + 3] = src_ptr[i + 3];
308 tex->set_wrap_u(SamplerState::WM_clamp);
309 tex->set_wrap_v(SamplerState::WM_clamp);
310 tex->set_minfilter(SamplerState::FT_nearest);
311 tex->set_magfilter(SamplerState::FT_nearest);
314 texture_handle = (Rocket::Core::TextureHandle) tex.p();
322void RocketRenderInterface::
323ReleaseTexture(Rocket::Core::TextureHandle texture_handle) {
324 Texture *tex = (Texture *)texture_handle;
325 if (tex !=
nullptr) {
334void RocketRenderInterface::
335EnableScissorRegion(
bool enable) {
336 _enable_scissor = enable;
342void RocketRenderInterface::
343SetScissorRegion(
int x,
int y,
int width,
int height) {
344 _scissor[0] = x / (PN_stdfloat) _dimensions.x;
345 _scissor[1] = (x + width) / (PN_stdfloat) _dimensions.x;
346 _scissor[2] = 1.0f - ((y + height) / (PN_stdfloat) _dimensions.y);
347 _scissor[3] = 1.0f - (y / (PN_stdfloat) _dimensions.y);
static ConstPointerTo< RenderAttrib > make_vertex()
Constructs a new ColorAttrib object that indicates geometry should be rendered according to its own v...
static ConstPointerTo< RenderAttrib > make(Mode mode)
Constructs a new ColorBlendAttrib object.
void ref() const
Increments the reference count of the underlying vector.
static ConstPointerTo< RenderAttrib > make(const std::string &bin_name, int draw_order)
Constructs a new CullBinAttrib assigning geometry into the named bin.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
const TransformState * get_world_transform() const
Returns the position of the starting node relative to the camera.
static ConstPointerTo< RenderAttrib > make(PandaCompareFunc mode)
Constructs a new DepthTestAttrib object.
static ConstPointerTo< RenderAttrib > make(Mode mode)
Constructs a new DepthWriteAttrib object.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
Defines a series of disconnected triangles.
This is the data for one array of a GeomVertexData structure.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
void add_data4i(int a, int b, int c, int d)
Sets the write row to a particular 4-component value, and advances the write row.
void add_data1i(int data)
Sets the write row to a particular 1-component value, and advances the write row.
void add_data2f(float x, float y)
Sets the write row to a particular 2-component value, and advances the write row.
void add_data3f(float x, float y, float z)
Sets the write row to a particular 3-component value, and advances the write row.
A container for geometry primitives.
set_auto_texture_scale
Set this flag to ATS_none, ATS_up, ATS_down, or ATS_pad to control how a texture is scaled from disk ...
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
static ConstPointerTo< RenderState > make(const RenderAttrib *attrib, int override=0)
Returns a RenderState with one attribute set.
ConstPointerTo< RenderState > add_attrib(const RenderAttrib *attrib, int override=0) const
Returns a new RenderState object that represents the same as the source state, with the new RenderAtt...
void render(Rocket::Core::Context *context, CullTraverser *trav)
Called by RocketNode in cull_callback.
static ConstPointerTo< RenderAttrib > make()
Constructs a new TextureAttrib object that does nothing.
static Texture * load_texture(const Filename &filename, int primary_file_num_channels=0, bool read_mipmaps=false, const LoaderOptions &options=LoaderOptions())
Loads the given filename up into a texture, if it has not already been loaded, and returns the new te...
LVecBase2 get_tex_scale() const
Returns a scale pair that is suitable for applying to geometry via NodePath::set_tex_scale(),...
static AutoTextureScale get_textures_power_2()
This flag returns ATS_none, ATS_up, or ATS_down and controls the scaling of textures in general.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.