616 617 - (void)end 618 { 619 assert(self->_drawCounter > 0); 620 621 self->_drawCounter--; 622 if (self->_drawCounter == 0) 623 { 624 GlassLayer3D *layer = (GlassLayer3D*)[self layer]; 625 [[layer getPainterOffscreen] unbind]; 626 [layer flush]; 627 } 628 LOG("end"); 629 } 630 631 - (void)drawRect:(NSRect)dirtyRect 632 { 633 [self->_delegate drawRect:dirtyRect]; 634 } 635 636 - (void)pushPixels:(void*)pixels withWidth:(GLuint)width withHeight:(GLuint)height withScale:(GLfloat)scale withEnv:(JNIEnv *)env 637 { 638 assert(self->_drawCounter > 0); 639 640 if (self->_texture == 0) 641 { 642 glGenTextures(1, &self->_texture); 643 } 644 645 BOOL uploaded = NO; 646 if ((self->_textureWidth != width) || (self->_textureHeight != height)) 647 { 648 uploaded = YES; 649 650 self->_textureWidth = width; 651 self->_textureHeight = height; 652 653 // GL_EXT_texture_rectangle is defined in OS X 10.6 GL headers, so we can depend on GL_TEXTURE_RECTANGLE_EXT being available 654 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, self->_texture); 655 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 656 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 657 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP); 658 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP); 659 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, (GLsizei)self->_textureWidth, (GLsizei)self->_textureHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 660 } 661 662 glEnable(GL_TEXTURE_RECTANGLE_EXT); 663 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, self->_texture); 664 { 665 if (uploaded == NO) 666 { 667 glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, (GLsizei)self->_textureWidth, (GLsizei)self->_textureHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 668 } 669 670 GLfloat w = self->_textureWidth; 671 GLfloat h = self->_textureHeight; 672 673 NSSize size = [self bounds].size; 674 size.width *= scale; 675 size.height *= scale; 676 if ((size.width != w) || (size.height != h)) 677 { 678 // This could happen on live resize, clear the FBO to avoid rendering garbage 679 glClear(GL_COLOR_BUFFER_BIT); 680 } 681 682 glMatrixMode(GL_PROJECTION); 683 glPushMatrix(); 684 glLoadIdentity(); 685 glOrtho(0.0f, size.width, size.height, 0.0f, -1.0f, 1.0f); 686 { 687 glMatrixMode(GL_MODELVIEW); 688 glPushMatrix(); 689 glLoadIdentity(); 690 { 691 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // copy 692 693 glBegin(GL_QUADS); 694 { 695 glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); | 616 617 - (void)end 618 { 619 assert(self->_drawCounter > 0); 620 621 self->_drawCounter--; 622 if (self->_drawCounter == 0) 623 { 624 GlassLayer3D *layer = (GlassLayer3D*)[self layer]; 625 [[layer getPainterOffscreen] unbind]; 626 [layer flush]; 627 } 628 LOG("end"); 629 } 630 631 - (void)drawRect:(NSRect)dirtyRect 632 { 633 [self->_delegate drawRect:dirtyRect]; 634 } 635 636 - (void)pushPixels:(void*)pixels withWidth:(GLuint)width withHeight:(GLuint)height withScaleX:(GLfloat)scalex withScaleY:(GLfloat)scaley withEnv:(JNIEnv *)env 637 { 638 assert(self->_drawCounter > 0); 639 640 if (self->_texture == 0) 641 { 642 glGenTextures(1, &self->_texture); 643 } 644 645 BOOL uploaded = NO; 646 if ((self->_textureWidth != width) || (self->_textureHeight != height)) 647 { 648 uploaded = YES; 649 650 self->_textureWidth = width; 651 self->_textureHeight = height; 652 653 // GL_EXT_texture_rectangle is defined in OS X 10.6 GL headers, so we can depend on GL_TEXTURE_RECTANGLE_EXT being available 654 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, self->_texture); 655 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 656 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 657 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP); 658 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP); 659 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, (GLsizei)self->_textureWidth, (GLsizei)self->_textureHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 660 } 661 662 glEnable(GL_TEXTURE_RECTANGLE_EXT); 663 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, self->_texture); 664 { 665 if (uploaded == NO) 666 { 667 glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, (GLsizei)self->_textureWidth, (GLsizei)self->_textureHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 668 } 669 670 GLfloat w = self->_textureWidth; 671 GLfloat h = self->_textureHeight; 672 673 NSSize size = [self bounds].size; 674 size.width *= scalex; 675 size.height *= scaley; 676 if ((size.width != w) || (size.height != h)) 677 { 678 // This could happen on live resize, clear the FBO to avoid rendering garbage 679 glClear(GL_COLOR_BUFFER_BIT); 680 } 681 682 glMatrixMode(GL_PROJECTION); 683 glPushMatrix(); 684 glLoadIdentity(); 685 glOrtho(0.0f, size.width, size.height, 0.0f, -1.0f, 1.0f); 686 { 687 glMatrixMode(GL_MODELVIEW); 688 glPushMatrix(); 689 glLoadIdentity(); 690 { 691 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // copy 692 693 glBegin(GL_QUADS); 694 { 695 glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); |