#include "../../frame/gpu_frame.h"\r
#include "../../../common/utility/memory.h"\r
#include "../../../common/gl/gl_check.h"\r
+#include "../../../common/gl/pixel_buffer_object.h"\r
\r
#include <boost/thread.hpp>\r
\r
#include <Glee.h>\r
#include <SFML/Window.hpp>\r
-#include <SFML/Graphics.hpp>\r
\r
#include <windows.h>\r
\r
struct consumer::implementation : boost::noncopyable\r
{ \r
implementation(const frame_format_desc& format_desc, unsigned int screen_index, stretch stretch, bool windowed) \r
- : format_desc_(format_desc), stretch_(stretch), pbo_index_(0), screen_width_(0), screen_height_(0), windowed_(windowed)\r
- {\r
- pbos_[0] = pbos_[1] = 0;\r
- \r
+ : index_(0), format_desc_(format_desc), stretch_(stretch), screen_width_(0), screen_height_(0), windowed_(windowed)\r
+ { \r
#ifdef _WIN32\r
DISPLAY_DEVICE dDevice; \r
memset(&dDevice,0,sizeof(dDevice));\r
{\r
frame_buffer_.push(nullptr),\r
thread_.join();\r
-\r
- if(pbos_[0] && pbos_[1])\r
- glDeleteBuffers(2, pbos_);\r
}\r
\r
void init() \r
window_.SetPosition(screenX_, screenY_);\r
window_.SetSize(screen_width_, screen_height_);\r
window_.SetActive();\r
- \r
+ GL(glEnable(GL_TEXTURE_2D));\r
+ GL(glDisable(GL_DEPTH_TEST)); \r
+ GL(glClearColor(0.0, 0.0, 0.0, 0.0));\r
+ GL(glViewport(0, 0, format_desc_.width, format_desc_.height));\r
+ glLoadIdentity();\r
+ \r
+ wratio_ = static_cast<float>(format_desc_.width)/static_cast<float>(format_desc_.width);\r
+ hratio_ = static_cast<float>(format_desc_.height)/static_cast<float>(format_desc_.height);\r
+\r
std::pair<float, float> target_ratio = None();\r
if(stretch_ == ogl::fill)\r
target_ratio = Fill();\r
else if(stretch_ == ogl::uniform_to_fill)\r
target_ratio = UniformToFill();\r
\r
- float wSize = target_ratio.first;\r
- float hSize = target_ratio.second;\r
+ wSize_ = target_ratio.first;\r
+ hSize_ = target_ratio.second;\r
\r
- image_.Create(format_desc_.width, format_desc_.height);\r
- sprite_.SetImage(image_);\r
- \r
- GL(glGenBuffersARB(2, pbos_));\r
- GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbos_[0]));\r
- GL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, format_desc_.size, 0, GL_STREAM_DRAW));\r
- GL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbos_[1]));\r
- GL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, format_desc_.size, 0, GL_STREAM_DRAW)); \r
-\r
- pbo_index_ = 0;\r
+ pbos_[0].create(format_desc_.width, format_desc_.height);\r
+ pbos_[1].create(format_desc_.width, format_desc_.height);\r
}\r
\r
std::pair<float, float> None()\r
}\r
\r
void render(const gpu_frame_ptr& frame)\r
- { \r
- // Render\r
- window_.Clear();\r
- \r
- image_.Bind();\r
- GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[pbo_index_])); \r
- GL(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, format_desc_.width, format_desc_.height, GL_BGRA, GL_UNSIGNED_BYTE, 0));\r
-\r
- window_.Draw(sprite_);\r
-\r
- // Update\r
- int nextPboIndex = pbo_index_ ^ 1;\r
-\r
- GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[nextPboIndex]));\r
- GL(glBufferData(GL_PIXEL_UNPACK_BUFFER, format_desc_.size, NULL, GL_STREAM_DRAW));\r
- GLubyte* ptr = static_cast<GLubyte*>(glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY));\r
-\r
- if(ptr != NULL) \r
- {\r
- common::copy(ptr, frame->data(), frame->size());\r
- GL(glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER));\r
- }\r
-\r
- // Swap\r
- pbo_index_ = nextPboIndex;\r
+ { \r
+ index_ = (index_ + 1) % 2;\r
+ int next_index = (index_ + 1) % 2;\r
+ \r
+ auto ptr = pbos_[index_].end_write();\r
+ common::aligned_memcpy(ptr, frame->data(), frame->size());\r
+\r
+ GL(glClear(GL_COLOR_BUFFER_BIT)); \r
+ pbos_[next_index].bind_texture(); \r
+ glBegin(GL_QUADS);\r
+ glTexCoord2f(0.0f, hratio_); glVertex2f(-wSize_, -hSize_);\r
+ glTexCoord2f(wratio_, hratio_); glVertex2f( wSize_, -hSize_);\r
+ glTexCoord2f(wratio_, 0.0f); glVertex2f( wSize_, hSize_);\r
+ glTexCoord2f(0.0f, 0.0f); glVertex2f(-wSize_, hSize_);\r
+ glEnd();\r
+\r
+ pbos_[next_index].begin_write();\r
}\r
\r
void display(const gpu_frame_ptr& frame)\r
}\r
} \r
while(frame != nullptr);\r
- }\r
- \r
+ } \r
\r
- GLuint dlist_;\r
+ float wratio_;\r
+ float hratio_;\r
+ \r
+ float wSize_;\r
+ float hSize_;\r
+\r
+ int index_;\r
+ common::gl::pixel_buffer_object pbos_[2];\r
\r
bool windowed_;\r
unsigned int screen_width_;\r
unsigned int screenX_;\r
unsigned int screenY_;\r
\r
- GLuint pbos_[2];\r
- int pbo_index_;\r
-\r
stretch stretch_;\r
frame_format_desc format_desc_;\r
\r
boost::thread thread_;\r
tbb::concurrent_bounded_queue<gpu_frame_ptr> frame_buffer_;\r
\r
- sf::Image image_;\r
- sf::Sprite sprite_;\r
- sf::RenderWindow window_;\r
+ sf::Window window_;\r
};\r
\r
consumer::consumer(const frame_format_desc& format_desc, unsigned int screen_index, stretch stretch, bool windowed)\r