SCM Library
Spherical Cube Map rendering library
 All Classes Files Functions Variables Friends Pages
scm-image.hpp
1 // Copyright (C) 2011-2012 Robert Kooima
2 //
3 // LIBSCM is free software; you can redistribute it and/or modify it under the
4 // terms of the GNU General Public License as published by the Free Software
5 // Foundation; either version 2 of the License, or (at your option) any later
6 // version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITH-
9 // OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 
13 #ifndef SCM_IMAGE_HPP
14 #define SCM_IMAGE_HPP
15 
16 #include <GL/glew.h>
17 
18 #include <string>
19 #include <vector>
20 
21 //------------------------------------------------------------------------------
22 
23 class scm_system;
24 class scm_cache;
25 
26 //------------------------------------------------------------------------------
27 
33 
34 class scm_image
35 {
36 public:
37 
39  ~scm_image();
40 
43 
44  void set_scm (const std::string& s);
45  void set_name (const std::string& s);
46  void set_channel (int c);
47  void set_normal_min(float k);
48  void set_normal_max(float k);
49 
53 
54  const std::string& get_scm() const { return scm; }
55  const std::string& get_name() const { return name; }
56  int get_channel() const { return channel; }
57  float get_normal_min() const { return k0; }
58  float get_normal_max() const { return k1; }
59 
60  bool is_channel(int c) const { return (channel == c || channel == -1); }
61  bool is_height() const { return (height); }
62 
66 
67  void init_uniforms(GLuint);
68 
69  void bind(GLuint, GLuint) const;
70  void unbind(GLuint) const;
71 
72  void bind_page(GLuint, int, int, long long) const;
73  void unbind_page(GLuint, int) const;
74  void touch_page( int, long long) const;
75 
76  float get_page_sample(const double *) const;
77  void get_page_bounds(long long, float &, float &) const;
78  bool get_page_status(long long) const;
79 
81 
82 private:
83 
84  scm_system *sys;
85  std::string scm;
86  std::string name;
87 
88  int channel;
89  bool height;
90  float k0;
91  float k1;
92 
93  GLint uS;
94  GLint ur;
95  GLint uk0;
96  GLint uk1;
97  GLint ua[16];
98  GLint ub[16];
99 
100  scm_cache *cache;
101  int index;
102 };
103 
104 //------------------------------------------------------------------------------
105 
106 #endif
void unbind(GLuint) const
Unbind the cache's texture by binding the texture unit to zero.
Definition: scm-image.cpp:160
bool get_page_status(long long) const
Return true if a page is present in this image.
Definition: scm-image.cpp:260
void set_normal_min(float k)
Set the input value to be mapped onto 0 in the output.
Definition: scm-image.cpp:102
void bind(GLuint, GLuint) const
Set all GLSL uniform values for this image and bind the cache's texture.
Definition: scm-image.cpp:140
An scm_image represents an SCM data file in use by an scm_scene.
Definition: scm-image.hpp:34
float get_page_sample(const double *) const
Sample this image at the given location, returning a normalized result.
Definition: scm-image.cpp:230
void set_scm(const std::string &s)
Configure this image to read data from the named SCM file.
Definition: scm-image.cpp:67
void unbind_page(GLuint, int) const
Set the texture mapping uniforms to reference cache line zero (which is always blank).
Definition: scm-image.cpp:208
scm_image(scm_system *)
Initialize a new empty image for use in the given SCM system.
Definition: scm-image.cpp:25
~scm_image()
Finalize this image's SCM file.
Definition: scm-image.cpp:41
void init_uniforms(GLuint)
Request and store GLSL uniform locations for this image's parameters.
Definition: scm-image.cpp:118
void set_normal_max(float k)
Set the input value to be mapped onto 1 in the output.
Definition: scm-image.cpp:109
void touch_page(int, long long) const
Set the last-used time of a page.
Definition: scm-image.cpp:216
void set_channel(int c)
Set the channel index for this image.
Definition: scm-image.cpp:95
void bind_page(GLuint, int, int, long long) const
Set the GLSL uniforms necessary to map a page of texture data.
Definition: scm-image.cpp:175
void get_page_bounds(long long, float &, float &) const
Determine the minimum and maximum values of one page, returning a normalized result.
Definition: scm-image.cpp:241
void set_name(const std::string &s)
Set the name by which GLSL sampler uniforms may access this image.
Definition: scm-image.cpp:84
An scm_system encapsulates all of the state of an SCM renderer. Its interface is the primary API of t...
Definition: scm-system.hpp:175
An scm_cache is a virtual texture, demand-paged with threaded data access, represented as a single la...
Definition: scm-cache.hpp:35