Skip to content

Commit fc520c7

Browse files
committed
Docs: New conventions for retrieving renderer information
Add the following conventions for attributes that retrieve information about the renderer: "renderer:name" "renderer:version" "renderer:versionstring" and the following attribute that retrieves an integer frame number: "camera:frame"
1 parent cd6081e commit fc520c7

File tree

5 files changed

+113
-13
lines changed

5 files changed

+113
-13
lines changed

src/doc/languagespec.tex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4922,12 +4922,15 @@ \section{Renderer state and message passing}
49224922
\apiend
49234923

49244924
\begin{table}[htbp]
4925-
\caption{Names of standard attributes that may be retrieved.}\label{tab:cameraattributes}
4925+
\caption{Names of standard attributes that may be retrieved.}\label{tab:standardattributes}
49264926
\begin{tabular}{|p{1.8in}|p{0.6in}|p{2.8in}|}
49274927
\hline
49284928
{\bf Name} & {\bf Type} & {\bf Description} \\
49294929
\hline
4930-
{\cf "osl:version"} & {\cf int} & Major*10000 + Minor*100 + patch. \\
4930+
{\cf "osl:version"} & {\cf int} & Major*10000 + Minor*100 + patch. \\[1ex]
4931+
{\cf "renderer:name"} & {\cf string} & Name of the renderer. \\
4932+
{\cf "renderer:version"} & {\cf int[4]} & Version of renderer (major, minor, release, patch). \\
4933+
{\cf "renderer:versionstring"} & {\cf string} & Version of renderer as a string (e.g. \qkw{1.2.7.0}).\\[1ex]
49314934
{\cf "shader:shadername"} & {\cf string} & Name of the shader master. \\
49324935
{\cf "shader:layername"} & {\cf string} & Name of the layer instance. \\
49334936
{\cf "shader:groupname"} & {\cf string} & Name of the shader group. \\
@@ -4957,6 +4960,7 @@ \section{Renderer state and message passing}
49574960
{\cf "camera:shutter_open"} & {\cf float} & Shutter open time. \\
49584961
{\cf "camera:shutter_close"} & {\cf float} & Shutter close time. \\
49594962
{\cf "camera:shutter"} & {\cf float[2]} & Shutter open and close times. \\
4963+
{\cf "camera:frame"} & {\cf int} & Frame number within the shot. \\
49604964
{\cf "camera:screen_window"} & {\cf float[4]} & Screen window (xmin, ymin, xmax, ymax). \\
49614965
\hline
49624966
\end{tabular}

src/testrender/simplerend.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static ustring u_s("s"), u_t("t");
3939
static TypeDesc TypeFloatArray2 (TypeDesc::FLOAT, 2);
4040
static TypeDesc TypeFloatArray4 (TypeDesc::FLOAT, 4);
4141
static TypeDesc TypeIntArray2 (TypeDesc::INT, 2);
42+
static TypeDesc TypeIntArray4 (TypeDesc::INT, 4);
4243

4344

4445

@@ -48,6 +49,7 @@ SimpleRenderer::SimpleRenderer ()
4849
Matrix44 M; M.makeIdentity();
4950
camera_params (M, u_perspective, 90.0f,
5051
0.1f, 1000.0f, 256, 256);
52+
shutter (0.0f, 1.0f/48, 0);
5153

5254
// Set up getters
5355
m_attr_getters[ustring("osl:version")] = &SimpleRenderer::get_osl_version;
@@ -62,6 +64,7 @@ SimpleRenderer::SimpleRenderer ()
6264
m_attr_getters[ustring("camera:shutter")] = &SimpleRenderer::get_camera_shutter;
6365
m_attr_getters[ustring("camera:shutter_open")] = &SimpleRenderer::get_camera_shutter_open;
6466
m_attr_getters[ustring("camera:shutter_close")] = &SimpleRenderer::get_camera_shutter_close;
67+
m_attr_getters[ustring("camera:frame")] = &SimpleRenderer::get_camera_frame;
6568
}
6669

6770

@@ -86,7 +89,6 @@ SimpleRenderer::camera_params (const Matrix44 &world_to_camera,
8689
m_pixelaspect = 1.0f; // hard-coded
8790
m_hither = hither;
8891
m_yon = yon;
89-
m_shutter[0] = 0.0f; m_shutter[1] = 1.0f; // hard-coded
9092
float frame_aspect = float(xres)/float(yres) * m_pixelaspect;
9193
m_screen_window[0] = -frame_aspect;
9294
m_screen_window[1] = -1.0f;
@@ -98,6 +100,16 @@ SimpleRenderer::camera_params (const Matrix44 &world_to_camera,
98100

99101

100102

103+
void
104+
SimpleRenderer::shutter (float open, float close, int framenumber)
105+
{
106+
m_shutter[0] = open;
107+
m_shutter[1] = close;
108+
m_frame = framenumber;
109+
}
110+
111+
112+
101113
bool
102114
SimpleRenderer::get_matrix (ShaderGlobals *sg, Matrix44 &result,
103115
TransformationPtr xform,
@@ -224,6 +236,25 @@ SimpleRenderer::get_array_attribute (ShaderGlobals *sg, bool derivatives, ustrin
224236
TypeDesc type, ustring name,
225237
int index, void *val)
226238
{
239+
if (OIIO::Strutil::starts_with (name, "renderer:")) {
240+
if (name == "renderer:name" && type == OIIO::TypeString) {
241+
*(ustring *)val = ustring("OSL testrender");
242+
return true;
243+
}
244+
if (name == "renderer:version" && type == TypeIntArray4) {
245+
int *ival = (int *)val;
246+
ival[0] = OSL_VERSION_MAJOR;
247+
ival[1] = OSL_VERSION_MINOR;
248+
ival[2] = OSL_VERSION_PATCH;
249+
ival[3] = 0;
250+
return true;
251+
}
252+
if (name == "renderer:versionstring" && type == OIIO::TypeString) {
253+
*(ustring *)val = ustring(OSL_LIBRARY_VERSION_STRING);
254+
return true;
255+
}
256+
}
257+
227258
AttrGetterMap::const_iterator g = m_attr_getters.find (name);
228259
if (g != m_attr_getters.end()) {
229260
AttrGetter getter = g->second;
@@ -451,6 +482,18 @@ SimpleRenderer::get_camera_screen_window (ShaderGlobals *sg, bool derivs, ustrin
451482
}
452483

453484

485+
bool
486+
SimpleRenderer::get_camera_frame (ShaderGlobals *sg, bool derivs, ustring object,
487+
TypeDesc type, ustring name, void *val)
488+
{
489+
if (type == TypeDesc::TypeInt) {
490+
((int *)val)[0] = m_frame;
491+
return true;
492+
}
493+
return false;
494+
}
495+
496+
454497

455498

456499
OSL_NAMESPACE_EXIT

src/testrender/simplerend.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,18 @@ class SimpleRenderer : public RendererServices
7373
void camera_params (const Matrix44 &world_to_camera, ustring projection,
7474
float hfov, float hither, float yon,
7575
int xres, int yres);
76-
76+
void shutter (float open, float close, int framenumber);
77+
7778
private:
7879
// Camera parameters
7980
Matrix44 m_world_to_camera;
80-
ustring m_projection;
81-
float m_fov, m_pixelaspect, m_hither, m_yon;
82-
float m_shutter[2];
83-
float m_screen_window[4];
81+
ustring m_projection {"perspective"};
82+
float m_fov {90}, m_pixelaspect {1.0};
83+
float m_hither {1e-6}, m_yon {1e6};
84+
float m_shutter[2] { 0.0f, 1.0f };
85+
float m_screen_window[4] { -1, 1, -1, 1 };
8486
int m_xres, m_yres;
87+
int m_frame = 0;
8588

8689
// Named transforms
8790
typedef std::map <ustring, std::shared_ptr<Transformation> > TransformMap;
@@ -123,6 +126,8 @@ class SimpleRenderer : public RendererServices
123126
TypeDesc type, ustring name, void *val);
124127
bool get_camera_screen_window (ShaderGlobals *sg, bool derivs, ustring object,
125128
TypeDesc type, ustring name, void *val);
129+
bool get_camera_frame (ShaderGlobals *sg, bool derivs, ustring object,
130+
TypeDesc type, ustring name, void *val);
126131

127132
};
128133

src/testshade/simplerend.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static ustring u_s("s"), u_t("t");
7878
static TypeDesc TypeFloatArray2 (TypeDesc::FLOAT, 2);
7979
static TypeDesc TypeFloatArray4 (TypeDesc::FLOAT, 4);
8080
static TypeDesc TypeIntArray2 (TypeDesc::INT, 2);
81+
static TypeDesc TypeIntArray4 (TypeDesc::INT, 4);
8182

8283

8384
void register_closures(OSL::ShadingSystem* shadingsys) {
@@ -148,6 +149,7 @@ SimpleRenderer::SimpleRenderer ()
148149
Matrix44 M; M.makeIdentity();
149150
camera_params (M, u_perspective, 90.0f,
150151
0.1f, 1000.0f, 256, 256);
152+
shutter (0.0f, 1.0f/48, 0);
151153

152154
// Set up getters
153155
m_attr_getters[ustring("osl:version")] = &SimpleRenderer::get_osl_version;
@@ -162,6 +164,7 @@ SimpleRenderer::SimpleRenderer ()
162164
m_attr_getters[ustring("camera:shutter")] = &SimpleRenderer::get_camera_shutter;
163165
m_attr_getters[ustring("camera:shutter_open")] = &SimpleRenderer::get_camera_shutter_open;
164166
m_attr_getters[ustring("camera:shutter_close")] = &SimpleRenderer::get_camera_shutter_close;
167+
m_attr_getters[ustring("camera:frame")] = &SimpleRenderer::get_camera_frame;
165168
}
166169

167170

@@ -198,6 +201,16 @@ SimpleRenderer::camera_params (const Matrix44 &world_to_camera,
198201

199202

200203

204+
void
205+
SimpleRenderer::shutter (float open, float close, int framenumber)
206+
{
207+
m_shutter[0] = open;
208+
m_shutter[1] = close;
209+
m_frame = framenumber;
210+
}
211+
212+
213+
201214
bool
202215
SimpleRenderer::get_matrix (ShaderGlobals *sg, Matrix44 &result,
203216
TransformationPtr xform,
@@ -324,6 +337,25 @@ SimpleRenderer::get_array_attribute (ShaderGlobals *sg, bool derivatives, ustrin
324337
TypeDesc type, ustring name,
325338
int index, void *val)
326339
{
340+
if (OIIO::Strutil::starts_with (name, "renderer:")) {
341+
if (name == "renderer:name" && type == OIIO::TypeString) {
342+
*(ustring *)val = ustring("OSL testshade");
343+
return true;
344+
}
345+
if (name == "renderer:version" && type == TypeIntArray4) {
346+
int *ival = (int *)val;
347+
ival[0] = OSL_VERSION_MAJOR;
348+
ival[1] = OSL_VERSION_MINOR;
349+
ival[2] = OSL_VERSION_PATCH;
350+
ival[3] = 0;
351+
return true;
352+
}
353+
if (name == "renderer:versionstring" && type == OIIO::TypeString) {
354+
*(ustring *)val = ustring(OSL_LIBRARY_VERSION_STRING);
355+
return true;
356+
}
357+
}
358+
327359
AttrGetterMap::const_iterator g = m_attr_getters.find (name);
328360
if (g != m_attr_getters.end()) {
329361
AttrGetter getter = g->second;
@@ -560,5 +592,16 @@ SimpleRenderer::get_camera_screen_window (ShaderGlobals *sg, bool derivs, ustrin
560592

561593

562594

595+
bool
596+
SimpleRenderer::get_camera_frame (ShaderGlobals *sg, bool derivs, ustring object,
597+
TypeDesc type, ustring name, void *val)
598+
{
599+
if (type == TypeDesc::TypeInt) {
600+
((int *)val)[0] = m_frame;
601+
return true;
602+
}
603+
return false;
604+
}
605+
563606

564607
OSL_NAMESPACE_EXIT

src/testshade/simplerend.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ class SimpleRenderer : public RendererServices
7676
void camera_params (const Matrix44 &world_to_camera, ustring projection,
7777
float hfov, float hither, float yon,
7878
int xres, int yres);
79-
79+
void shutter (float open, float close, int framenumber);
80+
8081
private:
8182
// Camera parameters
8283
Matrix44 m_world_to_camera;
83-
ustring m_projection;
84-
float m_fov, m_pixelaspect, m_hither, m_yon;
85-
float m_shutter[2];
86-
float m_screen_window[4];
84+
ustring m_projection {"perspective"};
85+
float m_fov {90}, m_pixelaspect {1.0};
86+
float m_hither {1e-6}, m_yon {1e6};
87+
float m_shutter[2] { 0.0f, 1.0f };
88+
float m_screen_window[4] { -1, 1, -1, 1 };
8789
int m_xres, m_yres;
90+
int m_frame = 0;
8891

8992
// Named transforms
9093
typedef std::map <ustring, std::shared_ptr<Transformation> > TransformMap;
@@ -126,6 +129,8 @@ class SimpleRenderer : public RendererServices
126129
TypeDesc type, ustring name, void *val);
127130
bool get_camera_screen_window (ShaderGlobals *sg, bool derivs, ustring object,
128131
TypeDesc type, ustring name, void *val);
132+
bool get_camera_frame (ShaderGlobals *sg, bool derivs, ustring object,
133+
TypeDesc type, ustring name, void *val);
129134

130135
};
131136

0 commit comments

Comments
 (0)