38 nassertv(context !=
nullptr);
43 _net_state = RenderState::make(
44 CullBinAttrib::make(
"unsorted", 0),
45 DepthTestAttrib::make(RenderAttrib::M_none),
46 DepthWriteAttrib::make(DepthWriteAttrib::M_off),
47 ColorBlendAttrib::make(ColorBlendAttrib::M_add,
48 ColorBlendAttrib::O_incoming_alpha,
49 ColorBlendAttrib::O_one_minus_incoming_alpha
51 ColorAttrib::make_vertex()
53 _dimensions = context->GetDimensions();
58 _net_transform =
nullptr;
66 make_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);
109 void RocketRenderInterface::
110 render_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";
127 _net_transform->compose(TransformState::make_pos(offset)));
139 void RocketRenderInterface::
140 RenderGeometry(Rocket::Core::Vertex* vertices,
141 int num_vertices,
int* indices,
int num_indices,
142 Rocket::Core::TextureHandle thandle,
143 const Rocket::Core::Vector2f& translation) {
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);
156 if (texture !=
nullptr) {
157 state = RenderState::make(TextureAttrib::make(texture));
159 state = RenderState::make_empty();
162 render_geom(geom, state, translation);
169 Rocket::Core::CompiledGeometryHandle RocketRenderInterface::
170 CompileGeometry(Rocket::Core::Vertex* vertices,
171 int num_vertices,
int* indices,
int num_indices,
172 Rocket::Core::TextureHandle 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";
187 stage->set_mode(TextureStage::M_modulate);
192 c->_state = RenderState::make(attr);
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;
210 void RocketRenderInterface::
211 RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry,
const Rocket::Core::Vector2f& translation) {
213 CompiledGeometry *c = (CompiledGeometry*) geometry;
214 render_geom(c->_geom, c->_state, translation);
220 void RocketRenderInterface::
221 ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry) {
222 delete (CompiledGeometry*) geometry;
228 bool RocketRenderInterface::
229 LoadTexture(Rocket::Core::TextureHandle& texture_handle,
230 Rocket::Core::Vector2i& texture_dimensions,
231 const Rocket::Core::String& source) {
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();
277 bool RocketRenderInterface::
278 GenerateTexture(Rocket::Core::TextureHandle& texture_handle,
279 const Rocket::Core::byte* source,
280 const Rocket::Core::Vector2i& source_dimensions) {
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();
322 void RocketRenderInterface::
323 ReleaseTexture(Rocket::Core::TextureHandle texture_handle) {
325 if (tex !=
nullptr) {
334 void RocketRenderInterface::
335 EnableScissorRegion(
bool enable) {
336 _enable_scissor = enable;
342 void RocketRenderInterface::
343 SetScissorRegion(
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);
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
CullHandler * get_cull_handler() const
Returns the object that will receive the culled Geoms.
void setup_2d_texture()
Sets the texture as an empty 2-d texture with no dimensions.
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 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.
Specifies parameters that may be passed to the loader.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const TransformState * get_cs_world_transform() const
Returns the position from the starting node relative to the camera, in the GSG's internal coordinate ...
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void render(Rocket::Core::Context *context, CullTraverser *trav)
Called by RocketNode in cull_callback.
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.
The smallest atom of cull.
void ref() const
Increments the reference count of the underlying vector.
The name of a file, such as a texture file or an Egg file.
PT(Geom) RocketRenderInterface
Called internally to make a Geom from Rocket data.
virtual void record_object(CullableObject *object, const CullTraverser *traverser)
This callback function is intended to be overridden by a derived class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
const TransformState * get_world_transform() const
Returns the position of the starting node relative to the camera.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void add_data3f(float x, float y, float z)
Sets the write row to a particular 3-component value, and advances the write row.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LVecBase2 get_tex_scale() const
Returns a scale pair that is suitable for applying to geometry via NodePath::set_tex_scale(),...
SceneSetup * get_scene() const
Returns the SceneSetup object.
Defines a series of disconnected triangles.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
Defines the properties of a named stage of the multitexture pipeline.
void unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
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,...
This is the data for one array of a GeomVertexData structure.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.